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 62FFCCD343F for ; Fri, 15 May 2026 14:14:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 438A510F53C; Fri, 15 May 2026 14:14:24 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="Lqu1H4mM"; 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 CF0A310F53C for ; Fri, 15 May 2026 14:14:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778854462; 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=VObRtO05jubkBNdePEiKs8bkHI05Ids5T/0ogzpYITY=; b=Lqu1H4mM1XUb+iN1CrV66E+RvjgBAglgImq2S6x4ws8vfgwpNqu+BtfNGWADIu2PKVP14U MXRSAfbsSsnc2f5k9zaGGcsIKIjn0Puazh3xCoGOc1GQMg/TbT4BfWgZoBVJKdlSE2wyua Pj4TkW36cR3VpDUv1zKcu1wdQrU9IMw= 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-591-GfKKwz-TM5mbcm-hEz9wgw-1; Fri, 15 May 2026 10:14:20 -0400 X-MC-Unique: GfKKwz-TM5mbcm-hEz9wgw-1 X-Mimecast-MFC-AGG-ID: GfKKwz-TM5mbcm-hEz9wgw_1778854460 Received: by mail-yx1-f72.google.com with SMTP id 956f58d0204a3-657e42cee12so13845082d50.0 for ; Fri, 15 May 2026 07:14:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778854460; x=1779459260; 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=VObRtO05jubkBNdePEiKs8bkHI05Ids5T/0ogzpYITY=; b=lVuFzEoRd/FLARqlkwShMiH7qBc5sA82HTT5D9q1yC5CvmzQE9LQ46YXueCN24XCOW 6vC2kcQLfhwMck5uy4IQgK+OWEvNj6clBJ0QpykrD8seZ2qzXdD7eosXUMDwaM713mCN eGELSYG+toFubM8YEfnaXpHmFuDlFX0qetsLK/TiKP87S4eHXlodPO7RvetpkVZm/opG CfcUpxfzMDGcc7CaGav8vrUKzhZu4+bydFDyBwdspNI9i7kW2tjyyW4hQfd8ERnk3Fo8 9UyUKgcSFoy6uZKbTjpLRLxxBD+GrQzx4PAW6Vq1PsrpmM7K0CA1YXhfEKbYlgNjs9O0 eK2Q== X-Forwarded-Encrypted: i=1; AFNElJ8jKmEd1Z3AckazqjReV9iFYu1Ho6BA2HqCY5gRSUOX+GmBuMPtaszHizBfLy7H/s/B2SDcfVCBPW8=@lists.freedesktop.org X-Gm-Message-State: AOJu0YzSA8FsW1ZoFClDcsHP0X4vhShmS0pfmI0Htlu3bvKMR3yfnp7n s6eU0q3anjiFRb4epn/PS3feQqGUtjoAsMXKCHr7/j/IkDDOtWq5Ztwb2HfDETR7rgEkBt0BAn5 6AnnqZP7s3SowKSY+I6sGFuAIsL9EgeBSUJ/k7UYplQNwtEDC73aXFkofNpEviUpaQEPARVGkWb lnLV4tqJlERp3rUOwVd+JF57CVe7cy1NAH0Ksx3MkaIgB6 X-Gm-Gg: Acq92OGR7KTSFKQVd12FomTby691q6ES6WllCppDxeEDdZ3xerLzhN7IeoPRhf+Zoh4 XdSXqT1s/z08k88eFWyPoc58IoCyPRQcd5U5YMmHV11HCYeQ5A1fSjOkmx2z5gBTJIojnpIMUb/ UuZag4IA7BrFwUMv1bqzEcbbwpexnDrNSAzfHBzpIW2gVVPX3+LYIfqSRdVGEb5spTElj/vBtPg Ybo5w== X-Received: by 2002:a05:690c:4a08:b0:7ba:ef98:9712 with SMTP id 00721157ae682-7c959a9a3e0mr45636177b3.11.1778854459918; Fri, 15 May 2026 07:14:19 -0700 (PDT) X-Received: by 2002:a05:690c:4a08:b0:7ba:ef98:9712 with SMTP id 00721157ae682-7c959a9a3e0mr45635597b3.11.1778854459379; Fri, 15 May 2026 07:14:19 -0700 (PDT) MIME-Version: 1.0 References: <20260515-kunit_add_support-v13-0-18ee42f96e7b@redhat.com> <20260515-kunit_add_support-v13-2-18ee42f96e7b@redhat.com> In-Reply-To: <20260515-kunit_add_support-v13-2-18ee42f96e7b@redhat.com> From: Albert Esteve Date: Fri, 15 May 2026 16:14:07 +0200 X-Gm-Features: AVHnY4KpgDDXeYFVXYd1aCpKGaTXXGfKzXerArdIzcyo8M52liefZmNjWABG4yY Message-ID: Subject: Re: [PATCH v13 2/4] kunit: Add backtrace suppression self-tests 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, Guenter Roeck , Linux Kernel Functional Testing , Alessandro Carminati , Dan Carpenter , Kees Cook X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: MBvz-4stOpCSlvVopP91CTD9ujqy_JomxIc2z6xeRUc_1778854460 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 2:30=E2=80=AFPM Albert Esteve = wrote: > > From: Guenter Roeck > > 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. > Another set of sashiko comments for this patch https://sashiko.dev/#/patchset/20260515-kunit_add_support-v13-0-18ee42f96e7= b%40redhat.com?part=3D2 here: 1. CPU spike from while (!kthread_should_stop()) schedule() Ha! I expected this one because I saw it in a previous review from the bot. schedule() from TASK_RUNNING yields the CPU; it does not spin-wait. The thread is rescheduled only when the scheduler gives it time, not in a tight loop. But the important thing is that the window where this loop actually runs is negligible: the parent calls kthread_stop() immediately after wait_for_completion() returns. Using set_current_state(TASK_INTERRUPTIBLE) would be slightly more CPU-friendly, but for a test that probably runs and exits in microseconds, it makes no practical difference. And it unnecessarily adds complexity. 2. Orphaned kthread on early abort This cannot happen in this test. The only KUNIT_ASSERT_* that could abort early is KUNIT_ASSERT_FALSE(test, IS_ERR(task)). If that assertion fails, it means kthread_run() itself returned an error, therefore, the kthread was never started and there is nothing to orphan. If kthread_run() succeeds, the assertion passes, and execution continues sequentially to kthread_stop(). No code path allows a live kthread to exist while bypassing kthread_stop(). > Tested-by: Linux Kernel Functional Testing > Acked-by: Dan Carpenter > Reviewed-by: Kees Cook > Signed-off-by: Guenter Roeck > Signed-off-by: Alessandro Carminati > Reviewed-by: David Gow > Signed-off-by: Albert Esteve > --- > lib/kunit/Makefile | 1 + > lib/kunit/backtrace-suppression-test.c | 192 +++++++++++++++++++++++++++= ++++++ > 2 files changed, 193 insertions(+) > > diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile > index 4592f9d0aa8dd..2e8a6b71a2ab0 100644 > --- a/lib/kunit/Makefile > +++ b/lib/kunit/Makefile > @@ -22,6 +22,7 @@ obj-$(if $(CONFIG_KUNIT),y) +=3D hooks.o > > obj-$(CONFIG_KUNIT_TEST) +=3D kunit-test.o > obj-$(CONFIG_KUNIT_TEST) +=3D platform-test.o > +obj-$(CONFIG_KUNIT_TEST) +=3D backtrace-suppression-test.o > > # 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= -suppression-test.c > new file mode 100644 > index 0000000000000..59a038b2739f5 > --- /dev/null > +++ b/lib/kunit/backtrace-suppression-test.c > @@ -0,0 +1,192 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * KUnit test for suppressing warning tracebacks. > + * > + * Copyright (C) 2024, Guenter Roeck > + * Author: Guenter Roeck > + */ > + > +#include > +#include > +#include > +#include > + > +static void backtrace_suppression_test_warn_direct(struct kunit *test) > +{ > + if (!IS_ENABLED(CONFIG_BUG)) > + kunit_skip(test, "requires CONFIG_BUG"); > + > + kunit_warning_suppress(test) { > + WARN(1, "This backtrace should be suppressed"); > + /* > + * Count must be checked inside the scope; the handle > + * is not accessible after the block exits. > + */ > + KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 1); > + } > + KUNIT_EXPECT_FALSE(test, kunit_has_active_suppress_warning()); > +} > + > +static noinline void trigger_backtrace_warn(void) > +{ > + WARN(1, "This backtrace should be suppressed"); > +} > + > +static void backtrace_suppression_test_warn_indirect(struct kunit *test) > +{ > + if (!IS_ENABLED(CONFIG_BUG)) > + kunit_skip(test, "requires CONFIG_BUG"); > + > + kunit_warning_suppress(test) { > + trigger_backtrace_warn(); > + KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 1); > + } > +} > + > +static void backtrace_suppression_test_warn_multi(struct kunit *test) > +{ > + if (!IS_ENABLED(CONFIG_BUG)) > + kunit_skip(test, "requires CONFIG_BUG"); > + > + kunit_warning_suppress(test) { > + WARN(1, "This backtrace should be suppressed"); > + trigger_backtrace_warn(); > + KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 2); > + } > +} > + > +static void backtrace_suppression_test_warn_on_direct(struct kunit *test= ) > +{ > + if (!IS_ENABLED(CONFIG_BUG)) > + kunit_skip(test, "requires CONFIG_BUG"); > + > + kunit_warning_suppress(test) { > + WARN_ON(1); > + KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 1); > + } > +} > + > +static noinline void trigger_backtrace_warn_on(void) > +{ > + WARN_ON(1); > +} > + > +static void backtrace_suppression_test_warn_on_indirect(struct kunit *te= st) > +{ > + if (!IS_ENABLED(CONFIG_BUG)) > + kunit_skip(test, "requires CONFIG_BUG"); > + > + kunit_warning_suppress(test) { > + trigger_backtrace_warn_on(); > + KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 1); > + } > +} > + > +static void backtrace_suppression_test_count(struct kunit *test) > +{ > + if (!IS_ENABLED(CONFIG_BUG)) > + kunit_skip(test, "requires CONFIG_BUG"); > + > + kunit_warning_suppress(test) { > + KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 0); > + > + WARN(1, "suppressed"); > + KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 1); > + > + WARN(1, "suppressed again"); > + KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 2); > + } > +} > + > +static void backtrace_suppression_test_active_state(struct kunit *test) > +{ > + KUNIT_EXPECT_FALSE(test, kunit_has_active_suppress_warning()); > + > + kunit_warning_suppress(test) { > + KUNIT_EXPECT_TRUE(test, kunit_has_active_suppress_warning= ()); > + } > + > + KUNIT_EXPECT_FALSE(test, kunit_has_active_suppress_warning()); > + > + kunit_warning_suppress(test) { > + KUNIT_EXPECT_TRUE(test, kunit_has_active_suppress_warning= ()); > + } > + > + KUNIT_EXPECT_FALSE(test, kunit_has_active_suppress_warning()); > +} > + > +static void backtrace_suppression_test_multi_scope(struct kunit *test) > +{ > + struct kunit_suppressed_warning *sw1, *sw2; > + > + if (!IS_ENABLED(CONFIG_BUG)) > + kunit_skip(test, "requires CONFIG_BUG"); > + > + sw1 =3D kunit_start_suppress_warning(test); > + trigger_backtrace_warn_on(); > + WARN(1, "suppressed by sw1"); > + kunit_end_suppress_warning(test, sw1); > + > + sw2 =3D kunit_start_suppress_warning(test); > + WARN(1, "suppressed by sw2"); > + kunit_end_suppress_warning(test, sw2); > + > + KUNIT_EXPECT_EQ(test, kunit_suppressed_warning_count(sw1), 2); > + KUNIT_EXPECT_EQ(test, kunit_suppressed_warning_count(sw2), 1); > +} > + > +struct cross_kthread_data { > + bool was_active; > + struct completion done; > +}; > + > +static int cross_kthread_fn(void *data) > +{ > + struct cross_kthread_data *d =3D data; > + > + d->was_active =3D kunit_has_active_suppress_warning(); > + complete(&d->done); > + while (!kthread_should_stop()) > + schedule(); > + return 0; > +} > + > +static void backtrace_suppression_test_cross_kthread(struct kunit *test) > +{ > + struct cross_kthread_data data; > + struct task_struct *task; > + > + data.was_active =3D false; > + init_completion(&data.done); > + > + kunit_warning_suppress(test) { > + task =3D kthread_run(cross_kthread_fn, &data, "kunit-cros= s-test"); > + KUNIT_ASSERT_FALSE(test, IS_ERR(task)); > + wait_for_completion(&data.done); > + kthread_stop(task); > + } > + > + KUNIT_EXPECT_FALSE(test, data.was_active); > +} > + > +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), > + KUNIT_CASE(backtrace_suppression_test_count), > + KUNIT_CASE(backtrace_suppression_test_active_state), > + KUNIT_CASE(backtrace_suppression_test_multi_scope), > + KUNIT_CASE(backtrace_suppression_test_cross_kthread), > + {} > +}; > + > +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")= ; > > -- > 2.53.0 >