Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp517111ybv; Wed, 5 Feb 2020 09:30:12 -0800 (PST) X-Google-Smtp-Source: APXvYqxxgtrqESHpfwSWRCoSWZAwDnACcaYALo8uQdp81oWeyHvwj7OyTH5DLA+hIDAejhm004ke X-Received: by 2002:a9d:58cb:: with SMTP id s11mr5104561oth.55.1580923812323; Wed, 05 Feb 2020 09:30:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580923812; cv=none; d=google.com; s=arc-20160816; b=GmqUNN+JwutL3VQ2ltAKG6tmj5shd6qsQoGB6yInxAmAtICKgXTtrMJrM6RDFuWrnl +NG93hd0Y9BlkB9qWQeujfAQm4jM3udgiVfEL2PpCZConwXutVTNnbdx0SQ4FSgRRb1v Cu4m4jm84eIAovgEgFpdvUx4MFhADKECmQjVivm0gynYpfILkGl/L5JKByIczqJGktJ1 0h+el57lnlZahzSC7jyRlMuwerdPq6nvM5NLlpZxyFhhzqdXkvnX0xXiB+VV8mrD6jnP kgnf7YQYKtrwzIGJ3o7uk8J/KR6Ev6AMOF31z0vJsNzA+VnOl8OisF0dI1kbgXqQfreA iCbg== 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=/J7K6eoBY50PYm0N/u4X3+dlKUZnt64LaOlAE9qk+tY=; b=zb/NBOQ074qi2AeCsw242uwwnPM2qp7c4yxb2RbleN3oqLsMSR+IB5XoUpIcO/zmLK QWJXLZm8CBie7ETNX8fO1JjzHz0SANbye3zY7H+Uh+K7yuj4pky00Kez5vq/4sUuwb+f Nkcran55/RXmQtZIPJDzLuggjpE80pCufPt4qsr4mhCgZ5LymX3eX+9A/QL6Is3efSsV oXMrkMMLQaUc77ttKNLj/0sLfBNelSxSpu377NIHssSBzIIXL1Yz3sY44RUhImkh8AuN /LIcnqMgB9pILyOt7gEmLYAWoA1pWfD18DO16FEVDcIOD2np7jvjueuPeF2Mhhyh7eWE GO6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lJaz2HSL; 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 e8si368440oie.96.2020.02.05.09.29.58; Wed, 05 Feb 2020 09:30:12 -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=lJaz2HSL; 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 S1727199AbgBER2B (ORCPT + 99 others); Wed, 5 Feb 2020 12:28:01 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:55564 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727083AbgBER2A (ORCPT ); Wed, 5 Feb 2020 12:28:00 -0500 Received: by mail-wm1-f68.google.com with SMTP id q9so3365351wmj.5 for ; Wed, 05 Feb 2020 09:27:58 -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=/J7K6eoBY50PYm0N/u4X3+dlKUZnt64LaOlAE9qk+tY=; b=lJaz2HSL0GodXUnBdAWn5vXGicOnSOjlEzL6WRhsXUYvoCwf2EksV/H80DsSr0HvVU jf5gZF9txDXrM3yAMqWtQrJa6rF6ZxYg2ABlbXin3ylMvhed2NeSefp4yc29oR7AO7Kq SForPuVGtkLxc0SWSZpIfaM7l+JRe3quj6YnZtk6CLCdH6Ya1+FowX4QH8PE8atAmrxL 2mwslJZqu1/pZH8QJ9X3mo5JZXE2zX0ovIXlKc9ZS9JoWrcs0qZi3ZNp1BsgCSehUGC7 pVPo2EESWoXfB1s0YdZHI7GfTR2svAMgYjRNn51zpIpuaTZN19/bg1o9tYC2NLTZCylr L8ig== 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=/J7K6eoBY50PYm0N/u4X3+dlKUZnt64LaOlAE9qk+tY=; b=M1IyWLz9T0bEoPs7NquVLizPX7s6x8AKXsqAPM7eFZahtN0m/P0B1+mz39iEhtpOi+ kjxP9KervuBoihSMG3ioir4FuGmqYMwu85vfXSxu+M2FtwJ63n8Oe+ak24fN5gfc8VAE cw05enYNHUgxCprlV19b06wWeevErWilrWNBqWTdXWoV6IMU8V6J3L6EJyrhIQq7QEQJ sujYx9UaXfJKP9uVg8mwpydGE7c29j5fGs1sMP3tdbisWsKQOmCshb+4VhG5tjQL92qh U8bmYKd1czoUcmKqo7a8PKFqZhxAd7LDbOaNf8Sgx+60WBc+AoBACIHgG0hIvPhZvqq6 Pmlw== X-Gm-Message-State: APjAAAWsi0cQMmrlA6duwfA50kG/WQMup3DA4VR27zw1OBLi8ylzf9G1 VFFQ2YJcBn7W9VyVlftRquZ21P+zX2H9JffID5iqkA== X-Received: by 2002:a1c:6a15:: with SMTP id f21mr6625580wmc.126.1580923677710; Wed, 05 Feb 2020 09:27:57 -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: From: Suren Baghdasaryan Date: Wed, 5 Feb 2020 09:27:45 -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 2:56 PM Suren Baghdasaryan wrot= e: > > On Fri, Jan 24, 2020 at 3:40 AM Michal Koutn=C3=BD wro= te: > > > > 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_EXITIN= G > > 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 dyin= g > > 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 i= n 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(struc= t css_task_iter *it) > > } > > } while (!css_set_populated(cset) && list_empty(&cset->dying_ta= sks)); > > > > - 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_ta= sk_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_ta= sk_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! Hi Folks, If this new version looks good could we get an Ack please? I need to start backporting this fix to Android and would like a confirmation before doing so. Thanks!