VM_FAULT_RETRY is returned from the page fault path for two different
reasons.  Usually it means that the fault handler had to drop its lock,
typically to wait for something, and 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
architecture fault handlers can not tell these two cases apart, so every
VM_FAULT_RETRY from a fault handled under the per-VMA lock results in a
retry under mmap_lock.

This series separates the two cases:

Patch 1 introduces should_retry_mm_fault() and uses it in the per-VMA lock
path of the architecture fault handlers, in fault_signal_pending() and in
mm_account_fault() instead of testing VM_FAULT_RETRY directly.

Patch 2 introduces VM_FAULT_RETRY_LOCK_MM and returns it from the places
that fall back from the per-VMA lock to mmap_lock: vmf_can_call_fault(),
__vmf_anon_prepare() and the device private paths in do_swap_page() and
do_huge_pmd_device_private(). VM_FAULT_RETRY keeps being returned in all
the other cases.

should_retry_mm_fault() accepts both codes and the architecture fault
handlers keep retrying under mmap_lock in both cases, so no functional
change is intended.  The series only makes the reason for the retry
visible to the callers of handle_mm_fault().

Only the checks in the per-VMA lock path are converted.  The checks done
after handling a fault under mmap_lock still test VM_FAULT_RETRY, since
VM_FAULT_RETRY_LOCK_MM is never returned there.

Drivers and filesystems that return VM_FAULT_RETRY are left unchanged.
panthor_gem_any_fault() might return it after dropping the per-VMA lock
and waiting, which is treated as a generic retry.

The series is based on mm-unstable.

Suren Baghdasaryan (2):
  mm: introduce should_retry_mm_fault() helper
  mm: split VM_FAULT_RETRY_LOCK_MM out of VM_FAULT_RETRY

 Documentation/filesystems/porting.rst |  4 ++--
 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              | 23 ++++++++++++++++++++++-
 include/linux/sched/signal.h          |  2 +-
 mm/huge_memory.c                      |  2 +-
 mm/hugetlb.c                          |  9 +++++----
 mm/internal.h                         |  2 +-
 mm/memory.c                           | 20 +++++++++++---------
 14 files changed, 57 insertions(+), 33 deletions(-)


base-commit: 890dc639d8a33e674caa7ea9993dbd2416660447
-- 
2.56.1.839.g22a8290db9-goog


Reply via email to