From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F9523750D6; Sat, 12 Sep 2026 09:32:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789205551; cv=none; b=uxw9020RruY5mhh4Djy3+DvSpnyN7jhs21XlVPDA7z8Z9mQiFAxE0Qu/Odn+G/EQUyi5kgbPIpyPyhUTBN4KzHr3OtscY5Ay1bCvdCPDVK6383bUbcuFGNEHXLrAGYB/kSNGHZoNTn36S7yKDchgCw1KUAQkxsIqKWFwbffJWJE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789205551; c=relaxed/simple; bh=UQfEkgjW+wenQ1ExtmXMMCNZebB7YNCRoensvl2z0kE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rySTClaQF8B7o+IBVJw+ybBaEqWXqF3jistHU8taD6HvDr2ajRCxINfxiu+wsTrYANG7CKOk4MwU3CdK1kRpgAu2g8LC0nK6D9kmvHhzkv7kRqbS9P5CMvPAfQ+a7nXfaWWQvRwewcLFGhzYiKgbG4VBVdG7ron/bQ846Pq2y18= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=eRITeSGw; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="eRITeSGw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AA3C1F000FF; Sat, 12 Sep 2026 09:32:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789205549; bh=2q6fGHQpJWMkRZJ7JRXg/YD6JZwroNtEx8I9hJMafuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eRITeSGw5VaohyfYqKnz9lXKDz/f/qPtiu6YfIuYQ6JRTDVOPGc9Ybx4faZNMbUDG bdub9MELM/rieiuvtTZKB8uyHSt3fv7QVlFHzUN33ENMtFE5+NPuibIjk7aqUM4RTv /v8Z0r4rHHnHo+oO+/s2Ay1eXNdT5P/n8HlzU9dk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Marco Elver , "Peter Zijlstra (Intel)" , Bart Van Assche , Sasha Levin Subject: [PATCH 6.18 0025/1518] compiler_types: Move lock checking attributes to compiler-context-analysis.h Date: Sat, 12 Sep 2026 08:36:34 +0200 Message-ID: <20260912065623.991449727@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065623.398859879@linuxfoundation.org> References: <20260912065623.398859879@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Marco Elver [ Upstream commit de15fecae44df8254fa597bad7eb3680a8b1c10c ] 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 Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Bart Van Assche Link: https://patch.msgid.link/20251219154418.3592607-2-elver@google.com Stable-dep-of: 912edebe8501 ("futex: Provide rt_mutex_.*_schedule() equivalents for futex scheduling") Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- 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 --- /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 */ --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -37,6 +37,8 @@ # define BTF_TYPE_TAG(value) /* nothing */ #endif +#include + /* sparse defines __CHECKER__; see Documentation/dev-tools/sparse.rst */ #ifdef __CHECKER__ /* address spaces */ @@ -47,14 +49,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)) @@ -75,14 +69,6 @@ static inline void __chk_io_ptr(const vo # 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