From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) (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 383FA301026 for ; Fri, 19 Dec 2025 19:12:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.65 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766171531; cv=none; b=ZiAeiizBnwByfVqxK2Drw8kBTM7AJWtidhduOd2S9kBSeuRt80O/rqtSArSDAnyteD2k4b7lwKtEQYNIc/An99+pB5ewCfOQR4DMHpven6Xoomo485QLRHYEkw8QpWqmlKd/Fp+2PQMlxv3TVWurCCE4O4mMACNHncJS9kMBErc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766171531; c=relaxed/simple; bh=UocQTd03vlm/TCD4q+onIixekG5jfPJUbAZfFLkbKEE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nBqGl1mOtW6D0VZxwiemofJLl7aSv+qyiaNeXKQODnLIbA5NwK4/Z6aEDZ8GuebCERqVIq2XYUHZwk+MndOReQQ2mDCaBNTlVISpidvUQH2cz0dTiUi5/w/G1EBBqSwLP411Rvo1pw9cH4SnXIdXy8vHJMUmwN0WTB8308QwgpQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Z2jSe4bw; arc=none smtp.client-ip=209.85.128.65 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Z2jSe4bw" Received: by mail-wm1-f65.google.com with SMTP id 5b1f17b1804b1-477ba2c1ca2so21152855e9.2 for ; Fri, 19 Dec 2025 11:12:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1766171528; x=1766776328; darn=vger.kernel.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=xBMt69sCffmrONEUk9HcTp6E3Zeeun0qAoojziALA+o=; b=Z2jSe4bwiWOMMxyuiAMa/WODkoI+++yxyG0pHlNpJtjzpcwsHk7n9IoxSgVQIuw5Rf MZKh24pZ3HmDpmfLX9LWU0MdMyZLf8fu6wmLqIYpxV1nPcqWYiATJCH5fOd9bJzi27by JITMlFumAr4Hwq2YDz3SUsqaVhEN1ok46Ub/wdgX3CasWupArUGrRw6xbolfsYCyJTKD HB7hpoBqZJxw8QplBMsAvL/1K8jT3VJ8TtggPbTO7Q4qxg5uz3SaVNLfoTUQsTxobD+4 74s6d88JU+S5/mfkzVMtzhwrXD1SGTN+eSJRHl0eCh2M/+GSI8KoypkQ5usFAaxhnkId Rpcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766171528; x=1766776328; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=xBMt69sCffmrONEUk9HcTp6E3Zeeun0qAoojziALA+o=; b=DLmJYBBkClsVpSsNIEJeLUssqDWd5ajdSW5zzD8SDaPC8rVyqf71HeydyiTCTR+/4r exATnBqE+Md5w4IGftGXUSEoAw1bJBtZBfJNiXFvk3WQGQBtQeWH/1Ke9TWjW+G/ZMgE Yp0jbuBY8FH4od96ABGNDUJI/BLXposXcL7/hCX1PLqkiz7rYyCPckLJ/VresR7mjLyn cHZCEvE+tk3vldrUE3edoOqWXnlu8NnIDc75BYIFEsOJz+bLerYQFOcz65qiboOoNZjS hNv04a0fQ5wnOkl7WukIbYs3F5BbivHsetfLj3SdFTG33we2pRNdfZfsMD+2fuFKFKih 0twQ== X-Forwarded-Encrypted: i=1; AJvYcCVAkhfTcpNapBDFwp+W6XOTMWakEk4hTZZOFgckPhDpTjbZuH/Ivedh5fH4oDZa08zksd8WvZIWb5cKww4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx8fzq3QQVwKvuIq9QcK5bSeaLd9xphqRfYVf3Ko/Qm/bSofJxM CEcMATAv2Rur1OllW/bqEgQ/RU4KWLEGYyCsG3Yie4ezcmk7Grint7ezoOqhtbcMAw== X-Gm-Gg: AY/fxX6CuE3xp/W5rAVmzy/6OvaTohBpthvpSZxUwhtgOgvP6C/9q0+kpdsmj9iG3Ab GHREM/2ye1K98QXDt/JGyz28p66KjeN5kqtYQhxrBCsB4NKm87IEFUQ8HzDe9AZghw8qqYRqpWK Shb5evgb3vo2CDiFPT88X6PuKNOqphqLt2eQ+SagRy4tYSBjP1k3Uj4DITWqfGWAKfUEg9+otMO qldKX2DsfFYadDY5Llzl3fBsYX0smuajkxIIzudQNLmICMp/3VeLKnJNyVEU+TJRe+X3tJd43Zs mAVJU0VhOkH7zJ45YgFvhOKrTgnJkFWOGtlhSqGcqp8RUAGrcPgg7TGihrs52LJnzjDIVPEjHJt f7ZiWeywY+uNGcK+T3AyqHJkDnrCaSEqZsm9lcqjr0gnodu/e+KPghlgTqRrXV0lAeVFEh55opl dgXkRHG0kFEWbyh3aYnz1mkOPW8o3kndBldBPJ0zVqDlYcz2klpDIaJ4I+368= X-Google-Smtp-Source: AGHT+IH9HIskBRHlFIQr/Osyy9yIUKVMwuoBBZxTrb8MCYHFqdOsUtEusA5GjiNqRLtoiyidJxfWVw== X-Received: by 2002:a05:600c:3506:b0:477:a246:8398 with SMTP id 5b1f17b1804b1-47d1953b774mr34567195e9.2.1766171527309; Fri, 19 Dec 2025 11:12:07 -0800 (PST) Received: from elver.google.com ([2a00:79e0:2834:9:f7c5:1bb4:fb06:fd5e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4324eaa2bdfsm6628486f8f.32.2025.12.19.11.12.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Dec 2025 11:12:06 -0800 (PST) Date: Fri, 19 Dec 2025 20:11:59 +0100 From: Marco Elver To: Bart Van Assche Cc: Peter Zijlstra , Boqun Feng , Ingo Molnar , Will Deacon , "David S. Miller" , Luc Van Oostenryck , Chris Li , "Paul E. McKenney" , Alexander Potapenko , Arnd Bergmann , 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 Subject: Re: [PATCH v5 02/36] compiler-context-analysis: Add infrastructure for Context Analysis with Clang Message-ID: References: <20251219154418.3592607-1-elver@google.com> <20251219154418.3592607-3-elver@google.com> <97e832b7-04a9-49cb-973a-bf9870c21c2f@acm.org> <2f0c27eb-eca5-4a7f-8035-71c6b0c84e30@acm.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <2f0c27eb-eca5-4a7f-8035-71c6b0c84e30@acm.org> User-Agent: Mutt/2.2.13 (2024-03-09) On Fri, Dec 19, 2025 at 11:04AM -0800, 'Bart Van Assche' via kasan-dev wrote: > On 12/19/25 10:59 AM, Marco Elver wrote: > > On Fri, 19 Dec 2025 at 19:39, 'Bart Van Assche' via kasan-dev > > wrote: > > > I'm concerned that the context_lock_struct() macro will make code harder > > > to read. Anyone who encounters the context_lock_struct() macro will have > > > to look up its definition to learn what it does. I propose to split this > > > macro into two macros: > > > * One macro that expands into "__ctx_lock_type(name)". > > > * A second macro that expands into the rest of the above macro. > > > > > > In other words, instead of having to write > > > context_lock_struct(struct_name, { ... }); developers will have to write > > > > > > struct context_lock_type struct_name { > > > ...; > > > }; > > > context_struct_helper_functions(struct_name); > > > > This doesn't necessarily help with not having to look up its > > definition to learn what it does. > > > > If this is the common pattern, it will blindly be repeated, and this > > adds 1 more line and makes this a bit more verbose. Maybe the helper > > functions aren't always needed, but I also think that context lock > > types should remain relatively few. For all synchronization > > primitives that were enabled in this series, the helpers are required. > > > > The current usage is simply: > > > > context_lock_struct(name) { > > ... struct goes here ... > > }; // note no awkward ) brace > > > > I don't know which way the current kernel style is leaning towards, > > but if we take as an example, a simple programming > > model / API is actually preferred. > Many kernel developers are used to look up the definition of a data > structure either by using ctags, etags or a similar tool or by using > grep and a pattern like "${struct_name} {\$". Breaking the tools kernel > developer use today to look up data structure definitions might cause > considerable frustration and hence shouldn't be done lightly. Fair point. In fact, it's as simple as e.g. (just tested with mutex) as this: diff --git a/include/linux/mutex_types.h b/include/linux/mutex_types.h index 80975935ec48..63ab9e65bb48 100644 --- a/include/linux/mutex_types.h +++ b/include/linux/mutex_types.h @@ -38,7 +38,8 @@ * - detects multi-task circular deadlocks and prints out all affected * locks and tasks (and only those tasks) */ -context_lock_struct(mutex) { +context_lock_struct(mutex); +struct mutex { atomic_long_t owner; raw_spinlock_t wait_lock; #ifdef CONFIG_MUTEX_SPIN_ON_OWNER @@ -59,7 +60,8 @@ context_lock_struct(mutex) { */ #include -context_lock_struct(mutex) { +context_lock_struct(mutex); +struct mutex { struct rt_mutex_base rtmutex; #ifdef CONFIG_DEBUG_LOCK_ALLOC struct lockdep_map dep_map; So the existing macro does support both use-cases as-is. I suppose we could force the above use pattern. The reason it works, is because it forward-declares the struct anyway to define the helper functions.