mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yury Norov <ynorov@nvidia.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Yury Norov" <ynorov@nvidia.com>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	"Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Matthew Wilcox" <willy@infradead.org>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@redhat.com>, "Will Deacon" <will@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>,
	"Waiman Long" <longman@redhat.com>,
	"Dennis Zhou" <dennis@kernel.org>, "Tejun Heo" <tj@kernel.org>,
	"Christoph Lameter" <cl@gentwo.org>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	"Frederic Weisbecker" <frederic@kernel.org>,
	"Neeraj Upadhyay" <neeraj.upadhyay@kernel.org>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	"Josh Triplett" <josh@joshtriplett.org>,
	"Uladzislau Rezki" <urezki@gmail.com>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
	"Lai Jiangshan" <jiangshanlai@gmail.com>,
	Zqiang <qiang.zhang@linux.dev>, "Onur Özkan" <work@onurozkan.dev>,
	"Kees Cook" <kees@kernel.org>,
	"Joel Granados" <joel.granados@kernel.org>,
	"Anna-Maria Behnsen" <anna-maria@linutronix.de>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
	"Ben Segall" <bsegall@google.com>, "Mel Gorman" <mgorman@suse.de>,
	"Valentin Schneider" <vschneid@redhat.com>,
	"K Prateek Nayak" <kprateek.nayak@amd.com>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Jann Horn" <jannh@google.com>,
	"Pedro Falcato" <pfalcato@suse.de>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowangio@gmail.com>,
	"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
	"Eugenio Pérez" <eperezma@redhat.com>,
	"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
	"Clark Williams" <clrkwllms@kernel.org>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Bill Wendling" <morbo@google.com>,
	"Justin Stitt" <justinstitt@google.com>,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	wireguard@lists.zx2c4.com, netdev@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	rcu@vger.kernel.org, virtualization@lists.linux.dev,
	linux-rt-devel@lists.linux.dev, llvm@lists.linux.dev,
	"Yury Norov" <yury.norov@gmail.com>
Subject: [PATCH 06/17] sched: assert static storage for wait queue and completion declarations
Date: Mon, 14 Sep 2026 23:13:21 -0400	[thread overview]
Message-ID: <20260915031334.1194975-1-ynorov@nvidia.com> (raw)
In-Reply-To: <20260915030336.1192299-1-ynorov@nvidia.com>

The ordinary wait queue and completion declarations statically initialize
their embedded locks. Automatic objects need runtime initialization so
lockdep receives persistent class keys.

Add ASSERT_STATIC_STORAGE() to DECLARE_WAIT_QUEUE_HEAD(),
DECLARE_SWAIT_QUEUE_HEAD() and DECLARE_COMPLETION(). Keep the _ONSTACK
variants usable without CONFIG_LOCKDEP by expanding to the underlying
initializer instead of an asserted declaration.

Convert the two automatic completions in the AMS PMU driver to
DECLARE_COMPLETION_ONSTACK().

Assisted-by: OpenAI Codex
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
 drivers/macintosh/ams/ams-pmu.c |  4 ++--
 include/linux/completion.h      | 10 +++++++---
 include/linux/swait.h           |  6 ++++--
 include/linux/wait.h            |  7 +++++--
 4 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/macintosh/ams/ams-pmu.c b/drivers/macintosh/ams/ams-pmu.c
