linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Michal Koutný" <mkoutny@suse.com>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Tejun Heo" <tj@kernel.org>, "Sasha Levin" <sashal@kernel.org>,
	cgroups@vger.kernel.org
Subject: [PATCH AUTOSEL 4.14 02/28] cgroup: Iterate tasks that did not finish do_exit()
Date: Wed, 18 Mar 2020 16:55:29 -0400	[thread overview]
Message-ID: <20200318205555.17447-2-sashal@kernel.org> (raw)
In-Reply-To: <20200318205555.17447-1-sashal@kernel.org>

From: Michal Koutný <mkoutny@suse.com>

[ Upstream commit 9c974c77246460fa6a92c18554c3311c8c83c160 ]

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 <surenb@google.com>
Fixes: c03cd7738a83 ("cgroup: Include dying leaders with live threads in PROCS iterations")
Signed-off-by: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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 0e21619f1c03c..61ab21c348661 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -61,6 +61,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 829943aad7beb..b275f0d0211aa 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -4051,12 +4051,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;
@@ -4114,10 +4118,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 {
@@ -4136,11 +4144,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.20.1


  reply	other threads:[~2020-03-18 21:01 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-18 20:55 [PATCH AUTOSEL 4.14 01/28] cgroup-v1: cgroup_pidlist_next should update position index Sasha Levin
2020-03-18 20:55 ` Sasha Levin [this message]
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 03/28] batman-adv: Don't schedule OGM for disabled interface Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 04/28] pinctrl: core: Remove extra kref_get which blocks hogs being freed Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 05/28] r8152: check disconnect status after long sleep Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 06/28] bnxt_en: reinitialize IRQs when MTU is modified Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 07/28] cpupower: avoid multiple definition with gcc -fno-common Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 08/28] fib: add missing attribute validation for tun_id Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 09/28] can: add missing attribute validation for termination Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 10/28] macsec: add missing attribute validation for port Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 11/28] team: add missing attribute validation for port ifindex Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 12/28] team: add missing attribute validation for array index Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 13/28] netfilter: cthelper: add missing attribute validation for cthelper Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 14/28] netfilter: nft_payload: add missing attribute validation for payload csum flags Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 15/28] drivers/of/of_mdio.c:fix of_mdiobus_register() Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 16/28] cgroup1: don't call release_agent when it is "" Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 17/28] dt-bindings: net: FMan erratum A050385 Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 18/28] arm64: dts: ls1043a: " Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 19/28] fsl/fman: detect " Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 20/28] virtio-blk: fix hw_queue stopped on arbitrary error Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 21/28] ipvlan: add cond_resched_rcu() while processing muticast backlog Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 22/28] ipvlan: do not use cond_resched_rcu() in ipvlan_process_multicast() Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 23/28] scsi: ipr: Fix softlockup when rescanning devices in petitboot Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 24/28] mac80211: Do not send mesh HWMP PREQ if HWMP is disabled Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 25/28] dpaa_eth: Remove unnecessary boolean expression in dpaa_get_headroom Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 26/28] sxgbe: Fix off by one in samsung driver strncpy size arg Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 27/28] iommu/vt-d: quirk_ioat_snb_local_iommu: replace WARN_TAINT with pr_warn + add_taint Sasha Levin
2020-03-18 20:55 ` [PATCH AUTOSEL 4.14 28/28] iommu/vt-d: Fix the wrong printing in RHSA parsing Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200318205555.17447-2-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkoutny@suse.com \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).