linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Murilo Opsfelder Araujo <muriloo@linux.ibm.com>
To: Christophe Leroy <christophe.leroy@c-s.fr>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v3 2/3] powerpc/process: fix interleaved output in show_user_instructions()
Date: Fri, 21 Sep 2018 17:25:05 -0300	[thread overview]
Message-ID: <20180921202505.GB19940@kermit-br-ibm-com> (raw)
In-Reply-To: <8f4de3aa04f00d67fdb5aaf90f41242197310d4d.1536327756.git.christophe.leroy@c-s.fr>

On Fri, Sep 07, 2018 at 01:47:31PM +0000, Christophe Leroy wrote:
> When two processes crash at the same time, we sometimes encounter
> interleaving in the middle of a line:
> 
> [    4.365317] init[1]: segfault (11) at 0 nip 0 lr 0 code 1
> [    4.370452] init[1]: code: XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
> [    4.372042] init[74]: segfault (11) at 10a74 nip 1000c198 lr 100078c8 code 1 in sh[10000000+14000]
> [    4.386829] XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
> [    4.391542] init[1]: code: XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
> [    4.400863] init[74]: code: 90010024 bf61000c 91490a7c 3fa01002 3be00000 7d3e4b78 3bbd0c20 3b600000
> [    4.409867] init[74]: code: 3b9d0040 7c7fe02e 2f830000 419e0028 <89230000> 2f890000 41be001c 4b7f6e79
> 
> This patch fixes it by preparing complete lines in a buffer and
> printing it at once.
> 
> Fixes: 88b0fe1757359 ("powerpc: Add show_user_instructions()")
> Cc: Murilo Opsfelder Araujo <muriloo@linux.ibm.com>
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>

Reviewed-by: Murilo Opsfelder Araujo <muriloo@linux.ibm.com>

> ---
>  v3: no change
>  v2: Using seq_buf and reworked the loop to avoid redundant prints.
> 
>  arch/powerpc/kernel/process.c | 37 +++++++++++++++++++------------------
>  1 file changed, 19 insertions(+), 18 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
> index e108e1ef2b85..2a39f7aca846 100644
> --- a/arch/powerpc/kernel/process.c
> +++ b/arch/powerpc/kernel/process.c
> @@ -43,6 +43,7 @@
>  #include <linux/uaccess.h>
>  #include <linux/elf-randomize.h>
>  #include <linux/pkeys.h>
> +#include <linux/seq_buf.h>
>  
>  #include <asm/pgtable.h>
>  #include <asm/io.h>
> @@ -1303,33 +1304,33 @@ static void show_instructions(struct pt_regs *regs)
>  void show_user_instructions(struct pt_regs *regs)
>  {
>  	unsigned long pc;
> -	int i;
> +	int n = instructions_to_print;
> +	struct seq_buf s;
> +	char buf[96]; /* enough for 8 times 9 + 2 chars */
>  
>  	pc = regs->nip - (instructions_to_print * 3 / 4 * sizeof(int));
>  
> -	pr_info("%s[%d]: code: ", current->comm, current->pid);
> +	seq_buf_init(&s, buf, sizeof(buf));
>  
> -	for (i = 0; i < instructions_to_print; i++) {
> -		int instr;
> +	while (n) {
> +		int i;
>  
> -		if (!(i % 8) && (i > 0)) {
> -			pr_cont("\n");
> -			pr_info("%s[%d]: code: ", current->comm, current->pid);
> -		}
> +		seq_buf_clear(&s);
>  
> -		if (probe_kernel_address((const void *)pc, instr)) {
> -			pr_cont("XXXXXXXX ");
> -		} else {
> -			if (regs->nip == pc)
> -				pr_cont("<%08x> ", instr);
> -			else
> -				pr_cont("%08x ", instr);
> +		for (i = 0; i < 8 && n; i++, n--, pc += sizeof(int)) {
> +			int instr;
> +
> +			if (probe_kernel_address((const void *)pc, instr)) {
> +				seq_buf_puts(&s, "XXXXXXXX ");
> +				continue;
> +			}
> +			seq_buf_printf(&s, regs->nip == pc ? "<%08x> " : "%08x ", instr);
>  		}
>  
> -		pc += sizeof(int);
> +		if (!seq_buf_has_overflowed(&s))
> +			pr_info("%s[%d]: code: %s\n", current->comm,
> +				current->pid, s.buffer);
>  	}
> -
> -	pr_cont("\n");
>  }
>  
>  struct regbit {
> -- 
> 2.13.3
> 

-- 
Murilo


  reply	other threads:[~2018-09-21 20:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-07 13:47 [PATCH v3 1/3] powerpc/process: fix casting and missing header Christophe Leroy
2018-09-07 13:47 ` [PATCH v3 2/3] powerpc/process: fix interleaved output in show_user_instructions() Christophe Leroy
2018-09-21 20:25   ` Murilo Opsfelder Araujo [this message]
2018-09-07 13:47 ` [PATCH v3 3/3] powerpc/process: Constify the number of insns printed by show instructions functions Christophe Leroy
2018-09-21 20:25   ` Murilo Opsfelder Araujo
2018-09-21 20:24 ` [PATCH v3 1/3] powerpc/process: fix casting and missing header Murilo Opsfelder Araujo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180921202505.GB19940@kermit-br-ibm-com \
    --to=muriloo@linux.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=christophe.leroy@c-s.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).