xen/sched: fix 2 bugs related to credit scheduler
cover xen/sched: fix 2 bugs related to credit scheduler
Juergen Gross (2):
xen/credit: fix race with schedule_cpu_rm() in csched_timer() xen/sched: fix schedule_dump() handling of free cpus
xen/common/sched/core.c | 2 +- xen/common/sched/credit.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.55.0
PATCH 1/2 xen/credit: fix race with schedule_cpu_rm() in csched_timer()
When removing a CPU from a cpupool running the credit scheduler, a race might happen between schedule_cpu_rm() and csched_timer(), resulting in a NULL dereference.
The timer associated with csched_timer() is killed only in csched_deinit_pdata(), which is called by schedule_cpu_rm() after setting the scheduler's per-cpu data to NULL AND after enabling interrupts again. This can result in the timer to fire before it is being killed, so csched_timer() needs to test the per-cpu data to be set before accessing it.
--- xen/common/sched/credit.c | 4 ++++ 1 file changed, 4 insertions(+)
xen/common/sched/credit.c +4 -0
@@ -1589,6 +1589,10 @@ static void cf_check csched_tick(void *_cpu)struct csched_pcpu *spc =CSCHED_PCPU (cpu);struct csched_private *prv =CSCHED_PRIV (sr->scheduler); +/* Handle race of timer disabling vs. firing when switching scheduler. */ +if ( !spc ) +return ; + spc->tick++;/*
Signature · 1 line
2.55.0
Re: [PATCH 1/2] xen/credit: fix race with schedule_cpu_rm() in csched_timer()
Quoted 9 lines · Juergen Gross
When removing a CPU from a cpupool running the credit scheduler, a race might happen between
schedule_cpu_rm()andcsched_timer(), resulting in a NULL dereference.The timer associated with
csched_timer()is killed only incsched_deinit_pdata(), which is called byschedule_cpu_rm()after setting the scheduler's per-cpu data to NULL AND after enabling interrupts again. This can result in the timer to fire before it is being killed,
"... the timer firing before being killed,"
Quoted 6 lines
so
csched_timer()needs to test the per-cpu data to be
set before accessing it.Fixes 78be3dbbfefa ("cpupools [1/6]: hypervisor changes")Reported-by Dietmar Hahn <[email protected]>Signed-off-by Juergen Gross <[email protected]>
Re: [PATCH 1/2] xen/credit: fix race with schedule_cpu_rm() in csched_timer()
Quoted 13 lines · Andrew Cooper
Quoted 9 lines · Juergen Gross
When removing a CPU from a cpupool running the credit scheduler, a race might happen between
schedule_cpu_rm()andcsched_timer(), resulting in a NULL dereference.The timer associated with
csched_timer()is killed only incsched_deinit_pdata(), which is called byschedule_cpu_rm()after setting the scheduler's per-cpu data to NULL AND after enabling interrupts again. This can result in the timer to fire before it is being killed,"... the timer firing before being killed,"
Quoted 9 lines
Quoted 6 lines
so
csched_timer()needs to test the per-cpu data to be
set before accessing it.Fixes 78be3dbbfefa ("cpupools [1/6]: hypervisor changes")Reported-by Dietmar Hahn <[email protected]>Signed-off-by Juergen Gross <[email protected]>Acked-by Andrew Cooper <[email protected]>
Despite the fact that the race is very unlikely, the fix is very simple and still resolves a race condition, so we could consider including it in 4.22:
Thanks.
~ Oleksii
PATCH 2/2 xen/sched: fix schedule_dump() handling of free cpus
In reply to Juergen GrossWith the introduction of core scheduling cpus not used by any cpupool have been switched to use the very simple idle scheduler instead of the default scheduler.
Trying to obtain diagnostic scheduling data via the "r" debug key is scanning through all cpupools using the per-cpupool scheduler to print the related data. Unfortunately the switch to use the idle scheduler for free cpus wasn't reflected in schedule_dump(), causing the default scheduler's dump_cpu_state callback to be used for free cpus.
This causes NULL dereferences in case the default scheduler is one of credit or null.
Fix that by using the idle scheduler instead of the default scheduler for free cpus. Note that it is fine for a scheduler to have no dump_cpu_state callback.
--- xen/common/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/sched/core.c +1 -1
@@ -3452,7 +3452,7 @@ void schedule_dump(struct cpupool *c) }else { - sched = &operations; + sched = &sched_idle_ops; cpus = &cpupool_free_cpus; }
Signature · 1 line
2.55.0
Re: [PATCH 2/2] xen/sched: fix schedule_dump() handling of free cpus
Quoted 1 line · Juergen Gross
With the introduction of core scheduling cpus not used by any cpupool
You want a comma between "scheduling, cpus". It took a little while to figure out the correct parsing of this sentence.
As written, it's ambiguous with one interpretation being "With the introduction of core scheduling cpus, ..." but with a grammatically invalid remainder of the sentence.
Quoted 12 lines
have been switched to use the very simple idle scheduler instead of the default scheduler.
Trying to obtain diagnostic scheduling data via the "r" debug key is scanning through all cpupools using the per-cpupool scheduler to print the related data. Unfortunately the switch to use the idle scheduler for free cpus wasn't reflected in
schedule_dump(), causing the default scheduler'sdump_cpu_statecallback to be used for free cpus.This causes NULL dereferences in case the default scheduler is one of credit or null.
Quoted 8 lines
Fix that by using the idle scheduler instead of the default scheduler for free cpus. Note that it is fine for a scheduler to have no
dump_cpu_statecallback.Fixes f855dd962523 ("sched: add minimalistic idle scheduler for free cpus")Reported-by Dietmar Hahn <[email protected]>Tested-by Dietmar Hahn <[email protected]>Signed-off-by Juergen Gross <[email protected]>
FWIW, Acked-by: Andrew Cooper <[email protected]>