public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Albert Esteve <aesteve@redhat.com>
Cc: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Brendan Higgins" <brendan.higgins@linux.dev>,
	"David Gow" <david@davidgow.net>,
	"Rae Moar" <raemoar63@gmail.com>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
	linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
	dri-devel@lists.freedesktop.org, workflows@vger.kernel.org,
	linux-doc@vger.kernel.org,
	"Alessandro Carminati" <acarmina@redhat.com>,
	"Guenter Roeck" <linux@roeck-us.net>,
	"Kees Cook" <kees@kernel.org>,
	"Linux Kernel Functional Testing" <lkft@linaro.org>,
	"Dan Carpenter" <dan.carpenter@linaro.org>,
	"Maíra Canal" <mcanal@igalia.com>,
	"Simona Vetter" <simona.vetter@ffwll.ch>
Subject: Re: [PATCH v6 0/5] kunit: Add support for suppressing warning backtraces
Date: Wed, 18 Mar 2026 12:51:34 +0100	[thread overview]
Message-ID: <20260318115134.GA3738786@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <CADSE00Jy=G7HhRkb7vmFSuGFmvpGGt1TQ2NA+7XGLZ4b=g3rxQ@mail.gmail.com>

On Wed, Mar 18, 2026 at 10:25:00AM +0100, Albert Esteve wrote:

