From nobody Wed Feb 11 01:27:35 2026 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (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 CDD77339879 for ; Fri, 19 Dec 2025 15:45:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766159132; cv=none; b=F6u3D9f8jSkpr4L4f6UOJ9/QRHj4V4nuPd5SCYf/PEzWPpTn5zH/3ERbunk+69jnEGnz9l4egHsBfOsygzxhSASsNIiWHwPbfmcU2xiLmD02t2UBDgHanH/gT/9YrL5NT1N+OJlobqpB5Aqxm4nriSfeidxtXfTVlQb1NqqAR3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766159132; c=relaxed/simple; bh=gnuFLX8kT8gqPaa+rke7bwea6K0Ca21iuuLPz3ICNfc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RsU4zQXtP4b11S6swnIL/s7CA1kaTqBuU4bB+p8+0T5xJmxnG0m2g8mNtoKMk0gJTuDafFY3EAV+X31gKJxQFBN0aG3H65O07BewSItuJubK51C/pbp5pjP6Uq73yfNrugER7sZG9nVXzn6lYLodKPo/cSrdPREwjtp8cI8ktVw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--elver.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=daBVCbPF; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--elver.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="daBVCbPF" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-430ffa9fccaso1471347f8f.1 for ; Fri, 19 Dec 2025 07:45:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1766159128; x=1766763928; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZIbRhS5yAElvokIR1MvQQLNlZ/WUUA5jS9gYnuf7mNE=; b=daBVCbPFfUXz9zEifF1ONdfb5QyEitFsgEPo/PJBmgHAgCmc6fSd624HkORoVkBnDH 3qg+/Da6j+vcpfIx8cLsC9vw9rzT4f+IUxajpMmCJmidWN4YZCYGNuGqLq0YyTP/xdxM /biPhGxX2+Apo9J+2IzDVjTMRZ7ctgKY7GzUHry5fePeOowoBr3LEVJLSRF68SCucSg8 BC7FmXIbUbIPbATg3GfcF5aIv7dD0pH7cIWScN1X853fT0Yz/z4bQ0UG5I08F6x1W865 k/KBiyOl/pZKouk0lh+UzZbs7PKiIcO+zIVC3XHmd7W5V7bBwNU/73VmohAFkCd8zv8F CtBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766159128; x=1766763928; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZIbRhS5yAElvokIR1MvQQLNlZ/WUUA5jS9gYnuf7mNE=; b=G9NTKjZqxFMUxDVagXos6lEa+JaEAWTDTk5nuA5Aoa0c8lE3bPvo4+LsTmcW5bHx3L pHvZxpAjJMeM6mglzNFToFyXvr5DJiMtD7NTFAKoyhE8dJD8xUP0nI5w5JSMh1b4jEGT d86r9DEm87IT+qRSder9pE3LhoUGpzSza00SzQeb3sv33pqjbL5Ih3QChk6RxhgcVVY1 5IGQS92BtW5JLtfT9ff13ruKMQ/M1vU4yDXwjlUI8C5Y1zj2/nlBIHv2Lb1fakgVAhYu L5D3uvEfaSNf0HBo1KAE0g0EwAX3v1oX9rTxdXGW1rivA+sioJYSWQPc64Wyl7iw9KwG Rg2w== X-Forwarded-Encrypted: i=1; AJvYcCVvfNfynU6ogp06DmanVXgeB4lC0E6n62PePS/0ScFLDiZZSpSOAvKKFdHYpnvONXJKvU5G+NMCwtBq8+g=@vger.kernel.org X-Gm-Message-State: AOJu0Ywyugs4RHxcK8p1dCXPbh1ZQI2vGYeZ5stLhPHRtfnieOzqOlt/ QxLayCDN6Fd1QFyWflDROurOBhfRhLWXm82QUM0tUFbp4wY3ax6sddvFVnA0YFg0EkxxV60VPYe d4g== X-Google-Smtp-Source: AGHT+IEWqNQ8B2uikI0R3t/CQ7ZJwgcNL1VKKMu3VpcFkJfSPyjiMbOXjCZK3QVkgDbXUfaVN8BdAwmGKw== X-Received: from wrbfu3.prod.google.com ([2002:a05:6000:25e3:b0:431:37f:7ba1]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:5d09:0:b0:42f:a025:92b3 with SMTP id ffacd0b85a97d-4324e4c0dd4mr3283947f8f.2.1766159127887; Fri, 19 Dec 2025 07:45:27 -0800 (PST) Date: Fri, 19 Dec 2025 16:39:52 +0100 In-Reply-To: <20251219154418.3592607-1-elver@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251219154418.3592607-1-elver@google.com> X-Mailer: git-send-email 2.52.0.322.g1dd061c0dc-goog Message-ID: <20251219154418.3592607-4-elver@google.com> Subject: [PATCH v5 03/36] compiler-context-analysis: Add test stub From: Marco Elver To: elver@google.com, Peter Zijlstra , Boqun Feng , Ingo Molnar , Will Deacon Cc: "David S. Miller" , Luc Van Oostenryck , Chris Li , "Paul E. McKenney" , Alexander Potapenko , Arnd Bergmann , Bart Van Assche , Christoph Hellwig , Dmitry Vyukov , Eric Dumazet , Frederic Weisbecker , Greg Kroah-Hartman , Herbert Xu , Ian Rogers , Jann Horn , Joel Fernandes , Johannes Berg , Jonathan Corbet , Josh Triplett , Justin Stitt , Kees Cook , Kentaro Takeda , Lukas Bulwahn , Mark Rutland , Mathieu Desnoyers , Miguel Ojeda , Nathan Chancellor , Neeraj Upadhyay , Nick Desaulniers , Steven Rostedt , Tetsuo Handa , Thomas Gleixner , Thomas Graf , Uladzislau Rezki , Waiman Long , kasan-dev@googlegroups.com, linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, linux-sparse@vger.kernel.org, linux-wireless@vger.kernel.org, llvm@lists.linux.dev, rcu@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a simple test stub where we will add common supported patterns that should not generate false positives for each new supported context lock. Signed-off-by: Marco Elver --- v5: * Rename "context guard" -> "context lock". v4: * Rename capability -> context analysis. --- lib/Kconfig.debug | 14 ++++++++++++++ lib/Makefile | 3 +++ lib/test_context-analysis.c | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 lib/test_context-analysis.c diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index cd557e7653a4..8ca42526ee43 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2835,6 +2835,20 @@ config LINEAR_RANGES_TEST =20 If unsure, say N. =20 +config CONTEXT_ANALYSIS_TEST + bool "Compiler context-analysis warnings test" + depends on EXPERT + help + This builds the test for compiler-based context analysis. The test + does not add executable code to the kernel, but is meant to test that + common patterns supported by the analysis do not result in false + positive warnings. + + When adding support for new context locks, it is strongly recommended + to add supported patterns to this test. + + If unsure, say N. + config CMDLINE_KUNIT_TEST tristate "KUnit test for cmdline API" if !KUNIT_ALL_TESTS depends on KUNIT diff --git a/lib/Makefile b/lib/Makefile index aaf677cf4527..89defefbf6c0 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -331,4 +331,7 @@ obj-$(CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED) +=3D devmem= _is_allowed.o =20 obj-$(CONFIG_FIRMWARE_TABLE) +=3D fw_table.o =20 +CONTEXT_ANALYSIS_test_context-analysis.o :=3D y +obj-$(CONFIG_CONTEXT_ANALYSIS_TEST) +=3D test_context-analysis.o + subdir-$(CONFIG_FORTIFY_SOURCE) +=3D test_fortify diff --git a/lib/test_context-analysis.c b/lib/test_context-analysis.c new file mode 100644 index 000000000000..68f075dec0e0 --- /dev/null +++ b/lib/test_context-analysis.c @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Compile-only tests for common patterns that should not generate false + * positive errors when compiled with Clang's context analysis. + */ + +#include + +/* + * Test that helper macros work as expected. + */ +static void __used test_common_helpers(void) +{ + BUILD_BUG_ON(context_unsafe(3) !=3D 3); /* plain expression */ + BUILD_BUG_ON(context_unsafe((void)2; 3) !=3D 3); /* does not swallow semi= -colon */ + BUILD_BUG_ON(context_unsafe((void)2, 3) !=3D 3); /* does not swallow comm= as */ + context_unsafe(do { } while (0)); /* works with void statements */ +} --=20 2.52.0.322.g1dd061c0dc-goog