From: Dario Faggioli <dario.faggioli@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: George Dunlap <george.dunlap@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Meng Xu <mengxu@cis.upenn.edu>, Jan Beulich <JBeulich@suse.com>
Subject: [PATCH v3 2/6] xen: sched: fix locking for insert_vcpu() in credit1 and RTDS
Date: Fri, 30 Oct 2015 00:04:20 +0100 [thread overview]
Message-ID: <20151029230420.25219.74544.stgit@Solace.station> (raw)
In-Reply-To: <20151029225158.25219.4625.stgit@Solace.station>
The insert_vcpu() hook is handled with inconsistent locking.
In fact, schedule_cpu_switch() calls the hook with runqueue
lock held, while sched_move_domain() relies on the hook
implementations to take the lock themselves (and, since that
is not done in Credit1 and RTDS, such operation is not safe
in those cases).
This is fixed as follows:
- take the lock in the hook implementations, in specific
schedulers' code;
- avoid calling insert_vcpu(), for the idle vCPU, in
schedule_cpu_switch(). In fact, idle vCPUs are set to run
immediately, and the various schedulers won't insert them
in their runqueues anyway, even when explicitly asked to.
While there, still in schedule_cpu_switch(), locking with
_irq() is enough (there's no need to do *_irqsave()).
Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
---
Cc: George Dunlap <george.dunlap@eu.citrix.com>
Cc: Meng Xu <mengxu@cis.upenn.edu>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Jan Beulich <JBeulich@suse.com>
---
Cahnges from v2:
* locking in schedule_cpu_switch() is left in place (but
turned to just _irq(), instead than *_irqsave());
* call to insert_vcpu() in schedule_cpu_switch() is
removed in this patch (rather than later in the series).
Changes from v1 (of this series):
* in Credit1, the lock wants to be an _irqsave() one. If
not, the ASSERT() in _spin_lock_irq() will trigger when
the hook is called, during boot, from sched_init_vcpu();
* reprhased the changelog (to be less verbose);
* add a few words, in the changelog, about why it is safe
to get rid of the locking in schedule_cpu_switch(). Proper
commentary and ASSERT()-s about that will come in another
patch.
Changes from the other series:
* split the patch (wrt the original patch, in the original
series), and take care, in this one, only of insert_vcpu();
---
xen/common/sched_credit.c | 6 ++++++
xen/common/sched_rt.c | 3 +++
xen/common/schedule.c | 6 ++----
3 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c
index 6f71e0d..e16bd3a 100644
--- a/xen/common/sched_credit.c
+++ b/xen/common/sched_credit.c
@@ -903,10 +903,16 @@ static void
csched_vcpu_insert(const struct scheduler *ops, struct vcpu *vc)
{
struct csched_vcpu *svc = vc->sched_priv;
+ spinlock_t *lock;
+ unsigned long flags;
+
+ lock = vcpu_schedule_lock_irqsave(vc, &flags);
if ( !__vcpu_on_runq(svc) && vcpu_runnable(vc) && !vc->is_running )
__runq_insert(vc->processor, svc);
+ vcpu_schedule_unlock_irqrestore(lock, flags, vc);
+
SCHED_STAT_CRANK(vcpu_insert);
}
diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c
index 822f23c..3a66c9a 100644
--- a/xen/common/sched_rt.c
+++ b/xen/common/sched_rt.c
@@ -622,16 +622,19 @@ rt_vcpu_insert(const struct scheduler *ops, struct vcpu *vc)
{
struct rt_vcpu *svc = rt_vcpu(vc);
s_time_t now = NOW();
+ spinlock_t *lock;
/* not addlocate idle vcpu to dom vcpu list */
if ( is_idle_vcpu(vc) )
return;
+ lock = vcpu_schedule_lock_irq(vc);
if ( now >= svc->cur_deadline )
rt_update_deadline(now, svc);
if ( !__vcpu_on_q(svc) && vcpu_runnable(vc) && !vc->is_running )
__runq_insert(ops, svc);
+ vcpu_schedule_unlock_irq(lock, vc);
/* add rt_vcpu svc to scheduler-specific vcpu list of the dom */
list_add_tail(&svc->sdom_elem, &svc->sdom->vcpu);
diff --git a/xen/common/schedule.c b/xen/common/schedule.c
index c5f640f..80d6fb7 100644
--- a/xen/common/schedule.c
+++ b/xen/common/schedule.c
@@ -1488,7 +1488,6 @@ void __init scheduler_init(void)
int schedule_cpu_switch(unsigned int cpu, struct cpupool *c)
{
- unsigned long flags;
struct vcpu *idle;
spinlock_t *lock;
void *ppriv, *ppriv_old, *vpriv, *vpriv_old;
@@ -1509,7 +1508,7 @@ int schedule_cpu_switch(unsigned int cpu, struct cpupool *c)
return -ENOMEM;
}
- lock = pcpu_schedule_lock_irqsave(cpu, &flags);
+ lock = pcpu_schedule_lock_irq(cpu);
SCHED_OP(old_ops, tick_suspend, cpu);
vpriv_old = idle->sched_priv;
@@ -1518,9 +1517,8 @@ int schedule_cpu_switch(unsigned int cpu, struct cpupool *c)
ppriv_old = per_cpu(schedule_data, cpu).sched_priv;
per_cpu(schedule_data, cpu).sched_priv = ppriv;
SCHED_OP(new_ops, tick_resume, cpu);
- SCHED_OP(new_ops, insert_vcpu, idle);
- pcpu_schedule_unlock_irqrestore(lock, flags, cpu);
+ pcpu_schedule_unlock_irq(lock, cpu);
SCHED_OP(old_ops, free_vdata, vpriv_old);
SCHED_OP(old_ops, free_pdata, ppriv_old, cpu);
next prev parent reply other threads:[~2015-10-29 23:04 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-29 23:04 [PATCH v3 0/6] xen: sched: fix locking of {insert, remove}_vcpu() Dario Faggioli
2015-10-29 23:04 ` [PATCH v3 1/6] xen: sched: fix locking of remove_vcpu() in credit1 Dario Faggioli
2015-11-02 18:04 ` George Dunlap
2015-11-03 17:15 ` Dario Faggioli
2015-10-29 23:04 ` Dario Faggioli [this message]
2015-10-30 23:00 ` [PATCH v3 2/6] xen: sched: fix locking for insert_vcpu() in credit1 and RTDS Meng Xu
2015-11-02 8:03 ` Dario Faggioli
2015-11-02 14:45 ` Meng Xu
2015-11-04 14:12 ` Dario Faggioli
2015-11-04 15:01 ` Meng Xu
2015-11-04 15:52 ` Dario Faggioli
2015-11-05 3:55 ` Meng Xu
2015-10-29 23:04 ` [PATCH v3 3/6] xen: sched: clarify use cases of schedule_cpu_switch() Dario Faggioli
2015-10-29 23:59 ` Dario Faggioli
2015-10-30 4:33 ` Juergen Gross
2015-11-02 18:23 ` George Dunlap
2015-10-29 23:04 ` [PATCH v3 4/6] xen: sched: better handle (not) inserting idle vCPUs in runqueues Dario Faggioli
2015-10-29 23:04 ` [PATCH v3 5/6] xen: sched: get rid of the per domain vCPU list in RTDS Dario Faggioli
2015-11-02 18:57 ` George Dunlap
2015-10-29 23:04 ` [PATCH v3 6/6] xen: sched: get rid of the per domain vCPU list in Credit2 Dario Faggioli
2015-11-02 18:56 ` George Dunlap
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151029230420.25219.74544.stgit@Solace.station \
--to=dario.faggioli@citrix.com \
--cc=JBeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=george.dunlap@eu.citrix.com \
--cc=mengxu@cis.upenn.edu \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.