Skip to contentSkip to conversation

sched_ext: Fix missing warning in scx_set_task_state() default case

PATCH In review Samuele Mariotti 2 participants 2 messages Apr 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched_ext: Fix missing warning in scx_set_task_state() default case

In scx_set_task_state(), the default case was setting the warn flag, but then returning immediately. This is problematic because the only purpose of the warn flag is to trigger WARN_ONCE, but the early return prevented it from ever firing, leaving invalid task states undetected and untraced.

To fix this, a WARN_ONCE call is now added directly in the default case.

The fix addresses two aspects:

- Guarantees the invalid task states are properly logged and traced.

- Provides a distinct warning message ("sched_ext: Invalid task state") specifically for states outside the defined scx_task_state enum values, making it easier to distinguish from other transition warnings.

This ensures proper detection and reporting of invalid states.

---
 kernel/sched/ext.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/ext.c +2 -1
index 1594987d637b..10683ce4e415 100644
@@ -2863,7 +2863,8 @@ static void scx_set_task_state(struct task_struct *p, enum scx_task_state state)
 		warn = prev_state != SCX_TASK_READY;
 		break;
 	default:
-		warn = true;
+		WARN_ONCE(1, "sched_ext: Invalid task state %d -> %d for %s[%d]",
+			  prev_state, state, p->comm, p->pid);
 		return;
 	}
 
Signature · 1 line
2.47.3
reviewer Reviewed-by on v1 1/1
#1 lore raw

Hi Samuele,

Quoted 20 lines · Samuele Mariotti

In scx_set_task_state(), the default case was setting the warn flag, but then returning immediately. This is problematic because the only purpose of the warn flag is to trigger WARN_ONCE, but the early return prevented it from ever firing, leaving invalid task states undetected and untraced.

To fix this, a WARN_ONCE call is now added directly in the default case.

The fix addresses two aspects:

- Guarantees the invalid task states are properly logged and traced.

- Provides a distinct warning message ("sched_ext: Invalid task state") specifically for states outside the defined scx_task_state enum values, making it easier to distinguish from other transition warnings.

Quoted 4 lines

This ensures proper detection and reporting of invalid states.

Nice catch, we should probably add:

Fixes f0e1a0643a59 ("sched_ext: Implement BPF extensible scheduler class")

With that:

Thanks,
-Andrea

Quoted 21 lines
---
 kernel/sched/ext.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/ext.c +2 -1
index 1594987d637b..10683ce4e415 100644
@@ -2863,7 +2863,8 @@ static void scx_set_task_state(struct task_struct *p, enum scx_task_state state)
 		warn = prev_state != SCX_TASK_READY;
 		break;
 	default:
-		warn = true;
+		WARN_ONCE(1, "sched_ext: Invalid task state %d -> %d for %s[%d]",
+			  prev_state, state, p->comm, p->pid);
 		return;
 	}
 
Signature · 1 line
2.47.3