Thread (37 messages) 37 messages, 3 authors, 2016-02-19

Re: [PATCH v4 09/22] kthread: Allow to cancel kthread work

From: Petr Mladek <pmladek@suse.com>
Date: 2016-02-19 16:22:44
Also in: linux-mm, lkml

On Mon 2016-01-25 14:17:09, Tejun Heo wrote:
On Mon, Jan 25, 2016 at 04:44:58PM +0100, Petr Mladek wrote:
quoted
+static bool __cancel_kthread_work_sync(struct kthread_work *work)
[...]
 > > +	work->canceling++;
quoted
+	ret = try_to_cancel_kthread_work(work, &worker->lock, &flags);
+
+	if (worker->current_work != work)
+		goto out_fast;
If there are two racing cancellers, wouldn't this allow the losing one
to return while the work item is still running?
If the work is running, worker->current_work must point to it.
All cancelers will see it and queue its own kthread_flush_work.
It is a bit sub-optimal but it is trivial. I doubt that there
will be many parallel cancelers in practice.
quoted
+	spin_unlock_irqrestore(&worker->lock, flags);
+	flush_kthread_work(work);
+	/*
+	 * Nobody is allowed to switch the worker or queue the work
+	 * when .canceling is set.
+	 */
+	spin_lock_irqsave(&worker->lock, flags);
+
+out_fast:
+	work->canceling--;
+	spin_unlock_irqrestore(&worker->lock, flags);
+out:
+	return ret;
Best Regards,
Petr

PS: I have updated the patchset according to your other comments.
In addition, I got rid of many try_lock games. We do not allow
to queue the same work to different workers. Therefore it should
be enough to warn if the worker changes unexpectedly. It makes
the code even more simple. I still need to do some testing.
I will send it next week, hopefully.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help