Linux real-time development
 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 v13 22/36] cgroup/cpuset: Refuse to take a deadline task out of its root domain
Date: Tue, 01 Dec 2026 19:29:03 +0000	[thread overview]
Message-ID: <sashiko-outbox-244064@kernel.org> (raw)
In-Reply-To: <1539531b02f82ae36ef7547965cbef9acefbdf4f.1796146461.git.mathieu.desnoyers@efficios.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] cgroup/cpuset: unchecked CPU return on isolated partition
  invalidation
- [Medium] cgroup/cpuset: missing root-domain check when shrinking
  partitions
- [Low] cgroup/cpuset: missing early dl_tasks_hold_bw() guard before
  cgroup walks
- [Low] cgroup/cpuset: missing subtree pruning on unchanged
  effective_cpus
--

commit 024194fef53c8203e8e662dd5e236d8d4627f15b
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

cgroup/cpuset: Refuse to take a deadline task out of its root domain

This commit refuses cpuset cpumask updates and invalidates or rejects
partition updates that would leave a SCHED_DEADLINE task with no CPUs in
the root domain accounting for its bandwidth.

> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 9461277ed0fa3..c811d7de35a59 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
[ ... ]
> @@ -1126,6 +1127,42 @@ static void update_partition_sd_lb(struct cpuset *cs, int old_prs)
>  		cpuset_force_rebuild();
>  }
>  
> +/*
> + * Return false if the CPUs of @new_cpus make a deadline task of @cp leave
> + * the root domain that counts its bandwidth. @pending, if not NULL, holds
> + * the CPUs that the rebuild at the end of the change gives to that root
> + * domain. @leaving, if not NULL, holds CPUs that the rebuild takes out of
> + * the default root domain. Called under rcu_read_lock(), which it drops
> + * and takes again.
> + */
> +static bool dl_tasks_keep_cpus(struct cpuset *cp, const struct cpumask *new_cpus,
> +			       const struct cpumask *pending,
> +			       const struct cpumask *leaving)
> +{
> +	struct css_task_iter it;
> +	struct task_struct *task;
> +	bool keep = true;
> +
> +	if (!dl_tasks_hold_bw() || !css_tryget_online(&cp->css))
> +		return true;

[Severity: Low]
Could dl_tasks_hold_bw() be checked on entry to dl_tasks_keep_without()
and dl_tasks_keep_root_domain() instead of only inside
dl_tasks_keep_cpus()?  Because cpuset_mutex prevents any task from
acquiring deadline bandwidth during the check, testing it only at the leaf
causes every cpuset mask and partition update to walk all descendant
cpusets and recompute effective_cpus_below() even when no task in the
system holds deadline bandwidth.

> +	rcu_read_unlock();
> +
> +	css_task_iter_start(&cp->css, 0, &it);
> +	while (keep && (task = css_task_iter_next(&it))) {
> +		/* The top cpuset leaves the mask of these tasks alone. */
> +		if (cp == &top_cpuset &&
> +		    (task->flags & (PF_KTHREAD | PF_NO_SETAFFINITY)))
> +			continue;
> +		keep = dl_task_keeps_root_domain(task, new_cpus, pending,
> +						 leaving);
> +	}
> +	css_task_iter_end(&it);
> +
> +	rcu_read_lock();
> +	css_put(&cp->css);
> +	return keep;
> +}
> +
>  /*
>   * Set @new_cpus to the effective CPUs that @cp gets. On entry, @new_cpus
>   * holds those that @from gets. @from is @cp or one of its ancestors. Work
> @@ -1148,6 +1185,119 @@ static void effective_cpus_below(struct cpuset *cp, struct cpuset *from,
>  	}
>  }
>  
> +/*
> + * Scratch masks for dl_tasks_keep_without(). Its callers still need
> + * each mask of their struct tmpmasks after the call. Protected by
> + * cpuset_mutex.
> + */
> +static cpumask_var_t dl_keep_cpus, dl_pending_cpus, dl_leaving_cpus;
> +
> +/*
> + * Return false if a partition that takes the CPUs of @xcpus makes a
> + * deadline task leave the root domain that counts its bandwidth. A cpuset
> + * can hold CPUs of two root domains: with isolcpus="domain", or on cgroup
> + * v1 with sched_load_balance off. Such a task would run in a root domain
> + * that did not admit it.
> + *
> + * @root is the partition root that gives the CPUs. @part is the cpuset
> + * that takes them. In the same change, @part can give the CPUs of @gives
> + * back to @root. @gives is NULL if it gives none back.
> + *
> + * Work out the new CPUs of each cpuset of @root from the top down, as
> + * update_cpumasks_hier() does, down to the next partition roots. If
> + * @enable, @part becomes a valid partition root. Then do the same for its own
> + * cpusets, starting from the active CPUs of @xcpus.
> + */
> +static bool dl_tasks_keep_without(struct cpuset *root, struct cpuset *part,
> +				  const struct cpumask *xcpus,
> +				  const struct cpumask *gives, bool enable)
> +{
[ ... ]
> +	rcu_read_lock();
> +	cpuset_for_each_descendant_pre(cp, pos_css, root) {
> +		if (cp == part || (cp != root && is_partition_valid(cp))) {
> +			pos_css = css_rightmost_descendant(pos_css);
> +			continue;
> +		}
> +		/* The CPUs that @root has after the change. */
> +		cpumask_copy(new_cpus, root->effective_cpus);
> +		if (gives) {
> +			cpumask_or(new_cpus, new_cpus, gives);
> +			cpumask_and(new_cpus, new_cpus, cpu_active_mask);
> +		}
> +		cpumask_andnot(new_cpus, new_cpus, xcpus);
> +		effective_cpus_below(cp, root, new_cpus);
> +		if (cpumask_equal(cp->effective_cpus, new_cpus))
> +			continue;

[Severity: Low]
When cpumask_equal(cp->effective_cpus, new_cpus) is true here, in the
second loop below, and in dl_tasks_keep_root_domain(), should the loop
advance pos_css = css_rightmost_descendant(pos_css) before continuing?
Since valid child partitions are already skipped and non-partition
descendants derive their effective_cpus only from their parent's
effective_cpus and their own unchanged cpus_allowed, no descendant in cp's
subtree can change effective_cpus, yet a plain continue walks every
descendant in unaffected subtrees and runs effective_cpus_below() on each
of them.

[ ... ]
> @@ -2035,6 +2194,21 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
>  			deleting = false;
>  			adding = cpumask_and(tmp->addmask,
>  					     cs->effective_xcpus, parent->effective_xcpus);
> +		} else if (deleting &&
> +			   !dl_tasks_keep_without(parent, cs, tmp->delmask,
> +						  adding ? tmp->addmask : NULL,
> +						  is_partition_invalid(cs))) {
> +			/*
> +			 * Make the partition invalid, as for PERR_NOCPUS above.
> +			 * Only a valid partition holds CPUs of its parent to
> +			 * give back.
> +			 */
> +			part_error = PERR_DLTASK;
> +			deleting = false;
> +			if (is_partition_valid(cs))
> +				adding = cpumask_and(tmp->addmask,
> +						     cs->effective_xcpus,
> +						     parent->effective_xcpus);
>  		}

[Severity: Medium]
When an update to a valid PRS_ISOLATED partition invalidates it, can
returning all of cs->effective_xcpus to a non-isolated parent move a
deadline task out of the default root domain without being caught by
dl_tasks_keep_given_back()?

dl_tasks_keep_given_back() only checks the CPUs in
cs->effective_xcpus & ~trialcs->effective_xcpus before
partition_cpus_change() runs.  If a valid isolated partition holding a
housekeeping CPU is grown (or otherwise updated without dropping that
housekeeping CPU in trialcs), dl_tasks_keep_given_back() returns true,
and if partition_cpus_change() then invalidates cs (for example via
PERR_DLTASK or PERR_NOCPUS here or in remote_cpus_update(), or via
validate_partition() or prstate_housekeeping_conflict()), all of
cs->effective_xcpus are returned to the parent and taken out of the
default root domain on the sched domain rebuild, allowing a deadline task
counted in the default root domain to move to the parent's root domain
without admission control.

[ ... ]
> +/*
> + * Return false if @cs gives housekeeping CPUs back to its parent, and a
> + * deadline task would then leave the default root domain: see
> + * dl_tasks_keep_without(). @cs is checked only if it is a valid isolated
> + * partition root, and its parent is not isolated. Making @cs invalid
> + * would not help: it would give these CPUs back all the same, and the
> + * task would still leave. So the caller refuses the write to cpuset.cpus
> + * or cpuset.cpus.exclusive. The CPUs that @cs takes in the same change
> + * count too. If @cs gives back only CPUs that isolcpus="domain" isolates,
> + * they stay in the default root domain. update_parent_effective_cpumask()
> + * then checks the CPUs that @cs takes.
> + */
> +static bool dl_tasks_keep_given_back(struct cpuset *cs, struct cpuset *trialcs,
> +				     struct tmpmasks *tmp)
> +{
> +	struct cpuset *parent = is_remote_partition(cs) ? &top_cpuset : parent_cs(cs);
> +
> +	if (cs->partition_root_state != PRS_ISOLATED ||
> +	    parent->partition_root_state == PRS_ISOLATED ||
> +	    !cpumask_andnot(tmp->delmask, cs->effective_xcpus, trialcs->effective_xcpus) ||
> +	    !cpumask_intersects(tmp->delmask, housekeeping_cpumask(HK_TYPE_DOMAIN_BOOT)))
> +		return true;
> +	cpumask_andnot(tmp->addmask, trialcs->effective_xcpus, cs->effective_xcpus);
> +	return dl_tasks_keep_without(parent, cs, tmp->addmask, tmp->delmask, false);
> +}

[Severity: Medium]
Can shrinking a partition still move a deadline task in the parent's
hierarchy out of its root domain in cases that dl_tasks_keep_given_back()
skips?

When a partition only gives CPUs back without taking new ones,
update_parent_effective_cpumask() and remote_cpus_update() do not call
dl_tasks_keep_without() because deleting (or adding in
remote_cpus_update()) is false.  As a result, three shrink paths bypass
the root-domain check:

1. A valid PRS_ROOT partition shrinks and returns a housekeeping CPU to
   top_cpuset: a deadline task in top_cpuset (or a member descendant)
   counted in the default root domain on an isolcpus="domain" CPU, whose
   user_cpus_ptr or child cpuset.cpus contains only the returned
   housekeeping CPU, becomes restricted to that CPU and moves to
   top_cpuset's root domain.

2. Symmetrically, a valid PRS_ISOLATED partition shrinks and returns only
   an isolcpus="domain" CPU to top_cpuset: a deadline task counted in
   top_cpuset's housekeeping root domain whose user_cpus_ptr or child
   cpuset.cpus contains only the returned isolated CPU moves to the
   default root domain.

3. Shrinking cpuset.cpus or cpuset.cpus.exclusive on an ancestor cpuset
   shrinks a descendant PRS_ISOLATED partition during
   update_cpumasks_hier(), returning housekeeping CPUs to its non-isolated
   parent without dl_tasks_keep_given_back() checking the descendant
   partition.

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

  reply	other threads:[~2026-12-01 19:29 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 17:43 [PATCH v13 00/36] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 01/36] sched/deadline: Hold a reference on the deadline donor of a boosted task Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 02/36] sched/deadline: Replenish a throttled task boosted while asleep Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 03/36] sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 04/36] sched/deadline: Count the 0-lag time from the next period Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 05/36] sched/deadline: Keep a departing constrained task until its " Mathieu Desnoyers
