linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Aaron Tomlin <atomlin@atomlin.com>
To: Wenchao Hao <haowenchao22@gmail.com>
Cc: Wenchao Hao <haowenchao2@huawei.com>, Tejun Heo <tj@kernel.org>,
	 Lai Jiangshan <jiangshanlai@gmail.com>,
	linux-kernel@vger.kernel.org, neelx@redhat.com
Subject: Re: [RFC PATCH] workqueue: Fix rescuer task's name truncated
Date: Sat, 11 May 2024 15:14:03 +0100	[thread overview]
Message-ID: <qww6bjezmlxic5j2k5hpgjml2266evixfmsrvdkwmypvuzureg@rnuc66f3vskm> (raw)
In-Reply-To: <96888d51-1abb-4a96-ba6d-f84dd1f7245e@gmail.com>

On Wed, Apr 24, 2024 at 11:12:24PM GMT, Wenchao Hao wrote:
> Hi Aaron, thanks a lot for your reply.

No problem.

> I think destroy_workqueue() may not race with wq_worker_comm(),
> wq_pool_attach_mutex is used to avoid race, below is my analysis.
> (Welcome to point out if my understand is incorrect)
> 
> t1 which call destroy_workqueue()     rescuer->task
> 
> destroy_workqueue()
>   kthread_stop(rescuer->task)
>                                       rescuer_thread()
> 	                                if (should_stop) {
> 	                                  __set_current_state(TASK_RUNNING);
> 	                                  set_pf_worker(false);
>                                             mutex_lock(&wq_pool_attach_mutex);
> 				            current->flags &= ~PF_WQ_WORKER;
> 				            mutex_unlock(&wq_pool_attach_mutex);
> 	                                  return 0;
> 	                                }
> 
>   kfree(rescuer)
> 
> wq_worker_comm() would acquire wq_pool_attach_mutex then check if task->flags
> is set PF_WQ_WORKER.
> If PF_WQ_WORKER is not set, wq_worker_comm() would not access this task's worker
> any more;
> If PF_WQ_WORKER is set, the wq_pool_attach_mutex is held durning access of task's
> worker.

Indeed. If I understand correctly then a use-after-free is theoretically
impossible due to the use of the 'wq_pool_attach_mutex' in the context of
rescuer_thread() and wq_pool_attach_mutex(), respectively.

> What confuse me mostly is why the origin logic only append worker's desc when
> worker is attached to a work pool.

I can only assume there was no intention to use the rescuer kworker's
description information for this purpose. Your patch looks fine to me now.




-- 
Aaron Tomlin

  reply	other threads:[~2024-05-11 14:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-23 18:21 [RFC PATCH] workqueue: Fix rescuer task's name truncated Wenchao Hao
2024-04-23  4:55 ` Wenchao Hao
2024-04-24  7:12   ` Aaron Tomlin
2024-04-24 15:12     ` Wenchao Hao
2024-05-11 14:14       ` Aaron Tomlin [this message]
2024-05-11 14:15 ` Aaron Tomlin
2024-05-13  2:28   ` Wenchao Hao
2024-05-13 17:17   ` Tejun Heo
2024-05-14  1:37     ` Wenchao Hao

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=qww6bjezmlxic5j2k5hpgjml2266evixfmsrvdkwmypvuzureg@rnuc66f3vskm \
    --to=atomlin@atomlin.com \
    --cc=haowenchao22@gmail.com \
    --cc=haowenchao2@huawei.com \
    --cc=jiangshanlai@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neelx@redhat.com \
    --cc=tj@kernel.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;
as well as URLs for NNTP newsgroup(s).