Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs/proc/task_mmu: reduce scope of lazy mmu region

Update the way arch_[enter|leave]_lazy_mmu_mode() is called in
pagemap_scan_pmd_entry() to follow the normal pattern of holding the ptl
for user space mappings. As a result the scope is reduced to only the pte
table, but that's where most of the performance win is.

While I believe there wasn't technically a bug here, the original scope
made it easier to accidentally nest or, worse, accidentally call something
like kmap() which would expect an immediate mode pte modification but it
would end up deferred.

Link: https://lkml.kernel.org/r/20250303141542.3371656-3-ryan.roberts@arm.com
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Juergen Gross <jgross@suse.com>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Borislav Betkov <bp@alien8.de>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Juegren Gross <jgross@suse.com>
Cc: Matthew Wilcow (Oracle) <willy@infradead.org>
Cc: Thomas Gleinxer <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Ryan Roberts and committed by
Andrew Morton
ad449d85 691ee97e

+4 -7
+4 -7
fs/proc/task_mmu.c
··· 2459 2459 spinlock_t *ptl; 2460 2460 int ret; 2461 2461 2462 - arch_enter_lazy_mmu_mode(); 2463 - 2464 2462 ret = pagemap_scan_thp_entry(pmd, start, end, walk); 2465 - if (ret != -ENOENT) { 2466 - arch_leave_lazy_mmu_mode(); 2463 + if (ret != -ENOENT) 2467 2464 return ret; 2468 - } 2469 2465 2470 2466 ret = 0; 2471 2467 start_pte = pte = pte_offset_map_lock(vma->vm_mm, pmd, start, &ptl); 2472 2468 if (!pte) { 2473 - arch_leave_lazy_mmu_mode(); 2474 2469 walk->action = ACTION_AGAIN; 2475 2470 return 0; 2476 2471 } 2472 + 2473 + arch_enter_lazy_mmu_mode(); 2477 2474 2478 2475 if ((p->arg.flags & PM_SCAN_WP_MATCHING) && !p->vec_out) { 2479 2476 /* Fast path for performing exclusive WP */ ··· 2540 2543 if (flush_end) 2541 2544 flush_tlb_range(vma, start, addr); 2542 2545 2543 - pte_unmap_unlock(start_pte, ptl); 2544 2546 arch_leave_lazy_mmu_mode(); 2547 + pte_unmap_unlock(start_pte, ptl); 2545 2548 2546 2549 cond_resched(); 2547 2550 return ret;