Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3692723pxb; Fri, 11 Feb 2022 05:52:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJzDM+130/j7T2J6HAex05Tqa2Oigdnt8zDb7zQSj6Xbx8qRpiYrxn/VcmRxPYliHzLtgTsq X-Received: by 2002:a17:90a:be02:: with SMTP id a2mr454734pjs.113.1644587529462; Fri, 11 Feb 2022 05:52:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644587529; cv=none; d=google.com; s=arc-20160816; b=AJVloyXP+qxQhriOYckmQyNJNyNvU7u5vntY7eaAK8TTr0X5+Ii5y+AH4IOQ9IROOC GDe3ZeOmF3brpDK2+OthRIvg4F0H/sGICK5VIQOxr29c2uFH3cxEdqiPkmzFojnTs9BL 2W0UNR57YMHKpIYD4mQtV1Rwaj7lp4qG1F8TN8pe1S+mrBHDGRaALeDWBNsz2tVfSKpm LXQmBrYfjnqiriLHEg5zMmbJ0cszXXlLy/OzVKhkINquGK2hQuvyeEQ9CxF1a1w7wKI2 7wRsRUy28/3Cq2TJ6zW0xVf7GElkFC00TRFULU19W2RP7fixlfjf4PaxjhZmtVnnYUCT LNLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=uSDjhUl1nOZHU5pEKXLZDfVBsvQRq/Com4smsm9i6gU=; b=cWI4UgOekud9HiDAlndRr1UeEgok8gYcBMmJlkbNYkzeYwM4rTSgDRetx8HLlQMPPc MFyvDs1loLSE/gmXxdKaa6o1WjcGNGs6vNkyQaxxXA3UTIj/l88SK+lp2zqHF/QnkCYy UXvOvNXb3i+MVmK4yz2sX4MMJz7sxXugCZKqpFZ3H83hg/ZlhGASO9ekigUbCGwApOu1 ABAHNLkhp7dw/MECBvPHmNQOx/YWA0YDbVJ88xbflCf7a3EP2cVCdX2QHzd+vvxfVB8Q AIru69CfecDA6L903iBXIyjUonN5UbSU4xUZAGS9PlS1NrJ9FEqkLeuu18HKcu6tSlSq 3Lzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=awKCh6S5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h23si21884064pgb.402.2022.02.11.05.51.55; Fri, 11 Feb 2022 05:52:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=awKCh6S5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345090AbiBKKeU (ORCPT + 99 others); Fri, 11 Feb 2022 05:34:20 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231628AbiBKKeT (ORCPT ); Fri, 11 Feb 2022 05:34:19 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 249C9EA6 for ; Fri, 11 Feb 2022 02:34:18 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id D53BB1F385; Fri, 11 Feb 2022 10:34:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1644575656; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=uSDjhUl1nOZHU5pEKXLZDfVBsvQRq/Com4smsm9i6gU=; b=awKCh6S5XIHwjhCiwMNtbbB4dhsqkpJwjewrf2kH+GFGJ8D/5LFZtgJTnhvy2XXB919W0q FgW/QuF5WxuCy25L0isHYaLcjBteFvymw3SHIzEFPb2kaPaOTVg5+J3a3q12XXHfRsUsk5 xp2/arpZHxZBl+XdFophoJRZydEcZcU= Received: from suse.cz (unknown [10.100.224.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 802E7A3B95; Fri, 11 Feb 2022 10:34:16 +0000 (UTC) Date: Fri, 11 Feb 2022 11:34:16 +0100 From: Petr Mladek To: John Sperbeck Cc: Steven Rostedt , John Ogness , Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [PATCH] kernel: count warnings and make count accessible to userspace Message-ID: References: <20220118060431.1368538-1-jsperbeck@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi John, I am sorry for the late reply. I had vacation last week. Many things accumulated... On Wed 2022-01-26 16:23:31, John Sperbeck wrote: > On Tue, Jan 25, 2022 at 12:52 AM Petr Mladek wrote: > > > > Adding Andrew back to Cc :-) > > > > On Sat 2022-01-22 12:58:39, John Sperbeck wrote: > > > On Wed, Jan 19, 2022 at 4:01 AM Petr Mladek wrote: > > > > > > > > Adding Andrew into Cc. Most changes in panic.c go via his tree. > > > > > > > > On Tue 2022-01-18 06:04:31, John Sperbeck wrote: > > > > > When testing, it's common to consider a warning to be a test failure, > > > > > but it's currently awkward to determine which of multiple sequential > > > > > tests is responsible for triggering a warning. Scraping dmesg or > > > > > /var/log/messages is somewhat expensive and error-prone. Setting > > > > > panic_on_warn is reliable, but spoils test runs for minor issues. > > > > > Looking at the taint bit is also reliable, but only works for a single > > > > > warning. > > > > > > > > > > We can track the warning count and expose it as a sysfs file. Test > > > > > infrastructures can snapshot the value before and after a test. If > > > > > the value changes, they can do more expensive things like extracting > > > > > logs. > > > > > > > > The counter makes sense. It might be useful even for normal debugging. > > > > It would be nice to show the value in the log. > > > > > > > > > Signed-off-by: John Sperbeck > > > > > --- > > > > > kernel/panic.c | 5 +++++ > > > > > 1 file changed, 5 insertions(+) > > > > > > > > > > diff --git a/kernel/panic.c b/kernel/panic.c > > > > > index cefd7d82366f..5262c2a0ebf4 100644 > > > > > --- a/kernel/panic.c > > > > > +++ b/kernel/panic.c > > > > > @@ -571,6 +571,8 @@ struct warn_args { > > > > > va_list args; > > > > > }; > > > > > > > > > > +static atomic_t __maybe_unused warn_counter; > > > > > + > > > > > void __warn(const char *file, int line, void *caller, unsigned taint, > > > > > struct pt_regs *regs, struct warn_args *args) > > > > > { > > > > > @@ -612,6 +614,8 @@ void __warn(const char *file, int line, void *caller, unsigned taint, > > > > > > > > > > /* Just a warning, don't kill lockdep. */ > > > > > add_taint(taint, LOCKDEP_STILL_OK); > > > > > + > > > > > + atomic_inc(&warn_counter); > > > > > } > > > > > > > > > > #ifndef __WARN_FLAGS > > > > > @@ -667,6 +671,7 @@ static __init int register_warn_debugfs(void) > > > > > /* Don't care about failure */ > > > > > debugfs_create_file_unsafe("clear_warn_once", 0200, NULL, NULL, > > > > > &clear_warn_once_fops); > > > > > + debugfs_create_atomic_t("warn_count", 0444, NULL, &warn_counter); > > > > > > > > Is the sysfs interface really important for you use case, please? > > > > Would the value in the log be enough? > > > > > > > > Anyway, we already count the number WARN() reports. It is quite hidden > > > > and hashed in init_oops_id()/print_oops_end_marker(). > > > > > > > > A solution would be to make this hidden counter more explicit. > > > > Something like: > > > > > > > > diff --git a/kernel/panic.c b/kernel/panic.c > > > > index cefd7d82366f..8ac19124ceb4 100644 > > > > --- a/kernel/panic.c > > > > +++ b/kernel/panic.c > > > > @@ -537,13 +537,12 @@ void oops_enter(void) > > > > * 64-bit random ID for oopses: > > > > */ > > > > static u64 oops_id; > > > > +static int oops_cnt; > > > > > > > > static int init_oops_id(void) > > > > { > > > > if (!oops_id) > > > > get_random_bytes(&oops_id, sizeof(oops_id)); > > > > - else > > > > - oops_id++; > > > > > > > > return 0; > > > > } > > > > @@ -552,7 +551,9 @@ late_initcall(init_oops_id); > > > > static void print_oops_end_marker(void) > > > > { > > > > init_oops_id(); > > > > - pr_warn("---[ end trace %016llx ]---\n", (unsigned long long)oops_id); > > > > + oops_cnt++; > > > > + pr_warn("---[ end trace %016llx:%d ]---\n", > > > > + (unsigned long long)oops_id, oops_cnt); > > > > } > > > > > > > > /* > > > > > > > > > > > > The report would like like: > > > > > > > > [ 1871.476204] WARNING: CPU: 2 PID: 2003 at samples/livepatch/livepatch-sample.c:60 livepatch_init+0x11/0x20 [livepatch_sample] > > > > [ 1871.476905] Modules linked in: livepatch_sample(EK+) [last unloaded: livepatch_sample] > > > > [ 1871.477509] CPU: 2 PID: 2003 Comm: modprobe Tainted: G W E K 5.16.0-default+ #312 > > > > [ 1871.478175] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.12.0-59-gc9ba527-rebuilt.opensuse.org 04/01/2014 > > > > [ 1871.478858] RIP: 0010:livepatch_init+0x11/0x20 [livepatch_sample] > > > > [...] > > > > [ 1871.489801] hardirqs last disabled at (9188): [] vprintk_emit+0x21e/0x2b0 > > > > [ 1871.489803] softirqs last enabled at (9096): [] __do_softirq+0x364/0x4ab > > > > [ 1871.489805] softirqs last disabled at (9083): [] irq_exit_rcu+0x10d/0x120 > > > > [ 1871.489807] ---[ end trace a19f0f55262cfcc8:2 ]--- > > > > > > > > Best Regards, > > > > Petr > > > > > > Thanks for adding the CC. > > > > > > The sysfs interface was kind of the main thing I'm after. The intent is > > > to avoid parsing logs unless something interesting is likely to be there. > > > > > > If we were to rely entirely on log parsing, adding a count to the logs > > > doesn't add much, I think. That is, if a warning is parsed, then we > > > already know it occurred, and don't need the counter value in the message > > > that we parsed to tell us what we just discovered. > > > > Fair enough. > > > > > I see some precedent for exposing counts for things like this: lockdep, > > > kfence, DMA-API debug. Warnings, KASAN, and UBSAN are some areas that > > > don't have this convenience. > > > > I see. > > > > > If the sysfs interface isn't palatable, that's okay. Supporting a > > > three-line patch locally isn't a tremendous burden. > > > > I am not against the debugfs interface. The counter might be useful. > > > > Well, I would still combine it with my proposal. The number of > > warnings is already "counted" by the number printed in > > 'end trace XXXXXXXXXXXXXX' line. It does not make sense to > > add yet another counter. > > > > Best Regards, > > Petr > > I'm not sure I understand the comment that it doesn't make sense to > add yet another counter? Isn't the alternate proposal to add > 'oops_cnt' adding a counter? The 2nd counter is already there. 'oops_id' is initialized with a random number but it is always incremented when print_oops_end_marker() is called. I though that 'oops_id' should be incremented together with your 'warn_count' to keep them in sync. But I see that print_oops_end_marker() is called in various situations when a backtrace is printed. I agree that we need another counter for __warn() calls. > Also, is a simple 'int' adequate? Are there any concerns about > multiple CPUs calling warn at the same time? Yes, it should be atomic to avoid any race. But oops_id is 'int'. Also oops_in_progress is simple 'int'. And it seems to be good enough. Well, it makes sense to do it properly when introducing new counter. The patch makes sense after all. Feel free to use: Acked-by: Petr Mladek Andrew, do you want to take it via -mm tree? Best Regards, Petr