All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] powerpc/mm: tell if a bad page fault on data is read or write.
@ 2019-08-21 15:21 ` Christophe Leroy
  0 siblings, 0 replies; 10+ messages in thread
From: Christophe Leroy @ 2019-08-21 15:21 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman
  Cc: linux-kernel, linuxppc-dev

DSISR has a bit to tell if the fault is due to a read or a write.

Display it.

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
 arch/powerpc/mm/fault.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index 8432c281de92..b5047f9b5dec 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -645,6 +645,7 @@ NOKPROBE_SYMBOL(do_page_fault);
 void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
 {
 	const struct exception_table_entry *entry;
+	int is_write = page_fault_is_write(regs->dsisr);
 
 	/* Are we prepared to handle this fault?  */
 	if ((entry = search_exception_tables(regs->nip)) != NULL) {
@@ -658,9 +659,10 @@ void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
 	case 0x300:
 	case 0x380:
 	case 0xe00:
-		pr_alert("BUG: %s at 0x%08lx\n",
+		pr_alert("BUG: %s on %s at 0x%08lx\n",
 			 regs->dar < PAGE_SIZE ? "Kernel NULL pointer dereference" :
-			 "Unable to handle kernel data access", regs->dar);
+			 "Unable to handle kernel data access",
+			 is_write ? "write" : "read", regs->dar);
 		break;
 	case 0x400:
 	case 0x480:
-- 
2.13.3


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

* [PATCH] powerpc/mm: tell if a bad page fault on data is read or write.
@ 2019-08-21 15:21 ` Christophe Leroy
  0 siblings, 0 replies; 10+ messages in thread
From: Christophe Leroy @ 2019-08-21 15:21 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman
  Cc: linuxppc-dev, linux-kernel

DSISR has a bit to tell if the fault is due to a read or a write.

