mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kunwu Chan <kunwu.chan@gmail.com>
To: frederic@kernel.org, longman@redhat.com, juri.lelli@redhat.com,
	peterz@infradead.org, kees+treewide@kernel.org,
	brauner@kernel.org
Cc: linux-kernel@vger.kernel.org, paulmck@kernel.org,
	Kunwu Chan <kunwu.chan@gmail.com>
Subject: [PATCH] kthread: Annotate lockless to_kthread() flags access
Date: Sun, 20 Sep 2026 15:07:50 +0800	[thread overview]
Message-ID: <20260920070750.2871923-1-kunwu.chan@gmail.com> (raw)

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


             reply	other threads:[~2026-09-20  7:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-20  7:07 Kunwu Chan [this message]
2026-09-20 13:17 ` Bradley Morgan
2026-09-25  9:34 ` Christian Brauner

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=20260920070750.2871923-1-kunwu.chan@gmail.com \
    --to=kunwu.chan@gmail.com \
    --cc=brauner@kernel.org \
    --cc=frederic@kernel.org \
    --cc=juri.lelli@redhat.com \
    --cc=kees+treewide@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    /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®