From nobody Mon Sep 28 18:33:57 2026 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 255AC46DFE7 for ; Tue, 18 Aug 2026 15:20:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787066436; cv=none; b=K4C/JLzH6EcTr84yXyK75JWGDRf9pyvLphBZcZ1BHVdYTrg6ku4CRWCNqTsr1iXvJM2PmB0AESPN+hxWeOkfj0rw0v5J1u9NPW6F6NDBTFosMQcDCw7hXyAoJUIaHMrjvgkdvOSIsOtClMFPYIDHuA7zkpQOeHXMESgZyc2RiPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787066436; c=relaxed/simple; bh=lVVGyoI0yNkmpTkc1xzUBaTF6I8x9HnW591ib48kPo8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ihAcES+lQK117Rqie9F1cZtyzLPlHYHXMNYIS7heDLykE32rRvYFs7UbqA6JBpaxCbOJ/GbhHRIunPNm3Pz6W8Nr+tcr9+HWH6Q/gGNnrIcqdPb7Kv8yVmcsh7KyVe/yDm3KH5Eoe25piJMppmIbuDouVXqk3N0YZWwZsJTp/+c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MnEtkvT6; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MnEtkvT6" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-c197e7e4e94so813926566b.2 for ; Tue, 18 Aug 2026 08:20:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787066433; x=1787671233; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=i7/V3zTAw391qLVLvjrhLrPuXnBwusW56ARNxgO7nP0=; b=MnEtkvT6n7mudbx2as2X7eOZhlITcm47M7YOg+ZH+xk4bRgmUU+ovDZWK+QC3Kid+n D8al3fpfnstEzXzhhGjOCNwCSJ9FSAtXQrYspdzpYH+iBF+OhyT2pBIQc7jfOkgP8i+B PXxzpNWENHsLDFW/IhzbedjKWNgFrRkXN/e9k+EWMlqRNONkENXAQUY179tI/geqGfdD wP+20LnDp5Gub8S9r6dN5Y8eGkgP3SgN3Za1dYbl9P6ZcHqKD17R/wvEps6RBi8VimN0 TrfsNbhiix4qaPZMe8pltBAuIIGteF1aFLdqZ9abN2AmDL5C4TTq62rzUP5La4h0qK/N K/aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787066433; x=1787671233; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=i7/V3zTAw391qLVLvjrhLrPuXnBwusW56ARNxgO7nP0=; b=QOrAKztpHuBovxmKpYm1bUi/nnAVVvj7xm19/tv30DXh6NVbd76IzRfY9TVI9yfHCQ jtYnre2wYDZUS6D+c2jSD91kyvwpjlOPR/COSAaReFO2T7WLnTov+TkTxbPKuTEqGhxb d14NeQY0bdbVICUXB7CtIsvYEYL3pU00heBEKeM4Zty/WPPDOEBKzkeX55PMzliYjhki OABLI364yFEsBishGaOVHF+U7No2RmvvOrE+yB2U510nizqmFiaTR25l8QAQGdmVyzkw H+aYKSSGtv6w4dT1pZ3brTA/AQp6dvPn0F7JIarWaX3nVT5rTG+jzdeS5bnH6bimO73S 70+A== X-Forwarded-Encrypted: i=1; AHgh+Ror/f4i+SDo2EDIq28NdHrsl3qltVl9Z+J/4pakR8xAW2wJQVRIF2rT+Z6GKP0s+z6WbGbWNZKNLuBPdNY=@vger.kernel.org X-Gm-Message-State: AOJu0YwXes4GcfthLNhxe8pBBDh4j7dR082FBQsd7g1mP3rr1Qefo9fn Bht3LatrBMaUz9C/woogA1orcOnccsd2x66RW6kLX9hydocJ1S3sfUFs X-Gm-Gg: AR+sD105+S4FRVg6bVo3gyb7TIxOM0r6dTyvzKDYc4xMQF34TzXGXCWXTADGdKYV1FX kidw7YgpyzggxqNQEfK7iaDAnEJlUhT075eyAwhD5VfVWg0aKlqSqIMpar6UVqNZcWUYKGoBSFe 3MBBlcHRDVvzHwbqO1eZa6aY7Jdo1cArQd75CDnCMt9IRPfY7HAFT7hEyAUr4+vlTNTpQJRZ+gj wVTu30ECttRVzZm2lezfiDWf8m9o1yUwSVqyCNUyrsjzOs0t76qc5Mm9Mgjaoc+hpq/p/SsrRt0 eQNZTF+QyK4aWnNb260u6G1O0rWmMmd0zipB368Co/XL1IY3r68mrkxmgbJ9Tx8VNwWb0CgC5KD z9vazUqom5MZ8tZCPsOkrc3Yv125qhtcwC+2D0wgM2HFotSglBGlhfBl3GiLQLiAF8hqFhYf6AA vaCjFfi0QWihrAIiQiuyCXaeu/ss9h/LP8dB1HQeY+d96fO3YrW2MPAb3JbLEl6/PemcZQ1xEPA xCUQVUedeS/ipK8lSPbsTvy X-Received: by 2002:a17:907:c78b:b0:c1f:e09d:12 with SMTP id a640c23a62f3a-c212a395aeemr1639036766b.25.1787066433278; Tue, 18 Aug 2026 08:20:33 -0700 (PDT) Received: from [127.0.0.2] ([195.100.225.50]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c217fea1e64sm213893266b.21.2026.08.18.08.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2026 08:20:32 -0700 (PDT) From: Malte Wechter Date: Tue, 18 Aug 2026 17:20:21 +0200 Subject: [PATCH 1/2] rust: kunit: add config to fail kunit tests if a lockdep warning is triggered 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: <20260818-lockdep-kunit-v1-1-66ceb1a272e3@gmail.com> References: <20260818-lockdep-kunit-v1-0-66ceb1a272e3@gmail.com> In-Reply-To: <20260818-lockdep-kunit-v1-0-66ceb1a272e3@gmail.com> To: Brendan Higgins , David Gow , Rae Moar , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Malte Wechter X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1787066429; l=2312; i=maltewechter@gmail.com; s=20260812; h=from:subject:message-id; bh=lVVGyoI0yNkmpTkc1xzUBaTF6I8x9HnW591ib48kPo8=; b=HGj1MbpngcLllNXMzXP2g3dYt2CDx0pP7ylYtXc5j2qZLhGojjgg1devKpZTqDNF8zhU1MGSr QAC9vK7vhL5D8eocII5w0+NRlmFq8CaiMmzljBtgXGeYDW259aG9FH8 X-Developer-Key: i=maltewechter@gmail.com; a=ed25519; pk=Ta/JQQMOW0Cbxp+yEwWqWFEyKFRyuQeSoYicwD7yvWI= When running KUnit tests and a lockdep warning is triggered, the test is still marked as passed based only on if test assertions are true. Thus, add a Kconfig option CONFIG_RUST_LOCKDEP_KUNIT_DEBUG_LOCKS. When this option selected, if lockdep triggers during a test, fail the test. Signed-off-by: Malte Wechter --- lib/kunit/Kconfig | 13 +++++++++++++ rust/macros/kunit.rs | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig index 94ff8e4089bfb..30bac00c42ce1 100644 --- a/lib/kunit/Kconfig +++ b/lib/kunit/Kconfig @@ -142,4 +142,17 @@ config KUNIT_UML_PCI =20 If unsure, say N. =20 +config RUST_LOCKDEP_KUNIT_DEBUG_LOCKS + bool "Enable extra debug_locks assertion in Rust KUnit tests" + depends on RUST + depends on LOCKDEP + default n + help + Adds an extra assertion to each Rust kunit test case that asserts + that the debug_locks flag from `lockdep` is unchanged. This is useful + when writing unit tests that could potentially trigger a lockdep warnin= g, + this makes it so the KUnit test does not succeed if the test assertions= are + true, but a lockdep warning is triggered. + + If unsure, say N. endif # KUNIT diff --git a/rust/macros/kunit.rs b/rust/macros/kunit.rs index ae20ed6768f15..d1cd0349f86f0 100644 --- a/rust/macros/kunit.rs +++ b/rust/macros/kunit.rs @@ -144,9 +144,19 @@ macro_rules! assert_eq { // here to reduce the length of the assert message. #(#cfg_attrs)* { + #[cfg(CONFIG_RUST_LOCKDEP_KUNIT_DEBUG_LOCKS)] + let __debug_locks_snapshot =3D ::kernel::bindings::deb= ug_locks; + (*_test).status =3D ::kernel::bindings::kunit_status_K= UNIT_SUCCESS; use ::kernel::kunit::is_test_result_ok; assert!(is_test_result_ok(#test())); + + #[cfg(CONFIG_RUST_LOCKDEP_KUNIT_DEBUG_LOCKS)] + { + let __debug_locks_ok =3D + ::kernel::bindings::debug_locks =3D=3D __debug= _locks_snapshot; + assert!(__debug_locks_ok); + } } } }); --=20 2.51.2 From nobody Mon Sep 28 18:33:57 2026 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71A224746C6 for ; Tue, 18 Aug 2026 15:20:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787066439; cv=none; b=YmQikaLx/Ie1WpOMvlXdQHnjROgGYEKEQmKo0MpuGFwszWpuwiN7l4+66FtJq/euDqtJ3gsDNIQeBwn4QnGh+nRQWnNaLLolaEmA5NHciCpWmgsOVk7yvhzOdj40ur7zGNN2+p2eLQn2YIVSHnWGLRjyB6A8aLBux+Ish+J6fbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787066439; c=relaxed/simple; bh=6dAacv04h6+fbKsAtNuH1TZu5kOgCxlFp0QG+NiXDjM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SwhYsDuOGVgfGCDupBx1PM+mAM/GegdjI2+yzIzuCvbEildQ/0VsCkG3fVdVPB0hhLkvpJsF9RSfBdbF1D2fXP/KJ11OAV0QI9HVi0nVxSGt2pYo9wnPsp+kUwX6tc6smS/Aj3Vm8T0o8I5M989iXbG7AKy/x98MsR9e3GmrTCU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=p12/inqK; arc=none smtp.client-ip=209.85.218.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="p12/inqK" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-c15d3cd51b2so553975266b.3 for ; Tue, 18 Aug 2026 08:20:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787066436; x=1787671236; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=06fwIs7Il0udcSLvnfSZmsAN+uvE4gcV1+TENh0/uk0=; b=p12/inqKw7vAnCiaXAPnFW7AF+hL98CmPnRqhT7PjAisREFK8l4QmqJw2mjltobb9s jD866ZMyenag4gsmWs2qVu7EfAD5IbDNpSlNQbDN1bW2lz1pIh9K0B7WM1zuK1tqvzV4 Sgp3Gmdn/w3Qz8AnjjpmpnkYMES1HoPUaItIAirG7f0HuH+YZxkqMgH1SZwefv4L+CeX kbFMmKcYOANo0I5CnWGk9QNUE3NtsRaMg9Nu0DtAvCKbnVv7koImMOaTHxYphp33yVzo czLE6nLH0a83GBxMvBoge2tbRnVoMEzXLWW63kkzml0h9ikV6nVXJIPZYnbp92G9NFcg nBJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787066436; x=1787671236; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=06fwIs7Il0udcSLvnfSZmsAN+uvE4gcV1+TENh0/uk0=; b=HV+elem/S2Gljft3Xkjkgy1mSAdhXo6lmaPi5MrQwc7IKIm4g7niafrtzuWp3jZEPl blfcXLD3uRE49EdrcQxpgwaDd2g2ukCgAmEULSqCZboiNF7rMgC+7Ko4IFzIxoyaBVi5 g/OvXVL8A8u7MLrfk2k1grKjUmESsQrzk8+bwQyxmRtqjDdy5It4WW2gIkZRXey3rStb hvrLbwZ2AKooAQNC5awlAMBJ+jqdka37EfUeMoU4YxSE7kmkMIk6dYfJ4IfZyH/eW9ny QBJXveFBOIv1XtzGv8uPFloo7T3f45sK5efTN7yEjmyJif1JFbOrj5WynMhsPEGUJa9K VW6A== X-Forwarded-Encrypted: i=1; AHgh+RooTWGdzn6z9J/6HN8GaNTIf7288fhVH7ky8pz0YbvQJbmbqzJWYPtCGVQUAieDA3RQjjS2VwD42jp8wgU=@vger.kernel.org X-Gm-Message-State: AOJu0Ywdb7QaB7pqDOvLaBkU9aK51cBVfNd825Kto1OaljYLHc5k1nWX KP9IXY8wfHNjLJJkfd2kHHJyvPCSUNSFBNVo6K5nbAQdQMzJEkkDHGlG X-Gm-Gg: AR+sD11+B14mRJi06wWBCJbZYOxBgmPPWBQMUkDeG+eRxYA9XFR1jb4N4msXkVYIWbB EJjZ95iswFBxKvRUuc3LiVyMJD3i46QtjSTksDNoE7LvVxzC/W5nUxCIGmBqmSJgsKR9w6QSGKX eelAajmU/f97jrbKHT1ZyD4Ef9w+Sfb0uqxxlZvFE4Zzrh4fCyr20ghlpOmlhFpZSeZCp45gA1m 4p3Ug85S3gYhuRNCmSGcF1VZOqL+hW6Eg43axnFCBIUk0R44oJD1Qv62wmaAOhsuferdwxuB3r+ iepQjcaDUY3KEUUmwxnBw6aBKo70UwhB/SV1ctbAt9kOpZ0syhPnmpRyG9jE5hyNFJTWKIfiRrH aSy6oMUEffTe28J7gSdjV1Zr11eTtkXOBVpT7JCxl/cTnfTsEDcHz6qNkIleqFcdEsJBCp8u/2B nqgi6qn//3UxktWP8Kt4vhgztxyTMh5XsZz7fbl1Xr80Aac1edmi3exweq1ptzIWDqaCsRFsvbP ffQpgpudvrgTcve03Ve3XsX X-Received: by 2002:a17:907:f495:b0:c21:35d0:f435 with SMTP id a640c23a62f3a-c216bba944fmr957126766b.10.1787066435233; Tue, 18 Aug 2026 08:20:35 -0700 (PDT) Received: from [127.0.0.2] ([195.100.225.50]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c217fea1e64sm213893266b.21.2026.08.18.08.20.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2026 08:20:34 -0700 (PDT) From: Malte Wechter Date: Tue, 18 Aug 2026 17:20:22 +0200 Subject: [PATCH 2/2] rust: kunit: add config to fail kunit if TAINT_WARN is set 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: <20260818-lockdep-kunit-v1-2-66ceb1a272e3@gmail.com> References: <20260818-lockdep-kunit-v1-0-66ceb1a272e3@gmail.com> In-Reply-To: <20260818-lockdep-kunit-v1-0-66ceb1a272e3@gmail.com> To: Brendan Higgins , David Gow , Rae Moar , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Malte Wechter X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1787066429; l=2506; i=maltewechter@gmail.com; s=20260812; h=from:subject:message-id; bh=6dAacv04h6+fbKsAtNuH1TZu5kOgCxlFp0QG+NiXDjM=; b=ahmFApyQ7Dw7FD/RQQuqEAn7g4Be0BUT/tBSNiJh0WjMb7WWzGAEfFksYvNuB0rAxm8slz8Lq wUa/pfQAaRWAK08/nIz373DF2ng1rriUZ6cBZRok1wFIZfcQVFglTCw X-Developer-Key: i=maltewechter@gmail.com; a=ed25519; pk=Ta/JQQMOW0Cbxp+yEwWqWFEyKFRyuQeSoYicwD7yvWI= Triggering a `BUG: sleeping function called from invalid context` does not mark the unit test as failed. Add a CONFIG_RUST_TAINT_WARN_CHECK to enable the assertion of TAINT_WARN being set during a unit test. Signed-off-by: Malte Wechter --- lib/kunit/Kconfig | 11 +++++++++++ rust/macros/kunit.rs | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig index 30bac00c42ce1..4025b5b305549 100644 --- a/lib/kunit/Kconfig +++ b/lib/kunit/Kconfig @@ -154,5 +154,16 @@ config RUST_LOCKDEP_KUNIT_DEBUG_LOCKS this makes it so the KUnit test does not succeed if the test assertions= are true, but a lockdep warning is triggered. =20 + If unsure, say N. + +config RUST_KUNIT_TAINT_WARN_CHECK + bool "Enable extra taint assertion in KUnit tests" + depends on RUST + default n + help + Adds an extra assertion to each Rust kunit test case that asserts + that the kernel is not tainted. If the kernel becomes tainted with a TA= INT_WARN, + Enabling this config marks the test as failed. + If unsure, say N. endif # KUNIT diff --git a/rust/macros/kunit.rs b/rust/macros/kunit.rs index d1cd0349f86f0..90264ef54a3a8 100644 --- a/rust/macros/kunit.rs +++ b/rust/macros/kunit.rs @@ -146,6 +146,10 @@ macro_rules! assert_eq { { #[cfg(CONFIG_RUST_LOCKDEP_KUNIT_DEBUG_LOCKS)] let __debug_locks_snapshot =3D ::kernel::bindings::deb= ug_locks; + #[cfg(CONFIG_RUST_KUNIT_TAINT_WARN_CHECK)] + let __is_tainted_snapshot =3D + ::kernel::bindings::test_taint(::kernel::bindings:= :TAINT_WARN); + =20 (*_test).status =3D ::kernel::bindings::kunit_status_K= UNIT_SUCCESS; use ::kernel::kunit::is_test_result_ok; @@ -157,6 +161,13 @@ macro_rules! assert_eq { ::kernel::bindings::debug_locks =3D=3D __debug= _locks_snapshot; assert!(__debug_locks_ok); } + #[cfg(CONFIG_RUST_KUNIT_TAINT_WARN_CHECK)] + { + let __is_tainted =3D + ::kernel::bindings::test_taint(::kernel::bindi= ngs::TAINT_WARN) + =3D=3D __is_tainted_snapshot; + assert!(__is_tainted); + } } } }); --=20 2.51.2