Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1164057pxb; Fri, 21 Jan 2022 11:12:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJxVT637x/opzxODIll9Ehl84omdZ370RkKvM/sPpWuTiwob22c0xHx/PXeM79B4NFsoT/20 X-Received: by 2002:a17:902:7297:b0:14a:9df9:6424 with SMTP id d23-20020a170902729700b0014a9df96424mr5189653pll.19.1642792354632; Fri, 21 Jan 2022 11:12:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642792354; cv=none; d=google.com; s=arc-20160816; b=0fcyKitiHki7J4BEAUa9TPx5sJ0YTp4gpnpLlO+orT/Z0XQVOOJ1UtK/Ps6HCqFIGY Y1T0OAhP5llalf6alUiUkgI7W63QgLNgxxCMJZXMj7WW415akEvvgW/OJQz/dBUifpBO UuYhSYcD/sDew27GrSydWN4q06TbbUAFz2P7SDjvpFCaGhms8jBznOJDPWaQUTHOeGhH KKkdoOs0jmJXCYrMtjZKsaIrrNl3h8+uza8PwZgBlWDLkCkTGlXKymK4b9yvjiueEaEi 37bGBjUBw709WT3VpvYVFIZq70Kd6Du3RPEhBHHktMNgoEGSRklxTCJoNhKi8fc3aOlW QS2g== 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=dMd+jDzPfFQgxkzSCXgmQcSxD69OBufpxj9V/lK7IfI=; b=vdrn7M6xbpihGw79bLNuQGteFwAGFTF+DzQtsm6UCVhzARWmokWMt8Ig+XY1dldcED OtQNZSFRjKrSopNGlBl7N1ZaKddGH6WnWWhXvFM4pvz/WkKvJmLvn4Y4M+K6wCfbUEHQ TSVq6bnMru1VxzXF6fMzNQl9o1vTpdFBuR/f/QhJTs1tPYgP0zbhMGbpE+phSYqtlCgE WjFOo5CFVmnkctgI/jtLeOE2s/WW+mkDEWgTLE6xtKcldQdePusXorZKJX5PH1Ie3QvR 3FDLbp0ymURa+UyrK2oqZ41gmrErLAK9LFMBqhgKoYE1yyzn8IkiZ9kt3bjqV1xCDz8C CPBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=GAQiAo3i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a70si4190157pge.522.2022.01.21.11.12.22; Fri, 21 Jan 2022 11:12:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=GAQiAo3i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1354397AbiASMBP (ORCPT + 99 others); Wed, 19 Jan 2022 07:01:15 -0500 Received: from smtp-out2.suse.de ([195.135.220.29]:49348 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240915AbiASMBK (ORCPT ); Wed, 19 Jan 2022 07:01:10 -0500 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 7DDF01F38B; Wed, 19 Jan 2022 12:01:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642593668; 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=dMd+jDzPfFQgxkzSCXgmQcSxD69OBufpxj9V/lK7IfI=; b=GAQiAo3iUwAGJxxVLc8jyo7I5AUA+1v4L1tBNqIZnew5cS7dPuHDKoExdHb4hx2VV2uub7 /Zy1xjDWwYQlOa47ag+lTStq0AOdhPLo/+YeNu5/zWsG9jD+pKgqCBFxIDl7wgvBRxX8to TMIQ7rbCC/roZonqbIa7pWyUhKau7Zw= 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 3340DA3B83; Wed, 19 Jan 2022 12:01:08 +0000 (UTC) Date: Wed, 19 Jan 2022 13:01:08 +0100 From: Petr Mladek To: John Sperbeck Cc: Steven Rostedt , John Ogness , 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: <20220118060431.1368538-1-jsperbeck@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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