From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A8FD12B98 for ; Fri, 29 Dec 2023 19:07:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="NdojJNSe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1D80C433C8; Fri, 29 Dec 2023 19:07:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1703876851; bh=fs9is5OXsokSrXSs/UYJym8gJ3IUVoTlHLI+Z8gwqJk=; h=Date:To:From:Subject:From; b=NdojJNSeLFCPdcOm4d211+gXA3dVY77+2485WwHuyg33anJ678uOEDCuNNSfpQ7XN ApH8diQ4i7btVm4gJyUZA81fVdufI+oCQqw2eTSJfeUEM0UsJRrMf1GJENp+gjsDts cKSmPEnRCxjLGA20+lNrFGzs6zlnf2L41iX9cKrE= Date: Fri, 29 Dec 2023 11:07:30 -0800 To: mm-commits@vger.kernel.org,willy@infradead.org,will@kernel.org,peterz@infradead.org,palmer@dabbelt.com,mpe@ellerman.id.au,luto@kernel.org,gerald.schaefer@linux.ibm.com,dave.hansen@linux.intel.com,christophe.leroy@csgroup.eu,catalin.marinas@arm.com,agordeev@linux.ibm.com,surenb@google.com,akpm@linux-foundation.org From: Andrew Morton Subject: [merged mm-hotfixes-stable] arch-mm-fault-fix-major-fault-accounting-when-retrying-under-per-vma-lock.patch removed from -mm tree Message-Id: <20231229190730.F1D80C433C8@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The quilt patch titled Subject: arch/mm/fault: fix major fault accounting when retrying under per-VMA lock has been removed from the -mm tree. Its filename was arch-mm-fault-fix-major-fault-accounting-when-retrying-under-per-vma-lock.patch This patch was dropped because it was merged into the mm-hotfixes-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm ------------------------------------------------------ From: Suren Baghdasaryan Subject: arch/mm/fault: fix major fault accounting when retrying under per-VMA lock Date: Tue, 26 Dec 2023 13:46:10 -0800 A test [1] in Android test suite started failing after [2] was merged. It turns out that after handling a major fault under per-VMA lock, the process major fault counter does not register that fault as major. Before [2] read faults would be done under mmap_lock, in which case FAULT_FLAG_TRIED flag is set before retrying. That in turn causes mm_account_fault() to account the fault as major once retry completes. With per-VMA locks we often retry because a fault can't be handled without locking the whole mm using mmap_lock. Therefore such retries do not set FAULT_FLAG_TRIED flag. This logic does not work after [2] because we can now handle read major faults under per-VMA lock and upon retry the fact there was a major fault gets lost. Fix this by setting FAULT_FLAG_TRIED after retrying under per-VMA lock if VM_FAULT_MAJOR was returned. Ideally we would use an additional VM_FAULT bit to indicate the reason for the retry (could not handle under per-VMA lock vs other reason) but this simpler solution seems to work, so keeping it simple. [1] https://cs.android.com/android/platform/superproject/+/master:test/vts-testcase/kernel/api/drop_caches_prop/drop_caches_test.cpp [2] https://lore.kernel.org/all/20231006195318.4087158-6-willy@infradead.org/ Link: https://lkml.kernel.org/r/20231226214610.109282-1-surenb@google.com Fixes: 12214eba1992 ("mm: handle read faults under the VMA lock") Signed-off-by: Suren Baghdasaryan Cc: Matthew Wilcox Cc: Alexander Gordeev Cc: Andy Lutomirski Cc: Catalin Marinas Cc: Christophe Leroy Cc: Dave Hansen Cc: Gerald Schaefer Cc: Michael Ellerman Cc: Palmer Dabbelt Cc: Peter Zijlstra Cc: Will Deacon Signed-off-by: Andrew Morton --- arch/arm64/mm/fault.c | 2 ++ arch/powerpc/mm/fault.c | 2 ++ arch/riscv/mm/fault.c | 2 ++ arch/s390/mm/fault.c | 3 +++ arch/x86/mm/fault.c | 2 ++ 5 files changed, 11 insertions(+) --- a/arch/arm64/mm/fault.c~arch-mm-fault-fix-major-fault-accounting-when-retrying-under-per-vma-lock +++ a/arch/arm64/mm/fault.c @@ -607,6 +607,8 @@ static int __kprobes do_page_fault(unsig goto done; } count_vm_vma_lock_event(VMA_LOCK_RETRY); + if (fault & VM_FAULT_MAJOR) + mm_flags |= FAULT_FLAG_TRIED; /* Quick path to respond to signals */ if (fault_signal_pending(fault, regs)) { --- a/arch/powerpc/mm/fault.c~arch-mm-fault-fix-major-fault-accounting-when-retrying-under-per-vma-lock +++ a/arch/powerpc/mm/fault.c @@ -497,6 +497,8 @@ static int ___do_page_fault(struct pt_re goto done; } count_vm_vma_lock_event(VMA_LOCK_RETRY); + if (fault & VM_FAULT_MAJOR) + flags |= FAULT_FLAG_TRIED; if (fault_signal_pending(fault, regs)) return user_mode(regs) ? 0 : SIGBUS; --- a/arch/riscv/mm/fault.c~arch-mm-fault-fix-major-fault-accounting-when-retrying-under-per-vma-lock +++ a/arch/riscv/mm/fault.c @@ -304,6 +304,8 @@ void handle_page_fault(struct pt_regs *r goto done; } count_vm_vma_lock_event(VMA_LOCK_RETRY); + if (fault & VM_FAULT_MAJOR) + flags |= FAULT_FLAG_TRIED; if (fault_signal_pending(fault, regs)) { if (!user_mode(regs)) --- a/arch/s390/mm/fault.c~arch-mm-fault-fix-major-fault-accounting-when-retrying-under-per-vma-lock +++ a/arch/s390/mm/fault.c @@ -337,6 +337,9 @@ static void do_exception(struct pt_regs return; } count_vm_vma_lock_event(VMA_LOCK_RETRY); + if (fault & VM_FAULT_MAJOR) + flags |= FAULT_FLAG_TRIED; + /* Quick path to respond to signals */ if (fault_signal_pending(fault, regs)) { if (!user_mode(regs)) --- a/arch/x86/mm/fault.c~arch-mm-fault-fix-major-fault-accounting-when-retrying-under-per-vma-lock +++ a/arch/x86/mm/fault.c @@ -1370,6 +1370,8 @@ void do_user_addr_fault(struct pt_regs * goto done; } count_vm_vma_lock_event(VMA_LOCK_RETRY); + if (fault & VM_FAULT_MAJOR) + flags |= FAULT_FLAG_TRIED; /* Quick path to respond to signals */ if (fault_signal_pending(fault, regs)) { _ Patches currently in -mm which might be from surenb@google.com are selftests-mm-call-uffd_test_ctx_clear-at-the-end-of-the-test.patch selftests-mm-add-uffd_test_case_ops-to-allow-test-case-specific-operations.patch selftests-mm-add-uffdio_move-ioctl-test.patch