index 1c3ce39e9a59..046a7d5dc5b2 100644
--- a/drivers/macintosh/ams/ams-pmu.c
+++ b/drivers/macintosh/ams/ams-pmu.c
@@ -48,7 +48,7 @@ static void ams_pmu_req_complete(struct adb_request *req)
 static void ams_pmu_set_register(u8 reg, u8 value)
 {
 	static struct adb_request req;
-	DECLARE_COMPLETION(req_complete);
+	DECLARE_COMPLETION_ONSTACK(req_complete);
 
 	req.arg = &req_complete;
 	if (pmu_request(&req, ams_pmu_req_complete, 4, ams_pmu_cmd, 0x00, reg, value))
@@ -61,7 +61,7 @@ static void ams_pmu_set_register(u8 reg, u8 value)
 static u8 ams_pmu_get_register(u8 reg)
 {
 	static struct adb_request req;
-	DECLARE_COMPLETION(req_complete);
+	DECLARE_COMPLETION_ONSTACK(req_complete);
 
 	req.arg = &req_complete;
 	if (pmu_request(&req, ams_pmu_req_complete, 3, ams_pmu_cmd, 0x01, reg))
diff --git a/include/linux/completion.h b/include/linux/completion.h
index fb2915676574..b514b5555722 100644
--- a/include/linux/completion.h
+++ b/include/linux/completion.h
@@ -9,6 +9,7 @@
  * See kernel/sched/completion.c for details.
  */
 
+#include <linux/compiler.h>
 #include <linux/swait.h>
 
 /*
@@ -50,7 +51,8 @@ static inline void complete_release(struct completion *x) {}
  * variables.
  */
 #define DECLARE_COMPLETION(work) \
-	struct completion work = COMPLETION_INITIALIZER(work)
+	struct completion work = COMPLETION_INITIALIZER(work);	\
+	ASSERT_STATIC_STORAGE(work)
 
 /*
  * Lockdep needs to run a non-constant initializer for on-stack
@@ -70,8 +72,10 @@ static inline void complete_release(struct completion *x) {}
 # define DECLARE_COMPLETION_ONSTACK_MAP(work, map) \
 	struct completion work = COMPLETION_INITIALIZER_ONSTACK_MAP(work, map)
 #else
-# define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
-# define DECLARE_COMPLETION_ONSTACK_MAP(work, map) DECLARE_COMPLETION(work)
+# define DECLARE_COMPLETION_ONSTACK(work) \
+	struct completion work = COMPLETION_INITIALIZER(work)
+# define DECLARE_COMPLETION_ONSTACK_MAP(work, map) \
+	DECLARE_COMPLETION_ONSTACK(work)
 #endif
 
 /**
diff --git a/include/linux/swait.h b/include/linux/swait.h
index d324419482a0..caa3028d1dd0 100644
--- a/include/linux/swait.h
+++ b/include/linux/swait.h
@@ -2,6 +2,7 @@
 #ifndef _LINUX_SWAIT_H
 #define _LINUX_SWAIT_H
 
+#include <linux/compiler.h>
 #include <linux/list.h>
 #include <linux/stddef.h>
 #include <linux/spinlock.h>
@@ -64,7 +65,8 @@ struct swait_queue {
 }
 
 #define DECLARE_SWAIT_QUEUE_HEAD(name)					\
-	struct swait_queue_head name = __SWAIT_QUEUE_HEAD_INITIALIZER(name)
+	struct swait_queue_head name = __SWAIT_QUEUE_HEAD_INITIALIZER(name);	\
+	ASSERT_STATIC_STORAGE(name)
 
 extern void __init_swait_queue_head(struct swait_queue_head *q, const char *name,
 				    struct lock_class_key *key);
@@ -82,7 +84,7 @@ extern void __init_swait_queue_head(struct swait_queue_head *q, const char *name
 	struct swait_queue_head name = __SWAIT_QUEUE_HEAD_INIT_ONSTACK(name)
 #else
 # define DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(name)			\
-	DECLARE_SWAIT_QUEUE_HEAD(name)
+	struct swait_queue_head name = __SWAIT_QUEUE_HEAD_INITIALIZER(name)
 #endif
 
 /**
diff --git a/include/linux/wait.h b/include/linux/wait.h
index 7e215330199c..5c7d49187396 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -4,6 +4,7 @@
 /*
  * Linux wait queue related types and methods
  */
+#include <linux/compiler.h>
 #include <linux/list.h>
 #include <linux/stddef.h>
 #include <linux/spinlock.h>
@@ -57,7 +58,8 @@ struct task_struct;
 	.head		= LIST_HEAD_INIT(name.head) }
 
 #define DECLARE_WAIT_QUEUE_HEAD(name) \
-	struct wait_queue_head name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
+	struct wait_queue_head name = __WAIT_QUEUE_HEAD_INITIALIZER(name);	\
+	ASSERT_STATIC_STORAGE(name)
 
 extern void __init_waitqueue_head(struct wait_queue_head *wq_head, const char *name, struct lock_class_key *);
 
@@ -74,7 +76,8 @@ extern void __init_waitqueue_head(struct wait_queue_head *wq_head, const char *n
 # define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) \
 	struct wait_queue_head name = __WAIT_QUEUE_HEAD_INIT_ONSTACK(name)
 #else
-# define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) DECLARE_WAIT_QUEUE_HEAD(name)
+# define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) \
+	struct wait_queue_head name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
 #endif
 
 static inline void init_waitqueue_entry(struct wait_queue_entry *wq_entry, struct task_struct *p)
-- 
2.53.0


  parent reply	other threads:[~2026-09-15  3:13 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15  3:03 [PATCH 00/17] Treewide: enforce static storage for object initializers Yury Norov
2026-09-15  3:03 ` [PATCH 01/17] locking/mutex: assert static storage for DEFINE_MUTEX() Yury Norov
2026-09-15  3:25   ` sashiko-bot
2026-09-15  8:23   ` Peter Zijlstra
2026-09-15  3:03 ` [PATCH 02/17] locking/rtmutex: assert static storage for DEFINE_RT_MUTEX() Yury Norov
2026-09-15  3:25   ` sashiko-bot
2026-09-15  3:03 ` [PATCH 03/17] locking/rwsem: assert static storage for semaphore definitions Yury Norov
2026-09-15  3:26   ` sashiko-bot
2026-09-15  3:03 ` [PATCH 04/17] locking/semaphore: assert static storage for DEFINE_SEMAPHORE() Yury Norov
2026-09-15  3:26   ` sashiko-bot
2026-09-15  3:03 ` [PATCH 05/17] locking/seqlock: assert static storage for DEFINE_SEQLOCK() Yury Norov
2026-09-15  3:26   ` sashiko-bot
2026-09-15  3:13 ` Yury Norov [this message]
2026-09-15  3:25   ` [PATCH 06/17] sched: assert static storage for wait queue and completion declarations sashiko-bot
2026-09-15  3:13 ` [PATCH 07/17] xarray: assert static storage for DEFINE_XARRAY_FLAGS() Yury Norov
2026-09-15  3:26   ` sashiko-bot
2026-09-15  3:13 ` [PATCH 08/17] idr: enforce the static-storage contract of DEFINE_IDR() Yury Norov
2026-09-15  3:25   ` sashiko-bot
2026-09-15  3:13 ` [PATCH 09/17] radix-tree: require static storage for RADIX_TREE() Yury Norov
2026-09-15  3:25   ` sashiko-bot
2026-09-15  3:13 ` [PATCH 10/17] klist: assert static storage for DEFINE_KLIST() Yury Norov
2026-09-15  3:25   ` sashiko-bot
2026-09-15  3:13 ` [PATCH 11/17] workqueue: assert static storage for work declarations Yury Norov
2026-09-15  3:25   ` sashiko-bot
2026-09-15  3:13 ` [PATCH 12/17] timers: assert static storage for DEFINE_TIMER() Yury Norov
2026-09-15  3:26   ` sashiko-bot
2026-09-15  3:13 ` [PATCH 13/17] kthread: assert static storage for delayed work declarations Yury Norov
2026-09-15  3:25   ` sashiko-bot
2026-09-15  3:13 ` [PATCH 14/17] ratelimit: assert static storage for DEFINE_RATELIMIT_STATE() Yury Norov
2026-09-15  3:26   ` sashiko-bot
2026-09-15  3:13 ` [PATCH 15/17] notifier: assert static storage for locking notifier heads Yury Norov
2026-09-15  3:26   ` sashiko-bot
2026-09-15  3:13 ` [PATCH 16/17] rcu: assert static storage for RCU sync and SRCU definitions Yury Norov
2026-09-15  3:26   ` sashiko-bot
2026-09-15  3:13 ` [PATCH 17/17] sysctl: assert static storage for DEFINE_CTL_TABLE_POLL() Yury Norov
2026-09-15  3:26   ` sashiko-bot
2026-09-15  6:14 ` [PATCH 00/17] Treewide: enforce static storage for object initializers Andrew Morton
2026-09-15  9:24   ` David Laight

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260915031334.1194975-1-ynorov@nvidia.com \
    --to=ynorov@nvidia.com \
    --cc=Jason@zx2c4.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=anna-maria@linutronix.de \
    --cc=bigeasy@linutronix.de \
    --cc=boqun@kernel.org \
    --cc=bsegall@google.com \
    --cc=cl@gentwo.org \
    --cc=clrkwllms@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dennis@kernel.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=edumazet@google.com \
    --cc=eperezma@redhat.com \
    --cc=frederic@kernel.org \
    --cc=jannh@google.com \
    --cc=jasowangio@gmail.com \
    --cc=jiangshanlai@gmail.com \
    --cc=joel.granados@kernel.org \
    --cc=joelagnelf@nvidia.com \
    --cc=josh@joshtriplett.org \
    --cc=juri.lelli@redhat.com \
    --cc=justinstitt@google.com \
    --cc=kees@kernel.org \
    --cc=kprateek.nayak@amd.com \
    --cc=kuba@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=ljs@kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=longman@redhat.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=morbo@google.com \
    --cc=mst@redhat.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pfalcato@suse.de \
    --cc=qiang.zhang@linux.dev \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=tglx@kernel.org \
    --cc=tj@kernel.org \
    --cc=urezki@gmail.com \
    --cc=vbabka@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=virtualization@lists.linux.dev \
    --cc=vschneid@redhat.com \
    --cc=will@kernel.org \
    --cc=willy@infradead.org \
    --cc=wireguard@lists.zx2c4.com \
    --cc=work@onurozkan.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®