From: George Dunlap Date: Fri, 5 Aug 2016 12:07:27 +0000 (+0200) Subject: xen: Have schedulers revise initial placement X-Git-Tag: RELEASE-4.5.4~26 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=c421378a8d14c811e5467d535bc71adc0328a316;p=xen.git xen: Have schedulers revise initial placement The generic domain creation logic in xen/common/domctl.c:default_vcpu0_location() attempts to try to do initial placement load-balancing by placing vcpu 0 on the least-busy non-primary hyperthread available. Unfortunately, the logic can end up picking a pcpu that's not in the online mask. When this is passed to a scheduler such which assumes that the initial assignment is valid, it causes a null pointer dereference looking up the runqueue. Furthermore, this initial placement doesn't take into account hard or soft affinity, or any scheduler-specific knowledge (such as historic runqueue load, as in credit2). To solve this, when inserting a vcpu, always call the per-scheduler "pick" function to revise the initial placement. This will automatically take all knowledge the scheduler has into account. csched2_cpu_pick ASSERTs that the vcpu's pcpu scheduler lock has been taken. Grab and release the lock to minimize time spend with irqs disabled. Signed-off-by: George Dunlap Reviewed-by: Meng Xu Reviwed-by: Dario Faggioli master commit: 9f358ddd69463fa8fb65cf67beb5f6f0d3350e32 master date: 2016-07-26 10:42:49 +0100 --- diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 54fd830efb..2e11aa27f9 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -892,6 +892,9 @@ csched_vcpu_insert(const struct scheduler *ops, struct vcpu *vc) spinlock_t *lock; unsigned long flags; + /* This is safe because vc isn't yet being scheduled */ + vc->processor = csched_cpu_pick(ops, vc); + lock = vcpu_schedule_lock_irqsave(vc, &flags); if ( !__vcpu_on_runq(svc) && vcpu_runnable(vc) && !vc->is_running ) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index db9e1c4a10..7a81db509a 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -269,6 +269,7 @@ struct csched2_dom { uint16_t nr_vcpus; }; +static int csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc); /* * Time-to-credit, credit-to-time. @@ -874,9 +875,16 @@ csched2_vcpu_insert(const struct scheduler *ops, struct vcpu *vc) /* FIXME: Do we need the private lock here? */ list_add_tail(&svc->sdom_elem, &svc->sdom->vcpu); - /* Add vcpu to runqueue of initial processor */ + /* csched2_cpu_pick() expects the pcpu lock to be held */ + lock = vcpu_schedule_lock_irq(vc); + + vc->processor = csched2_cpu_pick(ops, vc); + + spin_unlock_irq(lock); + lock = vcpu_schedule_lock_irq(vc); + /* Add vcpu to runqueue of initial processor */ runq_assign(ops, vc); vcpu_schedule_unlock_irq(lock, vc); diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index a77e80800a..bb972fa8f9 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -169,6 +169,8 @@ struct rt_dom { struct domain *dom; /* pointer to upper domain */ }; +static int rt_cpu_pick(const struct scheduler *ops, struct vcpu *vc); + /* * Useful inline functions */ @@ -554,6 +556,9 @@ rt_vcpu_insert(const struct scheduler *ops, struct vcpu *vc) if ( is_idle_vcpu(vc) ) return; + /* This is safe because vc isn't yet being scheduled */ + vc->processor = rt_cpu_pick(ops, vc); + lock = vcpu_schedule_lock_irq(vc); now = NOW();