linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] powerpc: Make the code in __show_regs nice-looking
@ 2021-04-22 15:10 Xiongwei Song
  2021-04-22 15:10 ` [PATCH 2/2] powerpc: Print esr register when hitting Program Interrupt Xiongwei Song
  2021-04-22 15:27 ` [PATCH 1/2] powerpc: Make the code in __show_regs nice-looking Christophe Leroy
  0 siblings, 2 replies; 8+ messages in thread
From: Xiongwei Song @ 2021-04-22 15:10 UTC (permalink / raw)
  To: mpe, benh, paulus, christophe.leroy, npiggin, ravi.bangoria,
	mikey, aneesh.kumar, 0x7f454c46
  Cc: linuxppc-dev, linux-kernel, Xiongwei Song

From: Xiongwei Song <sxwjean@gmail.com>

Create a new function named interrupt_detail_printable to judge which
interrupts can print esr/dsisr register.

Signed-off-by: Xiongwei Song <sxwjean@gmail.com>
---
 arch/powerpc/kernel/process.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 89e34aa273e2..5c3830837f3a 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1453,9 +1453,23 @@ static void print_msr_bits(unsigned long val)
 #define REGS_PER_LINE	8
 #endif
 
+static bool interrupt_detail_printable(int trap)
+{
+	switch (trap) {
+	case INTERRUPT_MACHINE_CHECK:
+	case INTERRUPT_DATA_STORAGE:
+	case INTERRUPT_ALIGNMENT:
+		return true;
+	default:
+		return false;
+	}
+
+	return false;
+}
+
 static void __show_regs(struct pt_regs *regs)
 {
-	int i, trap;
+	int i;
 
 	printk("NIP:  "REG" LR: "REG" CTR: "REG"\n",
 	       regs->nip, regs->link, regs->ctr);
@@ -1464,12 +1478,9 @@ static void __show_regs(struct pt_regs *regs)
 	printk("MSR:  "REG" ", regs->msr);
 	print_msr_bits(regs->msr);
 	pr_cont("  CR: %08lx  XER: %08lx\n", regs->ccr, regs->xer);
-	trap = TRAP(regs);
 	if (!trap_is_syscall(regs) && cpu_has_feature(CPU_FTR_CFAR))
 		pr_cont("CFAR: "REG" ", regs->orig_gpr3);
-	if (trap == INTERRUPT_MACHINE_CHECK ||
-	    trap == INTERRUPT_DATA_STORAGE ||
-	    trap == INTERRUPT_ALIGNMENT) {
+	if (interrupt_detail_printable(TRAP(regs))) {
 		if (IS_ENABLED(CONFIG_4xx) || IS_ENABLED(CONFIG_BOOKE))
 			pr_cont("DEAR: "REG" ESR: "REG" ", regs->dar, regs->dsisr);
 		else
-- 
2.17.1


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

* [PATCH 2/2] powerpc: Print esr register when hitting Program Interrupt
  2021-04-22 15:10 [PATCH 1/2] powerpc: Make the code in __show_regs nice-looking Xiongwei Song
@ 2021-04-22 15:10 ` Xiongwei Song
  2021-04-22 15:29   ` Christophe Leroy
  2021-04-22 15:27 ` [PATCH 1/2] powerpc: Make the code in __show_regs nice-looking Christophe Leroy
  1 sibling, 1 reply; 8+ messages in thread
From: Xiongwei Song @ 2021-04-22 15:10 UTC (permalink / raw)
  To: mpe, benh, paulus, christophe.leroy, npiggin, ravi.bangoria,
	mikey, aneesh.kumar, 0x7f454c46
  Cc: linuxppc-dev, linux-kernel, Xiongwei Song

From: Xiongwei Song <sxwjean@gmail.com>

The esr register has the details of Program Interrupt on BookE/4xx cpus,
printing its value is helpful.

Signed-off-by: Xiongwei Song <sxwjean@gmail.com>
---
 arch/powerpc/kernel/process.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 5c3830837f3a..664aecf8ee2e 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1459,6 +1459,7 @@ static bool interrupt_detail_printable(int trap)
 	case INTERRUPT_MACHINE_CHECK:
 	case INTERRUPT_DATA_STORAGE:
 	case INTERRUPT_ALIGNMENT:
+	case INTERRUPT_PROGRAM:
 		return true;
 	default:
 		return false;
-- 
2.17.1


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

* Re: [PATCH 1/2] powerpc: Make the code in __show_regs nice-looking
  2021-04-22 15:10 [PATCH 1/2] powerpc: Make the code in __show_regs nice-looking Xiongwei Song
  2021-04-22 15:10 ` [PATCH 2/2] powerpc: Print esr register when hitting Program Interrupt Xiongwei Song
@ 2021-04-22 15:27 ` Christophe Leroy
  2021-04-24 14:36   ` Xiongwei Song
  1 sibling, 1 reply; 8+ messages in thread
From: Christophe Leroy @ 2021-04-22 15:27 UTC (permalink / raw)
  To: Xiongwei Song, mpe, benh, paulus, npiggin, ravi.bangoria, mikey,
	aneesh.kumar, 0x7f454c46
  Cc: linuxppc-dev, linux-kernel, Xiongwei Song



Le 22/04/2021 à 17:10, Xiongwei Song a écrit :
> From: Xiongwei Song <sxwjean@gmail.com>
> 
> Create a new function named interrupt_detail_printable to judge which
> interrupts can print esr/dsisr register.

What is the benefit of that function ? It may be interesting if the test was done at several places, 
but as it is done at only one place, I don't thing it is an improvement.

Until know, you new immediately what was the traps that would print it. Now you have to go and look 
into a sub-function.

And the name is not nice either. All other functions testing anything on the trap type are called 
trap_is_something()

Here your function would be better called something like trap_sets_dsisr()

> 
> Signed-off-by: Xiongwei Song <sxwjean@gmail.com>
> ---
>   arch/powerpc/kernel/process.c | 21 ++++++++++++++++-----
>   1 file changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
> index 89e34aa273e2..5c3830837f3a 100644
> --- a/arch/powerpc/kernel/process.c
> +++ b/arch/powerpc/kernel/process.c
> @@ -1453,9 +1453,23 @@ static void print_msr_bits(unsigned long val)
>   #define REGS_PER_LINE	8
>   #endif
>   
> +static bool interrupt_detail_printable(int trap)
> +{
> +	switch (trap) {
> +	case INTERRUPT_MACHINE_CHECK:
> +	case INTERRUPT_DATA_STORAGE:
> +	case INTERRUPT_ALIGNMENT:
> +		return true;
> +	default:
> +		return false;
> +	}
> +
> +	return false;

That's redundant with the default case inside the switch.

> +}
> +
>   static void __show_regs(struct pt_regs *regs)
>   {
> -	int i, trap;
> +	int i;
>   
>   	printk("NIP:  "REG" LR: "REG" CTR: "REG"\n",
>   	       regs->nip, regs->link, regs->ctr);
> @@ -1464,12 +1478,9 @@ static void __show_regs(struct pt_regs *regs)
>   	printk("MSR:  "REG" ", regs->msr);
>   	print_msr_bits(regs->msr);
>   	pr_cont("  CR: %08lx  XER: %08lx\n", regs->ccr, regs->xer);
> -	trap = TRAP(regs);
>   	if (!trap_is_syscall(regs) && cpu_has_feature(CPU_FTR_CFAR))
>   		pr_cont("CFAR: "REG" ", regs->orig_gpr3);
> -	if (trap == INTERRUPT_MACHINE_CHECK ||
> -	    trap == INTERRUPT_DATA_STORAGE ||
> -	    trap == INTERRUPT_ALIGNMENT) {
> +	if (interrupt_detail_printable(TRAP(regs))) {
>   		if (IS_ENABLED(CONFIG_4xx) || IS_ENABLED(CONFIG_BOOKE))
>   			pr_cont("DEAR: "REG" ESR: "REG" ", regs->dar, regs->dsisr);
>   		else
> 

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

* Re: [PATCH 2/2] powerpc: Print esr register when hitting Program Interrupt
  2021-04-22 15:10 ` [PATCH 2/2] powerpc: Print esr register when hitting Program Interrupt Xiongwei Song
@ 2021-04-22 15:29   ` Christophe Leroy
  2021-04-22 16:49     ` Christophe Leroy
  2021-04-24 13:51     ` Xiongwei Song
  0 siblings, 2 replies; 8+ messages in thread
From: Christophe Leroy @ 2021-04-22 15:29 UTC (permalink / raw)
  To: Xiongwei Song, mpe, benh, paulus, npiggin, ravi.bangoria, mikey,
	aneesh.kumar, 0x7f454c46
  Cc: linuxppc-dev, linux-kernel, Xiongwei Song



Le 22/04/2021 à 17:10, Xiongwei Song a écrit :
> From: Xiongwei Song <sxwjean@gmail.com>
> 
> The esr register has the details of Program Interrupt on BookE/4xx cpus,
> printing its value is helpful.
> 
> Signed-off-by: Xiongwei Song <sxwjean@gmail.com>
> ---
>   arch/powerpc/kernel/process.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
> index 5c3830837f3a..664aecf8ee2e 100644
> --- a/arch/powerpc/kernel/process.c
> +++ b/arch/powerpc/kernel/process.c
> @@ -1459,6 +1459,7 @@ static bool interrupt_detail_printable(int trap)
>   	case INTERRUPT_MACHINE_CHECK:
>   	case INTERRUPT_DATA_STORAGE:
>   	case INTERRUPT_ALIGNMENT:
> +	case INTERRUPT_PROGRAM:

With this, it will also print the DSISR on 8xx/6xx so it will print garbage.

8xx/6xx provide the information in SRR1. If you want to proceed, you have to do the same as in ISI: 
Copy the content of SRR1 into regs->dsisr in the assembly handler in head_book3s_32.S and in the 
instruction TLB error handler in head_8xx.S

>   		return true;
>   	default:
>   		return false;
> 

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

* Re: [PATCH 2/2] powerpc: Print esr register when hitting Program Interrupt
  2021-04-22 15:29   ` Christophe Leroy
@ 2021-04-22 16:49     ` Christophe Leroy
  2021-04-24 14:21       ` Xiongwei Song
  2021-04-24 13:51     ` Xiongwei Song
  1 sibling, 1 reply; 8+ messages in thread
From: Christophe Leroy @ 2021-04-22 16:49 UTC (permalink / raw)
  To: Xiongwei Song, mpe, benh, paulus, npiggin, ravi.bangoria, mikey,
	aneesh.kumar, 0x7f454c46
  Cc: Xiongwei Song, linuxppc-dev, linux-kernel



Le 22/04/2021 à 17:29, Christophe Leroy a écrit :
> 
> 
> Le 22/04/2021 à 17:10, Xiongwei Song a écrit :
>> From: Xiongwei Song <sxwjean@gmail.com>
>>
>> The esr register has the details of Program Interrupt on BookE/4xx cpus,
>> printing its value is helpful.
>>
>> Signed-off-by: Xiongwei Song <sxwjean@gmail.com>
>> ---
>>   arch/powerpc/kernel/process.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
>> index 5c3830837f3a..664aecf8ee2e 100644
>> --- a/arch/powerpc/kernel/process.c
>> +++ b/arch/powerpc/kernel/process.c
>> @@ -1459,6 +1459,7 @@ static bool interrupt_detail_printable(int trap)
>>       case INTERRUPT_MACHINE_CHECK:
>>       case INTERRUPT_DATA_STORAGE:
>>       case INTERRUPT_ALIGNMENT:
>> +    case INTERRUPT_PROGRAM:
> 
> With this, it will also print the DSISR on 8xx/6xx so it will print garbage.
> 
> 8xx/6xx provide the information in SRR1. If you want to proceed, you have to do the same as in ISI: 
> Copy the content of SRR1 into regs->dsisr in the assembly handler in head_book3s_32.S and in the 
> instruction TLB error handler in head_8xx.S

In fact, we already have get_reason() called by do_program_check() to retrieve the reason of the 
program check exception. Maybe it could be used to print usefull information instead of starting 
doing almost the same is another way.

Or we do as I suggested above, and we remove that get_reason() stuff. But get_reason() is also used 
by the alignment exception. So that doesn't look easy.

I don't know what the best approach is.


> 
>>           return true;
>>       default:
>>           return false;
>>

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

* Re: [PATCH 2/2] powerpc: Print esr register when hitting Program Interrupt
  2021-04-22 15:29   ` Christophe Leroy
  2021-04-22 16:49     ` Christophe Leroy
@ 2021-04-24 13:51     ` Xiongwei Song
  1 sibling, 0 replies; 8+ messages in thread
From: Xiongwei Song @ 2021-04-24 13:51 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Xiongwei Song, Michael Ellerman, Benjamin Herrenschmidt,
	Paul Mackerras, npiggin, ravi.bangoria, mikey, aneesh.kumar,
	0x7f454c46, PowerPC, Linux Kernel Mailing List

On Thu, Apr 22, 2021 at 11:29 PM Christophe Leroy
<christophe.leroy@csgroup.eu> wrote:
>
>
>
> Le 22/04/2021 à 17:10, Xiongwei Song a écrit :
> > From: Xiongwei Song <sxwjean@gmail.com>
> >
> > The esr register has the details of Program Interrupt on BookE/4xx cpus,
> > printing its value is helpful.
> >
> > Signed-off-by: Xiongwei Song <sxwjean@gmail.com>
> > ---
> >   arch/powerpc/kernel/process.c | 1 +
> >   1 file changed, 1 insertion(+)
> >
> > diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
> > index 5c3830837f3a..664aecf8ee2e 100644
> > --- a/arch/powerpc/kernel/process.c
> > +++ b/arch/powerpc/kernel/process.c
> > @@ -1459,6 +1459,7 @@ static bool interrupt_detail_printable(int trap)
> >       case INTERRUPT_MACHINE_CHECK:
> >       case INTERRUPT_DATA_STORAGE:
> >       case INTERRUPT_ALIGNMENT:
> > +     case INTERRUPT_PROGRAM:
>
> With this, it will also print the DSISR on 8xx/6xx so it will print garbage.
>
> 8xx/6xx provide the information in SRR1. If you want to proceed, you have to do the same as in ISI:
> Copy the content of SRR1 into regs->dsisr in the assembly handler in head_book3s_32.S and in the
> instruction TLB error handler in head_8xx.S

Good point.

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

* Re: [PATCH 2/2] powerpc: Print esr register when hitting Program Interrupt
  2021-04-22 16:49     ` Christophe Leroy
@ 2021-04-24 14:21       ` Xiongwei Song
  0 siblings, 0 replies; 8+ messages in thread
From: Xiongwei Song @ 2021-04-24 14:21 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Xiongwei Song, Michael Ellerman, Benjamin Herrenschmidt,
	Paul Mackerras, npiggin, ravi.bangoria, mikey, aneesh.kumar,
	0x7f454c46, PowerPC, Linux Kernel Mailing List

On Fri, Apr 23, 2021 at 12:50 AM Christophe Leroy
<christophe.leroy@csgroup.eu> wrote:
>
>
>
> Le 22/04/2021 à 17:29, Christophe Leroy a écrit :
> >
> >
> > Le 22/04/2021 à 17:10, Xiongwei Song a écrit :
> >> From: Xiongwei Song <sxwjean@gmail.com>
> >>
> >> The esr register has the details of Program Interrupt on BookE/4xx cpus,
> >> printing its value is helpful.
> >>
> >> Signed-off-by: Xiongwei Song <sxwjean@gmail.com>
> >> ---
> >>   arch/powerpc/kernel/process.c | 1 +
> >>   1 file changed, 1 insertion(+)
> >>
> >> diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
> >> index 5c3830837f3a..664aecf8ee2e 100644
> >> --- a/arch/powerpc/kernel/process.c
> >> +++ b/arch/powerpc/kernel/process.c
> >> @@ -1459,6 +1459,7 @@ static bool interrupt_detail_printable(int trap)
> >>       case INTERRUPT_MACHINE_CHECK:
> >>       case INTERRUPT_DATA_STORAGE:
> >>       case INTERRUPT_ALIGNMENT:
> >> +    case INTERRUPT_PROGRAM:
> >
> > With this, it will also print the DSISR on 8xx/6xx so it will print garbage.
> >
> > 8xx/6xx provide the information in SRR1. If you want to proceed, you have to do the same as in ISI:
> > Copy the content of SRR1 into regs->dsisr in the assembly handler in head_book3s_32.S and in the
> > instruction TLB error handler in head_8xx.S
>
> In fact, we already have get_reason() called by do_program_check() to retrieve the reason of the
> program check exception. Maybe it could be used to print usefull information instead of starting
> doing almost the same is another way.

Yes, there is the get_reason() function. But if the program interrupt
is triggered in kernel mode,
the reason can be lost , see the code below:

335 static bool exception_common(int signr, struct pt_regs *regs, int code,
 336                               unsigned long addr)
 337 {
 338         if (!user_mode(regs)) {
 339                 die("Exception in kernel mode", regs, signr);
 340                 return false;
 341         }

The third parameter(int code) of exception_common is to pass the
reason, when in kernel
mode, the "code" parameter is lost, hence I append INTERRUPT_PROGRAM here.

This is for __show_regs(), so just printing the content of the
register is fine I think.

>
> Or we do as I suggested above, and we remove that get_reason() stuff. But get_reason() is also used
> by the alignment exception. So that doesn't look easy.
>
> I don't know what the best approach is.

Is it acceptable to print the interrupt reason before invoking die()
in exception_common()?

Regards,
Xiongwei

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

* Re: [PATCH 1/2] powerpc: Make the code in __show_regs nice-looking
  2021-04-22 15:27 ` [PATCH 1/2] powerpc: Make the code in __show_regs nice-looking Christophe Leroy
@ 2021-04-24 14:36   ` Xiongwei Song
  0 siblings, 0 replies; 8+ messages in thread
From: Xiongwei Song @ 2021-04-24 14:36 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Xiongwei Song, Michael Ellerman, Benjamin Herrenschmidt,
	Paul Mackerras, npiggin, ravi.bangoria, mikey, aneesh.kumar,
	0x7f454c46, PowerPC, Linux Kernel Mailing List

On Thu, Apr 22, 2021 at 11:27 PM Christophe Leroy
<christophe.leroy@csgroup.eu> wrote:
>
>
>
> Le 22/04/2021 à 17:10, Xiongwei Song a écrit :
> > From: Xiongwei Song <sxwjean@gmail.com>
> >
> > Create a new function named interrupt_detail_printable to judge which
> > interrupts can print esr/dsisr register.
>
> What is the benefit of that function ? It may be interesting if the test was done at several places,
> but as it is done at only one place, I don't thing it is an improvement.
>
> Until know, you new immediately what was the traps that would print it. Now you have to go and look
> into a sub-function.

How about replace if statement with switch statement directly, like
the changes below:

@@ -1467,13 +1481,17 @@ static void __show_regs(struct pt_regs *regs)
        trap = TRAP(regs);
        if (!trap_is_syscall(regs) && cpu_has_feature(CPU_FTR_CFAR))
                pr_cont("CFAR: "REG" ", regs->orig_gpr3);
-       if (trap == INTERRUPT_MACHINE_CHECK ||
-           trap == INTERRUPT_DATA_STORAGE ||
-           trap == INTERRUPT_ALIGNMENT) {
+       switch(trap){
+       case INTERRUPT_MACHINE_CHECK:
+       case INTERRUPT_DATA_STORAGE:
+       case INTERRUPT_ALIGNMENT:
                if (IS_ENABLED(CONFIG_4xx) || IS_ENABLED(CONFIG_BOOKE))
                        pr_cont("DEAR: "REG" ESR: "REG" ", regs->dar,
regs->dsisr);
                else
                        pr_cont("DAR: "REG" DSISR: %08lx ", regs->dar,
regs->dsisr);
+               break;
+       default:
+               break;
        }

Thanks,
Xiongwei

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

end of thread, other threads:[~2021-04-24 14:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-22 15:10 [PATCH 1/2] powerpc: Make the code in __show_regs nice-looking Xiongwei Song
2021-04-22 15:10 ` [PATCH 2/2] powerpc: Print esr register when hitting Program Interrupt Xiongwei Song
2021-04-22 15:29   ` Christophe Leroy
2021-04-22 16:49     ` Christophe Leroy
2021-04-24 14:21       ` Xiongwei Song
2021-04-24 13:51     ` Xiongwei Song
2021-04-22 15:27 ` [PATCH 1/2] powerpc: Make the code in __show_regs nice-looking Christophe Leroy
2021-04-24 14:36   ` Xiongwei Song

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).