Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp702503imm; Sat, 7 Jul 2018 06:56:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf4rvyi1WRpPMrV4DEIYOGh8hsTYxBo5VRoez50dhczIx1EOtWjUE8o/Xl3TodRDXmrl35b X-Received: by 2002:a17:902:a981:: with SMTP id bh1-v6mr13912699plb.2.1530971767730; Sat, 07 Jul 2018 06:56:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530971767; cv=none; d=google.com; s=arc-20160816; b=zL/pqnvYXwtqMaOSh22BGWELhlqP/4ryc3oGhmyxbXwhO2SjcavzvlS35mIKC2TykM SROT3B/SZNKV/f/J6DK+fBmd3oSf/UIe2/GS6xglJMAF1IvYyOO8amsRpgdcIDCAnCD0 9FZUc1JFGsz6FR7umY50mmcxo8a4gQQWwTMxzlGE7GbYklzfrNvYORPpRbmYN6511cAA JnKMLjzKxFPvuQ/prdHNg+MLToOuz68sxEGWj7wm4yrPkX44TImNvIhHKliUdUqfbr7u gSZVI7NT9XeMKG7EMw31DlLwn207cbagdxSxeKJRoSfWhgTgAECL7z3CcRFFflA89Q6u RJ9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=DnQQXGOfkPAOc6f1g962uIUcXbk9TLEfW8PnYj0N6os=; b=uIYt9X8yHp4UovxpGthrdOn/rp5F/uar3L/vcMzohaP4Ldg3LaglFLDv+fhK0C28Yg MorHA2v5woUyNo60JX2yd5QuxhxIpZJHe2Ijb5I/eND/vLVp9eME3L9a6y+R6VnbEvrV 3RWPIob/sPm9WnDBJ7uYz07iMvVL4Ic2kMElwlycB//Ng4eW/pFUdd3zybU4xNn7W1Qk JOt8cbrh0U1DcKs3lubKP/gn8OEOMAzYOpyC2c3x98hW+ukFSjtpBVsatHKzhhbrezHk xdOUOmhUOLMP6oL8EY5DpKz0rk96xH673yA+NtfAe2EMm4L3Fic88qDsDzu/q2xCB2LY Lx8Q== 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 m15-v6si7037113pls.439.2018.07.07.06.55.40; Sat, 07 Jul 2018 06:56:07 -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 S1753587AbeGGNyg (ORCPT + 99 others); Sat, 7 Jul 2018 09:54:36 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:51930 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752761AbeGGNyf (ORCPT ); Sat, 7 Jul 2018 09:54:35 -0400 Received: from fsav305.sakura.ne.jp (fsav305.sakura.ne.jp [153.120.85.136]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id w67DsWmD040434; Sat, 7 Jul 2018 22:54:32 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav305.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav305.sakura.ne.jp); Sat, 07 Jul 2018 22:54:32 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav305.sakura.ne.jp) Received: from [192.168.1.8] (softbank126074194044.bbtec.net [126.74.194.44]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id w67DsRdh040336 (version=TLSv1.2 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 7 Jul 2018 22:54:32 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Subject: Re: [PATCH] x86: Avoid pr_cont() in show_opcodes() To: Ingo Molnar Cc: mingo@redhat.com, linux-kernel@vger.kernel.org, Tetsuo Handa , Andy Lutomirski , Borislav Petkov , Josh Poimboeuf , Linus Torvalds , Peter Zijlstra , Thomas Gleixner References: <1530943625-3288-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> <20180707111209.GA27768@gmail.com> From: Tetsuo Handa Message-ID: Date: Sat, 7 Jul 2018 22:54:28 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.0 MIME-Version: 1.0 In-Reply-To: <20180707111209.GA27768@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018/07/07 20:12, Ingo Molnar wrote: > > * Tetsuo Handa wrote: > >> From: Tetsuo Handa >> >> Since syzbot is confused by concurrent printk() messages [1], >> this patch changes show_opcodes() to use snprintf(). >> >> 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 > > Does this change the output? > > - If yes, could you show the before/after output in the changelog, > > - If not (i.e. if only the number of printk calls is changed, the output is the > same), could you say so in the changelog? This patch will not change the output unless multiple threads concurrently call printk(). The purpose of this patch is to help parsing kernel messages when multiple threads are concurrently calling printk() for multiple times (e.g. backtrace) by reducing pr_cont()/KERN_CONT usage. > > Also, 3*OPCODE_BUFSIZE+2+1 is 195 bytes - isn't that a bit too much on-stack > footprint? Then, we can reduce it by OPCODE_BUFSIZE bytes by unionizing opcodes[] and buf[]. From 61752cef56fad2a910f6bfd277e1b9b028aeab43 Mon Sep 17 00:00:00 2001 From: Tetsuo Handa Date: Sat, 7 Jul 2018 22:45:30 +0900 Subject: [PATCH v2] x86: Avoid pr_cont() in show_opcodes() Since syzbot is confused by concurrent printk() messages [1], this patch changes show_opcodes() to use snprintf(). By this change, the Code: line will always be printed as one line even if multiple threads concurrently called printk(). To save on-stack footprint, this patch shares opcodes[] and buf[] because we sequentially reads from opcodes[] and sequentially writes to buf[]. 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 Cc: Borislav Petkov Cc: Thomas Gleixner Cc: Peter Zijlstra Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Andy Lutomirski --- arch/x86/kernel/dumpstack.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c index 666a284..6408123 100644 --- a/arch/x86/kernel/dumpstack.c +++ b/arch/x86/kernel/dumpstack.c @@ -94,25 +94,27 @@ 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; - u8 opcodes[OPCODE_BUFSIZE]; u8 *ip; int i; - - printk("%sCode: ", loglvl); + int pos = 0; + char buf[(3 * OPCODE_BUFSIZE + 2) + 1]; + u8 *opcodes = (u8 *) buf + sizeof(buf) - OPCODE_BUFSIZE; ip = (u8 *)rip - code_prologue; if (probe_kernel_read(opcodes, ip, OPCODE_BUFSIZE)) { - pr_cont("Bad RIP value.\n"); + printk("%sCode: Bad RIP value.\n", loglvl); return; } for (i = 0; i < OPCODE_BUFSIZE; i++, ip++) { if (ip == rip) - pr_cont("<%02x> ", opcodes[i]); + pos += snprintf(buf + pos, sizeof(buf) - pos, + "<%02x> ", opcodes[i]); else - pr_cont("%02x ", opcodes[i]); + pos += snprintf(buf + pos, sizeof(buf) - pos, + "%02x ", opcodes[i]); } - pr_cont("\n"); + printk("%sCode: %s\n", loglvl, buf); } void show_ip(struct pt_regs *regs, const char *loglvl) -- 1.8.3.1