Re: [PATCH, RFC] kthread: (possibly) a missing memory barrier in kthread_stop()

From: Dmitry Adamushko
Date: Tue Feb 19 2008 - 08:42:15 EST


btw.,

(a bit more of 'nit-picking' :-)

to work properly, kthread_stop() should also impose one of the
following requirements on a 'kthread' loop:

- a loop can be interrupted _only_ as a result of
'kthread_should_stop() == true'
and no concurrent kthread_stop() calls are possible;

or

- if it can exit due to another reason, a user has to use additional
synchronization means to make sure than kthread_stop() is never
called/running after a main loop has finished (makes sense as 'struct
task_struct *' can be 'obsolete')

otherwise,

note, the comment in kthread() that says "It might have exited on its
own, w/o kthread_stop. Check."

so let's suppose a 'kthread' is really "exiting on its own" and at the
same time, kthread_stop() is running on another CPU... as a result, we
may end up with kthread_stop() being blocked on
wait_for_completion(&kthread_stop_info.done) without anybody to call
complete().

Although, the requirements above don't seem to be so insane in this case.


static int kthread(void *_create)
{
...
if (!kthread_should_stop())
ret = threadfn(data); <---- our main loop is
inside this function

/* It might have exited on its own, w/o kthread_stop. Check. */
if (kthread_should_stop()) {
kthread_stop_info.err = ret;
complete(&kthread_stop_info.done);
}
return 0;
}

--
Best regards,
Dmitry Adamushko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/