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 06/16] sched: Take cpuset_mutex for a deadline policy change only with pi
Date: Wed, 18 Nov 2026 20:17:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-221922@kernel.org> (raw)
In-Reply-To: <9194486f15bb0cb36b51e4525f471d1150c0d58b.1795031605.git.mathieu.desnoyers@efficios.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] sched/deadline: bandwidth leak in __sched_setscheduler() on
  TASK_DEAD task [1]
--

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

sched: Take cpuset_mutex for a deadline policy change only with pi

This commit avoids taking cpuset_mutex in __sched_setscheduler() when pi
is unset, and retries under the runqueue lock if the target task entered
SCHED_DEADLINE after the unlocked policy check.

> diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
> index cb115aa9b0b33..9b04e77297aeb 100644
> --- a/kernel/sched/syscalls.c
> +++ b/kernel/sched/syscalls.c
> @@ -561,9 +561,11 @@ int __sched_setscheduler(struct task_struct *p,
>  
>  	/*
>  	 * SCHED_DEADLINE bandwidth accounting relies on stable cpusets
> -	 * information.
> +	 * information. Do not take cpuset_mutex when pi is unset: the
> +	 * caller is normalize_rt_tasks(), which holds tasklist_lock and
> +	 * cannot sleep.
>  	 */
> -	if (dl_policy(policy) || dl_policy(p->policy)) {
> +	if (pi && (dl_policy(policy) || dl_policy(p->policy))) {
>  		cpuset_locked = true;
>  		cpuset_lock();
>  	}
> @@ -643,7 +645,13 @@ int __sched_setscheduler(struct task_struct *p,
>  		}
>  	}
>  
> -	/* Re-check policy now with rq lock held: */
> +	/*
> +	 * The caller gave no policy (SETPARAM_POLICY): the request was
> +	 * derived from an unlocked read of p->policy above. If the task
> +	 * changed policy since, re-derive the request from scratch, and
> +	 * release cpuset_mutex: the re-derived request re-decides whether
> +	 * it is needed.
> +	 */
>  	if (unlikely(oldpolicy != -1 && oldpolicy != p->policy)) {
>  		policy = oldpolicy = -1;
>  		task_rq_unlock(rq, p, &rf);
> @@ -654,6 +662,18 @@ int __sched_setscheduler(struct task_struct *p,
>  		goto recheck;
>  	}
>  
> +	/*
> +	 * The caller gave an explicit policy, so the request needs no
> +	 * re-derivation (oldpolicy is -1 above). But the decision to
> +		 * take cpuset_mutex used the same unlocked read: the task
> +	 * entered SCHED_DEADLINE since, and the change below would take
> +	 * it out of the class. Retry to take the mutex.
> +	 */
> +	if (unlikely(pi && !cpuset_locked && task_has_dl_policy(p))) {
> +		task_rq_unlock(rq, p, &rf);
> +		goto recheck;
> +	}
> +
>  	oldprio = p->prio;
>  
>  	newprio = __normal_prio(policy, attr->sched_priority, attr->sched_nice);

[Severity: High]
This problem wasn't introduced by this patch, but can
__sched_setscheduler() leak deadline bandwidth and cpuset deadline task
counters if called on a zombie task [1]?

A task that has reached TASK_DEAD and been deactivated from its runqueue
remains reachable by PID until reaped.  If sched_setattr() sets
SCHED_DEADLINE on it, sched_dl_overflow() adds the requested bandwidth to
dl_b->total_bw and rq->dl.extra_bw, and switched_to_dl() increments
cs->nr_deadline_tasks via inc_dl_tasks_cs() and adds the bandwidth to
rq->dl.this_bw:

kernel/sched/deadline.c:switched_to_dl() {
	...
	inc_dl_tasks_cs(p);

	/* If p is not queued we will update its parameters at next wakeup. */
	if (!task_on_rq_queued(p)) {
		add_rq_bw(&p->dl, &rq->dl);

		return;
	}
	...
}

Because a TASK_DEAD task never wakes or runs again and release_task() does
not release deadline bandwidth or decrement cs->nr_deadline_tasks, the
bandwidth and cpuset task count are leaked until reboot, blocking cpuset
changes and eventually causing __dl_overflow() to reject all new
SCHED_DEADLINE admissions with -EBUSY.

[1] https://sashiko.dev/#/bug/linux-6b520332-dcc7-4d6b-b09a-5ec47df1d3cc

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

  reply	other threads:[~2026-11-18 20:17 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 20:06 [PATCH 00/16] sched/deadline: first bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 01/16] sched: Refuse SCHED_FLAG_KEEP_PARAMS that would change the policy or the class Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 02/16] sched/deadline: Do not admit bandwidth for parameters that are kept Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 03/16] sched: Let a task boosted by a deadline waiter change its policy Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 04/16] sched/deadline: Do not divide by zero active CPUs of a root domain Mathieu Desnoyers
2026-11-18 20:23   ` sashiko-bot
2026-11-18 20:06 ` [PATCH 05/16] sched/deadline: Refuse dl_server debugfs writes while the rq is offline Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 06/16] sched: Take cpuset_mutex for a deadline policy change only with pi Mathieu Desnoyers
2026-11-18 20:17   ` sashiko-bot [this message]
2026-11-18 20:06 ` [PATCH 07/16] sched/deadline: Do not lose a throttled task switched out and back Mathieu Desnoyers
2026-11-18 20:31   ` sashiko-bot
2026-11-18 20:06 ` [PATCH 08/16] sched/deadline: Do not replenish a boost from cleared parameters Mathieu Desnoyers
2026-11-18 20:35   ` sashiko-bot
2026-11-18 20:06 ` [PATCH 09/16] sched/deadline: Reset the deadline and the runtime with the parameters Mathieu Desnoyers
2026-11-18 20:38   ` sashiko-bot
2026-11-18 20:06 ` [PATCH 10/16] sched/deadline: Release the bandwidth of a task that leaves the class asleep Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 11/16] sched/deadline: Reject SCHED_DEADLINE on exited tasks Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 12/16] sched/deadline: Fix this_bw when a task is changed during a remote wakeup Mathieu Desnoyers
2026-11-18 20:46   ` sashiko-bot
2026-11-18 20:06 ` [PATCH 13/16] sched/deadline: Check SCHED_DEADLINE affinity under the rq lock Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 14/16] sched/debug: Show the deadline bandwidth of each runqueue Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 15/16] selftests/sched: Add a test of SCHED_DEADLINE policy round trips Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 16/16] selftests/sched: Add a test of SCHED_DEADLINE bandwidth accounting 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-221922@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®