From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50DAC606A325 for ; Sun, 29 Nov 2026 20:22:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ZVt1QMmT; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=W/Rmfucn DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Unsubscribe-Post:List-Owner; bh=LZJ9TqVg4cx0lSXR6HTUOobxw8W8I/MUtumTeCzl8Ps=; b=ZVt1QMmTAmfIYuXRuyWpk+j9i4 OZ4P4IGvHfLqTzHQD7sGugcPHDK/3xaRic0bmHmxjC9psMpoTw0dgVBPuHE/nnklUXCppuvR428Y3 o0zDxHmPgaPLAnp6ODqRJ5TyHll51Hv7bN4nHYqDlLx9SAM26BCBahZFGhdWzl7UzxxRiinSYIGxx VRJB5XR+muqFI3sJqhAeWntSNrTRr6Wow9ITsoFqt27qqLwtNNckubBKCPTcskq1316wYoBcrPhCW VZ/GG5w0EF5Zd+2Y+8tj7cplhaEM4sEgAZnb6WS2hUaWlYUOCfknxon7P4uYevVL7h9YT7CtaEQd6 67pstY+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXlPh-00000002SBK-2VLi; Sun, 29 Nov 2026 20:22:23 +0000 Received: from mail-dy1-x1345.google.com ([2607:f8b0:4864:20::1345]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXlPa-00000002S7n-3aUS for linux-riscv@lists.infradead.org; Sun, 29 Nov 2026 20:22:16 +0000 Received: by mail-dy1-x1345.google.com with SMTP id 5a478bee46e88-3846d5f54c1so10664797eec.1 for ; Sun, 29 Nov 2026 12:22:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795983731; x=1796588531; darn=lists.infradead.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=+I087uAHFfr3vIi2QzJD6zDcj5fneQUT1cINxigykdY=; b=W/RmfucnN+7PAPXiJ+wmEo75roavaggRtalB6ZiWC+Nd1WUay3XXpwPpPLMX0jYfqN uYK3/52rsg6m8VJvTUGXMJdnJrH6iTyOTtjpmanbBLAdX8XeuOufl1rEP1d6eG+R05J3 gt0wMN2uOGMnFwuOlVkpnUMmi+iOVQKMlWSv5m05yjpjvoRfFFMECnGMjeYcMxENSA/p y76J3FmPwpLY17BxW1U0cQzrOav0Sa5saXchuOjGWh4MMF4v2WIV2EqaQ1sxxVqB92Ad 1xv8Nft9XGaSS4IaG4+bczOk094Z3C566VVafDEVKmUze0Yk8c1LQFx70B4H4BebJJkd HUGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795983731; x=1796588531; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+I087uAHFfr3vIi2QzJD6zDcj5fneQUT1cINxigykdY=; b=HPDWT4m1OIDPoNI8FP/Q5sXuBpzFRS9bc0Q9YZ6hTrzkIVB74czCLzFjlS98e3edtS TL41ER4K+NxXmemGBCJ8rLy3LzVRsqhgmmvW3SKtSdiNQgSxTVRYCc4mJrIX85x3DepV IXIhrWWCXtfbbgO5vqKrkz4L1Xd7IJhk4LTjL1nX3N1kIxllZqyaxrpMlnD+uLG/TGai RHu4U9F0djgnl0/eG+bcAyEJ5dK/5lVlo5iEvHFX5zBeNXZ4uaV7v32wG0TXF/2AnPFZ r0COqgnPZ37DbndKrtX5Atkiu88X6v8MO8BJRNgulh7W8NQchIvYLQuClYlWHNSOs48u fFmA== X-Forwarded-Encrypted: i=1; AL+hErGaulbxX3AwNlpvtlunWPgyvg7j0jRcp1/Cgs/SKlH4GNzIJl0Xo/E++NgQ0ZgGaNB9UZtzQXV6MWDblw==@lists.infradead.org X-Gm-Message-State: APuU4Z/x4EvE4GFwIQa3Y0Nxj7EQwMYMbMO9UtPag3z8fV1ZoVa83f5k yoJFigNtWSZTDHaAMdt/ocGVQpmONhTlmsydYmR86H/MRZW0mjDGmYifyssFsEy1PUCoT7Mdmiz pc3mOdw== X-Received: from dybgk2.prod.google.com ([2002:a05:7301:182:b0:385:e49a:dd09]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:6486:b0:378:1191:43ca with SMTP id 5a478bee46e88-3863f1355b2mr25913017eec.18.1795983731013; Sun, 29 Nov 2026 12:22:11 -0800 (PST) Date: Sun, 29 Nov 2026 12:22:03 -0800 In-Reply-To: <20261129202203.1183277-1-surenb@google.com> X-Archived-By: Mime-Version: 1.0 References: <20261129202203.1183277-1-surenb@google.com> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261129202203.1183277-3-surenb@google.com> Subject: [RFC PATCH 2/2] mm: split VM_FAULT_RETRY_LOCK_MM out of VM_FAULT_RETRY From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: david@kernel.org, willy@infradead.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, jannh@google.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, muchun.song@linux.dev, osalvador@suse.de, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, linux@armlinux.org.uk, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, chenhuacai@kernel.org, kernel@xen0n.name, maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, ritesh.list@gmail.com, sshegde@linux.ibm.com, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, agordeev@linux.ibm.com, gerald.schaefer@linux.ibm.com, corbet@lwn.net, skhan@linuxfoundation.org, rdunlap@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-doc@vger.kernel.org, Suren Baghdasaryan X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261129_122214_953956_801C857E X-CRM114-Status: GOOD ( 24.25 ) X-Spam-Score: -9.5 (---------) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 VM_FAULT_RETRY is returned for two different reasons. It tells the caller that the fault handler had to drop its lock, usually to wait for something, so the fault has to be handled again. With per-VMA locks it is also returned when the fault can not be handled under the per-VMA lock at all and has to be handled under mmap_lock. The caller can not tell these two cases apart. Introduce VM_FAULT_RETRY_LOCK_MM for the second case and return it where the fault handler falls back from the per-VMA lock to mmap_lock. Those cases are: - vmf_can_call_fault(), when the VMA has ->fault but no ->map_pages; - __vmf_anon_prepare(), when the VMA has no anon_vma yet and mmap_lock can not be taken without blocking; - do_swap_page() and do_huge_pmd_device_private(), because migrate_to_ram() is not ready to operate under the per-VMA lock. VM_FAULT_RETRY keeps being returned in all the other cases. vmf_anon_prepare() and hugetlb release the per-VMA lock based on the result of __vmf_anon_prepare(), so make them check the new code. should_retry_mm_fault() accepts both codes, so page fault handlers keep retrying under mmap_lock in both cases. VM_FAULT_RETRY_LOCK_MM is never returned for a fault that is handled under mmap_lock, so the checks done after such a fault are left unchanged. No functional change intended. Signed-off-by: Suren Baghdasaryan --- Documentation/filesystems/porting.rst | 4 ++-- include/linux/mm_types.h | 13 +++++++++++-- mm/huge_memory.c | 2 +- mm/hugetlb.c | 9 +++++---- mm/internal.h | 2 +- mm/memory.c | 18 ++++++++++-------- 6 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Documentation/filesystems/porting.rst b/Documentation/filesystems/porting.rst index e41466904501..94db82f2195f 100644 --- a/Documentation/filesystems/porting.rst +++ b/Documentation/filesystems/porting.rst @@ -944,8 +944,8 @@ Calling convention for ->huge_fault has changed. It now takes a page order instead of an enum page_entry_size, and it may be called without the mmap_lock held. All in-tree users have been audited and do not seem to depend on the mmap_lock being held, but out of tree users should verify -for themselves. If they do need it, they can return VM_FAULT_RETRY to -be called with the mmap_lock held. +for themselves. If they do need it, they can drop the per-VMA lock and +return VM_FAULT_RETRY_LOCK_MM to be called with the mmap_lock held. --- diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 7a80c904eab9..b46a9dbfe2c8 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -1711,6 +1711,8 @@ typedef __bitwise unsigned int vm_fault_t; * fsync() to complete (for synchronous page faults * in DAX) * @VM_FAULT_COMPLETED: ->fault completed, meanwhile mmap lock released + * @VM_FAULT_RETRY_LOCK_MM: fault can not be handled under per-VMA lock, + * must retry under mmap_lock * @VM_FAULT_HINDEX_MASK: mask HINDEX value * */ @@ -1728,6 +1730,7 @@ enum vm_fault_reason { VM_FAULT_DONE_COW = (__force vm_fault_t)0x001000, VM_FAULT_NEEDDSYNC = (__force vm_fault_t)0x002000, VM_FAULT_COMPLETED = (__force vm_fault_t)0x004000, + VM_FAULT_RETRY_LOCK_MM = (__force vm_fault_t)0x008000, VM_FAULT_HINDEX_MASK = (__force vm_fault_t)0x0f0000, }; @@ -1743,12 +1746,17 @@ enum vm_fault_reason { * should_retry_mm_fault - Check whether a page fault has to be retried. * @fault: The fault result returned by handle_mm_fault(). * + * A fault handled under the per-VMA lock can fail with either + * VM_FAULT_RETRY_LOCK_MM, when it has to be handled under mmap_lock, or with + * VM_FAULT_RETRY for all the other reasons to retry. A fault handled under + * mmap_lock can only fail with the latter. + * * Return: true if the fault was not handled and the caller has to retry it, * false otherwise. */ static inline bool should_retry_mm_fault(vm_fault_t fault) { - return !!(fault & VM_FAULT_RETRY); + return !!(fault & (VM_FAULT_RETRY | VM_FAULT_RETRY_LOCK_MM)); } #define VM_FAULT_RESULT_TRACE \ @@ -1764,7 +1772,8 @@ static inline bool should_retry_mm_fault(vm_fault_t fault) { (__force u32)VM_FAULT_FALLBACK, "FALLBACK" }, \ { (__force u32)VM_FAULT_DONE_COW, "DONE_COW" }, \ { (__force u32)VM_FAULT_NEEDDSYNC, "NEEDDSYNC" }, \ - { (__force u32)VM_FAULT_COMPLETED, "COMPLETED" } + { (__force u32)VM_FAULT_COMPLETED, "COMPLETED" }, \ + { (__force u32)VM_FAULT_RETRY_LOCK_MM, "RETRY_LOCK_MM" } struct vm_special_mapping { const char *name; /* The name, e.g. "[vdso]". */ diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 4fc888ddfb69..23a5dfe05824 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1479,7 +1479,7 @@ vm_fault_t do_huge_pmd_device_private(struct vm_fault *vmf) if (vmf->flags & FAULT_FLAG_VMA_LOCK) { vma_end_read(vma); - return VM_FAULT_RETRY; + return VM_FAULT_RETRY_LOCK_MM; } ptl = pmd_lock(vma->vm_mm, vmf->pmd); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 4386425b5ce5..4f3eea0b1e67 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6130,9 +6130,9 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping, /* * We must check to release the per-VMA lock. __vmf_anon_prepare() is - * the only way ret can be set to VM_FAULT_RETRY. + * the only way ret can be set to VM_FAULT_RETRY_LOCK_MM. */ - if (unlikely(ret & VM_FAULT_RETRY)) + if (unlikely(ret & VM_FAULT_RETRY_LOCK_MM)) vma_end_read(vma); mutex_unlock(&hugetlb_fault_mutex_table[hash]); @@ -6391,9 +6391,10 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, /* * We must check to release the per-VMA lock. __vmf_anon_prepare() in - * hugetlb_wp() is the only way ret can be set to VM_FAULT_RETRY. + * hugetlb_wp() is the only way ret can be set to + * VM_FAULT_RETRY_LOCK_MM. */ - if (unlikely(ret & VM_FAULT_RETRY)) + if (unlikely(ret & VM_FAULT_RETRY_LOCK_MM)) vma_end_read(vma); mutex_unlock(&hugetlb_fault_mutex_table[hash]); diff --git a/mm/internal.h b/mm/internal.h index f865d7b0c94b..a65192d8358d 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -574,7 +574,7 @@ static inline vm_fault_t vmf_anon_prepare(struct vm_fault *vmf) { vm_fault_t ret = __vmf_anon_prepare(vmf); - if (unlikely(ret & VM_FAULT_RETRY)) + if (unlikely(ret & VM_FAULT_RETRY_LOCK_MM)) vma_end_read(vmf->vma); return ret; } diff --git a/mm/memory.c b/mm/memory.c index e0f1aeed713c..682d1167eb49 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4021,7 +4021,7 @@ static inline vm_fault_t vmf_can_call_fault(const struct vm_fault *vmf) if (vma->vm_ops->map_pages || !(vmf->flags & FAULT_FLAG_VMA_LOCK)) return 0; vma_end_read(vma); - return VM_FAULT_RETRY; + return VM_FAULT_RETRY_LOCK_MM; } /** @@ -4037,7 +4037,8 @@ static inline vm_fault_t vmf_can_call_fault(const struct vm_fault *vmf) * do with only the per-VMA lock held for this VMA. * * Return: 0 if fault handling can proceed. Any other value should be - * returned to the caller. + * returned to the caller. VM_FAULT_RETRY_LOCK_MM is returned with the + * per-VMA lock still held if the fault has to be retried under mmap_lock. */ vm_fault_t __vmf_anon_prepare(struct vm_fault *vmf) { @@ -4048,7 +4049,7 @@ vm_fault_t __vmf_anon_prepare(struct vm_fault *vmf) return 0; if (vmf->flags & FAULT_FLAG_VMA_LOCK) { if (!mmap_read_trylock(vma->vm_mm)) - return VM_FAULT_RETRY; + return VM_FAULT_RETRY_LOCK_MM; } if (__anon_vma_prepare(vma)) ret = VM_FAULT_OOM; @@ -5046,7 +5047,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) * under VMA lock. */ vma_end_read(vma); - ret = VM_FAULT_RETRY; + ret = VM_FAULT_RETRY_LOCK_MM; goto out; } @@ -6744,9 +6745,9 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) /* * On entry, we hold either the VMA lock or the mmap_lock - * (see FAULT_FLAG_VMA_LOCK). If VM_FAULT_RETRY is set in - * the result, the lock is not held on exit. See filemap_fault() - * and __folio_lock_or_retry(). + * (see FAULT_FLAG_VMA_LOCK). If VM_FAULT_RETRY or + * VM_FAULT_RETRY_LOCK_MM is set in the result, the lock is not held + * on exit. See filemap_fault() and __folio_lock_or_retry(). */ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma, unsigned long address, unsigned int flags) @@ -6966,7 +6967,8 @@ static vm_fault_t sanitize_fault_flags(struct vm_area_struct *vma, } /* * Per-VMA locks can't be used with FAULT_FLAG_RETRY_NOWAIT because of - * the assumption that lock is dropped on VM_FAULT_RETRY. + * the assumption that lock is dropped on VM_FAULT_RETRY and + * VM_FAULT_RETRY_LOCK_MM. */ if (WARN_ON_ONCE((*flags & (FAULT_FLAG_VMA_LOCK | FAULT_FLAG_RETRY_NOWAIT)) == -- 2.56.1.839.g22a8290db9-goog _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv