From: Juri Lelli <juri.lelli@redhat.com>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: peterz@infradead.org, mingo@redhat.com,
vincent.guittot@linaro.org, tglx@kernel.org, will@kernel.org,
boqun@kernel.org, dietmar.eggemann@arm.com, rostedt@goodmis.org,
bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
kprateek.nayak@amd.com, luca.abeni@santannapisa.it,
tommaso.cucinotta@gmail.com, mathieu.poirier@linaro.org,
longman@redhat.com, ridong.chen@linux.dev, tj@kernel.org,
hannes@cmpxchg.org, mkoutny@suse.com, shuah@kernel.org,
bigeasy@linutronix.de, clrkwllms@kernel.org,
parri.andrea@gmail.com, m.szyprowski@samsung.com,
kayracizmeci@gmail.com, weihengqiuu@gmail.com,
linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-rt-devel@lists.linux.dev,
oleg@redhat.com, brauner@kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v13 01/36] sched/deadline: Hold a reference on the deadline donor of a boosted task
Date: Wed, 2 Dec 2026 10:43:11 +0100 [thread overview]
Message-ID: <aw_oL0jVjsZnK7h-@jlelli-thinkpadt14gen4.remote.csb> (raw)
In-Reply-To: <1fe992bb3b14c04df8e9d2e58fd9ad794e6f806f.1796146461.git.mathieu.desnoyers@efficios.com>
Hello,
On 01/12/26 12:43, Mathieu Desnoyers wrote:
> A task boosted by a SCHED_DEADLINE waiter runs on the parameters of a
> donor, dl.pi_se. Since commit 2279f540ea7d ("sched/deadline: Fix
> priority inheritance with multiple scheduling classes"),
> rt_mutex_setprio() copies the donor of the top waiter to the owner. So
> each owner along a chain points at the deadline task at its head.
>
> rt_mutex_setprio() keeps the top waiter, pi_top_task, as a plain
> pointer. The top waiter is blocked, so it cannot exit. The donor further
> up the chain has no such guarantee. When it stops waiting, the owners
> below it are fixed by chain walks. A walk can be preempted, and it runs
> in the context of the task that started it, not the donor's. So the
> donor can exit before the walk reaches the last owner.
>
> M, O and P are SCHED_OTHER tasks. W is a SCHED_DEADLINE task:
>
> P O M W
>
> locks L3 locks L2 locks L1
> blocks on L3
> blocks on L2
> blocks on L1
> M, O, P get W's parameters
> times out on L2
> O deboosted
> walk from O: preempted
> times out on L1
> M not blocked: no walk
> exits
> runs out of runtime
> refill reads P->dl.pi_se:
> W's freed task_struct
>
> P would run on parameters read from freed memory, until M's walk
> reaches it. Setting up the deadline task needs CAP_SYS_NICE. The
> timeout of a FUTEX_LOCK_PI needs no privilege. This was found by
> reading.
>
> Fix this by holding a reference on the donor's task, for each task whose
> donor is another task. dl_set_donor() gives a task the donor of its top
> waiter. dl_clear_donor() ends the boost. Both move the reference. A
> late walk can still leave P on the parameters of an exited donor for a
> while. P now reads them from valid memory.
...
> +/* Reads of the donor of a waiter before the lookup falls back. */
> +#define DL_DONOR_TRIES 8
> +
> +/*
> + * Make the deadline donor of the waiter @pi_task the donor of @dl_se. A
> + * boosted entity holds a reference on the task of its donor. The donor
> + * is the deadline task at the head of the chain. It can stop waiting
> + * and exit before the chain walk reaches @dl_se: that walk can be
> + * preempted.
> + *
> + * The donor of @pi_task is read without the locks of @pi_task. Another
> + * CPU can change it meanwhile, and put the last reference on the old
> + * donor. That CPU stores the new donor first: read it again then. The
> + * old task_struct stays readable while the rq lock is held:
> + * put_task_struct() frees it through call_rcu(), and the rq lock holds
> + * off the grace period.
> + *
> + * Each failed tryget_task_struct() means that another CPU stored a newer
> + * donor. This holds as long as every writer of pi_se holds a reference
> + * on the new donor. A writer that breaks this rule could leave a dead
> + * donor in pi_se, and every read would fail on it. So stop after
> + * DL_DONOR_TRIES reads, rather than spin forever with interrupts off.
> + * Warn, and fall back to @pi_task itself. It waits on a lock, so it
> + * cannot exit. If it has no parameters of its own,
> + * replenish_dl_entity() handles it as a donor that left the class.
> + *
> + * The caller holds the rq lock and the pi_lock of the task of @dl_se.
> + */
> +static inline void dl_set_donor(struct sched_dl_entity *dl_se,
> + struct task_struct *pi_task)
> +{
> + struct sched_dl_entity *pi_se;
> + int tries;
> +
> + for (tries = 0; tries < DL_DONOR_TRIES; tries++) {
> + pi_se = READ_ONCE(pi_task->dl.pi_se);
> + if (pi_se == dl_se->pi_se)
> + return;
> + if (pi_se == dl_se ||
> + tryget_task_struct(container_of(pi_se, struct task_struct, dl)))
> + goto set;
> + /* Pairs with the ordering of refcount_dec_and_test(). */
> + smp_rmb();
> + }
> + WARN_ON_ONCE(1);
> + pi_se = &pi_task->dl;
> + if (pi_se == dl_se->pi_se)
> + return;
> + if (pi_se != dl_se)
> + get_task_struct(pi_task);
> +set:
> + dl_replace_donor(dl_se, pi_se);
> +}
This is what I had in mind, and the patch looks OK to me. Wonder what
Peter/others think of it, but I can give
Reviewed-by: Juri Lelli <juri.lelli@redhat.com>
Thanks,
Juri
next prev parent reply other threads:[~2026-12-02 9:43 UTC|newest]
Thread overview: 59+ 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-02 9:43 ` Juri Lelli [this message]
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-02 14:54 ` Mathieu Desnoyers
2026-12-02 14:55 ` Juri Lelli
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-02 14:54 ` Mathieu Desnoyers
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-02 14:54 ` Mathieu Desnoyers
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-02 14:54 ` Mathieu Desnoyers
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
2026-12-02 14:54 ` Mathieu Desnoyers
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-02 14:54 ` Mathieu Desnoyers
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 19:41 ` sashiko-bot
2026-12-02 14:54 ` 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 19:47 ` sashiko-bot
2026-12-02 14:54 ` 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 19:57 ` sashiko-bot
2026-12-02 14:54 ` 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 19:51 ` sashiko-bot
2026-12-02 14:54 ` 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=aw_oL0jVjsZnK7h-@jlelli-thinkpadt14gen4.remote.csb \
--to=juri.lelli@redhat.com \
--cc=bigeasy@linutronix.de \
--cc=boqun@kernel.org \
--cc=brauner@kernel.org \
--cc=bsegall@google.com \
--cc=cgroups@vger.kernel.org \
--cc=clrkwllms@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=hannes@cmpxchg.org \
--cc=kayracizmeci@gmail.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=longman@redhat.com \
--cc=luca.abeni@santannapisa.it \
--cc=m.szyprowski@samsung.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mathieu.poirier@linaro.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=mkoutny@suse.com \
--cc=oleg@redhat.com \
--cc=parri.andrea@gmail.com \
--cc=peterz@infradead.org \
--cc=ridong.chen@linux.dev \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tglx@kernel.org \
--cc=tj@kernel.org \
--cc=tommaso.cucinotta@gmail.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=weihengqiuu@gmail.com \
--cc=will@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®