* [PATCH] sched/core: Test online status in available_idle_cpu()
@ 2024-04-29 5:54 Sven Schnelle
2024-05-02 15:57 ` Valentin Schneider
0 siblings, 1 reply; 4+ messages in thread
From: Sven Schnelle @ 2024-04-29 5:54 UTC (permalink / raw
To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Daniel Bristot de Oliveira, Valentin Schneider
Cc: Heiko Carstens, linux-s390, linux-kernel
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.
Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
---
kernel/sched/core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 7019a40457a6..1d9b80411594 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -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;
--
2.40.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] sched/core: Test online status in available_idle_cpu()
2024-04-29 5:54 [PATCH] sched/core: Test online status in available_idle_cpu() Sven Schnelle
@ 2024-05-02 15:57 ` Valentin Schneider
2024-05-08 7:31 ` Sven Schnelle
0 siblings, 1 reply; 4+ messages in thread
From: Valentin Schneider @ 2024-05-02 15:57 UTC (permalink / raw
To: Sven Schnelle, Ingo Molnar, Peter Zijlstra, Juri Lelli,
Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
Mel Gorman, Daniel Bristot de Oliveira
Cc: Heiko Carstens, linux-s390, linux-kernel
On 29/04/24 07:54, Sven Schnelle wrote:
> 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.
>
> Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
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.
Reviewed-by: Valentin Schneider <vschneid@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] sched/core: Test online status in available_idle_cpu()
2024-05-02 15:57 ` Valentin Schneider
@ 2024-05-08 7:31 ` Sven Schnelle
2024-05-16 16:38 ` Sven Schnelle
0 siblings, 1 reply; 4+ messages in thread
From: Sven Schnelle @ 2024-05-08 7:31 UTC (permalink / raw
To: Valentin Schneider
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Daniel Bristot de Oliveira, Heiko Carstens, linux-s390,
linux-kernel
Valentin Schneider <vschneid@redhat.com> writes:
> On 29/04/24 07:54, Sven Schnelle wrote:
>> 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.
>>
>> Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
>
>
> 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.
>
> Reviewed-by: Valentin Schneider <vschneid@redhat.com>
Thanks for the review! Ingo/Peter, gentle ping, are you planning to take
this patch?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] sched/core: Test online status in available_idle_cpu()
2024-05-08 7:31 ` Sven Schnelle
@ 2024-05-16 16:38 ` Sven Schnelle
0 siblings, 0 replies; 4+ messages in thread
From: Sven Schnelle @ 2024-05-16 16:38 UTC (permalink / raw
To: Ingo Molnar, Peter Zijlstra
Cc: Valentin Schneider, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman,
Daniel Bristot de Oliveira, Heiko Carstens, linux-s390,
linux-kernel
Sven Schnelle <svens@linux.ibm.com> writes:
> Valentin Schneider <vschneid@redhat.com> writes:
>
>> On 29/04/24 07:54, Sven Schnelle wrote:
>>> 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.
>>>
>>> Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
>>
>>
>> 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.
>>
>> Reviewed-by: Valentin Schneider <vschneid@redhat.com>
>
> Thanks for the review! Ingo/Peter, gentle ping, are you planning to
> take
> this patch?
Ping?
Thanks,
Sven
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-16 16:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-29 5:54 [PATCH] sched/core: Test online status in available_idle_cpu() Sven Schnelle
2024-05-02 15:57 ` Valentin Schneider
2024-05-08 7:31 ` Sven Schnelle
2024-05-16 16:38 ` Sven Schnelle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).