[PATCH rfc v2 08/10] loongarch: mm: cleanup __do_page_fault()
Kefeng Wang
wangkefeng.wang at huawei.com
Mon Aug 21 22:30:54 AEST 2023
Cleanup __do_page_fault() by reuse bad_area_nosemaphore and
bad_area label.
Signed-off-by: Kefeng Wang <wangkefeng.wang at huawei.com>
---
arch/loongarch/mm/fault.c | 48 +++++++++++++--------------------------
1 file changed, 16 insertions(+), 32 deletions(-)
diff --git a/arch/loongarch/mm/fault.c b/arch/loongarch/mm/fault.c
index e6376e3dce86..5d4c742c4bc5 100644
--- a/arch/loongarch/mm/fault.c
+++ b/arch/loongarch/mm/fault.c
@@ -157,18 +157,15 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
if (!user_mode(regs))
no_context(regs, write, address);
else
- do_sigsegv(regs, write, address, si_code);
- return;
+ goto bad_area_nosemaphore;
}
/*
* If we're in an interrupt or have no user
* context, we must not take the fault..
*/
- if (faulthandler_disabled() || !mm) {
- do_sigsegv(regs, write, address, si_code);
- return;
- }
+ if (faulthandler_disabled() || !mm)
+ goto bad_area_nosemaphore;
if (user_mode(regs))
flags |= FAULT_FLAG_USER;
@@ -178,23 +175,7 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
vma = lock_mm_and_find_vma(mm, address, regs);
if (unlikely(!vma))
goto bad_area_nosemaphore;
- goto good_area;
-
-/*
- * Something tried to access memory that isn't in our memory map..
- * Fix it, but check if it's kernel or user first..
- */
-bad_area:
- mmap_read_unlock(mm);
-bad_area_nosemaphore:
- do_sigsegv(regs, write, address, si_code);
- return;
-/*
- * Ok, we have a good vm_area for this memory access, so
- * we can handle it..
- */
-good_area:
si_code = SEGV_ACCERR;
if (write) {
@@ -235,22 +216,25 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
*/
goto retry;
}
+
+ mmap_read_unlock(mm);
+
if (unlikely(fault & VM_FAULT_ERROR)) {
- mmap_read_unlock(mm);
- if (fault & VM_FAULT_OOM) {
+ if (fault & VM_FAULT_OOM)
do_out_of_memory(regs, write, address);
- return;
- } else if (fault & VM_FAULT_SIGSEGV) {
- do_sigsegv(regs, write, address, si_code);
- return;
- } else if (fault & (VM_FAULT_SIGBUS|VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
+ else if (fault & VM_FAULT_SIGSEGV)
+ goto bad_area_nosemaphore;
+ else if (fault & (VM_FAULT_SIGBUS|VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE))
do_sigbus(regs, write, address, si_code);
- return;
- }
- BUG();
+ else
+ BUG();
}
+ return;
+bad_area:
mmap_read_unlock(mm);
+bad_area_nosemaphore:
+ do_sigsegv(regs, write, address, si_code);
}
asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
--
2.27.0
More information about the Linuxppc-dev
mailing list