lkml.org 
[lkml]   [2015]   [Feb]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] de_thread: Move notify_count write under lock
On 02/05, Kirill Tkhai wrote:
>
> The write operation may be reordered with the setting of group_exit_task.
> If so, this fires in exit_notify().

How?

OK, yes, "sig->notify_count = -1" can be reordered with the last unlock,
but we do not care?

group_exit_task + notify_count is only checked under the same lock, and
"notify_count = -1" can't happen until de_thread() sees it is zero.

Could you explain why this is bad in more details?


> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -920,10 +920,16 @@ static int de_thread(struct task_struct *tsk)
> if (!thread_group_leader(tsk)) {
> struct task_struct *leader = tsk->group_leader;
>
> - sig->notify_count = -1; /* for exit_notify() */
> for (;;) {
> threadgroup_change_begin(tsk);
> write_lock_irq(&tasklist_lock);
> + /*
> + * We could set it once outside the for() cycle, but
> + * this requires to use SMP barriers there and in
> + * exit_notify(), because the write operation may
> + * be reordered with the setting of group_exit_task.
> + */
> + sig->notify_count = -1; /* for exit_notify() */
> if (likely(leader->exit_state))
> break;
> __set_current_state(TASK_KILLABLE);

Perhaps something like this makes sense anyway to make the code more
clear, but in this case I'd suggest to set ->notify_count after we
check ->exit_state. And without the (afaics!) misleading comment...

Or I missed something?

Oleg.



\
 
 \ /
  Last update: 2015-02-05 15:01    [W:0.041 / U:0.156 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site