mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kthread: update comment for __to_kthread
@ 2025-06-19 12:00 Jiazi Li
  2025-06-19 17:34 ` Eric W. Biederman
  0 siblings, 1 reply; 3+ messages in thread
From: Jiazi Li @ 2025-06-19 12:00 UTC (permalink / raw)
  To: Peter Zijlstra, Andrew Morton, Eric W . Biederman
  Cc: Jiazi Li, linux-kernel, mingzhu.wang

With commit 343f4c49f243 ("kthread: Don't allocate kthread_struct
for init and umh") and commit 753550eb0ce1 ("fork: Explicitly set
PF_KTHREAD"), umh task no longer have struct kthread and PF_KTHREAD flag.
Io_uring worker thread does not have PF_KTHREAD flag, but worker_private
is not null, so update comment for __to_kthread.

Signed-off-by: Jiazi Li <jqqlijiazi@gmail.com>
Signed-off-by: mingzhu.wang <mingzhu.wang@transsion.com>
---
 kernel/kthread.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/kernel/kthread.c b/kernel/kthread.c
index 85fc068f0083..810cc244b81c 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -88,13 +88,9 @@ static inline struct kthread *to_kthread(struct task_struct *k)
 /*
  * Variant of to_kthread() that doesn't assume @p is a kthread.
  *
- * Per construction; when:
- *
- *   (p->flags & PF_KTHREAD) && p->worker_private
- *
- * the task is both a kthread and struct kthread is persistent. However
- * PF_KTHREAD on it's own is not, kernel_thread() can exec() (See umh.c and
- * begin_new_exec()).
+ * For io_uring worker thread, p->worker_private point to io_worker
+ * struct, but they do not have PF_KTHREAD flag.
+ * Return NULL for such tasks.
  */
 static inline struct kthread *__to_kthread(struct task_struct *p)
 {
-- 
2.49.0


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

* Re: [PATCH] kthread: update comment for __to_kthread
  2025-06-19 12:00 [PATCH] kthread: update comment for __to_kthread Jiazi Li
@ 2025-06-19 17:34 ` Eric W. Biederman
  2025-06-20  1:10   ` Jiazi Li
  0 siblings, 1 reply; 3+ messages in thread
From: Eric W. Biederman @ 2025-06-19 17:34 UTC (permalink / raw)
  To: Jiazi Li; +Cc: Peter Zijlstra, Andrew Morton, linux-kernel, mingzhu.wang

Jiazi Li <jqqlijiazi@gmail.com> writes:

> With commit 343f4c49f243 ("kthread: Don't allocate kthread_struct
> for init and umh") and commit 753550eb0ce1 ("fork: Explicitly set
> PF_KTHREAD"), umh task no longer have struct kthread and PF_KTHREAD flag.
> Io_uring worker thread does not have PF_KTHREAD flag, but worker_private
> is not null, so update comment for __to_kthread.

I agree the comment is a bit dated and can use being updated.

Removing the portion describing the exceptions for init and umh is good
as they no longer apply.

However I don't think we want to go on about io_uring and whatever
else winds up using p->worker_private as exceptions.  That will just
mean the comment goes stale next time there is a change.

Can you update the comment to describe what the current rules
are to detect is something is a kthread?

Perhaps:
  *
  * When "(p->flags & PF_KTHREAD)" is set the task is a kthread and will
  * always remain a kthread.  For kthreads p->worker_private always
  * points to a struct kthread.  For tasks that are not kthreads
  * p->worker_private is used to point to other things.
  *
  * Return NULL for any task that is not a kthread.
  */

Eric


> Signed-off-by: Jiazi Li <jqqlijiazi@gmail.com>
> Signed-off-by: mingzhu.wang <mingzhu.wang@transsion.com>
> ---
>  kernel/kthread.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/kthread.c b/kernel/kthread.c
> index 85fc068f0083..810cc244b81c 100644
> --- a/kernel/kthread.c
> +++ b/kernel/kthread.c
> @@ -88,13 +88,9 @@ static inline struct kthread *to_kthread(struct task_struct *k)
>  /*
>   * Variant of to_kthread() that doesn't assume @p is a kthread.
>   *
> - * Per construction; when:
> - *
> - *   (p->flags & PF_KTHREAD) && p->worker_private
> - *
> - * the task is both a kthread and struct kthread is persistent. However
> - * PF_KTHREAD on it's own is not, kernel_thread() can exec() (See umh.c and
> - * begin_new_exec()).
> + * For io_uring worker thread, p->worker_private point to io_worker
> + * struct, but they do not have PF_KTHREAD flag.
> + * Return NULL for such tasks.
>   */
>  static inline struct kthread *__to_kthread(struct task_struct *p)
>  {

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

* Re: [PATCH] kthread: update comment for __to_kthread
  2025-06-19 17:34 ` Eric W. Biederman
