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

mm: rename walk_page_range_mm()

Patch series "mm: perform guard region install/remove under VMA lock", v2.

There is no reason why can't perform guard region operations under the VMA
lock, as long we take proper precautions to ensure that we do so in a safe
manner.

This is fine, as VMA lock acquisition is always best-effort, so if we are
unable to do so, we can simply fall back to using the mmap read lock.

Doing so will reduce mmap lock contention for callers performing guard
region operations and help establish a precedent of trying to use the VMA
lock where possible.

As part of this change we perform a trivial rename of page walk functions
which bypass safety checks (i.e. whether or not mm_walk_ops->install_pte
is specified) in order that we can keep naming consistent with the mm
walk.

This is because we need to expose a VMA-specific walk that still allows us
to install PTE entries.


This patch (of 2):

Make it clear we're referencing an unsafe variant of this function
explicitly.

This is laying the foundation for exposing more such functions and
maintaining a consistent naming scheme.

As a part of this change, rename check_ops_valid() to check_ops_safe() for
consistency.

Link: https://lkml.kernel.org/r/cover.1762795245.git.lorenzo.stoakes@oracle.com
Link: https://lkml.kernel.org/r/c684d91464a438d6e31172c9450416a373f10649.1762795245.git.lorenzo.stoakes@oracle.com
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: David Hildenbrand (Red Hat) <david@kernel.org>
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: SeongJae Park <sj@kernel.org>
Cc: Jann Horn <jannh@google.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes and committed by
Andrew Morton
f4af67ff bc8e51c0

+14 -14
+1 -1
mm/internal.h
··· 1649 1649 #endif /* CONFIG_UNACCEPTED_MEMORY */ 1650 1650 1651 1651 /* pagewalk.c */ 1652 - int walk_page_range_mm(struct mm_struct *mm, unsigned long start, 1652 + int walk_page_range_mm_unsafe(struct mm_struct *mm, unsigned long start, 1653 1653 unsigned long end, const struct mm_walk_ops *ops, 1654 1654 void *private); 1655 1655 int walk_page_range_debug(struct mm_struct *mm, unsigned long start,
+2 -2
mm/madvise.c
··· 1173 1173 unsigned long nr_pages = 0; 1174 1174 1175 1175 /* Returns < 0 on error, == 0 if success, > 0 if zap needed. */ 1176 - err = walk_page_range_mm(vma->vm_mm, range->start, range->end, 1177 - &guard_install_walk_ops, &nr_pages); 1176 + err = walk_page_range_mm_unsafe(vma->vm_mm, range->start, 1177 + range->end, &guard_install_walk_ops, &nr_pages); 1178 1178 if (err < 0) 1179 1179 return err; 1180 1180
+11 -11
mm/pagewalk.c
··· 452 452 * We usually restrict the ability to install PTEs, but this functionality is 453 453 * available to internal memory management code and provided in mm/internal.h. 454 454 */ 455 - int walk_page_range_mm(struct mm_struct *mm, unsigned long start, 455 + int walk_page_range_mm_unsafe(struct mm_struct *mm, unsigned long start, 456 456 unsigned long end, const struct mm_walk_ops *ops, 457 457 void *private) 458 458 { ··· 518 518 * This check is performed on all functions which are parameterised by walk 519 519 * operations and exposed in include/linux/pagewalk.h. 520 520 * 521 - * Internal memory management code can use the walk_page_range_mm() function to 522 - * be able to use all page walking operations. 521 + * Internal memory management code can use *_unsafe() functions to be able to 522 + * use all page walking operations. 523 523 */ 524 - static bool check_ops_valid(const struct mm_walk_ops *ops) 524 + static bool check_ops_safe(const struct mm_walk_ops *ops) 525 525 { 526 526 /* 527 527 * The installation of PTEs is solely under the control of memory ··· 579 579 unsigned long end, const struct mm_walk_ops *ops, 580 580 void *private) 581 581 { 582 - if (!check_ops_valid(ops)) 582 + if (!check_ops_safe(ops)) 583 583 return -EINVAL; 584 584 585 - return walk_page_range_mm(mm, start, end, ops, private); 585 + return walk_page_range_mm_unsafe(mm, start, end, ops, private); 586 586 } 587 587 588 588 /** ··· 639 639 640 640 if (start >= end) 641 641 return -EINVAL; 642 - if (!check_ops_valid(ops)) 642 + if (!check_ops_safe(ops)) 643 643 return -EINVAL; 644 644 645 645 return walk_pgd_range(start, end, &walk); ··· 678 678 pgd, private); 679 679 if (start >= end || !walk.mm) 680 680 return -EINVAL; 681 - if (!check_ops_valid(ops)) 681 + if (!check_ops_safe(ops)) 682 682 return -EINVAL; 683 683 684 684 /* ··· 709 709 return -EINVAL; 710 710 if (start < vma->vm_start || end > vma->vm_end) 711 711 return -EINVAL; 712 - if (!check_ops_valid(ops)) 712 + if (!check_ops_safe(ops)) 713 713 return -EINVAL; 714 714 715 715 process_mm_walk_lock(walk.mm, ops->walk_lock); ··· 729 729 730 730 if (!walk.mm) 731 731 return -EINVAL; 732 - if (!check_ops_valid(ops)) 732 + if (!check_ops_safe(ops)) 733 733 return -EINVAL; 734 734 735 735 process_mm_walk_lock(walk.mm, ops->walk_lock); ··· 780 780 unsigned long start_addr, end_addr; 781 781 int err = 0; 782 782 783 - if (!check_ops_valid(ops)) 783 + if (!check_ops_safe(ops)) 784 784 return -EINVAL; 785 785 786 786 lockdep_assert_held(&mapping->i_mmap_rwsem);