From: Pekka Enberg <penberg@gmail.com>
To: linux-riscv@lists.infradead.org
Cc: Pekka Enberg <penberg@kernel.org>, palmer@dabbelt.com
Subject: [PATCH 1/8] riscv/mm/fault: Move no context handling to no_context()
Date: Tue, 25 Aug 2020 21:39:00 +0300 [thread overview]
Message-ID: <20200825183907.275950-2-penberg@gmail.com> (raw)
In-Reply-To: <20200825183907.275950-1-penberg@gmail.com>
From: Pekka Enberg <penberg@kernel.org>
This patch moves the no context handling in do_page_fault() to
no_context() function and converts gotos to calls to the new function.
---
arch/riscv/mm/fault.c | 83 +++++++++++++++++++++++++++----------------
1 file changed, 52 insertions(+), 31 deletions(-)
diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c
index f5c2e4a249eb..1612552478c5 100644
--- a/arch/riscv/mm/fault.c
+++ b/arch/riscv/mm/fault.c
@@ -19,6 +19,24 @@
#include "../kernel/head.h"
+static inline void no_context(struct pt_regs *regs, unsigned long addr)
+{
+ /* Are we prepared to handle this kernel fault? */
+ if (fixup_exception(regs))
+ return;
+
+ /*
+ * Oops. The kernel tried to access some bad page. We'll have to
+ * terminate things with extreme prejudice.
+ */
+ bust_spinlocks(1);
+ pr_alert("Unable to handle kernel %s at virtual address " REG_FMT "\n",
+ (addr < PAGE_SIZE) ? "NULL pointer dereference" :
+ "paging request", addr);
+ die(regs, "Oops");
+ do_exit(SIGKILL);
+}
+
/*
* This routine handles page faults. It determines the address and the
* problem, and then passes it off to one of the appropriate routines.
@@ -59,8 +77,10 @@ asmlinkage void do_page_fault(struct pt_regs *regs)
* If we're in an interrupt, have no user context, or are running
* in an atomic region, then we must not take the fault.
*/
- if (unlikely(faulthandler_disabled() || !mm))
- goto no_context;
+ if (unlikely(faulthandler_disabled() || !mm)) {
+ no_context(regs, addr);
+ return;
+ }
if (user_mode(regs))
flags |= FAULT_FLAG_USER;
@@ -153,21 +173,8 @@ asmlinkage void do_page_fault(struct pt_regs *regs)
return;
}
-no_context:
- /* Are we prepared to handle this kernel fault? */
- if (fixup_exception(regs))
- return;
-
- /*
- * Oops. The kernel tried to access some bad page. We'll have to
- * terminate things with extreme prejudice.
- */
- bust_spinlocks(1);
- pr_alert("Unable to handle kernel %s at virtual address " REG_FMT "\n",
- (addr < PAGE_SIZE) ? "NULL pointer dereference" :
- "paging request", addr);
- die(regs, "Oops");
- do_exit(SIGKILL);
+ no_context(regs, addr);
+ return;
/*
* We ran out of memory, call the OOM killer, and return the userspace
@@ -175,16 +182,20 @@ asmlinkage void do_page_fault(struct pt_regs *regs)
*/
out_of_memory:
mmap_read_unlock(mm);
- if (!user_mode(regs))
- goto no_context;
+ if (!user_mode(regs)) {
+ no_context(regs, addr);
+ return;
+ }
pagefault_out_of_memory();
return;
do_sigbus:
mmap_read_unlock(mm);
/* Kernel mode? Handle exceptions or die */
- if (!user_mode(regs))
- goto no_context;
+ if (!user_mode(regs)) {
+ no_context(regs, addr);
+ return;
+ }
do_trap(regs, SIGBUS, BUS_ADRERR, addr);
return;
@@ -213,19 +224,25 @@ asmlinkage void do_page_fault(struct pt_regs *regs)
pgd = (pgd_t *)pfn_to_virt(csr_read(CSR_SATP)) + index;
pgd_k = init_mm.pgd + index;
- if (!pgd_present(*pgd_k))
- goto no_context;
+ if (!pgd_present(*pgd_k)) {
+ no_context(regs, addr);
+ return;
+ }
set_pgd(pgd, *pgd_k);
p4d = p4d_offset(pgd, addr);
p4d_k = p4d_offset(pgd_k, addr);
- if (!p4d_present(*p4d_k))
- goto no_context;
+ if (!p4d_present(*p4d_k)) {
+ no_context(regs, addr);
+ return;
+ }
pud = pud_offset(p4d, addr);
pud_k = pud_offset(p4d_k, addr);
- if (!pud_present(*pud_k))
- goto no_context;
+ if (!pud_present(*pud_k)) {
+ no_context(regs, addr);
+ return;
+ }
/*
* Since the vmalloc area is global, it is unnecessary
@@ -233,8 +250,10 @@ asmlinkage void do_page_fault(struct pt_regs *regs)
*/
pmd = pmd_offset(pud, addr);
pmd_k = pmd_offset(pud_k, addr);
- if (!pmd_present(*pmd_k))
- goto no_context;
+ if (!pmd_present(*pmd_k)) {
+ no_context(regs, addr);
+ return;
+ }
set_pmd(pmd, *pmd_k);
/*
@@ -244,8 +263,10 @@ asmlinkage void do_page_fault(struct pt_regs *regs)
* silently loop forever.
*/
pte_k = pte_offset_kernel(pmd_k, addr);
- if (!pte_present(*pte_k))
- goto no_context;
+ if (!pte_present(*pte_k)) {
+ no_context(regs, addr);
+ return;
+ }
/*
* The kernel assumes that TLBs don't cache invalid
--
2.26.2
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2020-08-25 18:39 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-25 18:38 [PATCH 0/8] riscv/mm/fault: Page fault handler cleanups Pekka Enberg
2020-08-25 18:39 ` Pekka Enberg [this message]
2020-08-25 18:39 ` [PATCH 2/8] riscv/mm/fault: Move bad area handling to bad_area() Pekka Enberg
2020-08-25 18:39 ` [PATCH 3/8] riscv/mm/fault: Move vmalloc fault handling to vmalloc_fault() Pekka Enberg
2020-08-25 18:39 ` [PATCH 4/8] riscv/mm/fault: Simplify fault error handling Pekka Enberg
2020-08-25 18:39 ` [PATCH 5/8] riscv/mm/fault: Move fault error handling to mm_fault_error() Pekka Enberg
2020-08-25 18:39 ` [PATCH 6/8] riscv/mm/fault: Simplify mm_fault_error() Pekka Enberg
2020-08-25 18:39 ` [PATCH 7/8] riscv/mm/fault: Move FAULT_FLAG_WRITE handling in do_page_fault() Pekka Enberg
2020-08-25 18:39 ` [PATCH 8/8] riscv/mm/fault: Move access error check to function Pekka Enberg
2020-08-25 19:08 ` [PATCH 0/8] riscv/mm/fault: Page fault handler cleanups Pekka Enberg
2020-09-04 17:37 ` Palmer Dabbelt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200825183907.275950-2-penberg@gmail.com \
--to=penberg@gmail.com \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=penberg@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox