Skip to contentSkip to conversation

sched/core: Test online status in available_idle_cpu()

PATCH In review Sven Schnelle 2 participants 4 messages Apr 29, 2024 – May 16, 2024

Subsystems (2)
lore
Share & tools
lore

Sven Schnelle

author reviewer
#0 lore raw

PATCH 1/1 sched/core: Test online status in available_idle_cpu()

The current implementation of available_idle_cpu() doesn't test whether a possible cpu is offline. On s390 this dereferences a NULL pointer in arch_vcpu_is_preempted() because lowcore is not allocated for offline cpus. On x86, tracing also shows calls to available_idle_cpu() after a cpu is disabled, but it looks like this isn't causing any (obvious) issue. Nevertheless, add a check and return early if the cpu isn't online.

---
 kernel/sched/core.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/sched/core.c +3 -0
index 7019a40457a6..1d9b80411594 100644
@@ -7434,6 +7434,9 @@ int idle_cpu(int cpu)
  */
 int available_idle_cpu(int cpu)
 {
+	if (!cpu_online(cpu))
+		return 0;
+
 	if (!idle_cpu(cpu))
 		return 0;
 
Signature · 1 line
2.40.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Sven Schnelle

The current implementation of available_idle_cpu() doesn't test whether a possible cpu is offline. On s390 this dereferences a NULL pointer in arch_vcpu_is_preempted() because lowcore is not allocated for offline cpus. On x86, tracing also shows calls to available_idle_cpu() after a cpu is disabled, but it looks like this isn't causing any (obvious) issue. Nevertheless, add a check and return early if the cpu isn't online.

So most of the uses of that function is in wakeup task placement.
o find_idlest_cpu() works on the sched_domain spans, so shouldn't deal with offline CPUs.
o select_idle_sibling() may issue an available_idle_cpu(prev) with an offline previous, which would trigger your issue.

Currently, even if select_idle_sibling() picks an offline CPU, this will get corrected by select_fallback_rq() at the end of select_task_rq(). However, it would make sense to realize @prev isn't a suitable pick before making it to the fallback machinery, in which case your patch makes sense beyond just fixing s390.

author reviewer
#2 lore raw
Quoted 18 lines · Valentin Schneider
Quoted 9 lines · Sven Schnelle

The current implementation of available_idle_cpu() doesn't test whether a possible cpu is offline. On s390 this dereferences a NULL pointer in arch_vcpu_is_preempted() because lowcore is not allocated for offline cpus. On x86, tracing also shows calls to available_idle_cpu() after a cpu is disabled, but it looks like this isn't causing any (obvious) issue. Nevertheless, add a check and return early if the cpu isn't online.

So most of the uses of that function is in wakeup task placement.
o find_idlest_cpu() works on the sched_domain spans, so shouldn't deal with offline CPUs.
o select_idle_sibling() may issue an available_idle_cpu(prev) with an offline previous, which would trigger your issue.

Quoted 7 lines

Currently, even if select_idle_sibling() picks an offline CPU, this will get corrected by select_fallback_rq() at the end of select_task_rq(). However, it would make sense to realize @prev isn't a suitable pick before making it to the fallback machinery, in which case your patch makes sense beyond just fixing s390.

Thanks for the review! Ingo/Peter, gentle ping, are you planning to take this patch?

author reviewer
#3 lore raw
Quoted 28 lines · Sven Schnelle
Quoted 9 lines · Valentin Schneider
Quoted 8 lines · Sven Schnelle

The current implementation of available_idle_cpu() doesn't test whether a possible cpu is offline. On s390 this dereferences a NULL pointer in arch_vcpu_is_preempted() because lowcore is not allocated for offline cpus. On x86, tracing also shows calls to available_idle_cpu() after a cpu is disabled, but it looks like this isn't causing any (obvious) issue. Nevertheless, add a check and return early if the cpu isn't online.

Quoted 5 lines
Quoted 1 line

So most of the uses of that function is in wakeup task placement.
o find_idlest_cpu() works on the sched_domain spans, so shouldn't

deal with

Quoted 2 lines

offline CPUs.
o select_idle_sibling() may issue an available_idle_cpu(prev) with

an

Quoted 3 lines

offline previous, which would trigger your issue.

Currently, even if select_idle_sibling() picks an offline CPU, this

will

Quoted 2 lines

get corrected by select_fallback_rq() at the end of select_task_rq(). However, it would make sense to realize @prev

isn't a

Quoted 1 line

suitable pick before making it to the fallback machinery, in which

Quoted 8 lines

case

Quoted 3 lines

your patch makes sense beyond just fixing s390.

Thanks for the review! Ingo/Peter, gentle ping, are you planning to take
this patch?

Ping?

Thanks,

Sven