Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1067633ybl; Fri, 24 Jan 2020 14:58:28 -0800 (PST) X-Google-Smtp-Source: APXvYqyBMeRfht8bjsk9gWkeNvEgpLZLu7D0ASLwrva7kn+4xL6BQubNgLxanx4R+xe/mp0dvFHi X-Received: by 2002:a9d:4e92:: with SMTP id v18mr4228875otk.47.1579906708874; Fri, 24 Jan 2020 14:58:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579906708; cv=none; d=google.com; s=arc-20160816; b=JA4mEJLyplBCU3XDSqFbq2Uuh3GrpxKq4et7bDYl2351GOFU1u7JW9bmtrxWi5/P8e cqeq5iTKk3mwjvkN1gyJaO1HtWLZemnuL0FKG0Q3p+FdSgoPnOHxbzT8wSj16dlsp+6j cHsAen4Vs4Lg2hOsbQIlg5Pk+epUS2M24WygdS08JbJWMmYVhefLHxbv+iLICFDC0c5z NwzfU8ir3M6ITHVH4Ht6jBtj+9hLVlnMrAAg6r2UI1fTIbQIRF7sOgK7y4i9TxTeCyFv vGe2R5QeFQbqQ4O6AIrsrawglTcwUaejGpgUFHvf6Oz01IREh54S6I4ybVrWTdnKATB9 PfRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=fNqODm3MPzAsBSCY9n8l1wXAgR4AKgIMTb5pUp7NU0U=; b=YCNLwXqqhT4xjO5wsJ3pTrQT7Kg0M+T8eVeru3OWsTVUkJ70k/Yfq3VkYY3vlDSc5w v53dPICfjRBAHyQeUqIjCw6MEF2zdmPl7GYyH+RzaJ7uriiDO4pvVCqVy2MsWdm6UuBY fq+blnQHMyY28XunhV76eE03pQ97lkEN+vgp3bxOOLvugJaiZ9tOW1KnB/rwfYwlbl5W +QPiFAMMCT9uA/GfvU/Vg7ORtInOjUg91p+gR+pdZAXePdv0653qkfBVlStlONsY3D4m CQUwKRgAjoQk6InTsgQVdBP06Mi5ITMAqf9itRwi+WQWZUokxUs3nw5uY6jY2ZvIo6Tw Zsvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=srTj1j2m; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 19si470021oiq.128.2020.01.24.14.58.16; Fri, 24 Jan 2020 14:58:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=srTj1j2m; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387491AbgAXW5G (ORCPT + 99 others); Fri, 24 Jan 2020 17:57:06 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37559 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729521AbgAXW5F (ORCPT ); Fri, 24 Jan 2020 17:57:05 -0500 Received: by mail-wr1-f68.google.com with SMTP id w15so3952510wru.4 for ; Fri, 24 Jan 2020 14:57:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=fNqODm3MPzAsBSCY9n8l1wXAgR4AKgIMTb5pUp7NU0U=; b=srTj1j2mPK8t2sakwkD7rQEbDNeFFM9BwDp93dCsDs1Q20oZf59EZmlmAzOPPdf+4y YxcM9llvhHsbhRScaQhg5pfhZuQ5EK2Wiabt848H4kBft/yOeKD0KfLCT/l9W4a5Y1L4 Ws4qptwOggL7bhfng7gBhzPp9HhaA+aTg36WNq74YBut1qhS4L/ZTMqXR3HYzj9r7FGA g3OhV0aJtCq6S5MwW9QcBqn3UQ760IxL5+/lie2pPtU7H3eL61wmjRFYGCWegua4o7px G9xsghTqHOYLmfB+t0+5wgQJi9Xa2XH6e7g4cwoQw8CdIX7jxs00HjMp1GrSPYPF2HYQ 4/Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=fNqODm3MPzAsBSCY9n8l1wXAgR4AKgIMTb5pUp7NU0U=; b=kHAzSoKYBcJYzBLnW37tSJOD4/R5KY+q8aIhMoBZtXE8MsnsyjMBfaoFc1UQh3A4sL yn2DUNndsYMKIL0+/Gd9xOj85WUnJkDapJunP1BZFqY0fCmEb5lwieMcfMfJFulMn77M 8iMLnm1h5jpmR4SYCyobg4B9feg9buUNuK6q5eByq9Txa0wjyVB8FGaJM3x+dvtFY/dn pQZiDqz53sGI6iuki7RaLSRrK5LiO+h8OdA0HGQJDvdiGQSaXGNHeHMrO4aB19ba+Wpo J+TqeuoeqBXFlr6cZWR1UQY3oEnma4vC8NQC4bl+y781aQC5cHLbYl7iWISMITkrgrau TltQ== X-Gm-Message-State: APjAAAVke+9Zn2A45Zu9PLUf09x9MmtNZcbX6GdQuxM3AVH6TNovLMwe oXVsykjoK7u0yXC7bwmzd///jvpmrtArBXh9GWSCwA== X-Received: by 2002:adf:e887:: with SMTP id d7mr6634585wrm.162.1579906622211; Fri, 24 Jan 2020 14:57:02 -0800 (PST) MIME-Version: 1.0 References: <20200120145635.GA30904@blackbody.suse.cz> <20200124114017.8363-1-mkoutny@suse.com> <20200124114017.8363-2-mkoutny@suse.com> In-Reply-To: <20200124114017.8363-2-mkoutny@suse.com> From: Suren Baghdasaryan Date: Fri, 24 Jan 2020 14:56:51 -0800 Message-ID: Subject: Re: [PATCH v2 1/3] cgroup: Iterate tasks that did not finish do_exit() To: =?UTF-8?Q?Michal_Koutn=C3=BD?= Cc: cgroups mailinglist , alex.shi@linux.alibaba.com, Roman Gushchin , Johannes Weiner , kernel-team , JeiFeng Lee , linux-arm-kernel@lists.infradead.org, LKML , linux-kselftest@vger.kernel.org, linux-mediatek@lists.infradead.org, Li Zefan , matthias.bgg@gmail.com, shuah@kernel.org, Tejun Heo , Tom Cherry Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 24, 2020 at 3:40 AM Michal Koutn=C3=BD wrote= : > > PF_EXITING is set earlier than actual removal from css_set when a task > is exitting. This can confuse cgroup.procs readers who see no PF_EXITING > tasks, however, rmdir is checking against css_set membership so it can > transitionally fail with EBUSY. > > Fix this by listing tasks that weren't unlinked from css_set active > lists. > It may happen that other users of the task iterator (without > CSS_TASK_ITER_PROCS) spot a PF_EXITING task before cgroup_exit(). This > is equal to the state before commit c03cd7738a83 ("cgroup: Include dying > leaders with live threads in PROCS iterations") but it may be reviewed > later. > > Reported-by: Suren Baghdasaryan > Fixes: c03cd7738a83 ("cgroup: Include dying leaders with live threads in = PROCS iterations") > Signed-off-by: Michal Koutn=C3=BD > --- > include/linux/cgroup.h | 1 + > kernel/cgroup/cgroup.c | 23 ++++++++++++++++------- > 2 files changed, 17 insertions(+), 7 deletions(-) > > diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h > index d7ddebd0cdec..e75d2191226b 100644 > --- a/include/linux/cgroup.h > +++ b/include/linux/cgroup.h > @@ -62,6 +62,7 @@ struct css_task_iter { > struct list_head *mg_tasks_head; > struct list_head *dying_tasks_head; > > + struct list_head *cur_tasks_head; > struct css_set *cur_cset; > struct css_set *cur_dcset; > struct task_struct *cur_task; > diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c > index 735af8f15f95..a6e3619e013b 100644 > --- a/kernel/cgroup/cgroup.c > +++ b/kernel/cgroup/cgroup.c > @@ -4404,12 +4404,16 @@ static void css_task_iter_advance_css_set(struct = css_task_iter *it) > } > } while (!css_set_populated(cset) && list_empty(&cset->dying_task= s)); > > - if (!list_empty(&cset->tasks)) > + if (!list_empty(&cset->tasks)) { > it->task_pos =3D cset->tasks.next; > - else if (!list_empty(&cset->mg_tasks)) > + it->cur_tasks_head =3D &cset->tasks; > + } else if (!list_empty(&cset->mg_tasks)) { > it->task_pos =3D cset->mg_tasks.next; > - else > + it->cur_tasks_head =3D &cset->mg_tasks; > + } else { > it->task_pos =3D cset->dying_tasks.next; > + it->cur_tasks_head =3D &cset->dying_tasks; > + } > > it->tasks_head =3D &cset->tasks; > it->mg_tasks_head =3D &cset->mg_tasks; > @@ -4467,10 +4471,14 @@ static void css_task_iter_advance(struct css_task= _iter *it) > else > it->task_pos =3D it->task_pos->next; > > - if (it->task_pos =3D=3D it->tasks_head) > + if (it->task_pos =3D=3D it->tasks_head) { > it->task_pos =3D it->mg_tasks_head->next; > - if (it->task_pos =3D=3D it->mg_tasks_head) > + it->cur_tasks_head =3D it->mg_tasks_head; > + } > + if (it->task_pos =3D=3D it->mg_tasks_head) { > it->task_pos =3D it->dying_tasks_head->next; > + it->cur_tasks_head =3D it->dying_tasks_head; > + } > if (it->task_pos =3D=3D it->dying_tasks_head) > css_task_iter_advance_css_set(it); > } else { > @@ -4489,11 +4497,12 @@ static void css_task_iter_advance(struct css_task= _iter *it) > goto repeat; > > /* and dying leaders w/o live member threads */ > - if (!atomic_read(&task->signal->live)) > + if (it->cur_tasks_head =3D=3D it->dying_tasks_head && > + !atomic_read(&task->signal->live)) > goto repeat; > } else { > /* skip all dying ones */ > - if (task->flags & PF_EXITING) > + if (it->cur_tasks_head =3D=3D it->dying_tasks_head) > goto repeat; > } > } > -- > 2.24.1 > Tested-by: Suren Baghdasaryan Thanks!