Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757609AbbBENjr (ORCPT ); Thu, 5 Feb 2015 08:39:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49892 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752019AbbBENjp (ORCPT ); Thu, 5 Feb 2015 08:39:45 -0500 Date: Thu, 5 Feb 2015 14:38:29 +0100 From: Oleg Nesterov To: Kirill Tkhai Cc: linux-kernel@vger.kernel.org, Andrew Morton , tkhai@yandex.ru Subject: Re: [PATCH] de_thread: Move notify_count write under lock Message-ID: <20150205133829.GA8322@redhat.com> References: <1423142000.6933.3.camel@tkhai> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1423142000.6933.3.camel@tkhai> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1662 Lines: 50 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. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/