FROMLIST: sched/wait: Fix a kthread_park race with wait_woken()

kthread_park and wait_woken have a similar race that kthread_stop and
wait_woken used to have before it was fixed in
cb6538e740. Extend that fix to also cover
kthread_park.

Bug: 274686101
Link: https://lore.kernel.org/lkml/20230406194053.876844-1-arve@android.com/
Change-Id: Iaec960d7e30862f4ccac5c98dd43d32bbcf9a72b
Signed-off-by: Arve Hjønnevåg <arve@android.com>
(cherry picked from commit 69eba53950444890063b1e0469a61b69f8301767)
This commit is contained in:
Arve Hjønnevåg
2023-04-05 16:47:02 -07:00
committed by Treehugger Robot
parent 3d9d54cf37
commit 12d161b7ae

View File

@@ -427,9 +427,9 @@ __sched int autoremove_wake_function(struct wait_queue_entry *wq_entry, unsigned
}
EXPORT_SYMBOL(autoremove_wake_function);
static inline bool is_kthread_should_stop(void)
static inline bool is_kthread_should_stop_or_park(void)
{
return (current->flags & PF_KTHREAD) && kthread_should_stop();
return (current->flags & PF_KTHREAD) && (kthread_should_stop() || kthread_should_park());
}
/*
@@ -461,7 +461,7 @@ __sched long wait_woken(struct wait_queue_entry *wq_entry, unsigned int mode, lo
* or woken_wake_function() sees our store to current->state.
*/
set_current_state(mode); /* A */
if (!(wq_entry->flags & WQ_FLAG_WOKEN) && !is_kthread_should_stop())
if (!(wq_entry->flags & WQ_FLAG_WOKEN) && !is_kthread_should_stop_or_park())
timeout = schedule_timeout(timeout);
__set_current_state(TASK_RUNNING);