From nobody Sun Apr 26 12:16:37 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FD6E81AA8 for ; Mon, 20 Apr 2026 12:29:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776688145; cv=none; b=QSCR+YAdHgZQ6HAi2gRRpCI/FHg6wirPqlqG/EnqeccnDrBL+ptVK3Y545zmV7JRffS+oHs/4Ya44xpRRPJ7re+DDlIDlEsDA+NWvvCM1zbObkYNuc/Sgy+OvRXwMdAamUefyhQJd0D/9vDuXGup1KETysCU9rEMuLoTyFppFdk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776688145; c=relaxed/simple; bh=4JF8gOEh/HS+eUiXFDV8H5Abhszo/6+xEqvSdS9CeHM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=udLZrj/lZijEZza91pJCLPaMGDHaQSZUt0nm5uIq5ZrcYPdI66PB2ivLYXdV6w2oPwPOj//mhI+dJwj3sTJcdtk6QtKDY1zigHKjiwWq7IiYcJA8LSVm3u+Cy3YLekfvHjSNAq0nFwxwtHmradPJpuAfU7qPHGAJuIqzAhNhIEE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=LYGW7RPT; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LYGW7RPT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776688142; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5N4SvvqpPGCuU/adH/G6UTKOPrktX0llzktW7X+FgjU=; b=LYGW7RPTbbGyvwT8mK65KXrLgRUnSqvtFOqJ+v3qSUuPRoqJLLLkKe6tMU/6CKrmDzLhv+ 3Xi0xTMwrEpPt0d8ONfOBcaUtdCkC+KdPUtSwVrKNL124C1QJH4Df8IB0qNBlEghgeCg8R DyEtkaQPTJn5rET6sGxEqgi/376aDpE= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-0ey2KhuUN9mfzBGbMlVSJA-1; Mon, 20 Apr 2026 08:28:58 -0400 X-MC-Unique: 0ey2KhuUN9mfzBGbMlVSJA-1 X-Mimecast-MFC-AGG-ID: 0ey2KhuUN9mfzBGbMlVSJA_1776688135 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EB2941955DE7; Mon, 20 Apr 2026 12:28:54 +0000 (UTC) Received: from [192.168.1.153] (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D4BF01956095; Mon, 20 Apr 2026 12:28:48 +0000 (UTC) From: Albert Esteve Date: Mon, 20 Apr 2026 14:28:03 +0200 Subject: [PATCH v7 1/5] bug/kunit: Core support for suppressing warning backtraces Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260420-kunit_add_support-v7-1-e8bc6e0f70de@redhat.com> References: <20260420-kunit_add_support-v7-0-e8bc6e0f70de@redhat.com> In-Reply-To: <20260420-kunit_add_support-v7-0-e8bc6e0f70de@redhat.com> To: Arnd Bergmann , Brendan Higgins , David Gow , Rae Moar , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jonathan Corbet , Shuah Khan , Andrew Morton 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, peterz@infradead.org, Alessandro Carminati , Guenter Roeck , Kees Cook , Albert Esteve X-Developer-Signature: v=1; a=ed25519-sha256; t=1776688120; l=9766; i=aesteve@redhat.com; s=20260303; h=from:subject:message-id; bh=cU5oxy+g0dVHWrerOQavnsmQiSz63wvfOWBi6ZWSwKQ=; b=9JWW2WOxVcp5V6/9UiYZcoM7smEZ5323qcNeaChqmmbB0TJUJWZz0RFJ2ug5UJUnLHmbsxQOg Hozfkn9+8lNAwI33hN9e738JCMQPmtcyFAnmzV+P7Mwg9lYXXKBXecV X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=YSFz6sOHd2L45+Fr8DIvHTi6lSIjhLZ5T+rkxspJt1s= X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 From: Alessandro Carminati Some unit tests intentionally trigger warning backtraces by passing bad parameters to kernel API functions. Such unit tests typically check the return value from such calls, not the existence of the warning backtrace. Such intentionally generated warning backtraces are neither desirable nor useful for a number of reasons: - They can result in overlooked real problems. - A warning that suddenly starts to show up in unit tests needs to be investigated and has to be marked to be ignored, for example by adjusting filter scripts. Such filters are ad hoc because there is no real standard format for warnings. On top of that, such filter scripts would require constant maintenance. Solve the problem by providing a means to identify and suppress specific warning backtraces while executing test code. Support suppressing multiple backtraces while at the same time limiting changes to generic code to the absolute minimum. Implementation details: Suppression is checked at two points in the warning path: - In warn_slowpath_fmt(), the check runs before any output, fully suppressing both message and backtrace. - In __report_bug(), the check runs before __warn() is called, suppressing the backtrace and stack dump. Note that on this path, the WARN() format message may still appear in the kernel log since __warn_printk() runs before the trap that enters __report_bug(). A helper function, `__kunit_is_suppressed_warning()`, walks an RCU-protected list of active suppressions, matching by current task. The suppression state is tied to the KUnit test lifecycle via kunit_add_action(), ensuring automatic cleanup at test exit. The list of suppressed warnings is protected with RCU to allow concurrent read access without locks. The implementation is deliberately simple and avoids architecture-specific optimizations to preserve portability. Signed-off-by: Guenter Roeck Signed-off-by: Alessandro Carminati Reviewed-by: Kees Cook Signed-off-by: Albert Esteve --- include/kunit/bug.h | 56 +++++++++++++++++++++++++++++++++++ include/kunit/test.h | 1 + kernel/panic.c | 8 ++++- lib/bug.c | 8 +++++ lib/kunit/Kconfig | 9 ++++++ lib/kunit/Makefile | 6 ++-- lib/kunit/bug.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 7 files changed, 169 insertions(+), 3 deletions(-) diff --git a/include/kunit/bug.h b/include/kunit/bug.h new file mode 100644 index 0000000000000..e52c9d21d9fe6 --- /dev/null +++ b/include/kunit/bug.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * KUnit helpers for backtrace suppression + * + * Copyright (C) 2025 Alessandro Carminati + * Copyright (C) 2024 Guenter Roeck + */ + +#ifndef _KUNIT_BUG_H +#define _KUNIT_BUG_H + +#ifndef __ASSEMBLY__ + +#include + +struct kunit; + +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE + +#include + +struct task_struct; + +struct __suppressed_warning { + struct list_head node; + struct task_struct *task; + int counter; +}; + +struct __suppressed_warning * +__kunit_start_suppress_warning(struct kunit *test); +void __kunit_end_suppress_warning(struct kunit *test, + struct __suppressed_warning *warning); +int __kunit_suppressed_warning_count(struct __suppressed_warning *warning); +bool __kunit_is_suppressed_warning(void); + +#define KUNIT_START_SUPPRESSED_WARNING(test) \ + struct __suppressed_warning *__kunit_suppress =3D \ + __kunit_start_suppress_warning(test) + +#define KUNIT_END_SUPPRESSED_WARNING(test) \ + __kunit_end_suppress_warning(test, __kunit_suppress) + +#define KUNIT_SUPPRESSED_WARNING_COUNT() \ + __kunit_suppressed_warning_count(__kunit_suppress) + +#else /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ + +#define KUNIT_START_SUPPRESSED_WARNING(test) +#define KUNIT_END_SUPPRESSED_WARNING(test) +#define KUNIT_SUPPRESSED_WARNING_COUNT() 0 +static inline bool __kunit_is_suppressed_warning(void) { return false; } + +#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ +#endif /* __ASSEMBLY__ */ +#endif /* _KUNIT_BUG_H */ diff --git a/include/kunit/test.h b/include/kunit/test.h index 9cd1594ab697d..4ec07b3fa0204 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -10,6 +10,7 @@ #define _KUNIT_TEST_H =20 #include +#include #include =20 #include diff --git a/kernel/panic.c b/kernel/panic.c index c78600212b6c1..d7a7a679f56c4 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -39,6 +39,7 @@ #include #include #include +#include =20 #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 =3D warn_rcu_enter(); + bool rcu; struct warn_args args; =20 + if (__kunit_is_suppressed_warning()) + return; + + rcu =3D warn_rcu_enter(); + pr_warn(CUT_HERE); =20 if (!fmt) { diff --git a/lib/bug.c b/lib/bug.c index 623c467a8b76c..606205c8c302f 100644 --- a/lib/bug.c +++ b/lib/bug.c @@ -48,6 +48,7 @@ #include #include #include +#include =20 extern struct bug_entry __start___bug_table[], __stop___bug_table[]; =20 @@ -223,6 +224,13 @@ static enum bug_trap_type __report_bug(struct bug_entr= y *bug, unsigned long buga no_cut =3D bug->flags & BUGFLAG_NO_CUT_HERE; has_args =3D bug->flags & BUGFLAG_ARGS; =20 + /* + * Before the once logic so suppressed warnings do not consume + * the single-fire budget of WARN_ON_ONCE(). + */ + if (warning && __kunit_is_suppressed_warning()) + return BUG_TRAP_TYPE_WARN; + if (warning && once) { if (done) return BUG_TRAP_TYPE_WARN; diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig index 498cc51e493dc..57527418fcf09 100644 --- a/lib/kunit/Kconfig +++ b/lib/kunit/Kconfig @@ -15,6 +15,15 @@ menuconfig KUNIT =20 if KUNIT =20 +config KUNIT_SUPPRESS_BACKTRACE + bool "KUnit - Enable backtrace suppression" + default y + help + Enable backtrace suppression for KUnit. If enabled, backtraces + generated intentionally by KUnit tests are suppressed. Disable + to reduce kernel image size if image size is more important than + suppression of backtraces generated by KUnit tests. + config KUNIT_DEBUGFS bool "KUnit - Enable /sys/kernel/debug/kunit debugfs representation" if != KUNIT_ALL_TESTS default KUNIT_ALL_TESTS diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 656f1fa35abcc..fe177ff3ebdef 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -16,8 +16,10 @@ ifeq ($(CONFIG_KUNIT_DEBUGFS),y) kunit-objs +=3D debugfs.o endif =20 -# KUnit 'hooks' are built-in even when KUnit is built as a module. -obj-$(if $(CONFIG_KUNIT),y) +=3D hooks.o +# KUnit 'hooks' and bug handling are built-in even when KUnit is built +# as a module. +obj-$(if $(CONFIG_KUNIT),y) +=3D hooks.o \ + bug.o =20 obj-$(CONFIG_KUNIT_TEST) +=3D kunit-test.o obj-$(CONFIG_KUNIT_TEST) +=3D platform-test.o diff --git a/lib/kunit/bug.c b/lib/kunit/bug.c new file mode 100644 index 0000000000000..356c8a5928828 --- /dev/null +++ b/lib/kunit/bug.c @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit helpers for backtrace suppression + * + * Copyright (C) 2025 Alessandro Carminati + * Copyright (C) 2024 Guenter Roeck + */ + +#include +#include +#include +#include +#include + +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE + +static LIST_HEAD(suppressed_warnings); + +static void __kunit_suppress_warning_remove(struct __suppressed_warning *w= arning) +{ + list_del_rcu(&warning->node); + synchronize_rcu(); /* Wait for readers to finish */ +} + +KUNIT_DEFINE_ACTION_WRAPPER(__kunit_suppress_warning_cleanup, + __kunit_suppress_warning_remove, + struct __suppressed_warning *); + +struct __suppressed_warning * +__kunit_start_suppress_warning(struct kunit *test) +{ + struct __suppressed_warning *warning; + int ret; + + warning =3D kunit_kzalloc(test, sizeof(*warning), GFP_KERNEL); + if (!warning) + return NULL; + + warning->task =3D current; + list_add_rcu(&warning->node, &suppressed_warnings); + + ret =3D kunit_add_action_or_reset(test, + __kunit_suppress_warning_cleanup, + warning); + if (ret) + return NULL; + + return warning; +} +EXPORT_SYMBOL_GPL(__kunit_start_suppress_warning); + +void __kunit_end_suppress_warning(struct kunit *test, + struct __suppressed_warning *warning) +{ + if (!warning) + return; + kunit_release_action(test, __kunit_suppress_warning_cleanup, warning); +} +EXPORT_SYMBOL_GPL(__kunit_end_suppress_warning); + +int __kunit_suppressed_warning_count(struct __suppressed_warning *warning) +{ + return warning ? warning->counter : 0; +} +EXPORT_SYMBOL_GPL(__kunit_suppressed_warning_count); + +bool __kunit_is_suppressed_warning(void) +{ + struct __suppressed_warning *warning; + + rcu_read_lock(); + list_for_each_entry_rcu(warning, &suppressed_warnings, node) { + if (warning->task =3D=3D current) { + warning->counter++; + rcu_read_unlock(); + return true; + } + } + rcu_read_unlock(); + + return false; +} + +#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ --=20 2.52.0 From nobody Sun Apr 26 12:16:37 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80D2639EF10 for ; Mon, 20 Apr 2026 12:29:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776688150; cv=none; b=TFck/3qB56/2VGr4IgXg7l0X5DVnpJ5NP+/zxF9SR5UuLiBCBNohh4cC5ykSER91z9Pddw+MRYvMPxqk+IH8j/X56N3i6oFzMerWbIiP3SEfMgK6vj/8WW66pC5vjVUFSn8RNbBNoV6De3aEJESh2UdWv3VhwaR6UVWnm1eKLuQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776688150; c=relaxed/simple; bh=4FL1qNZvSGv/5DGq/cbZr2lNaMcdYMM4e3KHS9MQE7Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=I0kIJMqQzyTJtSCoScBgRnKQNSWdTvAEGpSybB7rkjxmE5kflpF2daBjiBg1hDsPDeB8mO4mxSUKkgTfkK2GWx0C+IqmU8AwK9ZlUcL7A/0maef8v/rR9OwtNLR61ywCCXLqv8aW69YzEYNQqZXSy6jumcUaCaM+kwNUu+kbcGE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fpH2YCex; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fpH2YCex" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776688148; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BinESyPjYkBGzkTzM8DQoId3ZnfKuLEeV1CNBHsJlrs=; b=fpH2YCextRphMyUyNGOz19pImSoLdVe/HdRK13a8eDzqXHg9V6b0AtdkxNGBN3rGg7s1Ry ciMZAN2G+IbbQzNSUaBQjsiYbD+sM5QqxZ2VNnIDXlNmbq1dM2kVqvr4qoZax69L32cBMD ldCOw91haWqwwfPnak71RKtlPn0e1HE= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-462-7gbebslHPzGit0lhHsqkPQ-1; Mon, 20 Apr 2026 08:29:03 -0400 X-MC-Unique: 7gbebslHPzGit0lhHsqkPQ-1 X-Mimecast-MFC-AGG-ID: 7gbebslHPzGit0lhHsqkPQ_1776688141 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 711551800623; Mon, 20 Apr 2026 12:29:00 +0000 (UTC) Received: from [192.168.1.153] (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 49B12195608E; Mon, 20 Apr 2026 12:28:55 +0000 (UTC) From: Albert Esteve Date: Mon, 20 Apr 2026 14:28:04 +0200 Subject: [PATCH v7 2/5] bug/kunit: Reduce runtime impact of warning backtrace suppression Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260420-kunit_add_support-v7-2-e8bc6e0f70de@redhat.com> References: <20260420-kunit_add_support-v7-0-e8bc6e0f70de@redhat.com> In-Reply-To: <20260420-kunit_add_support-v7-0-e8bc6e0f70de@redhat.com> To: Arnd Bergmann , Brendan Higgins , David Gow , Rae Moar , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jonathan Corbet , Shuah Khan , Andrew Morton 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, peterz@infradead.org, Alessandro Carminati , Albert Esteve X-Developer-Signature: v=1; a=ed25519-sha256; t=1776688120; l=2136; i=aesteve@redhat.com; s=20260303; h=from:subject:message-id; bh=EvDxlJcVBpYxTjqabx/j+30VM9jjHc+hJIPtgz057gc=; b=j+JeD/zKKszRnXGwfEbR0r9dcHQNp/MyXjhdoyfX1FAy3fqvwC0OcnCv/UUdTcvBOsLKUBi2S dA2fZh+1VNoBwfgjSnMDrCw3A+9/UMFlFJCiT51jDA2HMIoSJPJRp4Q X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=YSFz6sOHd2L45+Fr8DIvHTi6lSIjhLZ5T+rkxspJt1s= X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 From: Alessandro Carminati 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 adds an atomic counter that tracks the number of active suppressions. __kunit_is_suppressed_warning() checks this counter first and returns immediately when no suppressions are active, avoiding RCU-protected list traversal in the common case. Signed-off-by: Alessandro Carminati Signed-off-by: Albert Esteve --- lib/kunit/bug.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/kunit/bug.c b/lib/kunit/bug.c index 356c8a5928828..a7a88f0670d44 100644 --- a/lib/kunit/bug.c +++ b/lib/kunit/bug.c @@ -8,6 +8,7 @@ =20 #include #include +#include #include #include #include @@ -15,11 +16,13 @@ #ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE =20 static LIST_HEAD(suppressed_warnings); +static atomic_t suppressed_warnings_cnt =3D ATOMIC_INIT(0); =20 static void __kunit_suppress_warning_remove(struct __suppressed_warning *w= arning) { list_del_rcu(&warning->node); synchronize_rcu(); /* Wait for readers to finish */ + atomic_dec(&suppressed_warnings_cnt); } =20 KUNIT_DEFINE_ACTION_WRAPPER(__kunit_suppress_warning_cleanup, @@ -37,6 +40,7 @@ __kunit_start_suppress_warning(struct kunit *test) return NULL; =20 warning->task =3D current; + atomic_inc(&suppressed_warnings_cnt); list_add_rcu(&warning->node, &suppressed_warnings); =20 ret =3D kunit_add_action_or_reset(test, @@ -68,6 +72,9 @@ bool __kunit_is_suppressed_warning(void) { struct __suppressed_warning *warning; =20 + if (!atomic_read(&suppressed_warnings_cnt)) + return false; + rcu_read_lock(); list_for_each_entry_rcu(warning, &suppressed_warnings, node) { if (warning->task =3D=3D current) { --=20 2.52.0 From nobody Sun Apr 26 12:16:37 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 705A139FCA5 for ; Mon, 20 Apr 2026 12:29:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776688156; cv=none; b=NtuJ8vBt0zhB2KtMARxv+ApnEjIPlCqqpiYvOnfwxNpvYzp2VBfuxrcU316ln/4s2pWP0OyP1ftNIMrjifpZUaaxECsNc4YuvBi8WA/2KQVhsmP8t0lA7wvkYkcl7XCsTr+dHvbSTsgjjcGq19b0ymje6M2l549McTkT4w120a8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776688156; c=relaxed/simple; bh=2ReGco5diB/JcWx1D3nTqkxNNlKZwwBtIlmygG3amqQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ibgSDwjC7uDQvMjNAdCldH2JVUbRPeW4XK4serHrNu+Jm3cCgfGCxxSXhvir0moWSJaLL0PyN2AP4MBrWoBCW9EXkJgIg+ZwS3Mso1BmVr3+3KUV0ZTaqBoDUYut8atQLsfF2FrsTVHsHestpxQz7mKQn3XWraNVIvsbKTFgMR8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=byVdaHN0; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="byVdaHN0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776688154; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hsLazpgDoZcx+ASK1eTTBe2uAy362phg74sYeHXc9dM=; b=byVdaHN0H59z51HfN9Den4sAjkLBJ/nejQHU9lr1ChTQFSGej5T4HWJTnGuVQw9yYQrBAl uAIi9TxwyXAGmI4WEEZWkMBnTMcXxCm75UZxsVvGvsIigK46V2kHfiw9lJYzfJAmvKxT6g wLFSIl1Ka1sEmI/NxQXeh0bM+rs4lR4= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-uOLzcwM6PmSvNgLFUozmdw-1; Mon, 20 Apr 2026 08:29:10 -0400 X-MC-Unique: uOLzcwM6PmSvNgLFUozmdw-1 X-Mimecast-MFC-AGG-ID: uOLzcwM6PmSvNgLFUozmdw_1776688147 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9FFB61955DDB; Mon, 20 Apr 2026 12:29:06 +0000 (UTC) Received: from [192.168.1.153] (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C5F5A1956095; Mon, 20 Apr 2026 12:29:00 +0000 (UTC) From: Albert Esteve Date: Mon, 20 Apr 2026 14:28:05 +0200 Subject: [PATCH v7 3/5] kunit: Add backtrace suppression self-tests Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260420-kunit_add_support-v7-3-e8bc6e0f70de@redhat.com> References: <20260420-kunit_add_support-v7-0-e8bc6e0f70de@redhat.com> In-Reply-To: <20260420-kunit_add_support-v7-0-e8bc6e0f70de@redhat.com> To: Arnd Bergmann , Brendan Higgins , David Gow , Rae Moar , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jonathan Corbet , Shuah Khan , Andrew Morton 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, peterz@infradead.org, Guenter Roeck , Linux Kernel Functional Testing , Dan Carpenter , Alessandro Carminati , Albert Esteve , Kees Cook X-Developer-Signature: v=1; a=ed25519-sha256; t=1776688120; l=4375; i=aesteve@redhat.com; s=20260303; h=from:subject:message-id; bh=vuDHildPEPNlCHogR5KyfnFhxEoODOxMc2R3mM4Q7g4=; b=ELW2SvmwsG5uXtj+qpzqCxqtNwG1LIsm1McB6sCN5QK+FOTG5/pEpAapAxC1WOUnBhwSOfayA 78HEDz1TIaDBD8o0X3gylq2LDZbflDbkE2QUYCuGRtZtRisEva92Z/E X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=YSFz6sOHd2L45+Fr8DIvHTi6lSIjhLZ5T+rkxspJt1s= X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 From: Guenter Roeck Add unit tests to verify that warning backtrace suppression works, covering WARN() and WARN_ON() with direct calls, indirect calls through helper functions, and multiple warnings in a single window. If backtrace suppression does _not_ work, the unit tests will likely trigger unsuppressed backtraces, which should actually help to get the affected architectures / platforms fixed. Tested-by: Linux Kernel Functional Testing Acked-by: Dan Carpenter Reviewed-by: Kees Cook Signed-off-by: Guenter Roeck Signed-off-by: Alessandro Carminati Signed-off-by: Albert Esteve Reviewed-by: David Gow --- lib/kunit/Makefile | 3 ++ lib/kunit/backtrace-suppression-test.c | 90 ++++++++++++++++++++++++++++++= ++++ 2 files changed, 93 insertions(+) diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index fe177ff3ebdef..b2f2b8ada7b71 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -23,6 +23,9 @@ obj-$(if $(CONFIG_KUNIT),y) +=3D hooks.o \ =20 obj-$(CONFIG_KUNIT_TEST) +=3D kunit-test.o obj-$(CONFIG_KUNIT_TEST) +=3D platform-test.o +ifeq ($(CONFIG_KUNIT_SUPPRESS_BACKTRACE),y) +obj-$(CONFIG_KUNIT_TEST) +=3D backtrace-suppression-test.o +endif =20 # string-stream-test compiles built-in only. ifeq ($(CONFIG_KUNIT_TEST),y) diff --git a/lib/kunit/backtrace-suppression-test.c b/lib/kunit/backtrace-s= uppression-test.c new file mode 100644 index 0000000000000..2ba5dcb5fef35 --- /dev/null +++ b/lib/kunit/backtrace-suppression-test.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit test for suppressing warning tracebacks. + * + * Copyright (C) 2024, Guenter Roeck + * Author: Guenter Roeck + */ + +#include +#include + +static void backtrace_suppression_test_warn_direct(struct kunit *test) +{ + KUNIT_START_SUPPRESSED_WARNING(test); + WARN(1, "This backtrace should be suppressed"); + KUNIT_END_SUPPRESSED_WARNING(test); + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(), 1); +} + +static void trigger_backtrace_warn(void) +{ + WARN(1, "This backtrace should be suppressed"); +} + +static void backtrace_suppression_test_warn_indirect(struct kunit *test) +{ + KUNIT_START_SUPPRESSED_WARNING(test); + trigger_backtrace_warn(); + KUNIT_END_SUPPRESSED_WARNING(test); + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(), 1); +} + +static void backtrace_suppression_test_warn_multi(struct kunit *test) +{ + KUNIT_START_SUPPRESSED_WARNING(test); + WARN(1, "This backtrace should be suppressed"); + trigger_backtrace_warn(); + KUNIT_END_SUPPRESSED_WARNING(test); + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(), 2); +} + +static void backtrace_suppression_test_warn_on_direct(struct kunit *test) +{ + if (!IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE) && !IS_ENABLED(CONFIG_KALLSYMS)) + kunit_skip(test, "requires CONFIG_DEBUG_BUGVERBOSE or CONFIG_KALLSYMS"); + + KUNIT_START_SUPPRESSED_WARNING(test); + WARN_ON(1); + KUNIT_END_SUPPRESSED_WARNING(test); + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(), 1); +} + +static void trigger_backtrace_warn_on(void) +{ + WARN_ON(1); +} + +static void backtrace_suppression_test_warn_on_indirect(struct kunit *test) +{ + if (!IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE)) + kunit_skip(test, "requires CONFIG_DEBUG_BUGVERBOSE"); + + KUNIT_START_SUPPRESSED_WARNING(test); + trigger_backtrace_warn_on(); + KUNIT_END_SUPPRESSED_WARNING(test); + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(), 1); +} + +static struct kunit_case backtrace_suppression_test_cases[] =3D { + KUNIT_CASE(backtrace_suppression_test_warn_direct), + KUNIT_CASE(backtrace_suppression_test_warn_indirect), + KUNIT_CASE(backtrace_suppression_test_warn_multi), + KUNIT_CASE(backtrace_suppression_test_warn_on_direct), + KUNIT_CASE(backtrace_suppression_test_warn_on_indirect), + {} +}; + +static struct kunit_suite backtrace_suppression_test_suite =3D { + .name =3D "backtrace-suppression-test", + .test_cases =3D backtrace_suppression_test_cases, +}; +kunit_test_suites(&backtrace_suppression_test_suite); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("KUnit test to verify warning backtrace suppression"); --=20 2.52.0 From nobody Sun Apr 26 12:16:37 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 192C33A1696 for ; Mon, 20 Apr 2026 12:29:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776688165; cv=none; b=CVbVgPpuj/JCOkki7xshrPdTkhCAjSr61NslCKKOd62auU0HJWR+nd8nTDLg2hAEbXU0q6Ia+ehhc+ITAlAemsGvwndjG16DsLUe3VOD0rbCfSCkyJAtRSW80GigM6rzlQ/f7x6YRk9r7sMVftih0JoRJ82cDSv9l0favCYqzx4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776688165; c=relaxed/simple; bh=dbQSC4BSME3eCMku0WzEnLwxciWEWu9GZ+riAUQr4Vs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hlm+2aTz279exUriUPKUPu/TwqtSP8kR4kVqi1Nk1hQv3zwH5uwsAFufIWIzVVD7qExpWI2V7uaZtmpKIHGLUOf6HNL7bm9/EBXyVjkeHzDYYSvQWzBoVb6Yx/cWneaIF62XKKQE9jLZlkv5BwtsxbnpfPr/zIQpj4xfRf7NmbY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hZkSzvRB; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hZkSzvRB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776688163; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x9wNNxm7+fJjttMUkZW8s7VuVwYypLZT4Qaeba7221k=; b=hZkSzvRBbGr5Dgsn/Q+sE/1ZA9iJ6WV4mK5evk7VZo4ZUnNqB8OQq4SUOHQJloaYpTPxTX DKYKf1+P3ZLH+SIAMqHaVAwPyxWf8w28lv9gJYRIn8Ppy5Z+hKlLNpLrFw0xr6mux8ggkG bF7ftPnQ0urpR5bD60RcDH9GKrd9t7s= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-433-h_fwfMKoPlSYiXvnMsViIA-1; Mon, 20 Apr 2026 08:29:16 -0400 X-MC-Unique: h_fwfMKoPlSYiXvnMsViIA-1 X-Mimecast-MFC-AGG-ID: h_fwfMKoPlSYiXvnMsViIA_1776688154 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8802519560BA; Mon, 20 Apr 2026 12:29:13 +0000 (UTC) Received: from [192.168.1.153] (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 02E55195608E; Mon, 20 Apr 2026 12:29:06 +0000 (UTC) From: Albert Esteve Date: Mon, 20 Apr 2026 14:28:06 +0200 Subject: [PATCH v7 4/5] drm: Suppress intentional warning backtraces in scaling unit tests Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260420-kunit_add_support-v7-4-e8bc6e0f70de@redhat.com> References: <20260420-kunit_add_support-v7-0-e8bc6e0f70de@redhat.com> In-Reply-To: <20260420-kunit_add_support-v7-0-e8bc6e0f70de@redhat.com> To: Arnd Bergmann , Brendan Higgins , David Gow , Rae Moar , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jonathan Corbet , Shuah Khan , Andrew Morton 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, peterz@infradead.org, Guenter Roeck , Linux Kernel Functional Testing , Dan Carpenter , =?utf-8?q?Ma=C3=ADra_Canal?= , Alessandro Carminati , Albert Esteve , Simona Vetter X-Developer-Signature: v=1; a=ed25519-sha256; t=1776688120; l=2448; i=aesteve@redhat.com; s=20260303; h=from:subject:message-id; bh=xJbFk9/mo8QSw4/wL3AlWKtaC4Q4ltW/+TVz3/PofkQ=; b=gVFlgGJk6seGtcX78y/BcpLHRxJDayUArWOoDfuMQw81TZcKi2J8oBj+UhcDZ+JfypZqXBzXi 5RBbni2EXXgDhGPrcRd1ijE4rDBoFpecSLhiXfiSqkdNMu38m5nsbT6 X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=YSFz6sOHd2L45+Fr8DIvHTi6lSIjhLZ5T+rkxspJt1s= X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 From: Guenter Roeck The drm_test_rect_calc_hscale and drm_test_rect_calc_vscale unit tests intentionally trigger warning backtraces by providing bad parameters to the tested functions. What is tested is the return value, not the existence of a warning backtrace. Suppress the backtraces to avoid clogging the kernel log and distraction from real problems. Tested-by: Linux Kernel Functional Testing Acked-by: Dan Carpenter Acked-by: Ma=C3=ADra Canal Cc: Maarten Lankhorst Cc: David Airlie Cc: Daniel Vetter Signed-off-by: Guenter Roeck Signed-off-by: Alessandro Carminati Signed-off-by: Albert Esteve Acked-by: David Gow --- drivers/gpu/drm/tests/drm_rect_test.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/= drm_rect_test.c index 17e1f34b76101..1dd7d819165e7 100644 --- a/drivers/gpu/drm/tests/drm_rect_test.c +++ b/drivers/gpu/drm/tests/drm_rect_test.c @@ -409,8 +409,15 @@ static void drm_test_rect_calc_hscale(struct kunit *te= st) const struct drm_rect_scale_case *params =3D test->param_value; int scaling_factor; =20 + /* + * drm_rect_calc_hscale() generates a warning backtrace whenever bad + * parameters are passed to it. This affects all unit tests with an + * error code in expected_scaling_factor. + */ + KUNIT_START_SUPPRESSED_WARNING(test); scaling_factor =3D drm_rect_calc_hscale(¶ms->src, ¶ms->dst, params->min_range, params->max_range); + KUNIT_END_SUPPRESSED_WARNING(test); =20 KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor); } @@ -420,8 +427,15 @@ static void drm_test_rect_calc_vscale(struct kunit *te= st) const struct drm_rect_scale_case *params =3D test->param_value; int scaling_factor; =20 + /* + * drm_rect_calc_vscale() generates a warning backtrace whenever bad + * parameters are passed to it. This affects all unit tests with an + * error code in expected_scaling_factor. + */ + KUNIT_START_SUPPRESSED_WARNING(test); scaling_factor =3D drm_rect_calc_vscale(¶ms->src, ¶ms->dst, params->min_range, params->max_range); + KUNIT_END_SUPPRESSED_WARNING(test); =20 KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor); } --=20 2.52.0 From nobody Sun Apr 26 12:16:37 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50ADC3A0EAB for ; Mon, 20 Apr 2026 12:29:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776688170; cv=none; b=HWwLiJXfD1UQDiYzV3ofFu3cGk5IQ5hIh7CyOngLIFCInNwt/ENiiS2lQYdrIrDfbeVj9KYKlv6XA0qkq/H92xUQTMd1MTzALTwfpc1XJj1Diez8fp7ojF8r2tg5M9Ybo2wu9UXCjiAZhsO7jQehEzBWhsyz07pFuqg1YTexTFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776688170; c=relaxed/simple; bh=zZnQ0VlElyX2HJ1r9qLjSAlH1p2ZV3USi55ESS5GWuQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DgnKxsqh2LrBK2K1W8UQCVR3O9gjqFfe8sn2JoblKT7ZV5HWEzHGFmZ00wFDBfnH2ZyQksrxtALio+B41js3qRHJ72V1UhB0DiHQ2W7Yr6omUgOk69hdNRe/4NchkvD72ADk69wX6UmmTYgrn13LMj11KOuYDmJhvD0euV/ns58= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XwMD4Vcg; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XwMD4Vcg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776688168; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eC+Gw15PYY2xMCVGISwvaMfqiq/SdhUQydGUlDgpOjE=; b=XwMD4VcgcARSU7b1JLNOJtPcZzLAGGLdvuSgCm0fT5aOAJtzUBhVhnJPMyVv/OL8t0dkSP pJQjS3Xh/LrD8ZdUMvFlUdlBup23aNn4EBaqKX+Hv09ROi7Zz7Oszrc3lG4aGgBXz2K0dY 0ErA8AhTdYS+kIjLVgG1kXiMAY0whPM= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-384-jGrVKFOPNCSD5jKV5mRJEQ-1; Mon, 20 Apr 2026 08:29:23 -0400 X-MC-Unique: jGrVKFOPNCSD5jKV5mRJEQ-1 X-Mimecast-MFC-AGG-ID: jGrVKFOPNCSD5jKV5mRJEQ_1776688160 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8B6451955DD1; Mon, 20 Apr 2026 12:29:19 +0000 (UTC) Received: from [192.168.1.153] (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DAEBF1956095; Mon, 20 Apr 2026 12:29:13 +0000 (UTC) From: Albert Esteve Date: Mon, 20 Apr 2026 14:28:07 +0200 Subject: [PATCH v7 5/5] kunit: Add documentation for warning backtrace suppression API Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260420-kunit_add_support-v7-5-e8bc6e0f70de@redhat.com> References: <20260420-kunit_add_support-v7-0-e8bc6e0f70de@redhat.com> In-Reply-To: <20260420-kunit_add_support-v7-0-e8bc6e0f70de@redhat.com> To: Arnd Bergmann , Brendan Higgins , David Gow , Rae Moar , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jonathan Corbet , Shuah Khan , Andrew Morton 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, peterz@infradead.org, Guenter Roeck , Linux Kernel Functional Testing , Dan Carpenter , Alessandro Carminati , Albert Esteve , Kees Cook , David Gow X-Developer-Signature: v=1; a=ed25519-sha256; t=1776688120; l=2318; i=aesteve@redhat.com; s=20260303; h=from:subject:message-id; bh=4lfzAn+gO6eKqXz4dSBewHEkwDQyO+2TvU94oaKAI+c=; b=+ZaIrx/JeqPsEIaFDyLvWFz4pvg2lbnhOY5zt6oosncq1QDT0Y5Q0/25t1JHOMOw24diZyoFj vqfK/ASGW5lCGqqXJLSNqwsl+LQanP8755c4a2aGKmzwc++v0RYLD87 X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=YSFz6sOHd2L45+Fr8DIvHTi6lSIjhLZ5T+rkxspJt1s= X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 From: Guenter Roeck Document API functions for suppressing warning backtraces. Tested-by: Linux Kernel Functional Testing Acked-by: Dan Carpenter Reviewed-by: Kees Cook Signed-off-by: Guenter Roeck Reviewed-by: David Gow Signed-off-by: Alessandro Carminati Signed-off-by: Albert Esteve Reviewed-by: David Gow --- Documentation/dev-tools/kunit/usage.rst | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-to= ols/kunit/usage.rst index ebd06f5ea4550..76e85412f240e 100644 --- a/Documentation/dev-tools/kunit/usage.rst +++ b/Documentation/dev-tools/kunit/usage.rst @@ -157,6 +157,34 @@ Alternatively, one can take full control over the erro= r message by using if (some_setup_function()) KUNIT_FAIL(test, "Failed to setup thing for testing"); =20 +Suppressing warning backtraces +------------------------------ + +Some unit tests trigger warning backtraces either intentionally or as side +effect. Such backtraces are normally undesirable since they distract from +the actual test and may result in the impression that there is a problem. + +Such backtraces can be suppressed with **task scope suppression**: while +``START`` / ``END`` is active on the current task, the backtrace and stack +dump from warnings on that task are suppressed. Wrap the call from your te= st +in that window, like shown in the following code. + +.. code-block:: c + + static void some_test(struct kunit *test) + { + KUNIT_START_SUPPRESSED_WARNING(test); + trigger_backtrace(); + KUNIT_END_SUPPRESSED_WARNING(test); + } + +``KUNIT_SUPPRESSED_WARNING_COUNT()`` returns the number of suppressed back= traces. +If the suppressed backtrace was triggered on purpose, this can be used to = check +if the backtrace was actually triggered. + +.. code-block:: c + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(), 1); =20 Test Suites ~~~~~~~~~~~ @@ -1211,4 +1239,4 @@ For example: dev_managed_string =3D devm_kstrdup(fake_device, "Hello, World!"); =20 // Everything is cleaned up automatically when the test ends. - } \ No newline at end of file + } --=20 2.52.0