> So back to my test on this. Alessandro detailed two strategies in the
> last version, one of them (storing the function name in `struct
> bug_entry`) was already used and discarded in older iterations of this
> series. So let's focus on the other strategy, using 'kallsyms`. Let's
> assume we still store the function name when registering a new symbol
> to suppress. Otherwise, we might need to check address ranges to
> ensure bugaddr is within the function's scope, which sounds trickier?

> With `kallsyms` we can infer the originating functionid. But this
> approach works unreliably with compiler-induced transformations (e.g.,
> inlining, cloning, code fragmentation). And we still cannot prevent
> all output. 

> Additionally, we would need to prevent prints in
> `warn_slowpath_fmt()`. There may be other `printk`s embedded in the
> macros, but let's focus on suppressing all warnings as a best effort.
> It would already improve the quality of life for testers.

warn_slowpath_fmt() should be completely unused on x86, s390 and
possibly others. But sure.

> Considering these remaining issues, I managed to create a centralised
> proposal. Please find the main changes at the bottom of this message.
> 
> But again, even with these, the solution remains unreliable. We can
> mitigate this by registering the test name on the suppression list (at
> least, I can make the new test in this series pass with that). Not
> ideal, but we could mention it in the documentation. Something like
> "Suppression is matched by the function where the warning is reported.
> If the warning is triggered from a helper (or the compiler inlines it
> into the test), that function name may differ. In that case, register
> and start suppression for both the test and the helper so the test
> passes regardless of inlining."
> 
> Would that be a more acceptable solution? Is there a better option I
> am not seeing?

Yes, definitely. This is the sort of thing I was aiming for.

Other option would be the __FILE__ and __LINE__ data, you can match
uniquely against that and not worry about the compiler transforms.
Perhaps less user friendly as a function identifier, but meh, this isn't
aimed at users anyway, but kernel devs.

The kunit userspace could even scrape the __FILE__ and __LINE__ from the
kernel it was compiled against if it so wants. It should be simple
enough to write a tool that takes the source and a function name and
outputs the relevant __FILE__ and __LINE__ thingies. All you need is a
very rudimentary C parser and we've got a ton of those around.

> diff --git a/kernel/panic.c b/kernel/panic.c
> index c78600212b6c1..3cb004a7803f4 100644
> --- a/kernel/panic.c
> +++ b/kernel/panic.c
> @@ -39,6 +39,7 @@
>  #include <linux/sys_info.h>
>  #include <trace/events/error_report.h>
>  #include <asm/sections.h>
> +#include <kunit/bug.h>
> 
>  #define PANIC_TIMER_STEP 100
>  #define PANIC_BLINK_SPD 18
> @@ -1080,9 +1081,14 @@ void __warn(const char *file, int line, void
> *caller, unsigned taint,
>  void warn_slowpath_fmt(const char *file, int line, unsigned taint,
>                        const char *fmt, ...)
>  {
> -       bool rcu = warn_rcu_enter();
> +       bool rcu;
>         struct warn_args args;
> 
> +       if (__kunit_is_suppressed_warning_at((unsigned long)__builtin_return_address(0)))
> +               return;
> +
> +       rcu = warn_rcu_enter();
> +
>         pr_warn(CUT_HERE);
> 
>         if (!fmt) {
> 
> diff --git a/lib/bug.c b/lib/bug.c
> index 623c467a8b76c..e90b038d9225e 100644
> --- a/lib/bug.c
> +++ b/lib/bug.c
> @@ -48,6 +48,7 @@
>  #include <linux/rculist.h>
>  #include <linux/ftrace.h>
>  #include <linux/context_tracking.h>
> +#include <kunit/bug.h>
> 
>  extern struct bug_entry __start___bug_table[], __stop___bug_table[];
> 
> @@ -223,6 +224,9 @@ static enum bug_trap_type __report_bug(struct
> bug_entry *bug, unsigned long buga
>         no_cut   = bug->flags & BUGFLAG_NO_CUT_HERE;
>         has_args = bug->flags & BUGFLAG_ARGS;
> 
> +       if (warning && __kunit_is_suppressed_warning_at(bugaddr))
> +               return BUG_TRAP_TYPE_WARN;
> +

I suppose there's a question here if a suppressed warn counts towards
the once logic below.

>         if (warning && once) {
>                 if (done)
>                         return BUG_TRAP_TYPE_WARN;
> 
> diff --git a/lib/kunit/bug.c b/lib/kunit/bug.c
> index 9c2c4ee013d92..13ffddb044636 100644
> --- a/lib/kunit/bug.c
> +++ b/lib/kunit/bug.c
> @@ -11,6 +11,7 @@
>  #include <linux/export.h>
>  #include <linux/instrumentation.h>
>  #include <linux/jump_label.h>
> +#include <linux/kallsyms.h>
>  #include <linux/rculist.h>
>  #include <linux/string.h>
> 
> @@ -68,4 +69,16 @@ noinstr bool __kunit_is_suppressed_warning(const
> char *function)
>  }
>  EXPORT_SYMBOL_GPL(__kunit_is_suppressed_warning);
> 
> +bool __kunit_is_suppressed_warning_at(unsigned long addr)
> +{
> +       char buf[KSYM_SYMBOL_LEN];
> +
> +       if (!static_branch_unlikely(&kunit_suppress_warnings_key))
> +               return false;

At this point you don't need this to be a static_branch either, both
callers are already in warn slowpaths and nobody cares.

> +       if (sprint_symbol_no_offset(buf, addr) <= 0)
> +               return false;
> +       return __kunit_check_suppress(buf);
> +}
> +EXPORT_SYMBOL_GPL(__kunit_is_suppressed_warning_at);

I don't think you need this export, both callers are definitely
in-kernel.

      reply	other threads:[~2026-03-18 11:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-17  9:24 [PATCH v6 0/5] kunit: Add support for suppressing warning backtraces Albert Esteve
2026-03-17  9:24 ` [PATCH v6 1/5] bug/kunit: Core " Albert Esteve
2026-03-17  9:24 ` [PATCH v6 2/5] bug/kunit: Suppressing warning backtraces reduced impact on WARN*() sites Albert Esteve
2026-03-17  9:24 ` [PATCH v6 3/5] Add unit tests to verify that warning backtrace suppression works Albert Esteve
2026-03-17  9:24 ` [PATCH v6 4/5] drm: Suppress intentional warning backtraces in scaling unit tests Albert Esteve
2026-03-17  9:24 ` [PATCH v6 5/5] kunit: Add documentation for warning backtrace suppression API Albert Esteve
2026-03-17 10:03 ` [PATCH v6 0/5] kunit: Add support for suppressing warning backtraces Dan Carpenter
2026-03-17 14:55   ` Guenter Roeck
2026-03-17 11:20 ` Vlastimil Babka (SUSE)
2026-03-17 11:30   ` Peter Zijlstra
2026-03-17 15:02     ` Guenter Roeck
2026-03-18  9:25     ` Albert Esteve
2026-03-18 11:51       ` Peter Zijlstra [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260318115134.GA3738786@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acarmina@redhat.com \
    --cc=aesteve@redhat.com \
    --cc=airlied@gmail.com \
    --cc=arnd@arndb.de \
    --cc=brendan.higgins@linux.dev \
    --cc=corbet@lwn.net \
    --cc=dan.carpenter@linaro.org \
    --cc=david@davidgow.net \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kees@kernel.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=lkft@linaro.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mcanal@igalia.com \
    --cc=mripard@kernel.org \
    --cc=raemoar63@gmail.com \
    --cc=simona.vetter@ffwll.ch \
    --cc=simona@ffwll.ch \
    --cc=skhan@linuxfoundation.org \
    --cc=tzimmermann@suse.de \
    --cc=vbabka@kernel.org \
    --cc=workflows@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox