Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp236782imm; Fri, 21 Sep 2018 13:27:10 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYbm2AyiJRAVfXGLcC5XgpkNGUdaUq9pcjPN52vJTEKF0FhN9+Kuv1qMQjcMSwstgFyspey X-Received: by 2002:a17:902:f096:: with SMTP id go22mr46790502plb.183.1537561630768; Fri, 21 Sep 2018 13:27:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537561630; cv=none; d=google.com; s=arc-20160816; b=L1VSa4Z42RgEDCcuWQ9H6bnwrwnwG39rFkSlgL5UUAZ6ps7ED1LSx8KlMxx+cnU8hg /MtuBGZFRsxg4qE9EsCqNhOJvRX00Gp6zkwWFE5vqoGeOOhjDhWqsuQ7on15FYkId9U6 A7YtCAknXz56XlqeSoTmrWC8q2xX7TYCe2hXhQzBhE055ybtf7xeXVzvZbsosOgrscN5 Atf7mZv5SceziIBI8XNofvtBm96xkNloCTOit53oOr5H5tIsUXHSQDvLDvHhaBAR6UJm sZ1AaaybaSAcZPrmxJQWpfg34DACHbLdHFIWbboWx+c9TMg0Vhth68AiIcM6DUm0GhQt TSBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:subject:cc:to:from:date; bh=qg/ppQuHf5/90Ut2VnwRlbiBc3eChvWvSu09Iq4T2T8=; b=zkW1jBzplzMW1paJWjlPLyMgZugJF2xCL/BtQWhQ8+QXnOvgG/r+6w/Mt6AW4vI/0d 8kP5WHnzYrUjvQyyrBUOFUKS2bITSVfKwU0EHvbNvvI+uAKRAqfWJ8QpELBCfvvK2ZRS 5y6aVuYpiX/KSI2cZxp3BIh95OR9Qp8FidLNYdhn5KJRgXlTfooBpBM8U+AwblCLGZ13 cbYFengBDJlepDLuoLPfYEnhkNcjxm7bdmZbM8YFwIhmyYD+TGsosklXp/RBpLXKhH/c MSOg1F09mMfxFVLqt4zLr+RC61ln07JzV3ryeoGaBHsTIZw7ZvqpUGRZ1FTKNseD1pxz Z6VQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e8-v6si27581536plt.57.2018.09.21.13.26.54; Fri, 21 Sep 2018 13:27:10 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391467AbeIVCPq (ORCPT + 99 others); Fri, 21 Sep 2018 22:15:46 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:57312 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2391279AbeIVCPp (ORCPT ); Fri, 21 Sep 2018 22:15:45 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w8LKOFXL132559 for ; Fri, 21 Sep 2018 16:25:14 -0400 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0b-001b2d01.pphosted.com with ESMTP id 2mn6a6b74m-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Sep 2018 16:25:13 -0400 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 21 Sep 2018 14:25:12 -0600 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 21 Sep 2018 14:25:09 -0600 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w8LKP8TQ29491402 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 21 Sep 2018 13:25:09 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DDC2BC6055; Fri, 21 Sep 2018 14:25:08 -0600 (MDT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4D760C6059; Fri, 21 Sep 2018 14:25:08 -0600 (MDT) Received: from localhost (unknown [9.80.102.110]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTPS; Fri, 21 Sep 2018 14:25:07 -0600 (MDT) Date: Fri, 21 Sep 2018 17:25:05 -0300 From: Murilo Opsfelder Araujo To: Christophe Leroy Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , 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() References: <113d4a559f6eec448b253bf5f0b4f2a8ffb187af.1536327756.git.christophe.leroy@c-s.fr> <8f4de3aa04f00d67fdb5aaf90f41242197310d4d.1536327756.git.christophe.leroy@c-s.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8f4de3aa04f00d67fdb5aaf90f41242197310d4d.1536327756.git.christophe.leroy@c-s.fr> User-Agent: Mutt/1.10.1 (2018-07-13) X-TM-AS-GCONF: 00 x-cbid: 18092120-8235-0000-0000-00000E04331F X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009747; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000266; SDB=6.01091681; UDB=6.00564082; IPR=6.00871706; MB=3.00023441; MTD=3.00000008; XFM=3.00000015; UTC=2018-09-21 20:25:12 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18092120-8236-0000-0000-000042B9A72E Message-Id: <20180921202505.GB19940@kermit-br-ibm-com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-21_08:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809210197 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > Signed-off-by: Christophe Leroy Reviewed-by: Murilo Opsfelder Araujo > --- > 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 > -- Murilo