diff mbox series

[1/2] powerpc: Use seq_buf to avoid pr_cont() in __die()

Message ID 20190108120500.2547-1-mpe@ellerman.id.au (mailing list archive)
State Superseded
Headers show
Series [1/2] powerpc: Use seq_buf to avoid pr_cont() in __die() | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success next/apply_patch Successfully applied
snowpatch_ozlabs/checkpatch warning total: 0 errors, 2 warnings, 0 checks, 48 lines checked

Commit Message

Michael Ellerman Jan. 8, 2019, 12:04 p.m. UTC
Using pr_cont() risks having our output interleaved with other output
from other CPUs. Instead use a seq_buf to construct the line and then
print it as a whole.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/kernel/traps.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

Comments

Christophe Leroy Jan. 8, 2019, 12:18 p.m. UTC | #1
Le 08/01/2019 à 13:04, Michael Ellerman a écrit :
> Using pr_cont() risks having our output interleaved with other output
> from other CPUs. Instead use a seq_buf to construct the line and then
> print it as a whole.

Why not simply doing a single printk() or similar on the same model as 
X86 for instance ? 
(https://elixir.bootlin.com/linux/v5.0-rc1/source/arch/x86/kernel/dumpstack.c#L368)

Christophe

> 
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
>   arch/powerpc/kernel/traps.c | 23 ++++++++++++++++-------
>   1 file changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
> index 64936b60d521..431a86d3f772 100644
> --- a/arch/powerpc/kernel/traps.c
> +++ b/arch/powerpc/kernel/traps.c
> @@ -38,6 +38,7 @@
>   #include <linux/kdebug.h>
>   #include <linux/ratelimit.h>
>   #include <linux/context_tracking.h>
> +#include <linux/seq_buf.h>
>   #include <linux/smp.h>
>   #include <linux/console.h>
>   #include <linux/kmsg_dump.h>
> @@ -255,26 +256,34 @@ NOKPROBE_SYMBOL(oops_end);
>   
>   static int __die(const char *str, struct pt_regs *regs, long err)
>   {
> +	char buf[128]; /* enough for all flags and a long platform name */
> +	struct seq_buf s;
> +
> +	seq_buf_init(&s, buf, sizeof(buf));
> +
>   	printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter);
>   
>   	if (IS_ENABLED(CONFIG_CPU_LITTLE_ENDIAN))
> -		printk("LE ");
> +		seq_buf_puts(&s, "LE ");
>   	else
> -		printk("BE ");
> +		seq_buf_puts(&s, "BE ");
>   
>   	if (IS_ENABLED(CONFIG_PREEMPT))
> -		pr_cont("PREEMPT ");
> +		seq_buf_puts(&s, "PREEMPT ");
>   
>   	if (IS_ENABLED(CONFIG_SMP))
> -		pr_cont("SMP NR_CPUS=%d ", NR_CPUS);
> +		seq_buf_printf(&s, "SMP NR_CPUS=%d ", NR_CPUS);
>   
>   	if (debug_pagealloc_enabled())
> -		pr_cont("DEBUG_PAGEALLOC ");
> +		seq_buf_puts(&s, "DEBUG_PAGEALLOC ");
>   
>   	if (IS_ENABLED(CONFIG_NUMA))
> -		pr_cont("NUMA ");
> +		seq_buf_puts(&s, "NUMA ");
> +
> +	if (ppc_md.name)
> +		seq_buf_puts(&s, ppc_md.name);
>   
> -	pr_cont("%s\n", ppc_md.name ? ppc_md.name : "");
> +	printk("%s\n", buf);
>   
>   	if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV) == NOTIFY_STOP)
>   		return 1;
>
Michael Ellerman Jan. 10, 2019, 10:54 a.m. UTC | #2
Christophe Leroy <christophe.leroy@c-s.fr> writes:
> Le 08/01/2019 à 13:04, Michael Ellerman a écrit :
>> Using pr_cont() risks having our output interleaved with other output
>> from other CPUs. Instead use a seq_buf to construct the line and then
>> print it as a whole.
>
> Why not simply doing a single printk() or similar on the same model as 
> X86 for instance ? 
> (https://elixir.bootlin.com/linux/v5.0-rc1/source/arch/x86/kernel/dumpstack.c#L368)

Yeah we could do it that way, though it can become a bit of a mess.

In this case I guess it's not *too* bad:

	printk("%s PAGE_SIZE=%luK%s%s%s%s%s %s\n",
	       IS_ENABLED(CONFIG_CPU_LITTLE_ENDIAN) ? "LE" : "BE",
	       PAGE_SIZE / 1024,
	       IS_ENABLED(CONFIG_PREEMPT) ? " PREEMPT" : "",
	       IS_ENABLED(CONFIG_SMP) ? " SMP" : "",
	       IS_ENABLED(CONFIG_SMP) ? (" NR_CPUS=" __stringify(NR_CPUS)) : "",
	       debug_pagealloc_enabled() ? " DEBUG_PAGEALLOC" : "",
	       IS_ENABLED(CONFIG_NUMA) ? " NUMA" : "",
	       ppc_md.name ? ppc_md.name : "");

And the generated code is obviously a lot smaller.

So yeah I'll go with that. Thanks for the review.

cheers
diff mbox series

Patch

diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 64936b60d521..431a86d3f772 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -38,6 +38,7 @@ 
 #include <linux/kdebug.h>
 #include <linux/ratelimit.h>
 #include <linux/context_tracking.h>
+#include <linux/seq_buf.h>
 #include <linux/smp.h>
 #include <linux/console.h>
 #include <linux/kmsg_dump.h>
@@ -255,26 +256,34 @@  NOKPROBE_SYMBOL(oops_end);
 
 static int __die(const char *str, struct pt_regs *regs, long err)
 {
+	char buf[128]; /* enough for all flags and a long platform name */
+	struct seq_buf s;
+
+	seq_buf_init(&s, buf, sizeof(buf));
+
 	printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter);
 
 	if (IS_ENABLED(CONFIG_CPU_LITTLE_ENDIAN))
-		printk("LE ");
+		seq_buf_puts(&s, "LE ");
 	else
-		printk("BE ");
+		seq_buf_puts(&s, "BE ");
 
 	if (IS_ENABLED(CONFIG_PREEMPT))
-		pr_cont("PREEMPT ");
+		seq_buf_puts(&s, "PREEMPT ");
 
 	if (IS_ENABLED(CONFIG_SMP))
-		pr_cont("SMP NR_CPUS=%d ", NR_CPUS);
+		seq_buf_printf(&s, "SMP NR_CPUS=%d ", NR_CPUS);
 
 	if (debug_pagealloc_enabled())
-		pr_cont("DEBUG_PAGEALLOC ");
+		seq_buf_puts(&s, "DEBUG_PAGEALLOC ");
 
 	if (IS_ENABLED(CONFIG_NUMA))
-		pr_cont("NUMA ");
+		seq_buf_puts(&s, "NUMA ");
+
+	if (ppc_md.name)
+		seq_buf_puts(&s, ppc_md.name);
 
-	pr_cont("%s\n", ppc_md.name ? ppc_md.name : "");
+	printk("%s\n", buf);
 
 	if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV) == NOTIFY_STOP)
 		return 1;