mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kthread: Annotate lockless to_kthread() flags access
@ 2026-09-20  7:07 Kunwu Chan
  2026-09-20 13:17 ` Bradley Morgan
  2026-09-25  9:34 ` Christian Brauner
  0 siblings, 2 replies; 3+ messages in thread
From: Kunwu Chan @ 2026-09-20  7:07 UTC (permalink / raw)
  To: frederic, longman, juri.lelli, peterz, kees+treewide, brauner
  Cc: linux-kernel, paulmck, Kunwu Chan

do_exit() calls synchronize_group_exit(), which modifies task->flags
under sighand->siglock:

	tsk->flags |= PF_POSTCOREDUMP;

The sanity check in to_kthread() reads the same flags word without
holding that lock:

	WARN_ON(!(k->flags & PF_KTHREAD));

PF_KTHREAD is set once when the task becomes a kthread and is never
cleared for the lifetime of the task.  Since PF_KTHREAD is immutable,
the check does not depend on synchronization with updates to other
bits in task->flags.

Use READ_ONCE() to annotate the intentional lockless access.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
 kernel/kthread.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/kthread.c b/kernel/kthread.c
index a3f95c90456b..cc8cb5d3eab7 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -81,7 +81,7 @@ enum KTHREAD_BITS {
 
 static inline struct kthread *to_kthread(struct task_struct *k)
 {
-	WARN_ON(!(k->flags & PF_KTHREAD));
+	WARN_ON(!(READ_ONCE(k->flags) & PF_KTHREAD));
 	return k->worker_private;
 }
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-25  9:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-20  7:07 [PATCH] kthread: Annotate lockless to_kthread() flags access Kunwu Chan
2026-09-20 13:17 ` Bradley Morgan
2026-09-25  9:34 ` Christian Brauner

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®