From: Albert Esteve <aesteve@redhat.com>
To: 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>
Cc: 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>,
Albert Esteve <aesteve@redhat.com>
Subject: [PATCH v6 2/5] bug/kunit: Suppressing warning backtraces reduced impact on WARN*() sites
Date: Tue, 17 Mar 2026 10:24:42 +0100 [thread overview]
Message-ID: <20260317-kunit_add_support-v6-2-dd22aeb3fe5d@redhat.com> (raw)
In-Reply-To: <20260317-kunit_add_support-v6-0-dd22aeb3fe5d@redhat.com>
From: Alessandro Carminati <acarmina@redhat.com>
KUnit support is not consistently present across distributions, some
include it in their stock kernels, while others do not.
While both KUNIT and KUNIT_SUPPRESS_BACKTRACE can be considered debug
features, the fact that some distros ship with KUnit enabled means it's
important to minimize the runtime impact of this patch.
To that end, this patch uses static branching to minimize code size
and runtime overhead when no suppressions are active. In that case,
the static branch compiles to a single no-op instruction (5 bytes on
x86), avoiding any memory loads or branch prediction overhead. The
branch is automatically enabled when the first suppression starts and
disabled when the last suppression ends.
Signed-off-by: Alessandro Carminati <acarmina@redhat.com>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
---
lib/kunit/bug.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/lib/kunit/bug.c b/lib/kunit/bug.c
index 53c98e225a895..9c2c4ee013d92 100644
--- a/lib/kunit/bug.c
+++ b/lib/kunit/bug.c
@@ -7,17 +7,25 @@
*/
#include <kunit/bug.h>
+#include <linux/atomic.h>
#include <linux/export.h>
#include <linux/instrumentation.h>
+#include <linux/jump_label.h>
#include <linux/rculist.h>
#include <linux/string.h>
#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE
static LIST_HEAD(suppressed_warnings);
+static atomic_t suppressed_symbols_cnt = ATOMIC_INIT(0);
+
+DEFINE_STATIC_KEY_FALSE(kunit_suppress_warnings_key);
+EXPORT_SYMBOL_GPL(kunit_suppress_warnings_key);
void __kunit_start_suppress_warning(struct __suppressed_warning *warning)
{
+ if (atomic_inc_return(&suppressed_symbols_cnt) == 1)
+ static_branch_enable(&kunit_suppress_warnings_key);
list_add_rcu(&warning->node, &suppressed_warnings);
}
EXPORT_SYMBOL_GPL(__kunit_start_suppress_warning);
@@ -26,6 +34,8 @@ void __kunit_end_suppress_warning(struct __suppressed_warning *warning)
{
list_del_rcu(&warning->node);
synchronize_rcu(); /* Wait for readers to finish */
+ if (atomic_dec_return(&suppressed_symbols_cnt) == 0)
+ static_branch_disable(&kunit_suppress_warnings_key);
}
EXPORT_SYMBOL_GPL(__kunit_end_suppress_warning);
@@ -49,6 +59,8 @@ noinstr bool __kunit_is_suppressed_warning(const char *function)
{
bool ret;
+ if (!static_branch_unlikely(&kunit_suppress_warnings_key))
+ return false;
instrumentation_begin();
ret = __kunit_check_suppress(function);
instrumentation_end();
--
2.52.0
next prev parent reply other threads:[~2026-03-17 9:25 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 ` Albert Esteve [this message]
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
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=20260317-kunit_add_support-v6-2-dd22aeb3fe5d@redhat.com \
--to=aesteve@redhat.com \
--cc=acarmina@redhat.com \
--cc=airlied@gmail.com \
--cc=arnd@arndb.de \
--cc=brendan.higgins@linux.dev \
--cc=corbet@lwn.net \
--cc=david@davidgow.net \
--cc=dri-devel@lists.freedesktop.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=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=raemoar63@gmail.com \
--cc=simona@ffwll.ch \
--cc=skhan@linuxfoundation.org \
--cc=tzimmermann@suse.de \
--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