Skip to contentSkip to conversation

softlockup: ensure the task has been switched out once

PATCH Applied Frederic Weisbecker 3 participants 3 messages Feb 10, 2009 – Feb 11, 2009 Hung task detector

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 softlockup: ensure the task has been switched out once

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.

---
 kernel/hung_task.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
kernel/hung_task.c +7 -1
index 0c924de..022a492 100644
@@ -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) {
Signature · 1 line
1.6.1
Acked-by on v1 1/1
#1 lore raw
Quoted 38 lines · Frederic Weisbecker

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.

---
 kernel/hung_task.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
kernel/hung_task.c +7 -1
index 0c924de..022a492 100644
@@ -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) {
Signature · 1 line
1.6.1

Looks good to me. Thanks for fixing this!

Applied
#2 lore raw
Quoted 43 lines · Mandeep Singh Baines
Quoted 38 lines · Frederic Weisbecker

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.

---
 kernel/hung_task.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
kernel/hung_task.c +7 -1
index 0c924de..022a492 100644
@@ -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) {
Signature · 1 line
1.6.1

Looks good to me. Thanks for fixing this!

Quoted 1 line

Applied to tip:core/softlockup, thanks guys!

Ingo