xen/sched: fix get_cpu_idle_time() with core scheduling
PATCH 1/1 xen/sched: fix get_cpu_idle_time() with core scheduling
get_cpu_idle_time() is calling vcpu_runstate_get() for an idle vcpu. With core scheduling active this is fragile, as idle vcpus are assigned to other scheduling units temporarily, and that assignment is changed in some cases without holding the scheduling lock, and vcpu_runstate_get() is using v->sched_unit as parameter for unit_schedule_[un]lock_irq(), resulting in an ASSERT() triggering in unlock in case v->sched_unit has changed meanwhile.
Fix that by using a local unit variable holding the correct unit.
---
I have verified that all other uses of v->sched_unit are not
problematic: they are all for non-idle vcpus, or in scheduling paths dealing with scheduling themselves and thus being aware of the potential problem or not vulnerable by it.
--- xen/common/sched/core.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
xen/common/sched/core.c +11 -2
@@ -308,17 +308,26 @@ void vcpu_runstate_get(const struct vcpu *v, {spinlock_t *lock;s_time_t delta; +struct sched_unit *unit;rcu_read_lock (&sched_res_rculock); - lock =likely (v == current) ?NULL :unit_schedule_lock_irq (v->sched_unit); +/* +* Be careful in case of an idle vcpu: the assignment to a unit might +* change even with the scheduling lock held, so be sure to use the +* correct unit for locking in order to avoid triggering an ASSERT() in +* the unlock function. +*/ + unit =is_idle_vcpu (v) ?get_sched_res (v->processor)->sched_unit_idle + : v->sched_unit; + lock =likely (v == current) ?NULL :unit_schedule_lock_irq (unit);memcpy (runstate, &v->runstate,sizeof (*runstate)); delta =NOW () - runstate->state_entry_time;if ( delta >0 ) runstate->time[runstate->state] += delta;if (unlikely (lock !=NULL ) ) -unit_schedule_unlock_irq (lock, v->sched_unit); +unit_schedule_unlock_irq (lock, unit);rcu_read_unlock (&sched_res_rculock); }
Signature · 7 lines
2.16.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 9 lines · Juergen Gross
get_cpu_idle_time()is callingvcpu_runstate_get()for an idle vcpu. With core scheduling active this is fragile, as idle vcpus are assigned
to other scheduling units temporarily, and that assignment is changed in some cases without holding the scheduling lock, andvcpu_runstate_get()is usingv->sched_unitas parameter for unit_schedule_[un]lock_irq(), resulting in anASSERT()triggering in unlock in casev->sched_unithas changed meanwhile.
Quoted 4 lines
Fix that by using a local unit variable holding the correct unit.
Signed-off-by Juergen Gross <[email protected]>
And...
Quoted 5 lines
I have verified that all other uses of
v->sched_unitare not
problematic: they are all for non-idle vcpus, or in scheduling paths dealing with scheduling themselves and thus being aware of the potential problem or not vulnerable by it.
... Thanks for having done this as well. :-)
Regards
Signature · 6 lines
Dario Faggioli, Ph.D http://about.me/dario.faggioli Virtualization Software Engineer SUSE Labs, SUSE https://www.suse.com/ ------------------------------------------------------------------- <<This happens because _I_ choose it to happen!>> (Raistlin Majere)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel