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 17/40] cgroup/cpuset: Refuse to take a deadline task out of its root domain
Date: Fri, 20 Nov 2026 21:22:59 +0000 [thread overview]
Message-ID: <sashiko-outbox-226169@kernel.org> (raw)
In-Reply-To: <4a72b203ecf2e3de65f7e0ef7fda8eb415af0014.1795207232.git.mathieu.desnoyers@efficios.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] cgroup/cpuset: dl_tasks_keep_without() omits pending CPUs for
PRS_ISOLATED
- [Low] sched/deadline: dl_task_keeps_root_domain() does not skip
TASK_DEAD tasks
--
commit 70ebc9e9b00f4d77522df69295e46140ef69f4bc
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
cgroup/cpuset: Refuse to take a deadline task out of its root domain
This commit rejects cpuset mask changes with -EBUSY or invalidates
partitions with PERR_DLTASK when the new effective CPU mask would leave a
SCHED_DEADLINE task without any CPUs in the root domain that accounts its
bandwidth.
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index e3c42c63844ba..ea0962f69ba4f 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
[ ... ]
> @@ -1148,6 +1181,91 @@ static void effective_cpus_below(struct cpuset *cp, struct cpuset *from,
> }
> }
>
> +/*
> + * A scratch mask 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;
> +
> +/*
> + * 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 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)
> +{
> + struct cpumask *new_cpus = dl_keep_cpus, *pending = NULL;
> + struct cgroup_subsys_state *pos_css;
> + struct cpuset *cp;
> + bool keep = true;
> +
> + lockdep_assert_cpuset_lock_held();
> + /*
> + * The CPUs of @root can have changed before the rebuild of the
> + * sched domains, which ends the change. Then the root domain of a
> + * task of @root does not span them yet. The rebuild gives the CPUs
> + * of a root partition to one root domain.
> + */
> + if (root->partition_root_state == PRS_ROOT) {
> + pending = dl_pending_cpus;
> + cpumask_copy(pending, root->effective_cpus);
> + if (root == &top_cpuset)
> + cpumask_and(pending, pending,
> + housekeeping_cpumask(HK_TYPE_DOMAIN_BOOT));
> + }
[Severity: Medium]
Should pending also be populated when root->partition_root_state is
PRS_ISOLATED (for example via is_partition_valid(root))?
An isolated partition root can have an isolated child partition and hold
SCHED_DEADLINE tasks whose bandwidth is counted in def_root_domain. When
an isolated parent partition holding a deadline task grows by acquiring a
new CPU, that CPU is not added to def_root_domain.span until
rebuild_sched_domains_locked() runs at the end of the change. While
update_cpumasks_hier() re-evaluates an invalid child isolated partition via
update_parent_effective_cpumask() -> dl_tasks_keep_without(), pending is
NULL, so dl_task_keeps_root_domain() only checks the pre-rebuild
def_root_domain.span and leaves the child partition invalid with
PERR_DLTASK.
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 604b105672103..d8a912ea13d18 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -5287,6 +5287,42 @@ int dl_bw_deactivate(int cpu)
> return ret;
> }
>
> +/*
> + * Return false if @p has CPUs in the root domain that counts its
> + * bandwidth and @new_mask holds none of them. A cpuset refuses such a
> + * mask: only a move to another cpuset makes room in another root domain.
> + * Like __set_cpus_allowed_ptr(), keep @new_mask within the affinity set by
> + * the user, if they intersect. @pending is NULL, or holds the CPUs that
> + * the rebuild at the end of the change gives to the root domain of a
> + * partition root.
> + */
> +bool dl_task_keeps_root_domain(struct task_struct *p,
> + const struct cpumask *new_mask,
> + const struct cpumask *pending)
> +{
> + const struct cpumask *span, *user = cpu_possible_mask;
> +
> + if (!dl_bandwidth_enabled() || !task_has_dl_policy(p))
> + return true;
> + /* pi_lock also protects p->user_cpus_ptr. */
> + guard(raw_spinlock_irqsave)(&p->pi_lock);
> + guard(rcu)();
> + span = dl_task_bw_span(p);
> + /* A task in a migrate_disable() section has a cpus_ptr of one CPU. */
> + if (!span || !cpumask_intersects(span, &p->cpus_mask))
> + return true;
[Severity: Low]
Should dl_task_keeps_root_domain() ignore tasks with
READ_ONCE(p->__state) == TASK_DEAD, the way dl_task_leaves_span() and
dl_task_in_cpuset() do?
When a SCHED_DEADLINE thread in a multi-threaded process exits before its
0-lag time, it stays on dl_departed_list with a non-NULL dl_task_bw_span(p)
and remains visible to css_task_iter_next() until do_cgroup_task_dead()
unlinks it from cset->tasks. Evaluating that dead thread here can cause a
cpuset.cpus write to fail with -EBUSY or a partition update to fail with
PERR_DLTASK.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795207232.git.mathieu.desnoyers@efficios.com?part=17
next prev parent reply other threads:[~2026-11-20 21:23 UTC|newest]
Thread overview: 54+ 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
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 [this message]
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 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 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 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-226169@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.