From patchwork Tue Feb 20 23:14:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13564726 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16C23C48BC3 for ; Tue, 20 Feb 2024 23:18:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 376036B0071; Tue, 20 Feb 2024 18:18:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 326406B0072; Tue, 20 Feb 2024 18:18:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1ED876B0075; Tue, 20 Feb 2024 18:18:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 127006B0071 for ; Tue, 20 Feb 2024 18:18:00 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CDB24C079D for ; Tue, 20 Feb 2024 23:17:59 +0000 (UTC) X-FDA: 81813747078.20.7F0471C Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf08.hostedemail.com (Postfix) with ESMTP id 0A5B816000B for ; Tue, 20 Feb 2024 23:17:57 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QWqUXPM3; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf08.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708471078; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=aW/E5QzrtW5KWaWO1KQggPctJlLZibTAzJ7k8sLAf4k=; b=DL3Y7HVAudwjKpr5OtWsMDYTtqnts/PBvt/z5eHDFWoR9hX5qYuozA1ph/5z868JCFLw/N n7U/Np6qkvCAt2UqYrWRNLOZNsbc2l/4vp65EiSt5opWUYt4pPbApArkeF/doMvIuJWzD6 aBbrhQT5Y5afgzeeyZcbl51Fc3lVfVs= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QWqUXPM3; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf08.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708471078; a=rsa-sha256; cv=none; b=T9P4Bh7u+MRAhax6BuUeKsLdefClRxxAbFq1fsUOUBierGoFG0AM5KDxNXRr7/ZozsQDv5 mfHOQVlczTbV5oZKM4oLRRv8HHPo6xTn/vpHLfpy7byi8ILrl+J1wga4td+IxjoXzDuRsr EQKhtTosBLBHiu+Nqtv/ECutUIU0Ccw= Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6e457fab0e2so1536512b3a.0 for ; Tue, 20 Feb 2024 15:17:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708471077; x=1709075877; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aW/E5QzrtW5KWaWO1KQggPctJlLZibTAzJ7k8sLAf4k=; b=QWqUXPM3DLwhmaK5IDfCej8+FiZtoG9i+QxqfxuttfS/WJfKvDFcXslboGDg1v7QzX YZ4hhj3BbDbyXL0bzriCLsADZAG8hNSGDqdsKBF1P5EMAAfde7EXfcMnSP82bi7C0/zA KSFOYFw6iyxFxYcBaNmSseL9vstGOZVH5jiO0KXZI2dWAEeSFSxZe6XP1WH+sMv39KnH 8L8tOv6lMSYVo8L8gkyWHVLProT/7o8Wcf22zW91KGdMSTTRMCl0qzHEZDIPWzIRZBus NHKtf+/lD9rzaUuD0MMgfMoHT/iqKWG8k3eRapybCqco1c6N36HwPgUh5wVedH4Dk1Ob jUyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708471077; x=1709075877; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aW/E5QzrtW5KWaWO1KQggPctJlLZibTAzJ7k8sLAf4k=; b=ANFjeAZosZZBDL0koliooDonjwRVhjl4GQ2SDNAwb4HdOJ/RHjFI/H3P2wk+yNZRF+ Hzjg4GE8ZDuYrZpHEWgrWLqt/PBbk8fDlT/fqG9+BDB4hcgNjUmSZY2fMbxDr82rSBXs FfWS0gUU77SWWmCm1uXK+UpgOqeE8e8A7B2jqCburGExkM2EWr/ZuH+4coa1gHhVSpaW E2qfx/MJVDO+jYPjJISYS1NRly5upOrWlKUXAjumYhe3LSs4oXRttDCsI4eHxEypeWbm /cz4GkPn4WFq4pwXyFz30EzaX4MdXPQzQpLIq3iHdE9ZfPR1FuAVpNGTdtzkGroCznNW tlHQ== X-Gm-Message-State: AOJu0YwMGr/CxXAxXtwXFtwI4bPTuuJTjRsU9JXppTk8oFT9VL48Xxbb E6QUfBlbQ3r3NdesqiKBoAr/pl36oXxA0SyWPFEcCNGBRHAPADUgV4re7joT X-Google-Smtp-Source: AGHT+IFPXuxHXTsoKb+rhglPR7fJPhGLbyzZMpYsYJF/K2X4fA7iFxHEPv599+mEA0511+dKVVlSEA== X-Received: by 2002:a05:6a00:4c98:b0:6e4:66a5:2870 with SMTP id eb24-20020a056a004c9800b006e466a52870mr7967423pfb.8.1708471076681; Tue, 20 Feb 2024 15:17:56 -0800 (PST) Received: from fedora.. (c-73-170-51-167.hsd1.ca.comcast.net. [73.170.51.167]) by smtp.googlemail.com with ESMTPSA id x16-20020aa784d0000000b006e13a5ab1e5sm5317803pfn.73.2024.02.20.15.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 15:17:56 -0800 (PST) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, muchun.song@linux.dev, "Vishal Moola (Oracle)" Subject: [PATCH 2/3] hugetlb: Use vmf_anon_prepare() instead of anon_vma_prepare() Date: Tue, 20 Feb 2024 15:14:23 -0800 Message-ID: <20240220231424.126600-3-vishal.moola@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240220231424.126600-1-vishal.moola@gmail.com> References: <20240220231424.126600-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 0A5B816000B X-Stat-Signature: mn53qrt46i35zxxkq4u9gnz7jkae7a5k X-Rspam-User: X-HE-Tag: 1708471077-471125 X-HE-Meta: U2FsdGVkX1+Jhp20kNet7L78ilu2okqM9MKZNqFACCxJmJ3x56lvTaqAiok/6JjifhMtYf5bxcfD8W0/IXU85RhGHrb5ymq3e1LFUSjO0DLIiZC1jibMYyJGzOSGDxU5fYJ7Hp8SV/BjjmlLg4KI/Z2Q7T57di/cB8k7ry9gSmtCD/rRRQav2DXV4+FWXbUunVI64Hbxh6x1lCrkAX922RRaLKP5q4KXPMeLYrVdpyq8I8MOmyPGdQeehWkYhuNxOQ8xwtC1m06rD2xo8DDi2SSZ9Vfsc0ZLAf/juK/CIIchIUzSlGGSxDbYPOFa+JMA9JlWb0FTeIgs5EIrD4MfLOnXDLImgAdqu+DOG8Zx0bw4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B30ZO8Uug1OvA7IEIkOx8WBUqHXAGOAVFpQCes2DFjc3++baAjVH8yPg7cqCKK4L3kQg4F13mgpuRMHj8QWj5jsZ4Io6WT+MJd4j0WXN6Vw3H+QTa+JnCWBV2UUud1RYKNo9XwQttPPpZw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: hugetlb_no_page() and hugetlb_wp() call anon_vma_prepare(). In preparation for hugetlb to safely handle faults under the VMA lock, use vmf_anon_prepare() here instead. Additionally, define a struct vm_fault at the top of each function. These can later be used to convert hugetlb to use struct vm_fault - similar to mm/memory. Signed-off-by: Vishal Moola (Oracle) --- mm/hugetlb.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ed1581b670d4..10f57306e1f0 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5834,9 +5834,15 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, struct folio *old_folio; struct folio *new_folio; int outside_reserve = 0; - vm_fault_t ret = 0; + vm_fault_t ret = 0, anon_ret = 0; unsigned long haddr = address & huge_page_mask(h); struct mmu_notifier_range range; + struct vm_fault vmf = { + .vma = vma, + .address = haddr, + .real_address = address, + .flags = flags, + }; /* * Never handle CoW for uffd-wp protected pages. It should be only @@ -5960,8 +5966,9 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, * When the original hugepage is shared one, it does not have * anon_vma prepared. */ - if (unlikely(anon_vma_prepare(vma))) { - ret = VM_FAULT_OOM; + anon_ret = vmf_anon_prepare(&vmf); + if (unlikely(anon_ret)) { + ret = anon_ret; goto out_release_all; } @@ -6119,7 +6126,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, pte_t old_pte, unsigned int flags) { struct hstate *h = hstate_vma(vma); - vm_fault_t ret = VM_FAULT_SIGBUS; + vm_fault_t ret = VM_FAULT_SIGBUS, anon_ret = 0; int anon_rmap = 0; unsigned long size; struct folio *folio; @@ -6128,6 +6135,12 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, unsigned long haddr = address & huge_page_mask(h); bool new_folio, new_pagecache_folio = false; u32 hash = hugetlb_fault_mutex_hash(mapping, idx); + struct vm_fault vmf = { + .vma = vma, + .address = haddr, + .real_address = address, + .flags = flags, + }; /* * Currently, we are forced to kill the process in the event the @@ -6221,8 +6234,10 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, new_pagecache_folio = true; } else { folio_lock(folio); - if (unlikely(anon_vma_prepare(vma))) { - ret = VM_FAULT_OOM; + + anon_ret = vmf_anon_prepare(&vmf); + if (unlikely(anon_ret)) { + ret = anon_ret; goto backout_unlocked; } anon_rmap = 1;