Skip to content

Commit e65855a

Browse files
Qais YousefPeter Zijlstra
authored andcommitted
sched/uclamp: Fix a deadlock when enabling uclamp static key
The following splat was caught when setting uclamp value of a task: BUG: sleeping function called from invalid context at ./include/linux/percpu-rwsem.h:49 cpus_read_lock+0x68/0x130 static_key_enable+0x1c/0x38 __sched_setscheduler+0x900/0xad8 Fix by ensuring we enable the key outside of the critical section in __sched_setscheduler() Fixes: 46609ce ("sched/uclamp: Protect uclamp fast path code with static key") Signed-off-by: Qais Yousef <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 21a6ee1 commit e65855a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

kernel/sched/core.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,15 @@ static int uclamp_validate(struct task_struct *p,
13461346
if (upper_bound > SCHED_CAPACITY_SCALE)
13471347
return -EINVAL;
13481348

1349+
/*
1350+
* We have valid uclamp attributes; make sure uclamp is enabled.
1351+
*
1352+
* We need to do that here, because enabling static branches is a
1353+
* blocking operation which obviously cannot be done while holding
1354+
* scheduler locks.
1355+
*/
1356+
static_branch_enable(&sched_uclamp_used);
1357+
13491358
return 0;
13501359
}
13511360

@@ -1376,8 +1385,6 @@ static void __setscheduler_uclamp(struct task_struct *p,
13761385
if (likely(!(attr->sched_flags & SCHED_FLAG_UTIL_CLAMP)))
13771386
return;
13781387

1379-
static_branch_enable(&sched_uclamp_used);
1380-
13811388
if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN) {
13821389
uclamp_se_set(&p->uclamp_req[UCLAMP_MIN],
13831390
attr->sched_util_min, true);

0 commit comments

Comments
 (0)