@ 2025-06-20  1:10   ` Jiazi Li
  0 siblings, 0 replies; 3+ messages in thread
From: Jiazi Li @ 2025-06-20  1:10 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Peter Zijlstra, Andrew Morton, linux-kernel, mingzhu.wang

On Thu, Jun 19, 2025 at 12:34:20PM -0500, Eric W. Biederman wrote:
> Jiazi Li <jqqlijiazi@gmail.com> writes:
> 
> > With commit 343f4c49f243 ("kthread: Don't allocate kthread_struct
> > for init and umh") and commit 753550eb0ce1 ("fork: Explicitly set
> > PF_KTHREAD"), umh task no longer have struct kthread and PF_KTHREAD flag.
> > Io_uring worker thread does not have PF_KTHREAD flag, but worker_private
> > is not null, so update comment for __to_kthread.
> 
> I agree the comment is a bit dated and can use being updated.
> 
> Removing the portion describing the exceptions for init and umh is good
> as they no longer apply.
> 
> However I don't think we want to go on about io_uring and whatever
> else winds up using p->worker_private as exceptions.  That will just
> mean the comment goes stale next time there is a change.
> 
> Can you update the comment to describe what the current rules
> are to detect is something is a kthread?
> 
> Perhaps:
>   *
>   * When "(p->flags & PF_KTHREAD)" is set the task is a kthread and will
>   * always remain a kthread.  For kthreads p->worker_private always
>   * points to a struct kthread.  For tasks that are not kthreads
>   * p->worker_private is used to point to other things.
>   *
>   * Return NULL for any task that is not a kthread.
>   */
> 
> Eric
> 
> 
Ok, thanks for your suggestion.
> > Signed-off-by: Jiazi Li <jqqlijiazi@gmail.com>
> > Signed-off-by: mingzhu.wang <mingzhu.wang@transsion.com>
> > ---
> >  kernel/kthread.c | 10 +++-------
> >  1 file changed, 3 insertions(+), 7 deletions(-)
> >
> > diff --git a/kernel/kthread.c b/kernel/kthread.c
> > index 85fc068f0083..810cc244b81c 100644
> > --- a/kernel/kthread.c
> > +++ b/kernel/kthread.c
> > @@ -88,13 +88,9 @@ static inline struct kthread *to_kthread(struct task_struct *k)
> >  /*
> >   * Variant of to_kthread() that doesn't assume @p is a kthread.
> >   *
> > - * Per construction; when:
> > - *
> > - *   (p->flags & PF_KTHREAD) && p->worker_private
> > - *
> > - * the task is both a kthread and struct kthread is persistent. However
> > - * PF_KTHREAD on it's own is not, kernel_thread() can exec() (See umh.c and
> > - * begin_new_exec()).
> > + * For io_uring worker thread, p->worker_private point to io_worker
> > + * struct, but they do not have PF_KTHREAD flag.
> > + * Return NULL for such tasks.
> >   */
> >  static inline struct kthread *__to_kthread(struct task_struct *p)
> >  {

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

end of thread, other threads:[~2025-06-20  1:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-19 12:00 [PATCH] kthread: update comment for __to_kthread Jiazi Li
2025-06-19 17:34 ` Eric W. Biederman
2025-06-20  1:10   ` Jiazi Li

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®