* [PATCH v3 REPOST] sched: Remove a preempt-disable section in rt_mutex_setprio()
@ 2025-11-27 15:55 Sebastian Andrzej Siewior
2025-11-28 10:06 ` Peter Zijlstra
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-11-27 15:55 UTC (permalink / raw)
To: linux-kernel
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider
rt_mutex_setprio() has only one caller: rt_mutex_adjust_prio(). It
expects that task_struct::pi_lock and rt_mutex_base::wait_lock are held.
Both locks are raw_spinlock_t and are acquired with disabled interrupts.
Nevertheless rt_mutex_setprio() disables preemption while invoking
__balance_callbacks() and raw_spin_rq_unlock(). Even if one of the
balance callbacks unlocks the rq then it must not enable interrupts
because rt_mutex_base::wait_lock is still locked.
Therefore interrupts should remain disabled and disabling preemption is
not needed.
Commit 4c9a4bc89a9cc ("sched: Allow balance callbacks for check_class_changed()")
adds a preempt-disable section to rt_mutex_setprio() and
__sched_setscheduler(). In __sched_setscheduler() the preemption is
disabled before rq is unlocked and interrupts enabled but I don't see
why it makes a difference in rt_mutex_setprio().
Remove the preempt_disable() section from rt_mutex_setprio().
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
v2…v3: https://lore.kernel.org/all/20250610144700.uBK6RS95@linutronix.de/
- Add a comment why IRQs are still disabled.
v1…v2: https://lore.kernel.org/all/20250513142954.ZM5QSQNc@linutronix.de/
- Repost without RFC
kernel/sched/core.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index f754a60de8484..61c3297b43756 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7440,14 +7440,11 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
check_class_changed(rq, p, prev_class, oldprio);
out_unlock:
- /* Avoid rq from going away on us: */
- preempt_disable();
+ /* Caller holds task_struct::pi_lock, IRQs are still disabled */
rq_unpin_lock(rq, &rf);
__balance_callbacks(rq);
raw_spin_rq_unlock(rq);
-
- preempt_enable();
}
#endif /* CONFIG_RT_MUTEXES */
--
2.51.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 REPOST] sched: Remove a preempt-disable section in rt_mutex_setprio()
2025-11-27 15:55 [PATCH v3 REPOST] sched: Remove a preempt-disable section in rt_mutex_setprio() Sebastian Andrzej Siewior
@ 2025-11-28 10:06 ` Peter Zijlstra
2025-12-03 18:25 ` [tip: sched/urgent] sched/rt: " tip-bot2 for Sebastian Andrzej Siewior
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Peter Zijlstra @ 2025-11-28 10:06 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: linux-kernel, Ingo Molnar, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider
On Thu, Nov 27, 2025 at 04:55:29PM +0100, Sebastian Andrzej Siewior wrote:
> rt_mutex_setprio() has only one caller: rt_mutex_adjust_prio(). It
> expects that task_struct::pi_lock and rt_mutex_base::wait_lock are held.
> Both locks are raw_spinlock_t and are acquired with disabled interrupts.
>
> Nevertheless rt_mutex_setprio() disables preemption while invoking
> __balance_callbacks() and raw_spin_rq_unlock(). Even if one of the
> balance callbacks unlocks the rq then it must not enable interrupts
> because rt_mutex_base::wait_lock is still locked.
> Therefore interrupts should remain disabled and disabling preemption is
> not needed.
>
> Commit 4c9a4bc89a9cc ("sched: Allow balance callbacks for check_class_changed()")
> adds a preempt-disable section to rt_mutex_setprio() and
> __sched_setscheduler(). In __sched_setscheduler() the preemption is
> disabled before rq is unlocked and interrupts enabled but I don't see
> why it makes a difference in rt_mutex_setprio().
>
> Remove the preempt_disable() section from rt_mutex_setprio().
>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tip: sched/urgent] sched/rt: Remove a preempt-disable section in rt_mutex_setprio()
2025-11-27 15:55 [PATCH v3 REPOST] sched: Remove a preempt-disable section in rt_mutex_setprio() Sebastian Andrzej Siewior
2025-11-28 10:06 ` Peter Zijlstra
@ 2025-12-03 18:25 ` tip-bot2 for Sebastian Andrzej Siewior
2025-12-03 18:31 ` tip-bot2 for Sebastian Andrzej Siewior
2025-12-06 9:10 ` tip-bot2 for Sebastian Andrzej Siewior
3 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2025-12-03 18:25 UTC (permalink / raw)
To: linux-tip-commits
Cc: Sebastian Andrzej Siewior, Peter Zijlstra (Intel),
Ingo Molnar, x86, linux-kernel
The following commit has been merged into the sched/urgent branch of tip:
Commit-ID: 81a325c5b4ebc387181c5aca7586ccc049a2e96e
Gitweb: https://git.kernel.org/tip/81a325c5b4ebc387181c5aca7586ccc049a2e96e
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate: Thu, 27 Nov 2025 16:55:29 +01:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 02 Dec 2025 15:27:16 +01:00
sched/rt: Remove a preempt-disable section in rt_mutex_setprio()
rt_mutex_setprio() has only one caller: rt_mutex_adjust_prio(). It
expects that task_struct::pi_lock and rt_mutex_base::wait_lock are held.
Both locks are raw_spinlock_t and are acquired with disabled interrupts.
Nevertheless rt_mutex_setprio() disables preemption while invoking
__balance_callbacks() and raw_spin_rq_unlock(). Even if one of the
balance callbacks unlocks the rq then it must not enable interrupts
because rt_mutex_base::wait_lock is still locked.
Therefore interrupts should remain disabled and disabling preemption is
not needed.
Commit 4c9a4bc89a9cc ("sched: Allow balance callbacks for check_class_changed()")
adds a preempt-disable section to rt_mutex_setprio() and
__sched_setscheduler(). In __sched_setscheduler() the preemption is
disabled before rq is unlocked and interrupts enabled but I don't see
why it makes a difference in rt_mutex_setprio().
Remove the preempt_disable() section from rt_mutex_setprio().
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://patch.msgid.link/20251127155529.t_sTatE4@linutronix.de
---
kernel/sched/core.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 0c4ff93..7dfb6a9 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7358,15 +7358,12 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
p->prio = prio;
}
out_unlock:
- /* Avoid rq from going away on us: */
- preempt_disable();
+ /* Caller holds task_struct::pi_lock, IRQs are still disabled */
rq_unpin_lock(rq, &rf);
__balance_callbacks(rq);
rq_repin_lock(rq, &rf);
__task_rq_unlock(rq, p, &rf);
-
- preempt_enable();
}
#endif /* CONFIG_RT_MUTEXES */
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tip: sched/urgent] sched/rt: Remove a preempt-disable section in rt_mutex_setprio()
2025-11-27 15:55 [PATCH v3 REPOST] sched: Remove a preempt-disable section in rt_mutex_setprio() Sebastian Andrzej Siewior
2025-11-28 10:06 ` Peter Zijlstra
2025-12-03 18:25 ` [tip: sched/urgent] sched/rt: " tip-bot2 for Sebastian Andrzej Siewior
@ 2025-12-03 18:31 ` tip-bot2 for Sebastian Andrzej Siewior
2025-12-06 9:10 ` tip-bot2 for Sebastian Andrzej Siewior
3 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2025-12-03 18:31 UTC (permalink / raw)
To: linux-tip-commits
Cc: Sebastian Andrzej Siewior, Peter Zijlstra (Intel),
Ingo Molnar, x86, linux-kernel
The following commit has been merged into the sched/urgent branch of tip:
Commit-ID: b53fb61525912e81519eedd4aefe5de8e6999b0c
Gitweb: https://git.kernel.org/tip/b53fb61525912e81519eedd4aefe5de8e6999b0c
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate: Thu, 27 Nov 2025 16:55:29 +01:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 03 Dec 2025 19:26:13 +01:00
sched/rt: Remove a preempt-disable section in rt_mutex_setprio()
rt_mutex_setprio() has only one caller: rt_mutex_adjust_prio(). It
expects that task_struct::pi_lock and rt_mutex_base::wait_lock are held.
Both locks are raw_spinlock_t and are acquired with disabled interrupts.
Nevertheless rt_mutex_setprio() disables preemption while invoking
__balance_callbacks() and raw_spin_rq_unlock(). Even if one of the
balance callbacks unlocks the rq then it must not enable interrupts
because rt_mutex_base::wait_lock is still locked.
Therefore interrupts should remain disabled and disabling preemption is
not needed.
Commit 4c9a4bc89a9cc ("sched: Allow balance callbacks for check_class_changed()")
adds a preempt-disable section to rt_mutex_setprio() and
__sched_setscheduler(). In __sched_setscheduler() the preemption is
disabled before rq is unlocked and interrupts enabled but I don't see
why it makes a difference in rt_mutex_setprio().
Remove the preempt_disable() section from rt_mutex_setprio().
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://patch.msgid.link/20251127155529.t_sTatE4@linutronix.de
---
kernel/sched/core.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 1711e9e..ee7dfbf 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7352,15 +7352,12 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
p->prio = prio;
}
out_unlock:
- /* Avoid rq from going away on us: */
- preempt_disable();
+ /* Caller holds task_struct::pi_lock, IRQs are still disabled */
rq_unpin_lock(rq, &rf);
__balance_callbacks(rq);
rq_repin_lock(rq, &rf);
__task_rq_unlock(rq, p, &rf);
-
- preempt_enable();
}
#endif /* CONFIG_RT_MUTEXES */
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tip: sched/urgent] sched/rt: Remove a preempt-disable section in rt_mutex_setprio()
2025-11-27 15:55 [PATCH v3 REPOST] sched: Remove a preempt-disable section in rt_mutex_setprio() Sebastian Andrzej Siewior
` (2 preceding siblings ...)
2025-12-03 18:31 ` tip-bot2 for Sebastian Andrzej Siewior
@ 2025-12-06 9:10 ` tip-bot2 for Sebastian Andrzej Siewior
3 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2025-12-06 9:10 UTC (permalink / raw)
To: linux-tip-commits
Cc: Sebastian Andrzej Siewior, Peter Zijlstra (Intel),
Ingo Molnar, x86, linux-kernel
The following commit has been merged into the sched/urgent branch of tip:
Commit-ID: 22abd832776b1317ae4c3f8a097c8b71bf83fb38
Gitweb: https://git.kernel.org/tip/22abd832776b1317ae4c3f8a097c8b71bf83fb38
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate: Thu, 27 Nov 2025 16:55:29 +01:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Sat, 06 Dec 2025 10:03:13 +01:00
sched/rt: Remove a preempt-disable section in rt_mutex_setprio()
rt_mutex_setprio() has only one caller: rt_mutex_adjust_prio(). It
expects that task_struct::pi_lock and rt_mutex_base::wait_lock are held.
Both locks are raw_spinlock_t and are acquired with disabled interrupts.
Nevertheless rt_mutex_setprio() disables preemption while invoking
__balance_callbacks() and raw_spin_rq_unlock(). Even if one of the
balance callbacks unlocks the rq then it must not enable interrupts
because rt_mutex_base::wait_lock is still locked.
Therefore interrupts should remain disabled and disabling preemption is
not needed.
Commit 4c9a4bc89a9cc ("sched: Allow balance callbacks for check_class_changed()")
adds a preempt-disable section to rt_mutex_setprio() and
__sched_setscheduler(). In __sched_setscheduler() the preemption is
disabled before rq is unlocked and interrupts enabled but I don't see
why it makes a difference in rt_mutex_setprio().
Remove the preempt_disable() section from rt_mutex_setprio().
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://patch.msgid.link/20251127155529.t_sTatE4@linutronix.de
---
kernel/sched/core.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 1711e9e..ee7dfbf 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7352,15 +7352,12 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
p->prio = prio;
}
out_unlock:
- /* Avoid rq from going away on us: */
- preempt_disable();
+ /* Caller holds task_struct::pi_lock, IRQs are still disabled */
rq_unpin_lock(rq, &rf);
__balance_callbacks(rq);
rq_repin_lock(rq, &rf);
__task_rq_unlock(rq, p, &rf);
-
- preempt_enable();
}
#endif /* CONFIG_RT_MUTEXES */
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-12-06 9:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-27 15:55 [PATCH v3 REPOST] sched: Remove a preempt-disable section in rt_mutex_setprio() Sebastian Andrzej Siewior
2025-11-28 10:06 ` Peter Zijlstra
2025-12-03 18:25 ` [tip: sched/urgent] sched/rt: " tip-bot2 for Sebastian Andrzej Siewior
2025-12-03 18:31 ` tip-bot2 for Sebastian Andrzej Siewior
2025-12-06 9:10 ` tip-bot2 for Sebastian Andrzej Siewior
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®