From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 036C8CD343F for ; Fri, 15 May 2026 11:46:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5AE1010E11C; Fri, 15 May 2026 11:46:34 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="YYbxeEmx"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id D549110E11C for ; Fri, 15 May 2026 11:46:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778845591; 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=SNN8cMKgiaWqMObumUCkNPIVEL2/GCdXnUUQepHs9Og=; b=YYbxeEmxcW81JtPojyhmfVyi4BOR6QE/1ulIs9j1sIsGO78KbwBtGsNyeRDv9MGT1Rp8a/ /C1LhY1y2pppGUElt2mYcV4oj9w+uMVYDdd7EOo7Ree58CUGw//0cHU+ykTO2BchzPAONw m5noVeuExS1B+BnuLsp1LMGcJMzIwWs= Received: from mail-yx1-f72.google.com (mail-yx1-f72.google.com [74.125.224.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-507-IzsMkB8mPs-BO5qXGe6YxQ-1; Fri, 15 May 2026 07:46:30 -0400 X-MC-Unique: IzsMkB8mPs-BO5qXGe6YxQ-1 X-Mimecast-MFC-AGG-ID: IzsMkB8mPs-BO5qXGe6YxQ_1778845589 Received: by mail-yx1-f72.google.com with SMTP id 956f58d0204a3-6596b8ee4b4so18864424d50.0 for ; Fri, 15 May 2026 04:46:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778845589; x=1779450389; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=SNN8cMKgiaWqMObumUCkNPIVEL2/GCdXnUUQepHs9Og=; b=DajKZl18UfrcXkwz8ezkwhiqhuOwowQSgP/UGo9GZQY1s/xd2F6dMduzrTqIyp+2ei TXTKiO8scArwe0dn0RcysKokp2x7qmNkLoCy5QOy5R66C57FCXFxSpeJDStG7ML4h//O m9eMtkaqVHZ1rKK9XajnIok09PF1TdlBVSCYBTs1L3F36Z26EOc+uj6wUzY/xcRfSZ8l we1U5yFJ7IEyGFYMYpPwD0uCyqQfef/kz+UxaNydWsoBOGRf9XcoT899qhhllSTZ4hRG kcKtNSCuYGsE+qFh+vQ32kUDnsOzI35AmUqKCnBoXDZ+Uibzg3cBu67b43UqsVh/8aaU OEAg== X-Forwarded-Encrypted: i=1; AFNElJ8o2UOl42YzEiDgrvejZk6Tt+9wyalSSdjWVde+xX24IcZ6iKjwc1cOkuRBxwN1ozithwDs9AaMXuM=@lists.freedesktop.org X-Gm-Message-State: AOJu0Yxrbfa2XTgFF8ui52m9ZonehhdPq49TdGU6lfEv3NC41UikcX2Z nYdC2Xet+ONIGjIMihq2gOjsuOVn7p22eCsT5VKT5CFgMCERDZwMez6qfvTgVpTeqCL0cu0NMAp 37zzp+HvUhhqAM4m7728Fp20wh8TjAkK1UNkMIK2WJCoVuaEa5Ft8HIk2qiEIy186KMgrTxXORR XEyYF0uJKMYsz+kkN9fOml0+uYtufEC9GUYuJIvkWeE6P9 X-Gm-Gg: Acq92OGsNwu5MB0FwlyicZ21ohvlTPji1iY8yIPjCG03AF2XRtOroPM45TwLpE2c8az WazA4TOQfSW3rPdLbvQ5aG36G0I7atkWf2WbvNJyguArX0ofX/ZY4a1giRtwzeWoODimSkcn8bE 4dtG/nh86XgBlvGu2R74t+6h+rGRwJ6otligETbdAJUqojcFD6G8UoxZODC01VHnbq1u4Ywh2kM O1KIA== X-Received: by 2002:a05:690c:698b:b0:7ba:f0ed:c5d0 with SMTP id 00721157ae682-7c95a472aa4mr36853487b3.13.1778845589283; Fri, 15 May 2026 04:46:29 -0700 (PDT) X-Received: by 2002:a05:690c:698b:b0:7ba:f0ed:c5d0 with SMTP id 00721157ae682-7c95a472aa4mr36852927b3.13.1778845588675; Fri, 15 May 2026 04:46:28 -0700 (PDT) MIME-Version: 1.0 References: <20260515-kunit_add_support-v12-0-a216dc228be8@redhat.com> In-Reply-To: <20260515-kunit_add_support-v12-0-a216dc228be8@redhat.com> From: Albert Esteve Date: Fri, 15 May 2026 13:46:15 +0200 X-Gm-Features: AVHnY4ImVOLCGbUqAjanuMO8o_HdN74f9pc42KZvCOECahFSsf1msDLsnbmjkj0 Message-ID: Subject: Re: [PATCH v12 0/4] kunit: Add support for suppressing warning backtraces 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 , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti 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-riscv@lists.infradead.org, linux-doc@vger.kernel.org, peterz@infradead.org, Alessandro Carminati , Guenter Roeck , Kees Cook , Linux Kernel Functional Testing , =?UTF-8?B?TWHDrXJhIENhbmFs?= , Dan Carpenter , Simona Vetter X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Vmw0bXhOhuORiktTOtykoZPuorXqoIZc2Th1nQQ5QGU_1778845589 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Fri, May 15, 2026 at 10:53=E2=80=AFAM Albert Esteve = wrote: > > 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. > > One option to address the problem would be to add messages such as > "expected warning backtraces start/end here" to the kernel log. > However, that would again require filter scripts, might result in > missing real problematic warning backtraces triggered while the test > is running, and the irrelevant backtrace(s) would still clog the > kernel log. > > 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, without requiring any > architecture-specific code. > > Overview: > Patch#1 Introduces the suppression infrastructure integrated into > KUnit's hook mechanism. > Patch#2 Adds selftests to validate the functionality. > Patch#3 Demonstrates real-world usage in the DRM subsystem. > Patch#4 Documents the new API and usage guidelines. > > Design Notes: > Suppression is integrated into the existing KUnit hooks infrastructure, > reusing the kunit_running static branch for zero overhead > when no tests are running. The implementation lives entirely in the > kunit module; only a static-inline wrapper and a function pointer > slot are added to built-in code. > > Suppression is checked at three points in the warning path: > - In `warn_slowpath_fmt()` (kernel/panic.c), for architectures without > __WARN_FLAGS. The check runs before any output, fully suppressing > both message and backtrace. > - In `__warn_printk()` (kernel/panic.c), for architectures that define > __WARN_FLAGS but not their own __WARN_printf (arm64, loongarch, > parisc, powerpc, riscv, sh). The check suppresses the warning message > text that is printed before the trap enters __report_bug(). > - In `__report_bug()` (lib/bug.c), for architectures that define > __WARN_FLAGS. 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, the hook takes a bool > parameter: true to increment the suppression counter, false to suppress > without counting. > > 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. Writer-side access to the global > suppression list is serialized with a spinlock; readers use RCU. > > Two API forms are provided: > - kunit_warning_suppress(test) { ... }: scoped blocks with automatic > cleanup. The suppression handle is not accessible outside the block, > so warning counts (if needed) must be checked inside. Multiple > suppression blocks are allowed. > - kunit_start/end_suppress_warning(test): direct functions that return > an explicit handle. Use when the handle needs to be retained, or passed > across helpers. Multiple suppression blocks are allowed. > > This series is based on the RFC patch and subsequent discussion at > https://patchwork.kernel.org/project/linux-kselftest/patch/02546e59-1afe-= 4b08-ba81-d94f3b691c9a@moroto.mountain/ > and offers a more comprehensive solution of the problem discussed there. > > Changes since RFC: > - Introduced CONFIG_KUNIT_SUPPRESS_BACKTRACE > - Minor cleanups and bug fixes > - Added support for all affected architectures > - Added support for counting suppressed warnings > - Added unit tests using those counters > - Added patch to suppress warning backtraces in dev_addr_lists tests > > Changes since v1: > - Rebased to v6.9-rc1 > - Added Tested-by:, Acked-by:, and Reviewed-by: tags > [I retained those tags since there have been no functional changes] > - Introduced KUNIT_SUPPRESS_BACKTRACE configuration option, enabled by > default. > > Changes since v2: > - Rebased to v6.9-rc2 > - Added comments to drm warning suppression explaining why it is needed. > - Added patch to move conditional code in arch/sh/include/asm/bug.h > to avoid kerneldoc warning > - Added architecture maintainers to Cc: for architecture specific patches > - No functional changes > > Changes since v3: > - Rebased to v6.14-rc6 > - Dropped net: "kunit: Suppress lock warning noise at end of dev_addr_lis= ts tests" > since 3db3b62955cd6d73afde05a17d7e8e106695c3b9 > - Added __kunit_ and KUNIT_ prefixes. > - Tested on interessed architectures. > > Changes since v4: > - Rebased to v6.15-rc7 > - Dropped all code in __report_bug() > - Moved all checks in WARN*() macros. > - Dropped all architecture specific code. > - Made __kunit_is_suppressed_warning nice to noinstr functions. > > Changes since v5: > - Rebased to v7.0-rc3 > - Added RCU protection for the suppressed warnings list. > - Added static key and branching optimization. > - Removed custom `strcmp` implementation and reworked > __kunit_is_suppressed_warning() entrypoint function. > > Changes since v6: > - Moved suppression checks from WARN*() macros to warn_slowpath_fmt() > and __report_bug(). > - Replaced stack-allocated suppression struct with kunit_kzalloc() heap > allocation tied to the KUnit test lifecycle. > - Changed suppression strategy from function-name matching to task-scoped= : > all warnings on the current task are suppressed between START and END, > rather than only warnings originating from a specific named function. > - Simplified macro API: removed KUNIT_DECLARE_SUPPRESSED_WARNING(), > the START macro now takes (test) and handles allocation internally. > - Removed static key and branching optiomization, as by the time it > was executed, callers are already in warn slowpaths. > - Link to v6: https://lore.kernel.org/r/20260317-kunit_add_support-v6-0-d= d22aeb3fe5d@redhat.com > > Changes since v7: > - Integrated suppression into existing KUnit hooks infrastructure > - Removed CONFIG_KUNIT_SUPPRESS_BACKTRACE > - Added suppression check in __warn_printk() > - Added spinlock for writer-side RCU protection > - Replaced explicit rcu_read_lock/unlock with guard(rcu)() > - Added scoped API (kunit_warning_suppress) using __cleanup attribute > - Updated DRM patch to use scoped API > - Expanded self-tests: incremental counting, cross-kthread isolation > - Rewrote documentation covering all three API forms with examples > - Link to v7: https://lore.kernel.org/r/20260420-kunit_add_support-v7-0-e= 8bc6e0f70de@redhat.com > > Changes since v8: > - Rebased to v7.1-rc2 > - Remove KUNIT_START/END_SUPPRESSED_WARNING() macros > - Add KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT checks to drm tests > - Link to v8: https://lore.kernel.org/r/20260504-kunit_add_support-v8-0-3= e5957cdd235@redhat.com > > Changes since v9: > - Fix silent false-pass when kunit_start_suppress_warning() returns NULL > - Fix RCU lockdep splat for kunit_is_suppressed_warning() calls > - Move disable_trace_on_warning() in __report_bug() > - Make suppress counter atomic > - Mark helper warn functions in selftest as noinline > - Add kunit_skip() for CONFIG_BUG=3Dn in selftests > - Fix potentially uninitialized data.was_active in kthread seltest > - Add kthread_stop() in kthread selftest early exit > - Initialize scaling_factor to INT_MIN in DRM scaling tests > - Add include for bool in test-bug.h to fix CONFIG_KUNIT=3Dn case > - Link to v9: https://lore.kernel.org/r/20260508-kunit_add_support-v9-0-9= 9df7aa880f6@redhat.com > > Changes since v10: > - Remove synchronize_rcu() to avoid sleeping in atomic context > - Pin task_struct refcount to prevent ABA false-positive matches > - Loop in suppression selftest to prevent use-after-free on kthread exit > - Skip DRM rect tests on CONFIG_BUG=3Dn > - Link to v10: https://lore.kernel.org/r/20260513-kunit_add_support-v10-0= -e379d206c8cd@redhat.com > > Changes since v11: > - Use call_rcu() to defer free without blocking > - Remove #ifdef CONFIG_KUNIT guard in lib/bug.c > - Remove stale config checks from selftest > - Replace skip on DRM rect tests with conditional expectation > - Link to v11: https://lore.kernel.org/r/20260514-kunit_add_support-v11-0= -b36a530a6d8f@redhat.com A regression occurred in this version because `kunit_kzalloc` was removed, following sashiko's suggestions in the last version. The handle cannot be used after the kunit_end_suppress_warning() call because we explicitly kfree(), resulting in a use-after-free. I should've seen it, but the tests passed so it did not click (not sure why exactly, probably the memory was still mapped during the grace period so the access succeeded spuriously). This back and forth is not going well, so I will revert lib/kunit/bug.c to v9, before removing `synchronize_rcu()`, which was working fine. It used `kunit_kzalloc` so KUnit correctly handled the memory lifetime. The problem is that `synchronize_rcu()` requires process context, which is always the case here, it should never be called under a spinlock or RCU read lock. Re-adding may trigger a comment from the automatic review, but I think it is the safest option. This time sashiko found another issue and suggested `in_task()`, which sounds like a nice addition to avoid suppressing real warnings within interrupt handlers. So one more version it is... > > -- > 2.34.1 > > --- > To: Brendan Higgins > To: David Gow > To: Rae Moar > To: Andrew Morton > To: Paul Walmsley > To: Palmer Dabbelt > To: Albert Ou > To: Alexandre Ghiti > To: Maarten Lankhorst > To: Maxime Ripard > To: Thomas Zimmermann > To: David Airlie > To: Simona Vetter > To: Jonathan Corbet > To: Shuah Khan > Cc: linux-kernel@vger.kernel.org > Cc: linux-kselftest@vger.kernel.org > Cc: kunit-dev@googlegroups.com > Cc: linux-riscv@lists.infradead.org > Cc: dri-devel@lists.freedesktop.org > Cc: workflows@vger.kernel.org > Cc: linux-doc@vger.kernel.org > > --- > Alessandro Carminati (1): > bug/kunit: Core support for suppressing warning backtraces > > Guenter Roeck (3): > kunit: Add backtrace suppression self-tests > drm: Suppress intentional warning backtraces in scaling unit tests > kunit: Add documentation for warning backtrace suppression API > > Documentation/dev-tools/kunit/usage.rst | 46 +++++++- > drivers/gpu/drm/tests/drm_rect_test.c | 36 +++++- > include/kunit/test-bug.h | 26 +++++ > include/kunit/test.h | 98 ++++++++++++++++ > kernel/panic.c | 11 ++ > lib/bug.c | 12 +- > lib/kunit/Makefile | 4 +- > lib/kunit/backtrace-suppression-test.c | 192 ++++++++++++++++++++++++++= ++++++ > lib/kunit/bug.c | 131 ++++++++++++++++++++++ > lib/kunit/hooks-impl.h | 2 + > 10 files changed, 548 insertions(+), 10 deletions(-) > --- > base-commit: 74fe02ce122a6103f207d29fafc8b3a53de6abaf > change-id: 20260312-kunit_add_support-2f35806b19dd > > Best regards, > -- > Albert Esteve >