From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D9E7606A31C for ; Sun, 29 Nov 2026 20:22:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=mwRmH3Vu Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4jcz8l0l0jz2xVY; Mon, 30 Nov 2026 07:22:15 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::1347" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1795983735; cv=none; b=ovsTUaPCgq+Irv9RAKGWxtnmmaMNtFyT21xdmiHdhT+lanlykzsaussRNtHDpH4KjF4bL5SvIYVr2d4c6yGfS+LFFELQSv6K0Mz6EZYTJJQlOCUw0eqLZBkAajvRqahWTbO7XBmNIQWFlCExbFz4Ckg6g5DhbjMObWKGoHeigcyCiFqDmbWEdn7cN9ScXmhFN55oDbijGcKvQBTk3XeuJLyUe58eJlPDWhiY9ySlyeZsfgqWuD7REd0XOt6YFVcaIYHdjJR0k4xgY4+SvBw/f6XGHntI/REuBmkd7xt3cayyA7YVzM7Ms53PieisV2G4vdTmyPcaj2wHkg/VNg3DZA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1795983735; c=relaxed/relaxed; bh=+I087uAHFfr3vIi2QzJD6zDcj5fneQUT1cINxigykdY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Fa3nwR9HZeoL/mhM/Quf5XAaYxzM45lGD1HvZHIV4fwWa3TOqkiKrJyCr+EoEWaha90BTz8jMf2o1uKsTJkh5Wfs37zQ3XMFonf4b5MjzqOkw03BppBb068Huyot7SiBMpCgYiDP0QqJm7S39Eps1LtBlOa7uPAvNwaUm2dSCPuajFR7R/L4D51/LtaT1uHU2JDP/rK2fuMAzGQj3Hi9qKOj5jSU4nt2Fk9DG0QYjGyO+WU9iRUgnoKoGtN3Lhv0hgD0F2CuMlYQVybcThyuV4qXSRgdQZtjRP3y6dM/ezFD585aPtNdZx7W32uonEHkBdOf4NH9OAYa9wr3mf9L9w== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=mwRmH3Vu; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::1347; helo=mail-dy1-x1347.google.com; envelope-from=3c4kmawykdbggif2bz4cc492.0ca96bildd0-12j96ghg.cn9yzg.cf4@flex--surenb.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--surenb.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=mwRmH3Vu; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--surenb.bounces.google.com (client-ip=2607:f8b0:4864:20::1347; helo=mail-dy1-x1347.google.com; envelope-from=3c4kmawykdbggif2bz4cc492.0ca96bildd0-12j96ghg.cn9yzg.cf4@flex--surenb.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-dy1-x1347.google.com (mail-dy1-x1347.google.com [IPv6:2607:f8b0:4864:20::1347]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4jcz8j33FXz2yRC for ; Mon, 30 Nov 2026 07:22:13 +1100 (AEDT) Received: by mail-dy1-x1347.google.com with SMTP id 5a478bee46e88-384c78aa0dbso12146994eec.0 for ; Sun, 29 Nov 2026 12:22:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795983731; x=1796588531; darn=lists.ozlabs.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=mwRmH3VuqzwHbjeMxEUduKesyhD09ViXruFeDN/B1lTgyfOozhd5fINKvL0nWwEnI3 HSotUkNtzQwgU3ExaHufsCl2U3xF8SgQGCaZse8wqSCFP8qPp4R7TdEdHYRVCinK+mqr ymTSbvjHq19M7vhTGX8pZKPlIYeQeUrpTv2n/43HPqCeZQ7MMtTO/achy3Sz2yW4mv+A FuCGg+twSxJWXf0fMUM3/i7j5KHImDC1OV3hHke03oTk+9gE6KfSAQc1HPMutOFA80ag YHkSJibIa1HPWalveNElQmeMeDe7yWzNIrjhoas3Qglyjiu1RSQ+ix6Hb5VpJk/bwXsu TpVw== 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=mOODX6pKd8y+qElCj+vmj//ifeK0JmFp5r6UE6Z9ih+K88pJWevQQ27rfQpbNV/CPi COFpnV+DtIhVY9QsUug/IMAJjMrmooCFDxfjV3F0KtewBqm1XZUe1jZ3ycPJfAR+mVFl dItHYSDPgLvy04fXax1nkAIDOMzfyNBpSiDC1emHBNmbqtthtrxmGeki+kOWRM1lWqHZ r50zLZblWyyoXXyGbwClkOjUOhhT3lF4NOHbQKdXttdCD9mku+12/r7mrkUVMT504gCc WH/VMnbemgr5jK2kON6wDoOFB2L+cyoGQglBb1A5J4fUIPCeHtIELdfPBAWmGj4RPeCM 3+0A== X-Forwarded-Encrypted: i=1; AL+hErHmbtEd9Jng9EE6tS3TwcTDvBxQf3mgq21VTavZu7j64nElmYvD+ymkiLY25MgLWE8nV+7gzFvreq3WYlQ=@lists.ozlabs.org X-Gm-Message-State: APuU4Z/DWt9YP0ZW8xbnNUh9foOS3aMAbJMXckaHp/UsWl/P9MEwEQqk /UyStqAvhttnCKpoMn705J/HERUpAtIYzjoN7nddylw4WGqbMHCU9KUywTlWNvebLdp9dU+iptf nSt27MQ== 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-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , Precedence: list 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable 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