mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
Cc: linux-rt-devel@lists.linux.dev, tj@kernel.org,
	hannes@cmpxchg.org, mkoutny@suse.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v10 16/40] sched/deadline: Keep the last CPU a task has in its root domain
Date: Fri, 20 Nov 2026 21:19:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-226157@kernel.org> (raw)
In-Reply-To: <efba6f58f1e0ef5cea319448374083b8149f26da.1795207232.git.mathieu.desnoyers@efficios.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] cgroup/cpuset: partition_child_lost() picks last sibling
  after gone not first
- [Medium] cgroup/cpuset: upward cascade of gone across unpopulated
  parent partitions
- [Medium] cgroup/cpuset: missed root domain move for tasks in isolated
  partition gone
- [Medium] cgroup/cpuset: skipping a == lost in
  cpuset_offline_moves_dl() ignores subpartitions
- [Medium] cgroup/cpuset: dl_task_in_cpuset() falsely matches
  SCHED_FLAG_SUGOV kthreads
--

commit 38c9a6cf11adbb513d6b034865c486d38c14c195
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

sched/deadline: Keep the last CPU a task has in its root domain

This commit refuses to take a CPU offline with -EBUSY when doing so would
leave a deadline task running in a different root domain that did not
admit its bandwidth, either because the task loses its last CPU in its
root domain or because the offline invalidates a cpuset partition.

> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 7bdb9e21a7edb..e3c42c63844ba 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
[ ... ]
> @@ -4312,6 +4334,259 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)
>  	spin_unlock_irqrestore(&callback_lock, flags);
>  }
[ ... ]
> +static struct cpuset *partition_child_lost(struct cpuset *p, int cpu,
> +					   struct cpumask *new_cpus,
> +					   struct cpuset *gone)
> +{
> +	bool populated = partition_populated_offline(p);
> +	struct cgroup_subsys_state *css;
> +	struct cpuset *child, *lost = NULL;
> +
> +	cpumask_and(new_cpus, p->effective_xcpus, cpu_active_mask);
> +	cpumask_clear_cpu(cpu, new_cpus);
> +	if (cpumask_empty(new_cpus))
> +		return NULL;
> +	cpuset_for_each_child(child, css, p) {
> +		if (child == gone) {
> +			populated = true;
> +			continue;
> +		}
> +		if (!is_partition_valid(child))
> +			continue;
> +		if (populated && cpumask_subset(new_cpus, child->effective_xcpus)) {
> +			lost = child;
> +			continue;
> +		}
> +		cpumask_andnot(new_cpus, new_cpus, child->effective_xcpus);
> +	}
> +	return lost;
> +}

[Severity: Medium]
When gone is set and p was initially unpopulated with no active CPUs of
its own, does partition_child_lost() pick the last valid sibling
partition after gone instead of the first?

During the pre-order walk in cpuset_handle_hotplug(), p is visited before
gone is invalidated, so p->effective_cpus remains empty.  Once gone is
visited and invalidated, p becomes populated while p->effective_cpus is
still empty.  When cpuset_hotplug_update_tasks() visits the first valid
sibling partition after gone, tasks_nocpu_error() checks
cpumask_subset(parent->effective_cpus, xcpus), which is immediately true
for an empty parent->effective_cpus:

kernel/cgroup/cpuset.c:tasks_nocpu_error() {
	return (cpumask_subset(parent->effective_cpus, xcpus) &&
		partition_is_populated(parent, cs)) ||
	       (!cpumask_intersects(xcpus, cpu_active_mask) &&
		partition_is_populated(cs, NULL));
}

That invalidates the first valid sibling partition after gone and gives
its active CPUs to p->effective_cpus, leaving later sibling partitions
valid.  Here, new_cpus still holds the union of all remaining children's
CPUs when visiting the first sibling after gone, so
cpumask_subset(new_cpus, child->effective_xcpus) is false until the last
valid sibling.  If p has two valid sibling partitions after gone where the
first holds a deadline task and the second does not,
cpuset_offline_moves_dl() and cpuset_cpus_allowed_without() inspect the
second sibling and accept the offline, merging the deadline tasks of gone
and the first sibling into p's root domain without admission control.

