diff options
| author | Chen Yu <[email protected]> | 2024-08-27 11:23:08 +0000 |
|---|---|---|
| committer | Peter Zijlstra <[email protected]> | 2024-09-10 07:51:14 +0000 |
| commit | 6b9ccbc033cf179956a37fef3ee415bdc3029d2f (patch) | |
| tree | bb29f076f87efd27451779aaeeec2fe2180891a8 /drivers/platform/surface/aggregator/ssh_parser.c | |
| parent | sched/pelt: Use rq_clock_task() for hw_pressure (diff) | |
| download | kernel-6b9ccbc033cf179956a37fef3ee415bdc3029d2f.tar.gz kernel-6b9ccbc033cf179956a37fef3ee415bdc3029d2f.zip | |
kthread: Fix task state in kthread worker if being frozen
When analyzing a kernel waring message, Peter pointed out that there is a race
condition when the kworker is being frozen and falls into try_to_freeze() with
TASK_INTERRUPTIBLE, which could trigger a might_sleep() warning in try_to_freeze().
Although the root cause is not related to freeze()[1], it is still worthy to fix
this issue ahead.
One possible race scenario:
CPU 0 CPU 1
----- -----
// kthread_worker_fn
set_current_state(TASK_INTERRUPTIBLE);
suspend_freeze_processes()
freeze_processes
static_branch_inc(&freezer_active);
freeze_kernel_threads
pm_nosig_freezing = true;
if (work) { //false
__set_current_state(TASK_RUNNING);
} else if (!freezing(current)) //false, been frozen
freezing():
if (static_branch_unlikely(&freezer_active))
if (pm_nosig_freezing)
return true;
schedule()
}
// state is still TASK_INTERRUPTIBLE
try_to_freeze()
might_sleep() <--- warning
Fix this by explicitly set the TASK_RUNNING before entering
try_to_freeze().
Fixes: b56c0d8937e6 ("kthread: implement kthread_worker")
Suggested-by: Peter Zijlstra <[email protected]>
Suggested-by: Andrew Morton <[email protected]>
Signed-off-by: Chen Yu <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Link: https://lore.kernel.org/lkml/Zs2ZoAcUsZMX2B%2FI@chenyu5-mobl2/ [1]
Diffstat (limited to 'drivers/platform/surface/aggregator/ssh_parser.c')
0 files changed, 0 insertions, 0 deletions
