linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] powerpc: Add VM_FAULT_HWPOISON handling to powerpc page fault handler
@ 2014-09-24  0:27 Anton Blanchard
  2014-09-24  0:27 ` [PATCH 2/2] powerpc: Fill in si_addr_lsb siginfo field Anton Blanchard
  2014-09-24  6:40 ` [PATCH 1/2] powerpc: Add VM_FAULT_HWPOISON handling to powerpc page fault handler Stephen Rothwell
  0 siblings, 2 replies; 4+ messages in thread
From: Anton Blanchard @ 2014-09-24  0:27 UTC (permalink / raw)
  To: benh, paulus, mpe; +Cc: linuxppc-dev

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 <anton@samba.org>
---
 arch/powerpc/mm/fault.c | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index 51ab9e7..c3728c1 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -114,22 +114,31 @@ 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;
 
 	up_read(&current->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;
+	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;
+
+#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;
 	}
-	return MM_FAULT_ERR(SIGBUS);
+#endif
+	force_sig_info(SIGBUS, &info, current);
+	return MM_FAULT_RETURN;
 }
 
 static int mm_fault_error(struct pt_regs *regs, unsigned long addr, int fault)
@@ -170,11 +179,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();
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] powerpc: Fill in si_addr_lsb siginfo field
  2014-09-24  0:27 [PATCH 1/2] powerpc: Add VM_FAULT_HWPOISON handling to powerpc page fault handler Anton Blanchard
@ 2014-09-24  0:27 ` Anton Blanchard
  2014-09-24  6:40 ` [PATCH 1/2] powerpc: Add VM_FAULT_HWPOISON handling to powerpc page fault handler Stephen Rothwell
  1 sibling, 0 replies; 4+ messages in thread
From: Anton Blanchard @ 2014-09-24  0:27 UTC (permalink / raw)
  To: benh, paulus, mpe; +Cc: linuxppc-dev

Fill 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 <anton@samba.org>
---
 arch/powerpc/mm/fault.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index c3728c1..3b16c58 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -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(&current->mm->mmap_sem);
 
@@ -136,7 +138,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;
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] powerpc: Add VM_FAULT_HWPOISON handling to powerpc page fault handler
  2014-09-24  0:27 [PATCH 1/2] powerpc: Add VM_FAULT_HWPOISON handling to powerpc page fault handler Anton Blanchard
  2014-09-24  0:27 ` [PATCH 2/2] powerpc: Fill in si_addr_lsb siginfo field Anton Blanchard
@ 2014-09-24  6:40 ` Stephen Rothwell
  2014-09-24  7:00   ` Anton Blanchard
  1 sibling, 1 reply; 4+ messages in thread
From: Stephen Rothwell @ 2014-09-24  6:40 UTC (permalink / raw)
  To: Anton Blanchard; +Cc: paulus, linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 838 bytes --]

Hi Anton,

On Wed, 24 Sep 2014 10:27:06 +1000 Anton Blanchard <anton@samba.org> wrote:
>
> -	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;
> +	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;

If you had done this as 2 patches (one to remove the indent and a
second to fix the actual problem), it would have been much easier to
review ...

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] powerpc: Add VM_FAULT_HWPOISON handling to powerpc page fault handler
  2014-09-24  6:40 ` [PATCH 1/2] powerpc: Add VM_FAULT_HWPOISON handling to powerpc page fault handler Stephen Rothwell
@ 2014-09-24  7:00   ` Anton Blanchard
  0 siblings, 0 replies; 4+ messages in thread
From: Anton Blanchard @ 2014-09-24  7:00 UTC (permalink / raw)
  To: Stephen Rothwell; +Cc: paulus, linuxppc-dev


Hi Stephen,

> If you had done this as 2 patches (one to remove the indent and a
> second to fix the actual problem), it would have been much easier to
> review ...

Good idea, I separated it out and resubmitted.

Anton

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-09-24  7:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-24  0:27 [PATCH 1/2] powerpc: Add VM_FAULT_HWPOISON handling to powerpc page fault handler Anton Blanchard
2014-09-24  0:27 ` [PATCH 2/2] powerpc: Fill in si_addr_lsb siginfo field Anton Blanchard
2014-09-24  6:40 ` [PATCH 1/2] powerpc: Add VM_FAULT_HWPOISON handling to powerpc page fault handler Stephen Rothwell
2014-09-24  7:00   ` Anton Blanchard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).