Also, if every active CPU in p->effective_xcpus belongs to child
partitions visited before gone, new_cpus becomes empty before gone, and
cpumask_subset(new_cpus, child->effective_xcpus) then matches a later
valid child partition whose effective_xcpus are all offline.

> +bool cpuset_cpus_allowed_without(struct task_struct *tsk, int cpu,
> +				 struct cpumask *pmask)
> +{
> +	const struct cpumask *possible = task_cpu_possible_mask(tsk);
> +	struct cpuset *cs = task_cs(tsk), *from, *gone = NULL;
> +
> +	guard(rcu)();
> +	if (!is_in_v2_mode()) {
[ ... ]
> +	} else {
> +		/*
> +		 * cgroup v2 works out the CPUs of each cpuset from the top
> +		 * down. A cpuset keeps those of its parent that cpuset.cpus
> +		 * holds, or takes all of them if there are none. Start from
> +		 * the nearest partition root that keeps an active CPU, or from
> +		 * the top cpuset. A partition root left with no CPU of its own
> +		 * can take those of a child partition. One left with tasks and
> +		 * no CPU becomes invalid, and its tasks count in its parent.
> +		 */
> +		for (from = cs; ; from = parent_cs(from)) {
> +			if (from != &top_cpuset && !is_partition_valid(from))
> +				continue;
> +			cpumask_and(pmask, from->effective_cpus, cpu_active_mask);
> +			cpumask_clear_cpu(cpu, pmask);
> +			if (cpumask_empty(pmask) && from != &top_cpuset &&
> +			    !partition_child_lost(from, cpu, pmask, gone))
> +				cpumask_clear(pmask);
> +			if (!cpumask_empty(pmask) || from == &top_cpuset)
> +				break;
> +			gone = gone || partition_populated_offline(from) ? from : NULL;
> +		}
> +		effective_cpus_below(cs, from, pmask);
> +	}

[Severity: Medium]
Can gone cascade upward across an unpopulated parent partition here and
in cpuset_offline_moves_dl()?

Suppose an unpopulated partition P1 has no active CPUs of its own and
only one valid child partition P2, which is populated and loses its last
active CPU.  cpuset_handle_hotplug() walks descendants in pre-order and
visits P1 before P2; at that point P2 is still valid, so
partition_is_populated(P1, NULL) is false and P1 remains a valid
partition with empty effective_cpus when P2 is later invalidated.  With
gone || partition_populated_offline(from), once gone is set to P2, the
next iteration at P1 sets gone = P1 and climbs to parent_cs(P1) (or
top_cpuset), so cpuset_cpus_allowed_without() returns the ancestor's CPUs
instead of taking the empty-mask fallback path, and
cpuset_offline_moves_dl() checks sibling partitions of P1 that are not
invalidated.

> +	if (!cpumask_and(pmask, pmask, possible)) {
[ ... ]
> +static bool dl_task_in_cpuset(struct cpuset *cs)
> +{
> +	struct css_task_iter it;
> +	struct task_struct *task;
> +	bool found = false;
> +
> +	css_task_iter_start(&cs->css, 0, &it);
> +	while (!found && (task = css_task_iter_next(&it)))
> +		found = task->policy == SCHED_DEADLINE &&
> +			READ_ONCE(task->__state) != TASK_DEAD;
> +	css_task_iter_end(&it);
> +	return found;
> +}

[Severity: Medium]
Does dl_task_in_cpuset() match sugov kthreads in top_cpuset that do not
hold root-domain deadline bandwidth?

sugov_kthread_create() creates SCHED_DEADLINE kernel threads with
SCHED_FLAG_SUGOV in top_cpuset, which dl_se_holds_bw() excludes from
root-domain bandwidth accounting.  When the last active CPU of
top_cpuset goes offline while a partition exists and dl_nr_bw_tasks is
non-zero, cpuset_offline_moves_dl() sets lost = &top_cpuset and calls
dl_task_in_cpuset(&top_cpuset), refusing the offline with -EBUSY whenever
a sugov kthread is present.

> +bool cpuset_offline_moves_dl(int cpu)
> +{
> +	struct cgroup_subsys_state *pos_css;
> +	struct cpuset *cp, *a, *p = &top_cpuset, *lost = NULL;
> +	bool found = false;
> +
> +	if (!is_in_v2_mode())
> +		return false;
> +	rcu_read_lock();
> +	cpuset_for_each_descendant_pre(cp, pos_css, &top_cpuset) {
> +		if (cp != &top_cpuset && is_partition_valid(cp) &&
> +		    cpumask_test_cpu(cpu, cp->effective_cpus)) {
> +			p = cp;
> +			break;
> +		}
> +	}
> +	if (p != &top_cpuset) {
> +		struct cpuset *gone = NULL;
> +
> +		/*
> +		 * A partition left with tasks and no CPU becomes invalid. Its
> +		 * tasks then count in its parent, which can take the CPUs of a
> +		 * later child partition. The parent is then the one that takes
> +		 * CPUs.
> +		 */
> +		while (!(lost = partition_child_lost(p, cpu, &dl_offline_cpus, gone)) &&
> +		       cpumask_empty(&dl_offline_cpus) &&
> +		       (gone || partition_populated_offline(p)) &&
> +		       parent_cs(p) != &top_cpuset && is_partition_valid(parent_cs(p))) {
> +			gone = p;
> +			p = parent_cs(p);
> +		}
> +	} else {
> +		cpumask_and(&dl_offline_cpus, top_cpuset.effective_cpus, cpu_active_mask);
> +		cpumask_clear_cpu(cpu, &dl_offline_cpus);
> +		if (cpumask_empty(&dl_offline_cpus) && !cpumask_empty(subpartitions_cpus))
> +			lost = &top_cpuset;
> +	}
> +	if (!lost) {
> +		rcu_read_unlock();
> +		return false;
> +	}
> +	cpuset_for_each_descendant_pre(cp, pos_css, lost) {

[Severity: Medium]
Can deadline tasks in gone change root domain undetected when gone is an
isolated partition and its parent p is a non-isolated partition?

Suppose p is PRS_ROOT with no active CPUs of its own and has two
PRS_ISOLATED child partitions: C1 on CPU 1 with deadline tasks (counted in
def_root_domain) and C2 on CPU 2 with no deadline tasks.  When CPU 1 goes
offline, C1 becomes gone and C2 becomes lost.  cpuset_offline_moves_dl()
only walks descendants of lost (C2) and finds no deadline tasks, while
dl_task_leaves_span() checks C1's tasks against the current
def_root_domain span, which still includes CPU 2 because C2 has not been
invalidated yet.  Both checks pass, and hotplug then invalidates C1 and
C2 into p, moving CPU 2 and C1's deadline tasks out of def_root_domain
into p's PRS_ROOT root domain without admission control.

> +		/* The partition that gives @cp its CPUs. */
> +		for (a = cp; a != lost && !is_partition_valid(a); a = parent_cs(a))
> +			;
> +		if (lost != &top_cpuset &&
> +		    ((a->partition_root_state == PRS_ISOLATED &&
> +		      p->partition_root_state == PRS_ISOLATED) ||
> +		     (a == lost && a->partition_root_state != PRS_ISOLATED &&
> +		      p->partition_root_state != PRS_ISOLATED)))
> +			continue;

[Severity: Medium]
Does skipping a == lost when neither lost nor p is PRS_ISOLATED hold when
lost has a valid child partition of its own?

When lost is invalidated, any valid child partition under lost is also
invalidated, so p's root domain takes all active CPUs of
lost->effective_xcpus rather than just lost->effective_cpus.  If lost had
effective_xcpus = {1, 2} and effective_cpus = {1} because a valid child
partition held CPU 2 (with no deadline tasks), a member cpuset under lost
configured with cpuset.cpus = 2 previously had an empty intersection with
lost->effective_cpus and inherited {1}, where its deadline task was
admitted.  Skipping a == lost lets the offline of p's last CPU succeed,
and once p's effective_cpus becomes {1, 2}, the member cpuset's
effective_cpus switches from {1} to {2} (or a deadline task in lost
pinned to {1} no longer spans its {1, 2} root domain).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795207232.git.mathieu.desnoyers@efficios.com?part=16

  reply	other threads:[~2026-11-20 21:19 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 20:41 [PATCH v10 00/40] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 01/40] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 02/40] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 03/40] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-11-20 21:18   ` sashiko-bot
2026-11-20 20:41 ` [PATCH v10 04/40] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 05/40] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-20 21:12   ` sashiko-bot
2026-11-20 20:41 ` [PATCH v10 06/40] selftests/sched: Test the root domain rebuild in deadline_bw_test Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 07/40] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 08/40] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 09/40] sched: Make deadline policy and affinity changes wait for a cpuset attach Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 10/40] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 11/40] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 12/40] selftests/sched: Test cpuset moves in deadline_bw_test Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 13/40] sched/deadline: Make a rebuild count a task in the root domain it runs in Mathieu Desnoyers
2026-11-20 21:11   ` sashiko-bot
2026-11-20 20:41 ` [PATCH v10 14/40] sched/deadline: Move a task's bandwidth to " Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 15/40] sched/deadline: Keep a task in the root domain that counts its bandwidth Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 16/40] sched/deadline: Keep the last CPU a task has in its root domain Mathieu Desnoyers
2026-11-20 21:19   ` sashiko-bot [this message]
2026-11-20 20:41 ` [PATCH v10 17/40] cgroup/cpuset: Refuse to take a deadline task out of " Mathieu Desnoyers
2026-11-20 21:22   ` sashiko-bot
2026-11-20 20:41 ` [PATCH v10 18/40] selftests/sched: Test the root domain of a task in deadline_bw_test Mathieu Desnoyers
2026-11-20 20:54   ` sashiko-bot
2026-11-20 20:41 ` [PATCH v10 19/40] sched/deadline: Count only active CPUs when spreading extra_bw Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 20/40] sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 21/40] rtmutex: Continue the chain walk when a waiter's deadline donor changes Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 22/40] rtmutex: Do not stop the chain walk at an owner whose top waiter changed Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 23/40] sched/deadline: Hold a reference on the deadline donor of a boosted task Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 24/40] selftests/sched: Test the rtmutex chain walk in deadline_bw_test Mathieu Desnoyers
2026-11-20 21:06   ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 25/40] sched/deadline: Reset the donor's runtime at a deboost in the class Mathieu Desnoyers
2026-11-20 21:26   ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 26/40] sched/deadline: Replenish a throttled task boosted while asleep Mathieu Desnoyers
2026-11-20 21:22   ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 27/40] sched/deadline: Count the bandwidth a boosted task is given Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 28/40] sched/deadline: Start a period for a task that enters the class blocked Mathieu Desnoyers
2026-11-20 21:21   ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 29/40] sched/deadline: Start a period at a deboost out of the class Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 30/40] sched/deadline: Start a period for a task requeued onto an rt_mutex Mathieu Desnoyers
2026-11-20 21:24   ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 31/40] selftests/sched: Test deadline boosts in deadline_bw_test Mathieu Desnoyers
2026-11-20 21:08   ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 32/40] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 33/40] sched/deadline: Cap the runtime left of a constrained task at dl_runtime Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 34/40] sched/deadline: Check the runtime of a task that comes back runnable Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 35/40] sched/deadline: Check the runtime of a task whose parameters change Mathieu Desnoyers
2026-11-20 21:38   ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 36/40] sched/deadline: Reschedule a running task throttled at its enqueue Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 37/40] sched/deadline: Keep the start of the period across a change of dl_deadline Mathieu Desnoyers
2026-11-20 21:21   ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 38/40] sched/deadline: Boost an owner that cannot run on its own reservation Mathieu Desnoyers
2026-11-20 21:33   ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 39/40] selftests/sched: Test parameter changes in deadline_bw_test Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 40/40] selftests/sched: Share the helpers of the deadline tests Mathieu Desnoyers
2026-11-20 21:15   ` sashiko-bot

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=sashiko-outbox-226157@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mkoutny@suse.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --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

all inboxes | Powered by JetHome®