Skip to content

Commit

Permalink
softlockup: ensure the task has been switched out once
Browse files Browse the repository at this point in the history
When we check if a task has been switched out since the last scan, we might
have a race condition on the following scenario:

- the task is freshly created and scheduled

- it puts its state to TASK_UNINTERRUPTIBLE and is not yet switched out

- check_hung_task() scans this task and will report a false positive because
  t->nvcsw + t->nivcsw == t->last_switch_count == 0

Add a check for such cases.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Mandeep Singh Baines <msb@google.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
fweisbec authored and Ingo Molnar committed Feb 11, 2009
1 parent 17406b8 commit cf2592f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion kernel/hung_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
{
unsigned long switch_count = t->nvcsw + t->nivcsw;

if (t->flags & PF_FROZEN)
/*
* Ensure the task is not frozen.
* Also, when a freshly created task is scheduled once, changes
* its state to TASK_UNINTERRUPTIBLE without having ever been
* switched out once, it musn't be checked.
*/
if (unlikely(t->flags & PF_FROZEN || !switch_count))
return;

if (switch_count != t->last_switch_count) {
Expand Down

0 comments on commit cf2592f

Please sign in to comment.