Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1964068imm; Fri, 7 Sep 2018 08:46:25 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaoQQWNIYrOSsrEKNvD/V/CZxbzbi94Xx61GE/Vb4ed8A6iKJ0YOqzsN41/x4uBcTt5LPVQ X-Received: by 2002:a63:3587:: with SMTP id c129-v6mr8896052pga.290.1536335185236; Fri, 07 Sep 2018 08:46:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536335185; cv=none; d=google.com; s=arc-20160816; b=xTiSytgGhbmsdoAsMnR5G8/1Ql2kDltchO26xdP2/twc0jrFy2XNJc64/TEujWjpx1 rC5sKW+oXmPB6g8lDlYpQnLWvYTCkQpGY3a68dMwSmD8N7OPC2luXtMLD2dV1Lz2K6RO Qta+nl6z89JbNvtPSnm8hgDXMJAfl9PMgceszwKhzuRElOpaZKX7rKtJFh2tWS1pjl+d S6XkPAZRkVPKKLaYiFpcynljzkOOa+4jbIsyyiM7aOSEmZERGU70Wta6PMmze4jYHJTh P4cWa28abuT0IrpduJZ8q85kKQMmTWQVzFX3LNxBPPgIKbjlxKiDNnhovx95fl4k5IDY c3CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id; bh=nAqR1E2Sz4VdTpiMFvsl+jPqcUDXQLY5Ka4EDj4tb2M=; b=BDQ6o4mxy2dSl5cG8TTj7HFRGmaNYVgp829NqzsoMkfkkQyVpkOcgQ4OuV7VjRC1xh 1OBazDU7hptUNtMsLg5QrE4H6NIf983z9Y/MKWUCokBgOaGmXxun9x1RpJKT7qvhlK2o kaRLWm2Gb/vvD1/ZlVIezoFnnufsQYofPLaZ027EAMZW+TiakwHDc+tbRumJKLMWf5L+ 5qi6689eHpLVLtiRJPSoPH1LI3FzOWgPiMmLzVyukGupw0jMdgrGDTNsUX4tmOwg89nU VBbNFOLjVwQBSfzo9HWTJ4yk5QvB801cmJPWWzhjECoRGAAcM1GiR0wD4UG2ZX4En1gV YQcw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3-v6si8265197pgc.122.2018.09.07.08.46.10; Fri, 07 Sep 2018 08:46:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729751AbeIGS2g (ORCPT + 99 others); Fri, 7 Sep 2018 14:28:36 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:11745 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729759AbeIGS2f (ORCPT ); Fri, 7 Sep 2018 14:28:35 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 426Jf81WqVz9ttFV; Fri, 7 Sep 2018 15:47:28 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id gvveKOW7ZczI; Fri, 7 Sep 2018 15:47:28 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 426Jf81275z9ttFK; Fri, 7 Sep 2018 15:47:28 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id CAA788B950; Fri, 7 Sep 2018 15:47:31 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id tih4xwaLPVHG; Fri, 7 Sep 2018 15:47:31 +0200 (CEST) Received: from pc16082vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.3]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8E98E8B94C; Fri, 7 Sep 2018 15:47:31 +0200 (CEST) Received: by pc16082vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 88A41718AB; Fri, 7 Sep 2018 13:47:31 +0000 (UTC) Message-Id: <8f4de3aa04f00d67fdb5aaf90f41242197310d4d.1536327756.git.christophe.leroy@c-s.fr> In-Reply-To: <113d4a559f6eec448b253bf5f0b4f2a8ffb187af.1536327756.git.christophe.leroy@c-s.fr> References: <113d4a559f6eec448b253bf5f0b4f2a8ffb187af.1536327756.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [PATCH v3 2/3] powerpc/process: fix interleaved output in show_user_instructions() To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , muriloo@linux.ibm.com Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Fri, 7 Sep 2018 13:47:31 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Christophe Leroy --- 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 #include #include +#include #include #include @@ -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