Display it.

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
 arch/powerpc/mm/fault.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index 8432c281de92..b5047f9b5dec 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -645,6 +645,7 @@ NOKPROBE_SYMBOL(do_page_fault);
 void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
 {
 	const struct exception_table_entry *entry;
+	int is_write = page_fault_is_write(regs->dsisr);
 
 	/* Are we prepared to handle this fault?  */
 	if ((entry = search_exception_tables(regs->nip)) != NULL) {
@@ -658,9 +659,10 @@ void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
 	case 0x300:
 	case 0x380:
 	case 0xe00:
-		pr_alert("BUG: %s at 0x%08lx\n",
+		pr_alert("BUG: %s on %s at 0x%08lx\n",
 			 regs->dar < PAGE_SIZE ? "Kernel NULL pointer dereference" :
-			 "Unable to handle kernel data access", regs->dar);
+			 "Unable to handle kernel data access",
+			 is_write ? "write" : "read", regs->dar);
 		break;
 	case 0x400:
 	case 0x480:
-- 
2.13.3


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

* Re: [PATCH] powerpc/mm: tell if a bad page fault on data is read or write.
  2019-08-21 15:21 ` Christophe Leroy
  (?)
@ 2019-08-26  5:35 ` Santosh Sivaraj
  -1 siblings, 0 replies; 10+ messages in thread
From: Santosh Sivaraj @ 2019-08-26  5:35 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras,
	Michael Ellerman
  Cc: linuxppc-dev, linux-kernel

Christophe Leroy <christophe.leroy@c-s.fr> writes:

> DSISR has a bit to tell if the fault is due to a read or a write.
>
> Display it.
>
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>

Reviewed-by: Santosh Sivaraj <santosh@fossix.org>

> ---
>  arch/powerpc/mm/fault.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
> index 8432c281de92..b5047f9b5dec 100644
> --- a/arch/powerpc/mm/fault.c
> +++ b/arch/powerpc/mm/fault.c
> @@ -645,6 +645,7 @@ NOKPROBE_SYMBOL(do_page_fault);
>  void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
>  {
>  	const struct exception_table_entry *entry;
> +	int is_write = page_fault_is_write(regs->dsisr);
>  
>  	/* Are we prepared to handle this fault?  */
>  	if ((entry = search_exception_tables(regs->nip)) != NULL) {
> @@ -658,9 +659,10 @@ void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
>  	case 0x300:
>  	case 0x380:
>  	case 0xe00:
> -		pr_alert("BUG: %s at 0x%08lx\n",
> +		pr_alert("BUG: %s on %s at 0x%08lx\n",
>  			 regs->dar < PAGE_SIZE ? "Kernel NULL pointer dereference" :
> -			 "Unable to handle kernel data access", regs->dar);
> +			 "Unable to handle kernel data access",
> +			 is_write ? "write" : "read", regs->dar);
>  		break;
>  	case 0x400:
>  	case 0x480:
> -- 
> 2.13.3

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

* Re: [PATCH] powerpc/mm: tell if a bad page fault on data is read or write.
  2019-08-21 15:21 ` Christophe Leroy
@ 2019-08-29 12:14   ` Michael Ellerman
  -1 siblings, 0 replies; 10+ messages in thread
From: Michael Ellerman @ 2019-08-29 12:14 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras
  Cc: linux-kernel, linuxppc-dev

Christophe Leroy <christophe.leroy@c-s.fr> writes:
> DSISR has a bit to tell if the fault is due to a read or a write.

Except some CPUs don't have a DSISR?

Which is why we have page_fault_is_write() that's used in
__do_page_fault().

Or is that old cruft?

I see eg. in head_40x.S we pass r5=0 for error code, and we don't set
regs->dsisr anywhere AFAICS. So it might just contain some junk.

cheers

> diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
> index 8432c281de92..b5047f9b5dec 100644
> --- a/arch/powerpc/mm/fault.c
> +++ b/arch/powerpc/mm/fault.c
> @@ -645,6 +645,7 @@ NOKPROBE_SYMBOL(do_page_fault);
>  void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
>  {
>  	const struct exception_table_entry *entry;
> +	int is_write = page_fault_is_write(regs->dsisr);
>  
>  	/* Are we prepared to handle this fault?  */
>  	if ((entry = search_exception_tables(regs->nip)) != NULL) {
> @@ -658,9 +659,10 @@ void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
>  	case 0x300:
>  	case 0x380:
>  	case 0xe00:
> -		pr_alert("BUG: %s at 0x%08lx\n",
> +		pr_alert("BUG: %s on %s at 0x%08lx\n",
>  			 regs->dar < PAGE_SIZE ? "Kernel NULL pointer dereference" :
> -			 "Unable to handle kernel data access", regs->dar);
> +			 "Unable to handle kernel data access",
> +			 is_write ? "write" : "read", regs->dar);

>  		break;
>  	case 0x400:
>  	case 0x480:
> -- 
> 2.13.3

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

* Re: [PATCH] powerpc/mm: tell if a bad page fault on data is read or write.
@ 2019-08-29 12:14   ` Michael Ellerman
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Ellerman @ 2019-08-29 12:14 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras
  Cc: linuxppc-dev, linux-kernel

Christophe Leroy <christophe.leroy@c-s.fr> writes:
> DSISR has a bit to tell if the fault is due to a read or a write.

Except some CPUs don't have a DSISR?

Which is why we have page_fault_is_write() that's used in
__do_page_fault().

Or is that old cruft?

I see eg. in head_40x.S we pass r5=0 for error code, and we don't set
regs->dsisr anywhere AFAICS. So it might just contain some junk.

cheers

> diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
> index 8432c281de92..b5047f9b5dec 100644
> --- a/arch/powerpc/mm/fault.c
> +++ b/arch/powerpc/mm/fault.c
> @@ -645,6 +645,7 @@ NOKPROBE_SYMBOL(do_page_fault);
>  void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
>  {
>  	const struct exception_table_entry *entry;
> +	int is_write = page_fault_is_write(regs->dsisr);
>  
>  	/* Are we prepared to handle this fault?  */
>  	if ((entry = search_exception_tables(regs->nip)) != NULL) {
> @@ -658,9 +659,10 @@ void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
>  	case 0x300:
>  	case 0x380:
>  	case 0xe00:
> -		pr_alert("BUG: %s at 0x%08lx\n",
> +		pr_alert("BUG: %s on %s at 0x%08lx\n",
>  			 regs->dar < PAGE_SIZE ? "Kernel NULL pointer dereference" :
> -			 "Unable to handle kernel data access", regs->dar);
> +			 "Unable to handle kernel data access",
> +			 is_write ? "write" : "read", regs->dar);

>  		break;
>  	case 0x400:
>  	case 0x480:
> -- 
> 2.13.3

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

* Re: [PATCH] powerpc/mm: tell if a bad page fault on data is read or write.
  2019-08-29 12:14   ` Michael Ellerman
@ 2019-08-29 12:59     ` Christophe Leroy
  -1 siblings, 0 replies; 10+ messages in thread
From: Christophe Leroy @ 2019-08-29 12:59 UTC (permalink / raw)
  To: Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras
  Cc: linux-kernel, linuxppc-dev



Le 29/08/2019 à 14:14, Michael Ellerman a écrit :
> Christophe Leroy <christophe.leroy@c-s.fr> writes:
>> DSISR has a bit to tell if the fault is due to a read or a write.
> 
> Except some CPUs don't have a DSISR?
> 
> Which is why we have page_fault_is_write() that's used in
> __do_page_fault().
> 
> Or is that old cruft?
> 
> I see eg. in head_40x.S we pass r5=0 for error code, and we don't set
> regs->dsisr anywhere AFAICS. So it might just contain some junk.

But then we have a problem with show_regs() as well, havent't we ?

	if (trap == 0x200 || trap == 0x300 || trap == 0x600)
#if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
		pr_cont("DEAR: "REG" ESR: "REG" ", regs->dar, regs->dsisr);
#else
		pr_cont("DAR: "REG" DSISR: %08lx ", regs->dar, regs->dsisr);
#endif

I need to look closer.

Christophe


> 
> cheers
> 
>> diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
>> index 8432c281de92..b5047f9b5dec 100644
>> --- a/arch/powerpc/mm/fault.c
>> +++ b/arch/powerpc/mm/fault.c
>> @@ -645,6 +645,7 @@ NOKPROBE_SYMBOL(do_page_fault);
>>   void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
>>   {
>>   	const struct exception_table_entry *entry;
>> +	int is_write = page_fault_is_write(regs->dsisr);
>>   
>>   	/* Are we prepared to handle this fault?  */
>>   	if ((entry = search_exception_tables(regs->nip)) != NULL) {
>> @@ -658,9 +659,10 @@ void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
>>   	case 0x300:
>>   	case 0x380:
>>   	case 0xe00:
>> -		pr_alert("BUG: %s at 0x%08lx\n",
>> +		pr_alert("BUG: %s on %s at 0x%08lx\n",
>>   			 regs->dar < PAGE_SIZE ? "Kernel NULL pointer dereference" :
>> -			 "Unable to handle kernel data access", regs->dar);
>> +			 "Unable to handle kernel data access",
>> +			 is_write ? "write" : "read", regs->dar);
> 
>>   		break;
>>   	case 0x400:
>>   	case 0x480:
>> -- 
>> 2.13.3

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

* Re: [PATCH] powerpc/mm: tell if a bad page fault on data is read or write.
@ 2019-08-29 12:59     ` Christophe Leroy
  0 siblings, 0 replies; 10+ messages in thread
From: Christophe Leroy @ 2019-08-29 12:59 UTC (permalink / raw)
  To: Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras
  Cc: linuxppc-dev, linux-kernel



Le 29/08/2019 à 14:14, Michael Ellerman a écrit :
> Christophe Leroy <christophe.leroy@c-s.fr> writes:
>> DSISR has a bit to tell if the fault is due to a read or a write.
> 
> Except some CPUs don't have a DSISR?
> 
> Which is why we have page_fault_is_write() that's used in
> __do_page_fault().
> 
> Or is that old cruft?
> 
> I see eg. in head_40x.S we pass r5=0 for error code, and we don't set
> regs->dsisr anywhere AFAICS. So it might just contain some junk.

But then we have a problem with show_regs() as well, havent't we ?

	if (trap == 0x200 || trap == 0x300 || trap == 0x600)
#if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
		pr_cont("DEAR: "REG" ESR: "REG" ", regs->dar, regs->dsisr);
#else
		pr_cont("DAR: "REG" DSISR: %08lx ", regs->dar, regs->dsisr);
#endif

I need to look closer.

Christophe


> 
> cheers
> 
>> diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
>> index 8432c281de92..b5047f9b5dec 100644
>> --- a/arch/powerpc/mm/fault.c
>> +++ b/arch/powerpc/mm/fault.c
>> @@ -645,6 +645,7 @@ NOKPROBE_SYMBOL(do_page_fault);
>>   void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
>>   {
>>   	const struct exception_table_entry *entry;
>> +	int is_write = page_fault_is_write(regs->dsisr);
>>   
>>   	/* Are we prepared to handle this fault?  */
>>   	if ((entry = search_exception_tables(regs->nip)) != NULL) {
>> @@ -658,9 +659,10 @@ void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
>>   	case 0x300:
>>   	case 0x380:
>>   	case 0xe00:
>> -		pr_alert("BUG: %s at 0x%08lx\n",
>> +		pr_alert("BUG: %s on %s at 0x%08lx\n",
>>   			 regs->dar < PAGE_SIZE ? "Kernel NULL pointer dereference" :
>> -			 "Unable to handle kernel data access", regs->dar);
>> +			 "Unable to handle kernel data access",
>> +			 is_write ? "write" : "read", regs->dar);
> 
>>   		break;
>>   	case 0x400:
>>   	case 0x480:
>> -- 
>> 2.13.3

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

* Re: [PATCH] powerpc/mm: tell if a bad page fault on data is read or write.
  2019-08-29 12:14   ` Michael Ellerman
@ 2019-08-30  7:41     ` Christophe Leroy
  -1 siblings, 0 replies; 10+ messages in thread
From: Christophe Leroy @ 2019-08-30  7:41 UTC (permalink / raw)
  To: Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras
  Cc: linux-kernel, linuxppc-dev



Le 29/08/2019 à 14:14, Michael Ellerman a écrit :
> Christophe Leroy <christophe.leroy@c-s.fr> writes:
>> DSISR has a bit to tell if the fault is due to a read or a write.
> 
> Except some CPUs don't have a DSISR?
> 
> Which is why we have page_fault_is_write() that's used in
> __do_page_fault().


And that's why I'm also using page_fault_is_write() in my patch.

> 
> Or is that old cruft?
> 
> I see eg. in head_40x.S we pass r5=0 for error code, and we don't set
> regs->dsisr anywhere AFAICS. So it might just contain some junk.


We pass r5=0 in ISI but r5=SPRN_ESR in DSI.
And r5 is also saved into _ESR(r11)

And in asm-offset.c, we have:

	STACK_PT_REGS_OFFSET(_ESR, dsisr);

So regs->dsisr has the expected content.

Christophe


> 
> cheers
> 
>> diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
>> index 8432c281de92..b5047f9b5dec 100644
>> --- a/arch/powerpc/mm/fault.c
>> +++ b/arch/powerpc/mm/fault.c
>> @@ -645,6 +645,7 @@ NOKPROBE_SYMBOL(do_page_fault);
>>   void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
>>   {
>>   	const struct exception_table_entry *entry;
>> +	int is_write = page_fault_is_write(regs->dsisr);
>>   
>>   	/* Are we prepared to handle this fault?  */
>>   	if ((entry = search_exception_tables(regs->nip)) != NULL) {
>> @@ -658,9 +659,10 @@ void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
>>   	case 0x300:
>>   	case 0x380:
>>   	case 0xe00:
>> -		pr_alert("BUG: %s at 0x%08lx\n",
>> +		pr_alert("BUG: %s on %s at 0x%08lx\n",
>>   			 regs->dar < PAGE_SIZE ? "Kernel NULL pointer dereference" :
>> -			 "Unable to handle kernel data access", regs->dar);
>> +			 "Unable to handle kernel data access",
>> +			 is_write ? "write" : "read", regs->dar);
> 
>>   		break;
>>   	case 0x400:
>>   	case 0x480:
>> -- 
>> 2.13.3

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

* Re: [PATCH] powerpc/mm: tell if a bad page fault on data is read or write.
@ 2019-08-30  7:41     ` Christophe Leroy
  0 siblings, 0 replies; 10+ messages in thread
From: Christophe Leroy @ 2019-08-30  7:41 UTC (permalink / raw)
  To: Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras
  Cc: linuxppc-dev, linux-kernel



Le 29/08/2019 à 14:14, Michael Ellerman a écrit :
> Christophe Leroy <christophe.leroy@c-s.fr> writes:
>> DSISR has a bit to tell if the fault is due to a read or a write.
> 
> Except some CPUs don't have a DSISR?
> 
> Which is why we have page_fault_is_write() that's used in
> __do_page_fault().


And that's why I'm also using page_fault_is_write() in my patch.

> 
> Or is that old cruft?
> 
> I see eg. in head_40x.S we pass r5=0 for error code, and we don't set
> regs->dsisr anywhere AFAICS. So it might just contain some junk.


We pass r5=0 in ISI but r5=SPRN_ESR in DSI.
And r5 is also saved into _ESR(r11)

And in asm-offset.c, we have:

	STACK_PT_REGS_OFFSET(_ESR, dsisr);

So regs->dsisr has the expected content.

Christophe


> 
> cheers
> 
>> diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
>> index 8432c281de92..b5047f9b5dec 100644
>> --- a/arch/powerpc/mm/fault.c
>> +++ b/arch/powerpc/mm/fault.c
>> @@ -645,6 +645,7 @@ NOKPROBE_SYMBOL(do_page_fault);
>>   void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
>>   {
>>   	const struct exception_table_entry *entry;
>> +	int is_write = page_fault_is_write(regs->dsisr);
>>   
>>   	/* Are we prepared to handle this fault?  */
>>   	if ((entry = search_exception_tables(regs->nip)) != NULL) {
>> @@ -658,9 +659,10 @@ void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
>>   	case 0x300:
>>   	case 0x380:
>>   	case 0xe00:
>> -		pr_alert("BUG: %s at 0x%08lx\n",
>> +		pr_alert("BUG: %s on %s at 0x%08lx\n",
>>   			 regs->dar < PAGE_SIZE ? "Kernel NULL pointer dereference" :
>> -			 "Unable to handle kernel data access", regs->dar);
>> +			 "Unable to handle kernel data access",
>> +			 is_write ? "write" : "read", regs->dar);
> 
>>   		break;
>>   	case 0x400:
>>   	case 0x480:
>> -- 
>> 2.13.3

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

* Re: [PATCH] powerpc/mm: tell if a bad page fault on data is read or write.
  2019-08-21 15:21 ` Christophe Leroy
                   ` (2 preceding siblings ...)
  (?)
@ 2019-11-25 10:46 ` Michael Ellerman
  -1 siblings, 0 replies; 10+ messages in thread
From: Michael Ellerman @ 2019-11-25 10:46 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras
  Cc: linuxppc-dev, linux-kernel

On Wed, 2019-08-21 at 15:21:55 UTC, Christophe Leroy wrote:
> DSISR has a bit to tell if the fault is due to a read or a write.
> 
> Display it.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/46ddcb3950a28c0df4815e8dbb8d4b91d5d9f22d

cheers

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

end of thread, other threads:[~2019-11-25 10:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-21 15:21 [PATCH] powerpc/mm: tell if a bad page fault on data is read or write Christophe Leroy
2019-08-21 15:21 ` Christophe Leroy
2019-08-26  5:35 ` Santosh Sivaraj
2019-08-29 12:14 ` Michael Ellerman
2019-08-29 12:14   ` Michael Ellerman
2019-08-29 12:59   ` Christophe Leroy
2019-08-29 12:59     ` Christophe Leroy
2019-08-30  7:41   ` Christophe Leroy
2019-08-30  7:41     ` Christophe Leroy
2019-11-25 10:46 ` Michael Ellerman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.