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 DF09B606A32D for ; Sun, 29 Nov 2026 20:22:18 +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=EVtMTfEG Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4jcz8h67zHz2yMl; Mon, 30 Nov 2026 07:22:12 +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=1795983732; cv=none; b=Ok+T5+yphSDqqP5sEdnBU3hJ1c+ky0Fqq8blM4oTZRRazz/CpbD3dEc0OzaPFIwhd3Y2qhY5IEJi75UzSXmqv56DzoINNURZDQ4M1inuXB/Wpr2hSpugRW+O+MtCZpgHmUya1YaqUjrCRCE4eg4CCyq/5T5ArlleuOLiFMtBEn3EKDQ8YxOTu1J1jcNyKJxjuYOAu6cSFzOXYc3c06htE28oI2GulexX70ayzg4YtVpD5BZaaX2H/d1uUkUxuWDje4+9FOETdSaRI6mmn0UmXAfqhtN+btJErA8yCdC4ut8nJnEHE+vFI54xy7+gk6VLjxyyvYVINKflTRSlXxcqXw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1795983732; c=relaxed/relaxed; bh=CHKBFWl9b3wYYmTM7OhHnzVQ2NjhljiITP8oBlnjhcc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PpZQ6tmg2ivagzSstJEpYt86BQHtT34pKntfZSTGxghr6oS1RfVjpO8JawWgN8FfUlEbtYRp30Rw9WeOuTS5A/+NVohjU4iOAyC/iN9VXG3rVdmV2mXXjrYjSBimK70/Ulf1A1s+AzAGl97fU18iEWv8kTUY4VNWVdKSA5Akkwn2yYmTORblJjuk9WbBb4kWh1bT/rSBUzovo/cQuCAXFAgTfZj47bDuACUYG6LPefrrs/pzZa5hI4H7exmp2JuD7lvbSoDrZIW1efPkxlG2Euj4RabQDnUok61BpsR1DahelZ0gqMci9MyiAqL05lGCPekX5CYLliG0V073YHmb0w== 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=EVtMTfEG; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::1347; helo=mail-dy1-x1347.google.com; envelope-from=3cikmawykdbudfcz8w19916z.x97638fiaax-yzg63ded.9k6vwd.9c1@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=EVtMTfEG; 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=3cikmawykdbudfcz8w19916z.x97638fiaax-yzg63ded.9k6vwd.9c1@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 4jcz8g56Hzz2xVY for ; Mon, 30 Nov 2026 07:22:11 +1100 (AEDT) Received: by mail-dy1-x1347.google.com with SMTP id 5a478bee46e88-38531c1a566so8123546eec.1 for ; Sun, 29 Nov 2026 12:22:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795983729; x=1796588529; 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=CHKBFWl9b3wYYmTM7OhHnzVQ2NjhljiITP8oBlnjhcc=; b=EVtMTfEGjtrZvMrUHGndsWXi/P9kH/lqsBNuR4x2EYeM3Cz/yQdXUJNdifoKIZB3vd nI3x5/AT/nXmTUow5R0Pkxtg6caPHy/ZJkzT0Yl8P/VTUouVltuYxrdkabomr8c2R5+d /qiqU7Mv3dZVAiyKcR30ZxEWznR9Kz5XZTW66Hf+KxwpIAi/tkI4XUlLgvgCb/bQlOIp ROOLvk+QZTrOqcd7fFQzoBfAOPbPI2Uquzl0FnfT58mt1BoLU/is8ddOo9f2432bhsqR i5C2nRxYh0HZxMVRc+BSb83D8QN0mE/RrItIIJyHIlWd16Mj1bqx5ZEe4d5dAw5x4IZP PKkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795983729; x=1796588529; 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=CHKBFWl9b3wYYmTM7OhHnzVQ2NjhljiITP8oBlnjhcc=; b=rbiqz43yC7Ki2kuNz1pELJpMLZHwmiq32IgourT5pSW9HuNAs9ipv3j82EK8tiPPLu JmKeguPb9TupdJUSPo4vl3PabNWY3ZDqY9I++YUA/2BrxWX22sSUI7I3hyQBcoq9Z3Vi UID0Hw9YuuNB1fQeyy4eg7xvMr4nxvm+r57jKqclqnWAvsic96DC0sC5QQEzVK/3KCtQ p9tDzJT5wv7Zkv0CsasPSP/LleXXxQ70wIrp8HDesSUJliJnkg1Oq7kkS3OvxPX72czz 06dCjjD0Q6r2eClwIJeti8+xprwUFMoDm3l3DZPMsXt1uEHqcOqVZ/qc9KScPPPoeSPc vLVg== X-Forwarded-Encrypted: i=1; AL+hErEX1mHFavC9rHI46VjPXgsjxqGz24jPyve3Fk12A/yZW00He3WPj0ANumECLbCpJSouQjG0AB1rRc5FveA=@lists.ozlabs.org X-Gm-Message-State: APuU4Z/cLN3gIpCnV/eDF9tJo+O17gENpPPUPn7M3fdpHSGL+Xc6a0Ky rs5v4dEE7XGos76VkoKbYFzhneXJc+Z0DRuz56U1xg+W6oNyeuG56/YOzxURX40BvTugnR5myCc oxBTGyw== X-Received: from dyrp21.prod.google.com ([2002:a05:693c:69d5:b0:36a:e67:fbc2]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:c3aa:b0:385:c28b:a4d5 with SMTP id 5a478bee46e88-385c28baffbmr32205191eec.17.1795983728731; Sun, 29 Nov 2026 12:22:08 -0800 (PST) Date: Sun, 29 Nov 2026 12:22:02 -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-2-surenb@google.com> Subject: [RFC PATCH 1/2] mm: introduce should_retry_mm_fault() helper 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=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 Page fault handlers test VM_FAULT_RETRY in the result of handle_mm_fault() to decide whether the fault has to be retried. For a fault that was handled under the per-VMA lock, this means falling back to handling it under mmap_lock. Introduce should_retry_mm_fault() and use it for these checks in the per-VMA lock path of the architecture fault handlers, in fault_signal_pending() and in mm_account_fault(). This keeps the set of fault codes that request a retry in one place, in preparation for splitting VM_FAULT_RETRY into separate codes. The checks done after handling the fault under mmap_lock are left unchanged. No functional change intended. Signed-off-by: Suren Baghdasaryan --- arch/arm/mm/fault.c | 4 ++-- arch/arm64/mm/fault.c | 4 ++-- arch/loongarch/mm/fault.c | 4 ++-- arch/powerpc/mm/fault.c | 4 ++-- arch/riscv/mm/fault.c | 4 ++-- arch/s390/mm/fault.c | 4 ++-- arch/x86/mm/fault.c | 4 ++-- include/linux/mm_types.h | 12 ++++++++++++ include/linux/sched/signal.h | 2 +- mm/memory.c | 2 +- 10 files changed, 28 insertions(+), 16 deletions(-) diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c index 0a09d4ff7718..48e2aa4dbb63 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -407,10 +407,10 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) goto bad_area; } fault = handle_mm_fault(vma, addr, flags | FAULT_FLAG_VMA_LOCK, regs); - if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) + if (!should_retry_mm_fault(fault) && !(fault & VM_FAULT_COMPLETED)) vma_end_read(vma); - if (!(fault & VM_FAULT_RETRY)) { + if (!should_retry_mm_fault(fault)) { count_vm_vma_lock_event(VMA_LOCK_SUCCESS); goto done; } diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index b22736853fcd..41165beccab0 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -718,10 +718,10 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, } fault = handle_mm_fault(vma, addr, mm_flags | FAULT_FLAG_VMA_LOCK, regs); - if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) + if (!should_retry_mm_fault(fault) && !(fault & VM_FAULT_COMPLETED)) vma_end_read(vma); - if (!(fault & VM_FAULT_RETRY)) { + if (!should_retry_mm_fault(fault)) { count_vm_vma_lock_event(VMA_LOCK_SUCCESS); goto done; } diff --git a/arch/loongarch/mm/fault.c b/arch/loongarch/mm/fault.c index 2c93d33356e5..edbf700af18e 100644 --- a/arch/loongarch/mm/fault.c +++ b/arch/loongarch/mm/fault.c @@ -247,10 +247,10 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, } fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs); - if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) + if (!should_retry_mm_fault(fault) && !(fault & VM_FAULT_COMPLETED)) vma_end_read(vma); - if (!(fault & VM_FAULT_RETRY)) { + if (!should_retry_mm_fault(fault)) { count_vm_vma_lock_event(VMA_LOCK_SUCCESS); goto done; } diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c index 806c74e0d5ab..eaadb8023eb2 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -503,10 +503,10 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, } fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs); - if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) + if (!should_retry_mm_fault(fault) && !(fault & VM_FAULT_COMPLETED)) vma_end_read(vma); - if (!(fault & VM_FAULT_RETRY)) { + if (!should_retry_mm_fault(fault)) { count_vm_vma_lock_event(VMA_LOCK_SUCCESS); goto done; } diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c index 04ed6f8acae4..742b2cc3b495 100644 --- a/arch/riscv/mm/fault.c +++ b/arch/riscv/mm/fault.c @@ -360,10 +360,10 @@ void handle_page_fault(struct pt_regs *regs) } fault = handle_mm_fault(vma, addr, flags | FAULT_FLAG_VMA_LOCK, regs); - if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) + if (!should_retry_mm_fault(fault) && !(fault & VM_FAULT_COMPLETED)) vma_end_read(vma); - if (!(fault & VM_FAULT_RETRY)) { + if (!should_retry_mm_fault(fault)) { count_vm_vma_lock_event(VMA_LOCK_SUCCESS); goto done; } diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c index 46d828926009..3056b33496ec 100644 --- a/arch/s390/mm/fault.c +++ b/arch/s390/mm/fault.c @@ -303,9 +303,9 @@ static void do_exception(struct pt_regs *regs, int access) return handle_fault_error_nolock(regs, SEGV_ACCERR); } fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs); - if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) + if (!should_retry_mm_fault(fault) && !(fault & VM_FAULT_COMPLETED)) vma_end_read(vma); - if (!(fault & VM_FAULT_RETRY)) { + if (!should_retry_mm_fault(fault)) { count_vm_vma_lock_event(VMA_LOCK_SUCCESS); goto done; } diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index aa88370ce739..23edca8f0555 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1341,10 +1341,10 @@ void do_user_addr_fault(struct pt_regs *regs, return; } fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs); - if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) + if (!should_retry_mm_fault(fault) && !(fault & VM_FAULT_COMPLETED)) vma_end_read(vma); - if (!(fault & VM_FAULT_RETRY)) { + if (!should_retry_mm_fault(fault)) { count_vm_vma_lock_event(VMA_LOCK_SUCCESS); goto done; } diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 4c576e24ce42..7a80c904eab9 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -1739,6 +1739,18 @@ enum vm_fault_reason { VM_FAULT_SIGSEGV | VM_FAULT_HWPOISON | \ VM_FAULT_HWPOISON_LARGE | VM_FAULT_FALLBACK) +/** + * should_retry_mm_fault - Check whether a page fault has to be retried. + * @fault: The fault result returned by handle_mm_fault(). + * + * 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); +} + #define VM_FAULT_RESULT_TRACE \ { (__force u32)VM_FAULT_OOM, "OOM" }, \ { (__force u32)VM_FAULT_SIGBUS, "SIGBUS" }, \ diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index 0adb51ab1542..9e1334379296 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -448,7 +448,7 @@ static inline int signal_pending_state(unsigned int state, struct task_struct *p static inline bool fault_signal_pending(vm_fault_t fault_flags, struct pt_regs *regs) { - return unlikely((fault_flags & VM_FAULT_RETRY) && + return unlikely(should_retry_mm_fault(fault_flags) && (fatal_signal_pending(current) || (user_mode(regs) && signal_pending(current)))); } diff --git a/mm/memory.c b/mm/memory.c index 90fc7c395124..e0f1aeed713c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6876,7 +6876,7 @@ static inline void mm_account_fault(struct mm_struct *mm, struct pt_regs *regs, bool major; /* Incomplete faults will be accounted upon completion. */ - if (ret & VM_FAULT_RETRY) + if (should_retry_mm_fault(ret)) return; /* -- 2.56.1.839.g22a8290db9-goog