Re: [PATCH v14 01/39] sched/deadline: Hold a reference on the deadline donor of a boosted task

From: sashiko-bot

Date: Thu Dec 03 2026 - 10:44:50 EST


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] sched/deadline: recursive rq lock via put_task_struct() in
dl_replace_donor()
--

commit 74640640e887acf19101fa00448dad6b61bef633
Author: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>

sched/deadline: Hold a reference on the deadline donor of a boosted task

This commit holds a task_struct reference on the deadline donor stored in
dl.pi_se for boosted tasks, updating it via dl_set_donor() and
dl_clear_donor() so an exited donor is not freed while still referenced.

> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index 20ad13f388cb2..4a73661b62b13 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -356,6 +356,82 @@ extern int sched_dl_global_validate(void);
> extern void sched_dl_do_global(void);
> extern int sched_dl_overflow(struct task_struct *p, int policy, const struct sched_attr *attr);
> extern void __setparam_dl(struct task_struct *p, const struct sched_attr *attr);
> +#ifdef CONFIG_RT_MUTEXES
> +/*
> + * Make @pi_se the deadline donor of @dl_se. The caller holds a reference
> + * on the task of @pi_se, unless @pi_se is @dl_se. Put the reference on
> + * the old donor.
> + */
> +static inline void dl_replace_donor(struct sched_dl_entity *dl_se,
> + struct sched_dl_entity *pi_se)
> +{
> + struct sched_dl_entity *old = dl_se->pi_se;
> +
> + WRITE_ONCE(dl_se->pi_se, pi_se);
> + if (old != dl_se)
> + put_task_struct(container_of(old, struct task_struct, dl));
> +}

[Severity: Medium]
Can calling put_task_struct() here recursively acquire rq->__lock?

dl_replace_donor() runs with rq->__lock held and lockdep-pinned. On a
CONFIG_TINY_RCU=y kernel with CONFIG_RCU_DEFER=n (or older stable kernels
without CONFIG_RCU_DEFER), a SysRq-N interrupt arriving while CPU 0 is idle
can drop the last reference on an already-exited donor via:

sysrq_handle_unrt() -> normalize_rt_tasks() -> __sched_setscheduler()
-> __setscheduler_dl_pi() -> dl_clear_donor() -> dl_replace_donor()
-> put_task_struct() -> call_rcu() -> rcu_resched_if_idle()
-> resched_cpu(0) -> raw_spin_rq_lock_irqsave()

That recursively acquires and prematurely unlocks cpu_rq(0)->__lock while
__sched_setscheduler() still holds and pins it, triggering lockdep
recursive-locking and pinned-lock warnings or CONFIG_DEBUG_SPINLOCK
recursion bugs.

Returning the old donor task_struct from dl_replace_donor(), dl_set_donor(),
and dl_clear_donor() and calling put_task_struct() after releasing
rq->__lock (as dl_task_timer() does) would avoid invoking call_rcu() under
the runqueue lock.

--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796296313.git.mathieu.desnoyers@xxxxxxxxxxxx?part=1