xen/sched: fix rare error case in cpu_schedule_down()
PATCH 1/1 xen/sched: fix rare error case in cpu_schedule_down()
In case cpu_schedule_up() is failing to allocate memory for struct sched_resource, cpu_schedule_down() will be called with the sched_resource pointer being NULL. This needs to be handled.
--- xen/common/sched/core.c | 3 +++ 1 file changed, 3 insertions(+)
xen/common/sched/core.c +3 -0
@@ -2829,6 +2829,8 @@ static void cpu_schedule_down(unsigned int cpu)rcu_read_lock (&sched_res_rculock); sr =get_sched_res (cpu); +if ( !sr ) + goto out;kill_timer (&sr->s_timer);
@@ -2839,6 +2841,7 @@ static void cpu_schedule_down(unsigned int cpu) sr->sched_unit_idle =NULL ;call_rcu (&sr->rcu, sched_res_free); + out:rcu_read_unlock (&sched_res_rculock); }
Signature · 1 line
2.35.3
Quoted 2 lines · Juergen Gross
In case
cpu_schedule_up()is failing to allocate memory for structsched_resource,
Or (just to mention it again) in case the function isn't called at all because some earlier CPU_UP_PREPARE handler fails.
Quoted 6 lines
cpu_schedule_down()will be called with thesched_resourcepointer being NULL. This needs to be handled.Reported-by Jan Beulich <[email protected]>Fixes 207589dbacd4 ("xen/sched: move per cpu scheduler private data into struct sched_resource")Signed-off-by Juergen Gross <[email protected]>
You didn't tag it for 4.19 and you also didn't Cc Oleksii, so I expect you deem this minor enough to be delayed until 4.20 opens, despite the Fixes:
tag?
Jan
Quoted 14 lines · Jan Beulich
Quoted 2 lines · Juergen Gross
In case
cpu_schedule_up()is failing to allocate memory for structsched_resource,Or (just to mention it again) in case the function isn't called at all because some earlier
CPU_UP_PREPAREhandler fails.Quoted 6 lines
cpu_schedule_down()will be called with thesched_resourcepointer being NULL. This needs to be handled.Reported-by Jan Beulich <[email protected]>Fixes 207589dbacd4 ("xen/sched: move per cpu scheduler private data into struct sched_resource")Signed-off-by Juergen Gross <[email protected]>
Quoted 5 lines
Reviewed-by Jan Beulich <[email protected]>You didn't tag it for 4.19 and you also didn't Cc Oleksii, so I expect you deem this minor enough to be delayed until 4.20 opens, despite the Fixes:
tag?
Correct.
Juergen
Quoted 6 lines · Jan Beulich
Quoted 2 lines · Juergen Gross
In case
cpu_schedule_up()is failing to allocate memory for structsched_resource,Or (just to mention it again) in case the function isn't called at all because some earlier
CPU_UP_PREPAREhandler fails.
This remark made me looking into the notifier implementation.
I think this patch should be reworked significantly:
In cpu_up() the CPU_UP_CANCELED notifier call is using the same notifier_block as the one used by CPU_UP_PREPARE before. This means, that only the handlers which didn't fail for CPU_UP_PREPARE will be called with CPU_UP_CANCELED.
So there is no such case as "in case the function isn't called at all because some earlier CPU_UP_PREPARE handler fails".
And a failure of cpu_schedule_up() needs to undo all externally visible modifications instead of hoping that the CPU_UP_CANCELED notifier will do that.
So: V2 of the patch will be needed.
Juergen