Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3283050imm; Tue, 17 Jul 2018 02:03:51 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfda5gXTnhX7MRzgTT2k+mGzSTMdvEoI2JF+Xfzaj7Ml6r/nplfkrzTPi4NcSqscPtzAfN4 X-Received: by 2002:a62:8b0f:: with SMTP id j15-v6mr830600pfe.33.1531818231733; Tue, 17 Jul 2018 02:03:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531818231; cv=none; d=google.com; s=arc-20160816; b=Rp2T/E7pr/bPx3CrMEGLB1+LzE97J9qxvmRqdT+pZXbIDWPC2Eqmk9ZsgBcva6o3Jv BaIsrXxcUX/lEM398Rvemyl8lyossF26o1/cPWTB2L5j1rO8fxBgvFU4OEfWd5NB5OBb pK27ob8vm5s6G4fMOc2hKT7JbKVreXrQU7bsfQeBXGJInW6MaYLBz4J/S3hl55SY2eeF sMeG3CsHcXcv+ggS3ORoOJEynpS51GZ+TiQ6DvgOUmVrGiWR9N0LbYZbEEksG2istq82 aT4Xg25q70q9WCUrq8dl1L9EkklGsAxcysWVqB8Xo8JduHZz6GNym/3XHxz1d+IBG4xx fECA== 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:dkim-signature :arc-authentication-results; bh=KFYtXehKt13DaWoTpc0385WJRkOF+xkM4v6NIlC+MLE=; b=eEPkwNNMAPPtp4/0GZ5RRHIbzmo0Q9G6fMcxNeHeGzdGEAYKUX2BOrqen5192LGnYE D5x0gvLOju3ZUMHmVCDvY00fs4PTHIbm1dYSUnpGt1sWAcW5wCtVnGcg+3ub7AfoKnX/ M/7rlLCR5f7fGohzYnw2cD1s54BbWUs/6ljAzstHVPGh4OLzQaSZIFN8fCyn43EVEIZD MDbxpUTwjlWKt89PbrKjYwstwKg9ev5BcshQ3pn0OZGqIXucpW5ajf+jFY+bka5ek/iP +EfyPTtvfZmVbg4uDJ8aLVcif8YdzFFT9Z2xWEKvhZbiGZznPqbL87PFGxNEoF6uB8tE z4mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=Cwu2ChZy; 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 u134-v6si472073pfc.244.2018.07.17.02.03.13; Tue, 17 Jul 2018 02:03:51 -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; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=Cwu2ChZy; 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 S1729704AbeGQJcx (ORCPT + 99 others); Tue, 17 Jul 2018 05:32:53 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:37962 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728340AbeGQJcx (ORCPT ); Tue, 17 Jul 2018 05:32:53 -0400 Received: by mail-lf0-f67.google.com with SMTP id a4-v6so280610lff.5 for ; Tue, 17 Jul 2018 02:01:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=KFYtXehKt13DaWoTpc0385WJRkOF+xkM4v6NIlC+MLE=; b=Cwu2ChZyIY+hsMI5jBGlSxwxfD9bEA0DY/TTCrS0paHPJ9RsSvPkXM3jnZLL0C6zVi vsrXDReh4R6ycpjVYndvYq2oHIVEoEuAMCK6Wtli1IsQTww1wBnOg0OkUQ2E9yzoT/4g vty2hOAbnRqtN6D2vProw3SVbz8JeDLTuEHdo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=KFYtXehKt13DaWoTpc0385WJRkOF+xkM4v6NIlC+MLE=; b=oBbxRQPMMiaodKNkYwduuBcZ0qmwJrdze7McSsQrFr61PJZilJnpSuXwb+7DUZBoAx E524c9DxdbCEdLXxfckDGkMBUXWsqRoJsDS/jcx2dqkZJZmliddbhYIbTUabU2t4jqrw pEzz8VpggcVcPQ3R2NwA6BMvGaAOr/KgYg+eRF3Q1Lc0Hy3YWhIe2oV4ih1YbEKq342w kXpP1sPLPJ8BhPrgOtNNSATh+9ED4RVxVcgpJSmFcDNWNhx+d4KKy1z2DEotP7lxj4Hh DWYTzH9vST2YXdZtNNUz2EdXfqAKQtbZ85QqfZ4AuCM/ktc+Jd9keTL/IVzp+nVXV/5S F8Dw== X-Gm-Message-State: AOUpUlHqjZe4hTw79O3DhH4Qxx43cEtcasKeOPW83l49SyyxyabYJS3Q kKntwqoBO2jYgbAFd6uQG2pQmA== X-Received: by 2002:a19:73c9:: with SMTP id h70-v6mr668911lfk.61.1531818076543; Tue, 17 Jul 2018 02:01:16 -0700 (PDT) Received: from [172.16.11.32] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id z7-v6sm72509lfg.89.2018.07.17.02.01.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 02:01:16 -0700 (PDT) Subject: Re: [PATCH] x86: Avoid pr_cont() in show_opcodes() To: Tetsuo Handa , 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: Rasmus Villemoes Message-ID: <12409dc4-c10a-d77a-f88d-165aa92b489e@rasmusvillemoes.dk> Date: Tue, 17 Jul 2018 11:01:14 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: 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 15:54, Tetsuo Handa wrote: > 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[]. Why not this instead? Less stack use, less code, no intermediary snprintfs, no pr_cont... diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c index 666a284116ac..c881e8a757d9 100644 --- a/arch/x86/kernel/dumpstack.c +++ b/arch/x86/kernel/dumpstack.c @@ -93,26 +93,16 @@ 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; + 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"); + if (probe_kernel_read(opcodes, rip - prologue, OPCODE_BUFSIZE)) { + printk("%sCode: Bad RIP value.\n", loglvl); 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"); + printk("%sCode: %*ph <%02x> %*ph\n", loglvl, + prologue, &opcodes[0], opcodes[prologue], + OPCODE_BUFSIZE - prologue - 1, &opcodes[prologue + 1]); } void show_ip(struct pt_regs *regs, const char *loglvl) Not compile-tested, probably whitespace-damaged, but you get the idea. Rasmus