From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796153343; b=n0rWfJrmGSyynCxK0IdTLL4xSj7QI1BqsYhMGAxUJNcbvhK9xQzGo+mFk94jkeCKA23q t+4XilrMlvR+LD/nmMF3dSEB5xG5yY6mOTJArd/UFIcdYArksNQjIngvsf0OE7Xyoe1t6 6kYWqClBtYUTjO51dSe3UO2EXO5wwVpYnfAKfXtQaYSQaInZDAB/xW1tJ9nXqgpNkLu9R cF3C9hwTm0xG8Tv4CKfX2J8OjuZxa9knkZzvqwRkdrZhJECi6a7rfBeJrdicLI3Re2X9r IAAuQmediOZPYiiqrNI8qwZElhm7Ua1jAG1vBvWc3VbC4HOU6h/s6oeA3AjhbPYjPNw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796153343; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=S93kkyIwoaode5tWIlC7axcRQ0l+RWuVzfY7jtmJncM=; b=pDqyUu2IQV3mrO8ueKUhdeKpbe1wTkO2Cik3bDq9n3lJf5WYP0n0vuW6HwcIXUgXLJo1 h6dLl143gvwOjttWhzv90+CcbERwfp/oZ8r2yTA/BocZNWnvebc9MNE2LYZcoYyxh5onE GrIrgCjIx3C0Dipo9a0q76p374n/w37/vv3Q+WxpfYYCYY5/h3I6xyk4MSqwP3NlqXBV1 CRMBnfToO74rha+IMgq0frTu6h4J0D8W3FRCwK39xlBzSUcT+0iCM6SaEwTLClEVXU0OS WSIudYyOt7cDTIOErof7yYrAlAZpozC9XsWSN9YjSYtGVWqksdXekk7y7o1TflwsCdg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lo+HA61G; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE716606A31A; Tue, 1 Dec 2026 19:29:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lo+HA61G Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B3D91F00893; Tue, 1 Dec 2026 19:29:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796153343; bh=S93kkyIwoaode5tWIlC7axcRQ0l+RWuVzfY7jtmJncM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=lo+HA61Gi8iBAnwX6rgjKnXwPaQMcaYo6eGw91hn0rR+p1hsDiSS+z9FWbNVm1rix lCEQSRN3o5F5xjhuG1/5O7KEel1HD/nubNqQw52m5sd8wfYsQ/GJw7nRqnJtM6NW7T /ITgcF76WdnS9YfDzORK8+twfXMcMj95rld5Fz76Xlk3EFc9kGk56YHj5e4gSHNPCg /Tb+DEEr/BKHbVtwryM0SaQ2SEzHWASEmX150sFAQOZLof09ddsccl5Fd4HVKfkLCr t+u4kQGOfiwRlyDcgIfkav3zD7q0mQTn2aiK+nbp6fRpstEApVQOASfOJbBdBmH7yF PDGY5oK5vPi0A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v13 22/36] cgroup/cpuset: Refuse to take a deadline task out of its root domain Reply-To: sashiko-reviews@lists.linux.dev To: "Mathieu Desnoyers" Cc: linux-rt-devel@lists.linux.dev, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com, linux-kernel@vger.kernel.org In-Reply-To: <1539531b02f82ae36ef7547965cbef9acefbdf4f.1796146461.git.mathieu.desnoyers@efficios.com> References: <1539531b02f82ae36ef7547965cbef9acefbdf4f.1796146461.git.mathieu.desnoyers@efficios.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 19:29:03 +0000 X-Mailing-List: linux-rt-devel@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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(); > } > =20 > +/* > + * Return false if the CPUs of @new_cpus make a deadline task of @cp lea= ve > + * the root domain that counts its bandwidth. @pending, if not NULL, hol= ds > + * 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 =3D 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 =3D css_task_iter_next(&it))) { > + /* The top cpuset leaves the mask of these tasks alone. */ > + if (cp =3D=3D &top_cpuset && > + (task->flags & (PF_KTHREAD | PF_NO_SETAFFINITY))) > + continue; > + keep =3D 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. Wo= rk > @@ -1148,6 +1185,119 @@ static void effective_cpus_below(struct cpuset *c= p, struct cpuset *from, > } > } > =20 > +/* > + * 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 cpus= et > + * can hold CPUs of two root domains: with isolcpus=3D"domain", or on cg= roup > + * 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 i= ts own > + * cpusets, starting from the active CPUs of @xcpus. > + */ > +static bool dl_tasks_keep_without(struct cpuset *root, struct cpuset *pa= rt, > + const struct cpumask *xcpus, > + const struct cpumask *gives, bool enable) > +{ [ ... ] > + rcu_read_lock(); > + cpuset_for_each_descendant_pre(cp, pos_css, root) { > + if (cp =3D=3D part || (cp !=3D root && is_partition_valid(cp))) { > + pos_css =3D 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 =3D 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 =3D false; > adding =3D 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 =3D PERR_DLTASK; > + deleting =3D false; > + if (is_partition_valid(cs)) > + adding =3D 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=3D"domain" isola= tes, > + * 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 *t= rialcs, > + struct tmpmasks *tmp) > +{ > + struct cpuset *parent =3D is_remote_partition(cs) ? &top_cpuset : paren= t_cs(cs); > + > + if (cs->partition_root_state !=3D PRS_ISOLATED || > + parent->partition_root_state =3D=3D PRS_ISOLATED || > + !cpumask_andnot(tmp->delmask, cs->effective_xcpus, trialcs->effecti= ve_xcpus) || > + !cpumask_intersects(tmp->delmask, housekeeping_cpumask(HK_TYPE_DOMA= IN_BOOT))) > + return true; > + cpumask_andnot(tmp->addmask, trialcs->effective_xcpus, cs->effective_xc= pus); > + return dl_tasks_keep_without(parent, cs, tmp->addmask, tmp->delmask, fa= lse); > +} [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=3D"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=3D"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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796146461.gi= t.mathieu.desnoyers@efficios.com?part=3D22