Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp929548ybl; Fri, 24 Jan 2020 12:09:06 -0800 (PST) X-Google-Smtp-Source: APXvYqzP6UyRLQyQO8g8WEmZKx9BFAKecFwChyj+FQyauSG9xH17RaJCXT0MxwQKUPEpmc9+CkiV X-Received: by 2002:a05:6830:1586:: with SMTP id i6mr3891553otr.221.1579896546068; Fri, 24 Jan 2020 12:09:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579896546; cv=none; d=google.com; s=arc-20160816; b=NE1XYu/MQSACYtycY/X60LV3pNLAm4c0ehnbbj8LjQaJB0qY7SnJETKJwmjhXBpNeE 3+7OCEMO6K8Ep2jQD2725JZQtIs7Px8oPYNlED7TD8TJdrUYcUkZ2tA4AkbdLk3/n/lX lhnT11sncnAdMicpI1xX+ER5ZmPBsnBoAvgWFr6rHRAOYh/2QsGTMvF14/otTpw9wPLe QRhYPbf29hUN28lH7AWSNfo7F3Yt9p5UmrlpvhudEF0BCloCH1N9aZTZWnAgfJdLw7WR F5NaBHneWEP+0L/nS4g6Hk+8WnjiRB55nVnjX2SgGzKJmbzvHQ3tnNvIkbE+v0vkNAyc KySw== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=8nEizScazXgzppAq4oLMG2yJAd886BT4PrJnMsxJkXU=; b=vUoZnMpD5m5rBD8loebXjGyFXM/bxQ1eNRN6Y2KXUl14o0RT/w5MQAsufEyRM6od5M 7BP3UulDbpJEYMZK0y9a6j2T7GPeiMtXJd8BlHkUCdEK2lqRAweYP7eZTKGQJT6kkoN4 u4a61Y88Wrch68LtXSBb3ju7McyI3R5oM8MOeAhwrhj9BJ78zUJBsQP+8tVbQX8y4G2s +uVQR6xwYVcvHY7KAlG5uwyG8D8ta3RcDzxbImqsdnefkrErA/grf5p2ma5Ry8FmB25k lXgYHE3kgFZF3mVKB4mWbTmWM+bEmZYeN/pRNDPmhNBDni7vIkk8c5SDIAWKj3zbg3e+ 0uyQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n25si266612oij.175.2020.01.24.12.08.54; Fri, 24 Jan 2020 12:09:06 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392065AbgAXLkf (ORCPT + 99 others); Fri, 24 Jan 2020 06:40:35 -0500 Received: from mx2.suse.de ([195.135.220.15]:50776 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391200AbgAXLkd (ORCPT ); Fri, 24 Jan 2020 06:40:33 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 43407B149; Fri, 24 Jan 2020 11:40:30 +0000 (UTC) From: =?UTF-8?q?Michal=20Koutn=C3=BD?= To: cgroups@vger.kernel.org Cc: alex.shi@linux.alibaba.com, guro@fb.com, hannes@cmpxchg.org, kernel-team@android.com, linger.lee@mediatek.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mediatek@lists.infradead.org, lizefan@huawei.com, matthias.bgg@gmail.com, shuah@kernel.org, surenb@google.com, tj@kernel.org, tomcherry@google.com Subject: [PATCH v2 1/3] cgroup: Iterate tasks that did not finish do_exit() Date: Fri, 24 Jan 2020 12:40:15 +0100 Message-Id: <20200124114017.8363-2-mkoutny@suse.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200124114017.8363-1-mkoutny@suse.com> References: <20200120145635.GA30904@blackbody.suse.cz> <20200124114017.8363-1-mkoutny@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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ý --- 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_tasks)); - if (!list_empty(&cset->tasks)) + if (!list_empty(&cset->tasks)) { it->task_pos = cset->tasks.next; - else if (!list_empty(&cset->mg_tasks)) + it->cur_tasks_head = &cset->tasks; + } else if (!list_empty(&cset->mg_tasks)) { it->task_pos = cset->mg_tasks.next; - else + it->cur_tasks_head = &cset->mg_tasks; + } else { it->task_pos = cset->dying_tasks.next; + it->cur_tasks_head = &cset->dying_tasks; + } it->tasks_head = &cset->tasks; it->mg_tasks_head = &cset->mg_tasks; @@ -4467,10 +4471,14 @@ static void css_task_iter_advance(struct css_task_iter *it) else it->task_pos = it->task_pos->next; - if (it->task_pos == it->tasks_head) + if (it->task_pos == it->tasks_head) { it->task_pos = it->mg_tasks_head->next; - if (it->task_pos == it->mg_tasks_head) + it->cur_tasks_head = it->mg_tasks_head; + } + if (it->task_pos == it->mg_tasks_head) { it->task_pos = it->dying_tasks_head->next; + it->cur_tasks_head = it->dying_tasks_head; + } if (it->task_pos == 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 == 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 == it->dying_tasks_head) goto repeat; } } -- 2.24.1