From nobody Tue Dec 2 02:06:43 2025 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.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 84F572F693A for ; Thu, 20 Nov 2025 15:02:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763650972; cv=none; b=kadWwAOQPau1LrJWkwwX1QEONAO/esFv/SG5rG+/3oMOUHdB4peL7rtv/7jRkEp2aQEw7KtG9bm0Z3kxHDkFxhqNTka3fruTHRQ1Y5OEdWQ9KhIGVVi2+Q31B7d8RZ5W+VMJlG1T1/q5cJmZWrVpv6M91ECRQuhB4PQKK/1kxg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763650972; c=relaxed/simple; bh=g/pcRuqNqSJ9il1AN9uXiWPsEHGF2sqboQr2ZT1RndI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oCYP/8/CcFn3qjNIbc3djr9H5mYqNNSnQvQRs/e8eFz8adQjF4VfhKSMkM+coyAs0GXhDQfo78NCzK/wbAE+gClfOxe/pQWoyl8DAVzqwgT7ObOIusDQfjYBvIhU6Ikvr1EcMdt5tD63WvtiC/Dqw0Y8L84zuX7c+gGXGRealC4= 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=2l8HqkQ7; arc=none smtp.client-ip=209.85.128.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="2l8HqkQ7" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-47106a388cfso6312625e9.0 for ; Thu, 20 Nov 2025 07:02:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763650968; x=1764255768; 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=+xm08Oqaiz0C+41w88sCv4Knf0HeT4Y61beURoEgshc=; b=2l8HqkQ71zJDzTmEBSxYyjhjsek9KqM6EKRmA2DqPBhmWVaXIxDjonC+1GAO16KA5k McapSz6xQJu3X5ntV04jI/XKwWWs80RL7lFA/Wb1Xv5ngMBhkj0fWD6ki/kXIRPNGkZe JVkYaLz8SdZdFSBc1i/Oz2yFD1QMvrDLeePKo8LOz/Roqaniow0W3GSknfjBbgVB79H/ zsYrLGjjuUfiPlpjXkpj3LiH9ORmrj6lt9X94Kyx0xZLs68QrACXUjIJ8v1Y0kdnAy6d REcqDh0qHyqYnSViaf2iQA0SgneatjkicvSEi2q2w0BfH/93+1YSu0PMgQbHMLy4Ycjl ArwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763650968; x=1764255768; 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=+xm08Oqaiz0C+41w88sCv4Knf0HeT4Y61beURoEgshc=; b=k3VbOroKCotO9qgorNcX3E7WpkEcj6S/4VUewnvo+k6qlBjFMIMdigYLqCZwWYBaqx rd9LqFG0mWJ+wIncee7RtkRjNeXL3lSChKOKD9ewI6wuYir3+qWgfVXKU+rxbrzan+Sx MeD7HK90eGKDcGQqfdHWemh+zpUHoFHlcFxkVm6/ZKHVXxGQYnQEX5rpcP0vZFOwbbz8 24QuwsTTFxHISv8pa+BLsd5EROwbPA1vh6jXpaRspQKbwq+v0DcFJxZ+STEukcD1UEnJ l2GUUAwE6tE4IJ8tB6q9XDI1rSnuFZyOdzZXQbvIf6yMHaxXHZeEFk+hbzUA6GRKQs40 2uxg== X-Forwarded-Encrypted: i=1; AJvYcCX0LVGnP9mT9f+8u2/GccaGAb2HQh2/E+bDba6n3HT+VY1w1bV3bC461Rk4bibzXz/Idh55Vq/JGKMwRno=@vger.kernel.org X-Gm-Message-State: AOJu0YydDl2OmONjuRxVKTVm126xlL7k/rZZQg21NMzyD8q08NxBLL82 5nNM1Fvcgt5SgrQF3Al9UpkbQ+lR76iok778zsI8pVmIxOncFogAsNdfq2iq94nFMPVYoP1r02T WZw== X-Google-Smtp-Source: AGHT+IGUHW8T7PbhGDmbj5YjoSY8aOAhL/hfcFkM7c1fjnxT41/dPSOy7IIJVzHNh1nc5oCgWusA4fLoNQ== X-Received: from wmbd17.prod.google.com ([2002:a05:600c:58d1:b0:477:76e1:9b4e]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:470a:b0:477:1bb6:17e5 with SMTP id 5b1f17b1804b1-477b8d8b887mr39140845e9.30.1763650967589; Thu, 20 Nov 2025 07:02:47 -0800 (PST) Date: Thu, 20 Nov 2025 15:49:03 +0100 In-Reply-To: <20251120145835.3833031-2-elver@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251120145835.3833031-2-elver@google.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog Message-ID: <20251120145835.3833031-3-elver@google.com> Subject: [PATCH v4 01/35] compiler_types: Move lock checking attributes to compiler-context-analysis.h 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" The conditional definition of lock checking macros and attributes is about to become more complex. Factor them out into their own header for better readability, and to make it obvious which features are supported by which mode (currently only Sparse). This is the first step towards generalizing towards "context analysis". No functional change intended. Signed-off-by: Marco Elver Reviewed-by: Bart Van Assche --- v4: * Rename capability -> context analysis. --- include/linux/compiler-context-analysis.h | 32 +++++++++++++++++++++++ include/linux/compiler_types.h | 18 ++----------- 2 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 include/linux/compiler-context-analysis.h diff --git a/include/linux/compiler-context-analysis.h b/include/linux/comp= iler-context-analysis.h new file mode 100644 index 000000000000..f8af63045281 --- /dev/null +++ b/include/linux/compiler-context-analysis.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Macros and attributes for compiler-based static context analysis. + */ + +#ifndef _LINUX_COMPILER_CONTEXT_ANALYSIS_H +#define _LINUX_COMPILER_CONTEXT_ANALYSIS_H + +#ifdef __CHECKER__ + +/* Sparse context/lock checking support. */ +# define __must_hold(x) __attribute__((context(x,1,1))) +# define __acquires(x) __attribute__((context(x,0,1))) +# define __cond_acquires(x) __attribute__((context(x,0,-1))) +# define __releases(x) __attribute__((context(x,1,0))) +# define __acquire(x) __context__(x,1) +# define __release(x) __context__(x,-1) +# define __cond_lock(x, c) ((c) ? ({ __acquire(x); 1; }) : 0) + +#else /* !__CHECKER__ */ + +# define __must_hold(x) +# define __acquires(x) +# define __cond_acquires(x) +# define __releases(x) +# define __acquire(x) (void)0 +# define __release(x) (void)0 +# define __cond_lock(x, c) (c) + +#endif /* __CHECKER__ */ + +#endif /* _LINUX_COMPILER_CONTEXT_ANALYSIS_H */ diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index 0a1b9598940d..7eb8d8db6c28 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -24,6 +24,8 @@ # define BTF_TYPE_TAG(value) /* nothing */ #endif =20 +#include + /* sparse defines __CHECKER__; see Documentation/dev-tools/sparse.rst */ #ifdef __CHECKER__ /* address spaces */ @@ -34,14 +36,6 @@ # define __rcu __attribute__((noderef, address_space(__rcu))) static inline void __chk_user_ptr(const volatile void __user *ptr) { } static inline void __chk_io_ptr(const volatile void __iomem *ptr) { } -/* context/locking */ -# define __must_hold(x) __attribute__((context(x,1,1))) -# define __acquires(x) __attribute__((context(x,0,1))) -# define __cond_acquires(x) __attribute__((context(x,0,-1))) -# define __releases(x) __attribute__((context(x,1,0))) -# define __acquire(x) __context__(x,1) -# define __release(x) __context__(x,-1) -# define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0) /* other */ # define __force __attribute__((force)) # define __nocast __attribute__((nocast)) @@ -62,14 +56,6 @@ static inline void __chk_io_ptr(const volatile void __io= mem *ptr) { } =20 # define __chk_user_ptr(x) (void)0 # define __chk_io_ptr(x) (void)0 -/* context/locking */ -# define __must_hold(x) -# define __acquires(x) -# define __cond_acquires(x) -# define __releases(x) -# define __acquire(x) (void)0 -# define __release(x) (void)0 -# define __cond_lock(x,c) (c) /* other */ # define __force # define __nocast --=20 2.52.0.rc1.455.g30608eb744-goog