Commit 91dabf3
Peter Zijlstra
sched: Fix race in task_call_func()
There is a very narrow race between schedule() and task_call_func().
CPU0 CPU1
__schedule()
rq_lock();
prev_state = READ_ONCE(prev->__state);
if (... && prev_state) {
deactivate_tasl(rq, prev, ...)
prev->on_rq = 0;
task_call_func()
raw_spin_lock_irqsave(p->pi_lock);
state = READ_ONCE(p->__state);
smp_rmb();
if (... || p->on_rq) // false!!!
rq = __task_rq_lock()
ret = func();
next = pick_next_task();
rq = context_switch(prev, next)
prepare_lock_switch()
spin_release(&__rq_lockp(rq)->dep_map...)
So while the task is on it's way out, it still holds rq->lock for a
little while, and right then task_call_func() comes in and figures it
doesn't need rq->lock anymore (because the task is already dequeued --
but still running there) and then the __set_task_frozen() thing observes
it's holding rq->lock and yells murder.
Avoid this by waiting for p->on_cpu to get cleared, which guarantees
the task is fully finished on the old CPU.
( While arguably the fixes tag is 'wrong' -- none of the previous
task_call_func() users appears to care for this case. )
Fixes: f5d39b0 ("freezer,sched: Rewrite core freezer logic")
Reported-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://lkml.kernel.org/r/Y1kdRNNfUeAU+FNl@hirez.programming.kicks-ass.net1 parent 448dca8 commit 91dabf3
1 file changed
+35
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4200 | 4200 | | |
4201 | 4201 | | |
4202 | 4202 | | |
| 4203 | + | |
| 4204 | + | |
| 4205 | + | |
| 4206 | + | |
| 4207 | + | |
| 4208 | + | |
| 4209 | + | |
| 4210 | + | |
| 4211 | + | |
| 4212 | + | |
| 4213 | + | |
| 4214 | + | |
| 4215 | + | |
| 4216 | + | |
| 4217 | + | |
| 4218 | + | |
| 4219 | + | |
| 4220 | + | |
| 4221 | + | |
| 4222 | + | |
| 4223 | + | |
| 4224 | + | |
| 4225 | + | |
| 4226 | + | |
| 4227 | + | |
| 4228 | + | |
| 4229 | + | |
| 4230 | + | |
| 4231 | + | |
| 4232 | + | |
| 4233 | + | |
| 4234 | + | |
| 4235 | + | |
| 4236 | + | |
4203 | 4237 | | |
4204 | 4238 | | |
4205 | 4239 | | |
| |||
4217 | 4251 | | |
4218 | 4252 | | |
4219 | 4253 | | |
4220 | | - | |
4221 | 4254 | | |
4222 | 4255 | | |
4223 | 4256 | | |
4224 | 4257 | | |
4225 | 4258 | | |
4226 | | - | |
4227 | | - | |
4228 | | - | |
4229 | | - | |
4230 | | - | |
4231 | | - | |
4232 | | - | |
4233 | | - | |
4234 | | - | |
4235 | | - | |
4236 | | - | |
4237 | | - | |
4238 | | - | |
4239 | | - | |
4240 | | - | |
4241 | | - | |
| 4259 | + | |
4242 | 4260 | | |
4243 | 4261 | | |
4244 | 4262 | | |
| |||
0 commit comments