public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Samu Onkalo <samu.p.onkalo@nokia.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] workqueues: change cancel_work_sync() to clear	work->data
Date: Thu, 25 Feb 2010 12:13:44 +0900	[thread overview]
Message-ID: <4B85EAE8.8040104@kernel.org> (raw)
In-Reply-To: <20100224202031.GA26987@redhat.com>

Hello,

On 02/25/2010 05:20 AM, Oleg Nesterov wrote:
> In short: change cancel_work_sync(work) to mark this work as "never
> queued" upon return.
> 
> When cancel_work_sync(work) succeeds, we know that this work can't be
> queued or running, and since we own WORK_STRUCT_PENDING nobody can change
> the bits in work->data under us. This means we can also clear the "cwq"
> part along with _PENDING bit lockless before return, unless the work is
> queued nobody can assume get_wq_data() is stable even under cwq->lock.
> 
> This change can speedup the subsequent cancel/flush requests, and as
> Dmitry pointed out this simplifies the usage of work_struct's which
> can be queued on different workqueues. Consider this pseudo code from
> the input subsystem:
> 
> 	struct workqueue_struct *WQ;
> 	struct work_struct *WORK;
> 
> 	for (;;) {
> 		WQ = create_workqueue();
> 		...
> 		if (condition())
> 			queue_work(WQ, WORK);
> 		...
> 		cancel_work_sync(WORK);
> 		destroy_workqueue(WQ);
> 	}
> 
> If condition() returns T and then F, cancel_work_sync() will crash the
> kernel because WORK->data still points to the already destroyed workqueue.
> With this patch the code like above becomes correct.
> 
> Suggested-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>

Yeap, generally looks good to me and I've been doing similar things to
implement non-reentrant workqueues (records the last cpu a work was on
in work->dataa after the work is dispatched to a worker thread).  I'll
add this to the series.

Thank you.

-- 
tejun

  reply	other threads:[~2010-02-25  3:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-24 20:20 [PATCH 1/3] workqueues: change cancel_work_sync() to clear work->data Oleg Nesterov
2010-02-25  3:13 ` Tejun Heo [this message]
2010-02-25  9:53 ` Dmitry Torokhov

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=4B85EAE8.8040104@kernel.org \
    --to=tj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=samu.p.onkalo@nokia.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