powerpc: Simplify do_sigbus
PATCH 1/3 powerpc: Simplify do_sigbus
Exit out early for a kernel fault, avoiding indenting of most of the function.
Signed-off-by Anton Blanchard <[email protected]>
--- arch/powerpc/mm/fault.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
arch/powerpc/mm/fault.c +10 -10
@@ -120,16 +120,16 @@ static int do_sigbus(struct pt_regs *regs, unsigned long address)up_read (¤t->mm->mmap_sem); -if (user_mode (regs)) { - current->thread.trap_nr =BUS_ADRERR ; - info.si_signo =SIGBUS ; - info.si_errno =0 ; - info.si_code =BUS_ADRERR ; - info.si_addr = (void __user *)address; -force_sig_info (SIGBUS , &info, current); -return MM_FAULT_RETURN ; - } -return MM_FAULT_ERR (SIGBUS ); +if (!user_mode (regs)) +return MM_FAULT_ERR (SIGBUS ); + + current->thread.trap_nr =BUS_ADRERR ; + info.si_signo =SIGBUS ; + info.si_errno =0 ; + info.si_code =BUS_ADRERR ; + info.si_addr = (void __user *)address; +force_sig_info (SIGBUS , &info, current); +return MM_FAULT_RETURN ; }static int mm_fault_error (struct pt_regs *regs,unsigned long addr,int fault)
Signature · 1 line
1.9.1
PATCH 2/3 powerpc: Add VM_FAULT_HWPOISON handling to powerpc page fault handler
do_page_fault was missing knowledge of HWPOISON, and we would oops if userspace tried to access a poisoned page:
kernel BUG at arch/powerpc/mm/fault.c:180!
Signed-off-by Anton Blanchard <[email protected]>
--- arch/powerpc/mm/fault.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
arch/powerpc/mm/fault.c +11 -6
@@ -114,7 +114,8 @@ static int store_updates_sp(struct pt_regs *regs)#define MM_FAULT_CONTINUE -1#define MM_FAULT_ERR (sig) (sig) -static int do_sigbus (struct pt_regs *regs,unsigned long address) +static int do_sigbus (struct pt_regs *regs,unsigned long address, +unsigned int fault) {siginfo_t info;
@@ -128,6 +129,13 @@ static int do_sigbus(struct pt_regs *regs, unsigned long address) info.si_errno =0 ; info.si_code =BUS_ADRERR ; info.si_addr = (void __user *)address; +#ifdef CONFIG_MEMORY_FAILURE +if (fault & (VM_FAULT_HWPOISON |VM_FAULT_HWPOISON_LARGE )) { +pr_err ("MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n" , + current->comm, current->pid, address); + info.si_code =BUS_MCEERR_AR ; + } +#endif force_sig_info (SIGBUS , &info, current);return MM_FAULT_RETURN ; }
@@ -170,11 +178,8 @@ static int mm_fault_error(struct pt_regs *regs, unsigned long addr, int fault)return MM_FAULT_RETURN ; } -/* Bus error. x86 handles HWPOISON here, we'll add this if/when -* we support the feature in HW -*/ -if (fault &VM_FAULT_SIGBUS ) -return do_sigbus (regs, addr); +if (fault & (VM_FAULT_SIGBUS |VM_FAULT_HWPOISON |VM_FAULT_HWPOISON_LARGE )) +return do_sigbus (regs, addr, fault);/* We don't understand the fault code, this is fatal */ BUG ();
Signature · 1 line
1.9.1
PATCH 3/3 powerpc: Fill in si_addr_lsb siginfo field
In reply to Anton BlanchardFill in the si_addr_lsb siginfo field so the hwpoison code can pass to userspace the length of memory that has been corrupted.
Signed-off-by Anton Blanchard <[email protected]>
--- arch/powerpc/mm/fault.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/powerpc/mm/fault.c +8 -0
@@ -33,6 +33,7 @@#include <linux/magic.h> #include <linux/ratelimit.h> #include <linux/context_tracking.h> +#include <linux/hugetlb.h> #include <asm/firmware.h> #include <asm/page.h>
@@ -118,6 +119,7 @@ static int do_sigbus(struct pt_regs *regs, unsigned long address, unsigned int fault) {siginfo_t info; +unsigned int lsb =0 ;up_read (¤t->mm->mmap_sem);
@@ -135,7 +137,13 @@ static int do_sigbus(struct pt_regs *regs, unsigned long address, current->comm, current->pid, address); info.si_code = BUS_MCEERR_AR; } + +if (fault &VM_FAULT_HWPOISON_LARGE ) + lsb =hstate_index_to_shift (VM_FAULT_GET_HINDEX (fault)); +if (fault &VM_FAULT_HWPOISON ) + lsb =PAGE_SHIFT ;#endif + info.si_addr_lsb = lsb;force_sig_info (SIGBUS , &info, current);return MM_FAULT_RETURN ; }
Signature · 1 line
1.9.1