From nobody Mon Apr 6 23:46:16 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 E097A39F164 for ; Tue, 17 Mar 2026 09:25:12 +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=1773739514; cv=none; b=s7X42Zvwg7PbkXzDFO0JOZhSjL2Fau/082FjO5HIg/Fgvn0mle4SVuPsr1uRPhyhOX+QbzK70r431qw2b3I7N1ZrVe8X3A+GN3cq981aNSYToTdZkuGc/2hdW0TgvOFwaDo4ptVdm+luC87agBkl/7d12vZdtPGO9NwKEzLiqnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773739514; c=relaxed/simple; bh=CmX/LqdIOJS1Ct1RBcik9DLTDYba7/p3qMd9LakEEKk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HwaMqFlRyEDln2sQSbVK0QxBEissMXWcZ10F+aDbjMTqp6ffQ/ceGZQWs9NLgBXEoKUeNHI8/SgG63TvUsR5AnVmovDz1exDTIZLykNdY1CvEd4iPGAASrPTkPaElwfXowBRe10iLIdI6hkmnhZRe495Xn7rjiMcxb5dlhninlc= 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=IXAPmh3H; 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="IXAPmh3H" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773739512; 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=vl38m1bfQraLOcvKSMlDF9R7LfHO8MoiUxQ5e03K4cE=; b=IXAPmh3HI89EnKL0HO5TwqSBXFEv2aflAn9HJMKoLBiNM9vAHV6y3+gfWy2J6viyzjpqp1 0WnmiMcVwQN8BGM52n4L+meW4cil10hI2VwsEIJxiVRPoj7l9rySQrReGx/4l9fxp5W7Pb zUoQh0BAax/DFxvKLOPFtqpU1l9yqOE= 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-575-UMz29TRVM6qwxuPwb0y7-A-1; Tue, 17 Mar 2026 05:25:07 -0400 X-MC-Unique: UMz29TRVM6qwxuPwb0y7-A-1 X-Mimecast-MFC-AGG-ID: UMz29TRVM6qwxuPwb0y7-A_1773739504 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 ED05018002DD; Tue, 17 Mar 2026 09:25:03 +0000 (UTC) Received: from [192.168.1.153] (unknown [10.45.224.69]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 95F621800576; Tue, 17 Mar 2026 09:24:56 +0000 (UTC) From: Albert Esteve Date: Tue, 17 Mar 2026 10:24:41 +0100 Subject: [PATCH v6 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: <20260317-kunit_add_support-v6-1-dd22aeb3fe5d@redhat.com> References: <20260317-kunit_add_support-v6-0-dd22aeb3fe5d@redhat.com> In-Reply-To: <20260317-kunit_add_support-v6-0-dd22aeb3fe5d@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 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 , Guenter Roeck , Kees Cook , Albert Esteve X-Developer-Signature: v=1; a=ed25519-sha256; t=1773739485; l=10954; i=aesteve@redhat.com; s=20260303; h=from:subject:message-id; bh=9HDzKd2Q+voitfuDwnjvb0TVH3+Mu4gPG+q0/QE7BAQ=; b=upqDoz1QY8TvBDSLFwGn2/f4tjZfHSWNQJI8mG6XunJuXaMDpwmkOShrxyt1Qx8LKUAREE/xV 7+94VvRYSS4D3cBQZaa+Poe5o1PhH9yy2A2PN4ZRqFwMDRK0vc6j6Vs X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=YSFz6sOHd2L45+Fr8DIvHTi6lSIjhLZ5T+rkxspJt1s= X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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: Check suppression directly in the `WARN()` Macros. This avoids the need for function symbol resolution or ELF section modification. Use unlikely() with KUNIT_IS_SUPPRESSED_WARNING() in the Macros so the common case (no suppression) stays on the hot path, improving performance and keeping the critical path smaller. A helper function, `__kunit_is_suppressed_warning()`, is used to determine whether suppression applies. It is marked as `noinstr`, since some `WARN*()` sites reside in non-instrumentable sections. As it uses `strcmp`, which is not `noinstr`-safe, its use is wrapped within `__kunit_check_suppress()` and surounded by instrumentation_begin()/end() calls. The list of supressed warnings includes RCU protection. 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/asm-generic/bug.h | 44 ++++++++++++++++++++++------------ include/kunit/bug.h | 61 +++++++++++++++++++++++++++++++++++++++++++= ++++ include/kunit/test.h | 1 + lib/kunit/Kconfig | 9 +++++++ lib/kunit/Makefile | 6 +++-- lib/kunit/bug.c | 59 +++++++++++++++++++++++++++++++++++++++++++= ++ 6 files changed, 163 insertions(+), 17 deletions(-) diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h index 09e8eccee8ed9..7c766fde49a90 100644 --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -27,6 +27,7 @@ #endif /* WARN_CONDITION_STR */ =20 #ifndef __ASSEMBLY__ +#include #include #include =20 @@ -71,9 +72,13 @@ struct bug_entry { */ #ifndef HAVE_ARCH_BUG #define BUG() do { \ - printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \ - barrier_before_unreachable(); \ - panic("BUG!"); \ + if (!unlikely(KUNIT_IS_SUPPRESSED_WARNING(__func__))) { \ + printk("BUG: failure at %s:%d/%s()!\n", __FILE__, \ + __LINE__, __func__); \ + barrier_before_unreachable(); \ + panic("BUG!"); \ + } \ + __builtin_unreachable(); \ } while (0) #endif =20 @@ -129,18 +134,23 @@ extern __printf(1, 2) void __warn_printk(const char *= fmt, ...); =20 #if defined(__WARN_FLAGS) && !defined(__WARN_printf) #define __WARN_printf(taint, arg...) do { \ - instrumentation_begin(); \ - __warn_printk(arg); \ - __WARN_FLAGS("", BUGFLAG_NO_CUT_HERE | BUGFLAG_TAINT(taint));\ - instrumentation_end(); \ + if (!unlikely(KUNIT_IS_SUPPRESSED_WARNING(__func__))) { \ + instrumentation_begin(); \ + __warn_printk(arg); \ + __WARN_FLAGS("", BUGFLAG_NO_CUT_HERE | \ + BUGFLAG_TAINT(taint)); \ + instrumentation_end(); \ + } \ } while (0) #endif =20 #ifndef __WARN_printf -#define __WARN_printf(taint, arg...) do { \ - instrumentation_begin(); \ - warn_slowpath_fmt(__FILE__, __LINE__, taint, arg); \ - instrumentation_end(); \ +#define __WARN_printf(taint, arg...) do { \ + if (!unlikely(KUNIT_IS_SUPPRESSED_WARNING(__func__))) { \ + instrumentation_begin(); \ + warn_slowpath_fmt(__FILE__, __LINE__, taint, arg); \ + instrumentation_end(); \ + } \ } while (0) #endif =20 @@ -153,7 +163,8 @@ extern __printf(1, 2) void __warn_printk(const char *fm= t, ...); #ifndef WARN_ON #define WARN_ON(condition) ({ \ int __ret_warn_on =3D !!(condition); \ - if (unlikely(__ret_warn_on)) \ + if (unlikely(__ret_warn_on) && \ + !unlikely(KUNIT_IS_SUPPRESSED_WARNING(__func__))) \ __WARN(); \ unlikely(__ret_warn_on); \ }) @@ -170,7 +181,8 @@ extern __printf(1, 2) void __warn_printk(const char *fm= t, ...); =20 #define WARN_TAINT(condition, taint, format...) ({ \ int __ret_warn_on =3D !!(condition); \ - if (unlikely(__ret_warn_on)) \ + if (unlikely(__ret_warn_on) && \ + !unlikely(KUNIT_IS_SUPPRESSED_WARNING(__func__))) \ __WARN_printf(taint, format); \ unlikely(__ret_warn_on); \ }) @@ -191,8 +203,10 @@ extern __printf(1, 2) void __warn_printk(const char *f= mt, ...); #else /* !CONFIG_BUG */ #ifndef HAVE_ARCH_BUG #define BUG() do { \ - do {} while (1); \ - unreachable(); \ + if (!unlikely(KUNIT_IS_SUPPRESSED_WARNING(__func__))) { \ + do {} while (1); \ + } \ + unreachable(); \ } while (0) #endif =20 diff --git a/include/kunit/bug.h b/include/kunit/bug.h new file mode 100644 index 0000000000000..9a5cd226c2139 --- /dev/null +++ b/include/kunit/bug.h @@ -0,0 +1,61 @@ +/* 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 + +#ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE + +#include +#include + +struct __suppressed_warning { + struct list_head node; + const char *function; + int counter; +}; + +void __kunit_start_suppress_warning(struct __suppressed_warning *warning); +void __kunit_end_suppress_warning(struct __suppressed_warning *warning); +bool __kunit_is_suppressed_warning(const char *function); + +#define KUNIT_DEFINE_SUPPRESSED_WARNING(func) \ + struct __suppressed_warning __kunit_suppress_##func =3D \ + { .function =3D __stringify(func), .counter =3D 0 } + +#define KUNIT_START_SUPPRESSED_WARNING(func) \ + __kunit_start_suppress_warning(&__kunit_suppress_##func) + +#define KUNIT_END_SUPPRESSED_WARNING(func) \ + __kunit_end_suppress_warning(&__kunit_suppress_##func) + +#define KUNIT_IS_SUPPRESSED_WARNING(func) \ + __kunit_is_suppressed_warning(func) + +#define KUNIT_SUPPRESSED_WARNING_COUNT(func) \ + (__kunit_suppress_##func.counter) + +#define KUNIT_SUPPRESSED_WARNING_COUNT_RESET(func) \ + __kunit_suppress_##func.counter =3D 0 + +#else /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ + +#define KUNIT_DEFINE_SUPPRESSED_WARNING(func) +#define KUNIT_START_SUPPRESSED_WARNING(func) +#define KUNIT_END_SUPPRESSED_WARNING(func) +#define KUNIT_IS_SUPPRESSED_WARNING(func) ((void)(func), false) +#define KUNIT_SUPPRESSED_WARNING_COUNT(func) ((void)(func), 0) +#define KUNIT_SUPPRESSED_WARNING_COUNT_RESET(func) + +#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/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..53c98e225a895 --- /dev/null +++ b/lib/kunit/bug.c @@ -0,0 +1,59 @@ +// 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); + +void __kunit_start_suppress_warning(struct __suppressed_warning *warning) +{ + list_add_rcu(&warning->node, &suppressed_warnings); +} +EXPORT_SYMBOL_GPL(__kunit_start_suppress_warning); + +void __kunit_end_suppress_warning(struct __suppressed_warning *warning) +{ + list_del_rcu(&warning->node); + synchronize_rcu(); /* Wait for readers to finish */ +} +EXPORT_SYMBOL_GPL(__kunit_end_suppress_warning); + +static bool __kunit_check_suppress(const char *function) +{ + struct __suppressed_warning *warning; + + if (!function) + return false; + + list_for_each_entry(warning, &suppressed_warnings, node) { + if (!strcmp(function, warning->function)) { + warning->counter++; + return true; + } + } + return false; +} + +noinstr bool __kunit_is_suppressed_warning(const char *function) +{ + bool ret; + + instrumentation_begin(); + ret =3D __kunit_check_suppress(function); + instrumentation_end(); + return ret; +} +EXPORT_SYMBOL_GPL(__kunit_is_suppressed_warning); + +#endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ --=20 2.52.0 From nobody Mon Apr 6 23:46:16 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 EA6D339FCB6 for ; Tue, 17 Mar 2026 09:25:19 +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=1773739521; cv=none; b=X9329Q5VipGxW/Jrf1NEHijJ+YqMgN4TQfUY1Tz6dRWFwihTsUgb+7i8nK1u0ssWjT+tFU0k6q3rmX9dI085bc25A5u2+OUh5kfkY0NZNHiokrh6J9kswvHk31I8J+fBf1j18/HWZCC6KFsmZMzjJB8XyvOtDeGnSIkqNPnT5pA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773739521; c=relaxed/simple; bh=5cUTuyT74M1ojJ8O1F2DSZ1Z6HcZkw/+k+1xRs9jdDE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SIPgRHGTFE1vR4bp69rnTt8MncqriDoXLTDGj7WNtWdW4Z9JYnDsyvGAmOYYm1Lb/MktPJ2PI8tqLccCSLAb5xpohyBtHbt+aFqbW0Bmk6eYYWJNa0uNbkSJKIabkCpO8bBzDG3C5zHCI2FV2r1j+l+17pFPpg0NIWe4zlJwUzE= 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=J074GBZ2; 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="J074GBZ2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773739519; 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=iu26JzW2BE1qFVqqYnDWECATcFEfXbKaDpd4Fk/QFDA=; b=J074GBZ2WPxv/syIHfJ1HUnqt0xSwhuOp0P8Q/KsCO8OwzoDpbEWQIP4McSPlnEhzpYVcP WHNBr5PAFK/F1WKA4ykjt0Y6zydZwEmLckiLbZwwXks7KycDztxNy5Xwv9oQCpDtRQ7BAX l+1pbBwW8Pa5byvWQU/71uWjnbS9eo8= Received: from mx-prod-mc-01.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-592-m6g32FopMQGMpxkGZtozOw-1; Tue, 17 Mar 2026 05:25:14 -0400 X-MC-Unique: m6g32FopMQGMpxkGZtozOw-1 X-Mimecast-MFC-AGG-ID: m6g32FopMQGMpxkGZtozOw_1773739511 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B782F195608C; Tue, 17 Mar 2026 09:25:11 +0000 (UTC) Received: from [192.168.1.153] (unknown [10.45.224.69]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 92BED1800361; Tue, 17 Mar 2026 09:25:04 +0000 (UTC) From: Albert Esteve Date: Tue, 17 Mar 2026 10:24:42 +0100 Subject: [PATCH v6 2/5] bug/kunit: Suppressing warning backtraces reduced impact on WARN*() sites 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: <20260317-kunit_add_support-v6-2-dd22aeb3fe5d@redhat.com> References: <20260317-kunit_add_support-v6-0-dd22aeb3fe5d@redhat.com> In-Reply-To: <20260317-kunit_add_support-v6-0-dd22aeb3fe5d@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 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 , Albert Esteve X-Developer-Signature: v=1; a=ed25519-sha256; t=1773739485; l=2494; i=aesteve@redhat.com; s=20260303; h=from:subject:message-id; bh=HqTbvkL2qatyFCLaW9ftzFuA7IHBU2Z5TfsvY4qRWpc=; b=2JcEn3cIAWR6YXbKBW2zwURhD/Aw/6CbCOWAfArN7xelgYYKJca/lYt8/khkA1n+x7960ypP2 FRPzHMfTCn+C+Ahx7ewn70h7UCKtoGC5FuTcRNNhd7uqMfuYTaR9xXg X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=YSFz6sOHd2L45+Fr8DIvHTi6lSIjhLZ5T+rkxspJt1s= X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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 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 Signed-off-by: Albert Esteve --- 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 @@ */ =20 #include +#include #include #include +#include #include #include =20 #ifdef CONFIG_KUNIT_SUPPRESS_BACKTRACE =20 static LIST_HEAD(suppressed_warnings); +static atomic_t suppressed_symbols_cnt =3D ATOMIC_INIT(0); + +DEFINE_STATIC_KEY_FALSE(kunit_suppress_warnings_key); +EXPORT_SYMBOL_GPL(kunit_suppress_warnings_key); =20 void __kunit_start_suppress_warning(struct __suppressed_warning *warning) { + if (atomic_inc_return(&suppressed_symbols_cnt) =3D=3D 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_war= ning *warning) { list_del_rcu(&warning->node); synchronize_rcu(); /* Wait for readers to finish */ + if (atomic_dec_return(&suppressed_symbols_cnt) =3D=3D 0) + static_branch_disable(&kunit_suppress_warnings_key); } EXPORT_SYMBOL_GPL(__kunit_end_suppress_warning); =20 @@ -49,6 +59,8 @@ noinstr bool __kunit_is_suppressed_warning(const char *fu= nction) { bool ret; =20 + if (!static_branch_unlikely(&kunit_suppress_warnings_key)) + return false; instrumentation_begin(); ret =3D __kunit_check_suppress(function); instrumentation_end(); --=20 2.52.0 From nobody Mon Apr 6 23:46:16 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 3831935F17C for ; Tue, 17 Mar 2026 09:25:27 +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=1773739528; cv=none; b=C5Qv9uxCJjeCqVHtItGYPxG00PHZl+t3xJ7QZjVirTeqnoCobBNPtIZtd+ch+AtOT/zKxrrgQzukezihVODYMpGswD/R63bbEBhqyIsRjS9W0mG1cTZ8ebhPU0Cwo13y/n91ssHdBvH37tOPxK/B1Z5tTHnTAbiNeAPSnqeQivw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773739528; c=relaxed/simple; bh=KSXqUccS0vGS9Yucdj/P0P0q8GQUeasfjqx1kXhROCA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UzeAYiiMdj8Y92g6AQ64xi24tx1ft4J2DFW2QjMY2i04SDlk4C7YjbyUdbYxIUu2CzHWDSdK6tqqBolaeAfg/HI24mgpVBaZrxzVoULTcUlwfYxNfRuc8MF78X3IgqqjY/6VWl+4iscy9B3MyKR5AUo46owgvMQP65kNaKAf9Vs= 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=IiNhg+T3; 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="IiNhg+T3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773739526; 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=qWq1auirtZsMIPEJ33nm5DPWJ0FEd8YwZ+yePh9+/ac=; b=IiNhg+T3qJdp2bjPof8XonE1WYPWJ5sLH7uy3UFo7+KOa17kF1dlIe4N2L2bjr+42QCIIN rc8X7cOojoIiI9xc4SsyyD/V5VUImBT8qMquFW+ndXeGTnyH40G5zCp1ITQbUA0km/5qMy QeK92ZamNpw5sls+yvQzu99HN6Sj1qU= 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-673-SXLi687jOPyypbNfsFOhsA-1; Tue, 17 Mar 2026 05:25:23 -0400 X-MC-Unique: SXLi687jOPyypbNfsFOhsA-1 X-Mimecast-MFC-AGG-ID: SXLi687jOPyypbNfsFOhsA_1773739520 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 221C4180034E; Tue, 17 Mar 2026 09:25:20 +0000 (UTC) Received: from [192.168.1.153] (unknown [10.45.224.69]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 38B271800576; Tue, 17 Mar 2026 09:25:11 +0000 (UTC) From: Albert Esteve Date: Tue, 17 Mar 2026 10:24:43 +0100 Subject: [PATCH v6 3/5] Add unit tests to verify that warning backtrace suppression works. 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: <20260317-kunit_add_support-v6-3-dd22aeb3fe5d@redhat.com> References: <20260317-kunit_add_support-v6-0-dd22aeb3fe5d@redhat.com> In-Reply-To: <20260317-kunit_add_support-v6-0-dd22aeb3fe5d@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 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, Guenter Roeck , Linux Kernel Functional Testing , Dan Carpenter , Alessandro Carminati , Albert Esteve , Kees Cook X-Developer-Signature: v=1; a=ed25519-sha256; t=1773739485; l=5347; i=aesteve@redhat.com; s=20260303; h=from:subject:message-id; bh=aN8lhV9oV3+rqrJyEZpR/bhaV4YKkqadbu7CZzQ+IVY=; b=Y+j+a4oUFn8pUI2Wx852BBj0WfPjG2PWnZdJyZx4Odr8xpXK+2wvxX3ZSiY15RuV8KAe3qwgp EAAgh3YOlEiBoIlJT6LYYpZWYVaxfVCRRN7BY0c2rHUV5KVhBaV+Ntt X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=YSFz6sOHd2L45+Fr8DIvHTi6lSIjhLZ5T+rkxspJt1s= X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 From: Guenter Roeck Add unit tests to verify that warning backtrace suppression works. 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 --- lib/kunit/Makefile | 3 + lib/kunit/backtrace-suppression-test.c | 109 +++++++++++++++++++++++++++++= ++++ 2 files changed, 112 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..524aecee0ee23 --- /dev/null +++ b/lib/kunit/backtrace-suppression-test.c @@ -0,0 +1,109 @@ +// 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_DEFINE_SUPPRESSED_WARNING(backtrace_suppression_test_warn_direct); + + KUNIT_START_SUPPRESSED_WARNING(backtrace_suppression_test_warn_direct); + WARN(1, "This backtrace should be suppressed"); + KUNIT_END_SUPPRESSED_WARNING(backtrace_suppression_test_warn_direct); + + KUNIT_EXPECT_EQ(test, + KUNIT_SUPPRESSED_WARNING_COUNT(backtrace_suppression_test_warn_direct),= 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_DEFINE_SUPPRESSED_WARNING(trigger_backtrace_warn); + + KUNIT_START_SUPPRESSED_WARNING(trigger_backtrace_warn); + trigger_backtrace_warn(); + KUNIT_END_SUPPRESSED_WARNING(trigger_backtrace_warn); + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(trigger_backtrace_wa= rn), 1); +} + +static void backtrace_suppression_test_warn_multi(struct kunit *test) +{ + KUNIT_DEFINE_SUPPRESSED_WARNING(trigger_backtrace_warn); + KUNIT_DEFINE_SUPPRESSED_WARNING(backtrace_suppression_test_warn_multi); + + KUNIT_START_SUPPRESSED_WARNING(backtrace_suppression_test_warn_multi); + KUNIT_START_SUPPRESSED_WARNING(trigger_backtrace_warn); + WARN(1, "This backtrace should be suppressed"); + trigger_backtrace_warn(); + KUNIT_END_SUPPRESSED_WARNING(trigger_backtrace_warn); + KUNIT_END_SUPPRESSED_WARNING(backtrace_suppression_test_warn_multi); + + KUNIT_EXPECT_EQ(test, + KUNIT_SUPPRESSED_WARNING_COUNT(backtrace_suppression_test_warn_multi), = 1); + KUNIT_EXPECT_EQ(test, + KUNIT_SUPPRESSED_WARNING_COUNT(trigger_backtrace_warn), 1); +} + +static void backtrace_suppression_test_warn_on_direct(struct kunit *test) +{ + KUNIT_DEFINE_SUPPRESSED_WARNING(backtrace_suppression_test_warn_on_direct= ); + + if (!IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE) && !IS_ENABLED(CONFIG_KALLSYMS)) + kunit_skip(test, "requires CONFIG_DEBUG_BUGVERBOSE or CONFIG_KALLSYMS"); + + KUNIT_START_SUPPRESSED_WARNING(backtrace_suppression_test_warn_on_direct); + WARN_ON(1); + KUNIT_END_SUPPRESSED_WARNING(backtrace_suppression_test_warn_on_direct); + + KUNIT_EXPECT_EQ(test, + KUNIT_SUPPRESSED_WARNING_COUNT( + backtrace_suppression_test_warn_on_direct), 1); +} + +static void trigger_backtrace_warn_on(void) +{ + WARN_ON(1); +} + +static void backtrace_suppression_test_warn_on_indirect(struct kunit *test) +{ + KUNIT_DEFINE_SUPPRESSED_WARNING(trigger_backtrace_warn_on); + + if (!IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE)) + kunit_skip(test, "requires CONFIG_DEBUG_BUGVERBOSE"); + + KUNIT_START_SUPPRESSED_WARNING(trigger_backtrace_warn_on); + trigger_backtrace_warn_on(); + KUNIT_END_SUPPRESSED_WARNING(trigger_backtrace_warn_on); + + KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(trigger_backtrace_wa= rn_on), 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 Mon Apr 6 23:46:16 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 5D8F635CB7E for ; Tue, 17 Mar 2026 09:25:36 +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=1773739537; cv=none; b=QnejqWMSlIUyiRGOfS6unnrHAemaBysRLG9uxj9PubpZiMTydC/cjA4n75HOx90ViewgRPPEmqe/cZA977r09PdGXPGr3TmryxKiywiwabzai987xLA4ueqwN0/ulnwgSIZvt1+tZRrHs5RMty2adUvKc4yoNpkFAwJdcKaKIaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773739537; c=relaxed/simple; bh=ybqyd+a6fzE126XIY3+cIlWElt2D9ywK8QqCKAZoT3M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Dx4toTWrmNYuiXJCqflRsvw0JgTdMY6ys3ZrJ4u8NXrHpmkSTM+WMJAFWyA17TcjY4WUwYNkxVQ0h/bbGGbX1Vgd8BB29rv8GzHGc0riSPX3yfn4gTcm1aBe9gs25XRHoQ6KcJX7ywblrxckk3CfQTfDVEGMRq7VpUF54cSaw8Q= 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=cEmfu/bY; 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="cEmfu/bY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773739535; 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=4PPXdMPn0kCtQcC88lrFgotNdls7u7d7we65eaKeE9E=; b=cEmfu/bY5Cbs4usLjIttpRRQ0W4lbp1qQbGYMcSB1SlO8OiKrO0f7vaZKxnDMWqiMM01uZ eL1PpjzT3+AS6+3gBuoh+pOe7izDXtGHcHZ7MlR4ktAK5lrhWjhjdqBNeSu3aQy37r/Nm1 IDiqVlbtZT2F6c43ORSPmGH7aLxtaSI= Received: from mx-prod-mc-01.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-442-GlVJTbV7Msyg99JQlEir9A-1; Tue, 17 Mar 2026 05:25:32 -0400 X-MC-Unique: GlVJTbV7Msyg99JQlEir9A-1 X-Mimecast-MFC-AGG-ID: GlVJTbV7Msyg99JQlEir9A_1773739529 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3B05B19560A6; Tue, 17 Mar 2026 09:25:29 +0000 (UTC) Received: from [192.168.1.153] (unknown [10.45.224.69]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CFCEE180035F; Tue, 17 Mar 2026 09:25:20 +0000 (UTC) From: Albert Esteve Date: Tue, 17 Mar 2026 10:24:44 +0100 Subject: [PATCH v6 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: <20260317-kunit_add_support-v6-4-dd22aeb3fe5d@redhat.com> References: <20260317-kunit_add_support-v6-0-dd22aeb3fe5d@redhat.com> In-Reply-To: <20260317-kunit_add_support-v6-0-dd22aeb3fe5d@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 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, 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=1773739485; l=2672; i=aesteve@redhat.com; s=20260303; h=from:subject:message-id; bh=dgDPFwMzbwS7QQINim4WCBJEzudRgecx9bfpAoePY5M=; b=g94GzHpUTfjq+uP/n18WL3tY/0EmOZxMsmYqe2yh21ZXogKhGzdD7JUVOOcQsOQ4wJ8xZEjK8 uLc6BWvIL7gCWP9g0XqyuIm5TcTKkUMDArAaKE5AIPf4vgFzwaK/nQj X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=YSFz6sOHd2L45+Fr8DIvHTi6lSIjhLZ5T+rkxspJt1s= X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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 --- drivers/gpu/drm/tests/drm_rect_test.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/= drm_rect_test.c index 17e1f34b76101..867845e7d5ab6 100644 --- a/drivers/gpu/drm/tests/drm_rect_test.c +++ b/drivers/gpu/drm/tests/drm_rect_test.c @@ -406,22 +406,38 @@ KUNIT_ARRAY_PARAM(drm_rect_scale, drm_rect_scale_case= s, drm_rect_scale_case_desc =20 static void drm_test_rect_calc_hscale(struct kunit *test) { + KUNIT_DEFINE_SUPPRESSED_WARNING(drm_calc_scale); 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(drm_calc_scale); scaling_factor =3D drm_rect_calc_hscale(¶ms->src, ¶ms->dst, params->min_range, params->max_range); + KUNIT_END_SUPPRESSED_WARNING(drm_calc_scale); =20 KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor); } =20 static void drm_test_rect_calc_vscale(struct kunit *test) { + KUNIT_DEFINE_SUPPRESSED_WARNING(drm_calc_scale); 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(drm_calc_scale); scaling_factor =3D drm_rect_calc_vscale(¶ms->src, ¶ms->dst, params->min_range, params->max_range); + KUNIT_END_SUPPRESSED_WARNING(drm_calc_scale); =20 KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor); } --=20 2.52.0 From nobody Mon Apr 6 23:46:16 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 3A28C374183 for ; Tue, 17 Mar 2026 09:25:45 +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=1773739546; cv=none; b=uLIfMZUHKNR6hRUp60sfev9IXrIq12vaM6qA1IPvT2LQjDeoxIdWPNLjy5TWGzGoZYDRIyzkULe79lltrQAyUBUovx8639wWX0YfuZR6GNdHNCII7JUBxXwohB9lVbRJsCIYRJss+Pn+ysjbooFui1MeHGNd+8sno7VSmF8s4HY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773739546; c=relaxed/simple; bh=NlEYLh+CSv2ptFyqAFOscytJpzqxlTIZEPiPfda0LhE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mXCD5zpHn8V49nbe1tddaQvm4gbT+t4zUEWRkho6KOySuT3/5VQYh/50eKacBdfIi+zcXwoltYJlfjhUtO+q2xoEOXz6gTq/xhoZDKADyWZdIfuhUr9oMrwvmxaiVwbw56WN6XBecV6uoSFAhu8tjH/tift1c/jq8L5ljeeNLwQ= 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=UUrUlere; 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="UUrUlere" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773739544; 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=HGsi5yl8JKiyZRFNdI9Aenref4UbeHYmyNWTDritDOs=; b=UUrUlered6b2nMNg/6DgK8J8W7H3VzOJUOhE2vpBzLZqq4pRzH8cZbkVB9CAGu7Lisaq2n JLf8dqvt0zUUpN2qgs87zmwyb19tAXyD8Z1Trrn0E8NlFaz3HkySaATyGnD8m/5rE8A87/ dEhAMw16dieew1ZIfvg/IZpuA9BxavI= Received: from mx-prod-mc-06.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-648-8GGVyfOnN6un6g9XQ-spTg-1; Tue, 17 Mar 2026 05:25:39 -0400 X-MC-Unique: 8GGVyfOnN6un6g9XQ-spTg-1 X-Mimecast-MFC-AGG-ID: 8GGVyfOnN6un6g9XQ-spTg_1773739537 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D4CDE18005B0; Tue, 17 Mar 2026 09:25:36 +0000 (UTC) Received: from [192.168.1.153] (unknown [10.45.224.69]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CE3161800576; Tue, 17 Mar 2026 09:25:29 +0000 (UTC) From: Albert Esteve Date: Tue, 17 Mar 2026 10:24:45 +0100 Subject: [PATCH v6 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: <20260317-kunit_add_support-v6-5-dd22aeb3fe5d@redhat.com> References: <20260317-kunit_add_support-v6-0-dd22aeb3fe5d@redhat.com> In-Reply-To: <20260317-kunit_add_support-v6-0-dd22aeb3fe5d@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 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, 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=1773739485; l=2206; i=aesteve@redhat.com; s=20260303; h=from:subject:message-id; bh=zffkV3aP+LRb63HE4Cugtw9tkVeluLJxk1TZs6/vS7w=; b=xi7QMbvvT0J1dRWy0KlqnqQitH/PSQLUAgKbbKLFYdzU0n6EX8wvnLuZoSc5f5tmfTND76HVS bouO5u5E76MAyvEjL9Wl88tqUS1vAldKxm8cG0kkE/uNJu+J4Va4LFO X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=YSFz6sOHd2L45+Fr8DIvHTi6lSIjhLZ5T+rkxspJt1s= X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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 --- 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..f1f8e2619d2d6 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. To suppress a backtrace in some_functio= n(), +use the following code. + +.. code-block:: c + + static void some_test(struct kunit *test) + { + DEFINE_SUPPRESSED_WARNING(some_function); + + KUNIT_START_SUPPRESSED_WARNING(some_function); + trigger_backtrace(); + KUNIT_END_SUPPRESSED_WARNING(some_function); + } + +SUPPRESSED_WARNING_COUNT() returns the number of suppressed backtraces. 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, SUPPRESSED_WARNING_COUNT(some_function), 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