From mboxrd@z Thu Jan 1 00:00:00 1970 From: Frederic Weisbecker Subject: Re: Q: cgroup: Questions about possible issues in cgroup locking Date: Wed, 21 Dec 2011 18:56:35 +0100 Message-ID: <20111221175632.GF17668__36026.38311354$1324490212$gmane$org@somewhere> References: <20111221034334.GD17668@somewhere> <20111221130848.GA19679@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <20111221130848.GA19679-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: Oleg Nesterov Cc: Containers , LKML , Paul Menage , Tejun Heo , Cgroups , Andrew Morton , "Paul E. McKenney" , Mandeep Singh Baines List-Id: containers.vger.kernel.org On Wed, Dec 21, 2011 at 02:08:48PM +0100, Oleg Nesterov wrote: > On 12/21, Frederic Weisbecker wrote: > > Hi, > > > > Starring at some parts of cgroups, I have a few questions: > > > > - Is cgroup_enable_task_cg_list()'s while_each_thread() safe > > against concurrent exec()? The leader may change in de_thread() > > and invalidate the test done in while_each_thread(). > > Yes. Oh, we need to do something with while_each_thread. Would something like this work? diff --git a/include/linux/sched.h b/include/linux/sched.h index c0c5876..e002a00 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2293,8 +2293,12 @@ extern bool current_is_single_threaded(void); #define do_each_thread(g, t) \ for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do -#define while_each_thread(g, t) \ - while ((t = next_thread(t)) != g) +#define while_each_thread(g, t) \ + while (({ \ + struct task_struct *__prev = t; \ + t = next_thread(t); \ + t != __prev && t != g; \ + })) static inline int get_nr_threads(struct task_struct *tsk) {