[PW_SID:1095409] kunit: Add support for suppressing warning backtraces#1947
[PW_SID:1095409] kunit: Add support for suppressing warning backtraces#1947linux-riscv-bot wants to merge 4 commits into
Conversation
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 suppress warning backtraces
originating from the current kthread while executing test code. Since
each KUnit test runs in its own kthread, this effectively scopes
suppression to the test that enabled it. Limit changes to generic code
to the absolute minimum.
Implementation details:
Suppression is integrated into the existing KUnit hooks infrastructure
in test-bug.h, reusing the kunit_running static branch for zero
overhead when no tests are running.
Suppression is checked at three points in the warning path:
- In warn_slowpath_fmt(), the check runs before any output, fully
suppressing both message and backtrace. This covers architectures
without __WARN_FLAGS.
- In __warn_printk(), the check suppresses the warning message text.
This covers architectures that define __WARN_FLAGS but not their own
__WARN_printf (arm64, loongarch, parisc, powerpc, riscv, sh), where
the message is printed before the trap enters __report_bug().
- In __report_bug(), the check runs before __warn() is called,
suppressing the backtrace and stack dump.
To avoid double-counting on architectures where both __warn_printk()
and __report_bug() run for the same warning, kunit_is_suppressed_warning()
takes a bool parameter: true to increment the suppression counter
(used in warn_slowpath_fmt and __report_bug), false to check only
(used in __warn_printk).
The suppression state is dynamically allocated via kunit_kzalloc() and
tied to the KUnit test lifecycle via kunit_add_action(), ensuring
automatic cleanup at test exit. On cleanup, the node is removed with
list_del_rcu() followed by synchronize_rcu() to wait for any concurrent
RCU readers to finish. Because kunit_end_suppress_warning() (and the
__cleanup wrapper) always runs from process context, synchronize_rcu()
is safe. The handle memory remains valid until the test exits, so the
suppression count can be read after the scope closes. Writer-side
access to the global suppression list is serialized with a spinlock;
readers use RCU. To avoid false suppression of warnings fired from
hardware interrupt handlers (where current still points to the test
task), the check exits early when not in task context.
Two API forms are provided:
- kunit_warning_suppress(test) { ... }: scoped, uses __cleanup for
automatic teardown on scope exit, kunit_add_action() as safety net
for abnormal exits (e.g. kthread_exit from failed assertions).
Suppression handle is only accessible inside the block.
- kunit_start/end_suppress_warning(test): direct functions returning
an explicit handle, for retaining the handle within the test,
or for cross-function usage.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Alessandro Carminati <acarmina@redhat.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Reviewed-by: David Gow <david@davidgow.net>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Add unit tests to verify that warning backtrace suppression works. Tests cover both API forms: - Scoped: kunit_warning_suppress() with in-block count verification and post-block inactivity check. - Direct functions: kunit_start/end_suppress_warning() with sequential independent suppression blocks and per-block counts. Furthermore, tests verify incremental warning counting, that kunit_has_active_suppress_warning() transitions correctly around suppression boundaries, and that suppression active in the test kthread does not leak to a separate kthread. 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 <lkft@linaro.org> Acked-by: Dan Carpenter <dan.carpenter@linaro.org> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Alessandro Carminati <acarmina@redhat.com> Reviewed-by: David Gow <david@davidgow.net> Signed-off-by: Albert Esteve <aesteve@redhat.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
The drm_test_rect_calc_hscale and drm_test_rect_calc_vscale unit tests intentionally trigger warning backtraces by providing invalid parameters the tested functions. Suppress the backtraces to avoid clogging the kernel log and distracting from real problems. The suppression API also exposes a warning counter, which is used to assert that the expected warning was actually triggered. On CONFIG_BUG=n, WARN_ON() is a no-op and the counter stays zero; the expected count is adjusted accordingly, preserving the return value check on all configurations. Tested-by: Linux Kernel Functional Testing <lkft@linaro.org> Acked-by: Dan Carpenter <dan.carpenter@linaro.org> Acked-by: Maíra Canal <mcanal@igalia.com> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Cc: David Airlie <airlied@gmail.com> Cc: Daniel Vetter <daniel@ffwll.ch> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Alessandro Carminati <acarmina@redhat.com> Acked-by: David Gow <david@davidgow.net> Signed-off-by: Albert Esteve <aesteve@redhat.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Document API functions for suppressing warning backtraces. Tested-by: Linux Kernel Functional Testing <lkft@linaro.org> Acked-by: Dan Carpenter <dan.carpenter@linaro.org> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Alessandro Carminati <acarmina@redhat.com> Reviewed-by: David Gow <david@davidgow.net> Signed-off-by: Albert Esteve <aesteve@redhat.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[v13,1/4] bug/kunit: Core support for suppressing warning backtraces" |
|
Patch 1: "[v13,1/4] bug/kunit: Core support for suppressing warning backtraces" |
|
Patch 1: "[v13,1/4] bug/kunit: Core support for suppressing warning backtraces" |
|
Patch 1: "[v13,1/4] bug/kunit: Core support for suppressing warning backtraces" |
|
Patch 1: "[v13,1/4] bug/kunit: Core support for suppressing warning backtraces" |
|
Patch 1: "[v13,1/4] bug/kunit: Core support for suppressing warning backtraces" |
|
Patch 1: "[v13,1/4] bug/kunit: Core support for suppressing warning backtraces" |
|
Patch 1: "[v13,1/4] bug/kunit: Core support for suppressing warning backtraces" |
|
Patch 1: "[v13,1/4] bug/kunit: Core support for suppressing warning backtraces" |
|
Patch 1: "[v13,1/4] bug/kunit: Core support for suppressing warning backtraces" |
|
Patch 1: "[v13,1/4] bug/kunit: Core support for suppressing warning backtraces" |
|
Patch 1: "[v13,1/4] bug/kunit: Core support for suppressing warning backtraces" |
|
Patch 2: "[v13,2/4] kunit: Add backtrace suppression self-tests" |
|
Patch 2: "[v13,2/4] kunit: Add backtrace suppression self-tests" |
|
Patch 2: "[v13,2/4] kunit: Add backtrace suppression self-tests" |
|
Patch 2: "[v13,2/4] kunit: Add backtrace suppression self-tests" |
|
Patch 2: "[v13,2/4] kunit: Add backtrace suppression self-tests" |
|
Patch 2: "[v13,2/4] kunit: Add backtrace suppression self-tests" |
|
Patch 2: "[v13,2/4] kunit: Add backtrace suppression self-tests" |
|
Patch 2: "[v13,2/4] kunit: Add backtrace suppression self-tests" |
|
Patch 2: "[v13,2/4] kunit: Add backtrace suppression self-tests" |
|
Patch 2: "[v13,2/4] kunit: Add backtrace suppression self-tests" |
|
Patch 2: "[v13,2/4] kunit: Add backtrace suppression self-tests" |
|
Patch 2: "[v13,2/4] kunit: Add backtrace suppression self-tests" |
|
Patch 3: "[v13,3/4] drm: Suppress intentional warning backtraces in scaling unit tests" |
|
Patch 3: "[v13,3/4] drm: Suppress intentional warning backtraces in scaling unit tests" |
|
Patch 3: "[v13,3/4] drm: Suppress intentional warning backtraces in scaling unit tests" |
|
Patch 3: "[v13,3/4] drm: Suppress intentional warning backtraces in scaling unit tests" |
|
Patch 3: "[v13,3/4] drm: Suppress intentional warning backtraces in scaling unit tests" |
|
Patch 3: "[v13,3/4] drm: Suppress intentional warning backtraces in scaling unit tests" |
|
Patch 3: "[v13,3/4] drm: Suppress intentional warning backtraces in scaling unit tests" |
|
Patch 3: "[v13,3/4] drm: Suppress intentional warning backtraces in scaling unit tests" |
|
Patch 3: "[v13,3/4] drm: Suppress intentional warning backtraces in scaling unit tests" |
|
Patch 3: "[v13,3/4] drm: Suppress intentional warning backtraces in scaling unit tests" |
|
Patch 3: "[v13,3/4] drm: Suppress intentional warning backtraces in scaling unit tests" |
|
Patch 3: "[v13,3/4] drm: Suppress intentional warning backtraces in scaling unit tests" |
|
Patch 4: "[v13,4/4] kunit: Add documentation for warning backtrace suppression API" |
|
Patch 4: "[v13,4/4] kunit: Add documentation for warning backtrace suppression API" |
|
Patch 4: "[v13,4/4] kunit: Add documentation for warning backtrace suppression API" |
|
Patch 4: "[v13,4/4] kunit: Add documentation for warning backtrace suppression API" |
|
Patch 4: "[v13,4/4] kunit: Add documentation for warning backtrace suppression API" |
|
Patch 4: "[v13,4/4] kunit: Add documentation for warning backtrace suppression API" |
|
Patch 4: "[v13,4/4] kunit: Add documentation for warning backtrace suppression API" |
|
Patch 4: "[v13,4/4] kunit: Add documentation for warning backtrace suppression API" |
|
Patch 4: "[v13,4/4] kunit: Add documentation for warning backtrace suppression API" |
|
Patch 4: "[v13,4/4] kunit: Add documentation for warning backtrace suppression API" |
|
Patch 4: "[v13,4/4] kunit: Add documentation for warning backtrace suppression API" |
|
Patch 4: "[v13,4/4] kunit: Add documentation for warning backtrace suppression API" |
PR for series 1095409 applied to workflow__riscv__fixes
Name: kunit: Add support for suppressing warning backtraces
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1095409
Version: 13