2026-12-01 18:17   ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 06/36] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-12-01 18:20   ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 07/36] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 08/36] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 09/36] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 10/36] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 11/36] selftests/sched: Test the root domain rebuild in deadline_bw_test Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 12/36] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 13/36] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 14/36] sched: Make deadline policy and affinity changes wait for a cpuset attach Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 15/36] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 16/36] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 17/36] selftests/sched: Test cpuset moves in deadline_bw_test Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 18/36] sched/deadline: Make a rebuild count a task in the root domain it runs in Mathieu Desnoyers
2026-12-01 19:11   ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 19/36] sched/deadline: Move a task's bandwidth to " Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 20/36] sched/deadline: Keep a task in the root domain that counts its bandwidth Mathieu Desnoyers
2026-12-01 19:02   ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 21/36] sched/deadline: Keep the last CPU a task has in its root domain Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 22/36] cgroup/cpuset: Refuse to take a deadline task out of " Mathieu Desnoyers
2026-12-01 19:29   ` sashiko-bot [this message]
2026-12-01 17:44 ` [PATCH v13 23/36] selftests/sched: Test the root domain of a task in deadline_bw_test Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 24/36] sched/deadline: Count only active CPUs when spreading extra_bw Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 25/36] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 26/36] sched/deadline: Cap the runtime left of a constrained task at dl_runtime Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 27/36] sched/deadline: Check the runtime of a task that comes back runnable Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 28/36] sched/deadline: Record the start of the period Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 29/36] sched/deadline: Keep the debt of a task across a change of parameters Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 30/36] selftests/sched: Test parameter changes in deadline_bw_test Mathieu Desnoyers
2026-12-01 19:34   ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 31/36] sched/deadline: Count a task that departs while a rebuild walks the tasks Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 32/36] sched/deadline: Count again a departed task that a boost brings back Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 33/36] sched/deadline: Keep a reaped deadline task in a rebuild Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 34/36] sched/deadline: Warn when a runqueue keeps the bandwidth of a task Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 35/36] selftests/sched: Test PI against hotplug and rebuilds in deadline_bw_test Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 36/36] selftests/sched: Share the helpers of the deadline tests Mathieu Desnoyers

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-244064@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