Skip to content

Commit 70d4cbc

Browse files
ldu4akpm00
authored andcommitted
powerc/mm: try VMA lock-based page fault handling first
Attempt VMA lock-based page fault handling first, and fall back to the existing mmap_lock-based handling if that fails. Copied from "x86/mm: try VMA lock-based page fault handling first" [ldufour@linux.ibm.com: powerpc/mm: fix mmap_lock bad unlock] Link: https://lkml.kernel.org/r/20230306154244.17560-1-ldufour@linux.ibm.com Link: https://lore.kernel.org/linux-mm/842502FB-F99C-417C-9648-A37D0ECDC9CE@linux.ibm.com Link: https://lkml.kernel.org/r/20230227173632.3292573-32-surenb@google.com Signed-off-by: Laurent Dufour <ldufour@linux.ibm.com> Signed-off-by: Suren Baghdasaryan <surenb@google.com> Cc: Sachin Sant <sachinp@linux.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent cd7f176 commit 70d4cbc

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

arch/powerpc/mm/fault.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,40 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address,
474474
if (is_exec)
475475
flags |= FAULT_FLAG_INSTRUCTION;
476476

477+
#ifdef CONFIG_PER_VMA_LOCK
478+
if (!(flags & FAULT_FLAG_USER))
479+
goto lock_mmap;
480+
481+
vma = lock_vma_under_rcu(mm, address);
482+
if (!vma)
483+
goto lock_mmap;
484+
485+
if (unlikely(access_pkey_error(is_write, is_exec,
486+
(error_code & DSISR_KEYFAULT), vma))) {
487+
vma_end_read(vma);
488+
goto lock_mmap;
489+
}
490+
491+
if (unlikely(access_error(is_write, is_exec, vma))) {
492+
vma_end_read(vma);
493+
goto lock_mmap;
494+
}
495+
496+
fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs);
497+
vma_end_read(vma);
498+
499+
if (!(fault & VM_FAULT_RETRY)) {
500+
count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
501+
goto done;
502+
}
503+
count_vm_vma_lock_event(VMA_LOCK_RETRY);
504+
505+
if (fault_signal_pending(fault, regs))
506+
return user_mode(regs) ? 0 : SIGBUS;
507+
508+
lock_mmap:
509+
#endif /* CONFIG_PER_VMA_LOCK */
510+
477511
/* When running in the kernel we expect faults to occur only to
478512
* addresses in user space. All other faults represent errors in the
479513
* kernel and should generate an OOPS. Unfortunately, in the case of an
@@ -550,6 +584,9 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address,
550584

551585
mmap_read_unlock(current->mm);
552586

587+
#ifdef CONFIG_PER_VMA_LOCK
588+
done:
589+
#endif
553590
if (unlikely(fault & VM_FAULT_ERROR))
554591
return mm_fault_error(regs, address, fault);
555592

arch/powerpc/platforms/powernv/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ config PPC_POWERNV
1616
select PPC_DOORBELL
1717
select MMU_NOTIFIER
1818
select FORCE_SMP
19+
select ARCH_SUPPORTS_PER_VMA_LOCK
1920
default y
2021

2122
config OPAL_PRD

arch/powerpc/platforms/pseries/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ config PPC_PSERIES
2222
select HOTPLUG_CPU
2323
select FORCE_SMP
2424
select SWIOTLB
25+
select ARCH_SUPPORTS_PER_VMA_LOCK
2526
default y
2627

2728
config PARAVIRT

0 commit comments

Comments
 (0)