linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
To: Rasmus Villemoes <mail@rasmusvillemoes.dk>,
	Ingo Molnar <mingo@kernel.org>
Cc: mingo@redhat.com, linux-kernel@vger.kernel.org,
	Tetsuo Handa <penguin-kernel@I-love.SKAURA.ne.jp>,
	Andy Lutomirski <luto@amacapital.net>,
	Borislav Petkov <bp@suse.de>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] x86: Avoid pr_cont() in show_opcodes()
Date: Tue, 17 Jul 2018 22:53:55 +0900	[thread overview]
Message-ID: <f486debf-e824-0d0c-c0c9-cf1e278ee9eb@i-love.sakura.ne.jp> (raw)
In-Reply-To: <12409dc4-c10a-d77a-f88d-165aa92b489e@rasmusvillemoes.dk>

On 2018/07/17 18:01, Rasmus Villemoes wrote:
> Why not this instead? Less stack use, less code, no intermediary
> snprintfs, no pr_cont...

Excellent! I didn't notice %ph extension.

> Not compile-tested, probably whitespace-damaged, but you get the idea.

Yes, it works well.



From 96d9d4d135994a081e54d33d23f5007c53d9b5dd Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Date: Tue, 17 Jul 2018 22:47:11 +0900
Subject: [PATCH v3] x86: Avoid pr_cont() in show_opcodes()

Since syzbot is confused by concurrent printk() messages [1],
this patch changes show_opcodes() to use %*ph format string.

When we start adding prefix to each line of printk() output,
we will be able to handle concurrent printk() messages.

[1] https://syzkaller.appspot.com/text?tag=CrashReport&x=139d342c400000

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SKAURA.ne.jp>
Signed-off-by: Rasmus Villemoes <mail@rasmusvillemoes.dk>
Cc: Borislav Petkov <bp@suse.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
---
 arch/x86/kernel/dumpstack.c | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
index 666a284..ffdd484 100644
--- a/arch/x86/kernel/dumpstack.c
+++ b/arch/x86/kernel/dumpstack.c
@@ -93,26 +93,15 @@ static void printk_stack_address(unsigned long address, int reliable,
  */
 void show_opcodes(u8 *rip, const char *loglvl)
 {
-	unsigned int code_prologue = OPCODE_BUFSIZE * 2 / 3;
+	const unsigned int prologue = OPCODE_BUFSIZE * 2 / 3;
 	u8 opcodes[OPCODE_BUFSIZE];
-	u8 *ip;
-	int i;
 
-	printk("%sCode: ", loglvl);
-
-	ip = (u8 *)rip - code_prologue;
-	if (probe_kernel_read(opcodes, ip, OPCODE_BUFSIZE)) {
-		pr_cont("Bad RIP value.\n");
-		return;
-	}
-
-	for (i = 0; i < OPCODE_BUFSIZE; i++, ip++) {
-		if (ip == rip)
-			pr_cont("<%02x> ", opcodes[i]);
-		else
-			pr_cont("%02x ", opcodes[i]);
-	}
-	pr_cont("\n");
+	if (probe_kernel_read(opcodes, rip - prologue, OPCODE_BUFSIZE))
+		printk("%sCode: Bad RIP value.\n", loglvl);
+	else
+		printk("%sCode: %*ph <%02x> %*ph\n", loglvl, prologue, opcodes,
+		       opcodes[prologue], OPCODE_BUFSIZE - prologue - 1,
+		       &opcodes[prologue + 1]);
 }
 
 void show_ip(struct pt_regs *regs, const char *loglvl)
-- 
1.8.3.1


  reply	other threads:[~2018-07-17 13:54 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-07  6:07 [PATCH] x86: Avoid pr_cont() in show_opcodes() Tetsuo Handa
2018-07-07 11:12 ` Ingo Molnar
2018-07-07 13:54   ` Tetsuo Handa
2018-07-09  8:49     ` Peter Zijlstra
2018-07-09 13:22       ` David Laight
2018-07-09 19:11       ` Josh Poimboeuf
2018-07-10 11:55         ` Tetsuo Handa
2018-07-10 16:51         ` David Laight
2018-07-10 21:08           ` Tetsuo Handa
2018-07-16 12:47     ` Tetsuo Handa
2018-07-17  9:01     ` Rasmus Villemoes
2018-07-17 13:53       ` Tetsuo Handa [this message]
2018-07-17 14:24         ` Rasmus Villemoes
2018-07-17 20:54           ` Tetsuo Handa
2018-07-17 21:19             ` Joe Perches
2018-07-18  8:41               ` Joe Perches
2018-07-17 21:07       ` Andy Shevchenko

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=f486debf-e824-0d0c-c0c9-cf1e278ee9eb@i-love.sakura.ne.jp \
    --to=penguin-kernel@i-love.sakura.ne.jp \
    --cc=bp@suse.de \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mail@rasmusvillemoes.dk \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=penguin-kernel@I-love.SKAURA.ne.jp \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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).