From: George Dunlap <george.dunlap@eu.citrix.com>
To: David Vrabel <david.vrabel@citrix.com>, xen-devel@lists.xen.org
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Juergen Gross <juergen.gross@ts.fujitsu.com>
Subject: Re: [PATCH] sched: fix race between sched_move_domain() and vcpu_wake()
Date: Fri, 11 Oct 2013 11:32:50 +0100 [thread overview]
Message-ID: <5257D3D2.4020907@eu.citrix.com> (raw)
In-Reply-To: <1381426196-11392-1-git-send-email-david.vrabel@citrix.com>
On 10/10/13 18:29, David Vrabel wrote:
> From: David Vrabel <david.vrabel@citrix.com>
>
> sched_move_domain() changes v->processor for all the domain's VCPUs.
> If another domain, softirq etc. triggers a simultaneous call to
> vcpu_wake() (e.g., by setting an event channel as pending), then
> vcpu_wake() may lock one schedule lock and try to unlock another.
>
> vcpu_schedule_lock() attempts to handle this but only does so for the
> window between reading the schedule_lock from the per-CPU data and the
> spin_lock() call. This does not help with sched_move_domain()
> changing v->processor between the calls to vcpu_schedule_lock() and
> vcpu_schedule_unlock().
>
> Fix the race by taking the schedule_lock for v->processor in
> sched_move_domain().
>
> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
> Cc: George Dunlap <george.dunlap@eu.citrix.com>
> Cc: Juergen Gross <juergen.gross@ts.fujitsu.com>
> Cc: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
>
> Just taking the lock for the old processor seemed sufficient to me as
> anything seeing the new value would lock and unlock using the same new
> value. But do we need to take the schedule_lock for the new processor
> as well (in the right order of course)?
So going through the code and trying to reconstruct all the state in my
head...
If you look at vcpu_migrate(), it grabs both locks. But it looks like
the main purpose for that is so that we can call the migrate SCHED_OP(),
which for credit2 needs to do some mucking about with runqueues, and
thus needs both locks. In the case of move_domain, this is unnecessary,
since it is removed from the old scheduler and then added to the new one.
In a sense, Andrew, you're right: if you change v->processor, then you
no longer hold v's schedule lock (unless you do what vcpu_migrate()
does, and grab the lock of the processor you're moving to as well). In
this case, it doesn't matter, because you're just about to release the
lock anyway. But it may be misleading to people in the future trying to
figure out what the right thing is to do -- we should at very least put
a comment saying that changing v->processor without having the new lock
effectively unlocks v, so don't do any more changes to the processor
state. (Or we can do as Keir says, and do the double-locking, but that's
a bit of a pain, as you can see from vcpu_migrate().)
But I think this patch is still not quite right: both v->processor and
per_cpu(schedule_data, ...).schedule_lock may change under your feet; so
you always need to do the lock in a loop, checking to make sure that you
*still* have the right lock after you have actually grabbed it.
The gears on this code are rusty, however, so please do double-check my
thinking here...
-George
next prev parent reply other threads:[~2013-10-11 10:32 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-10 17:29 [PATCH] sched: fix race between sched_move_domain() and vcpu_wake() David Vrabel
2013-10-10 18:01 ` Andrew Cooper
2013-10-10 18:27 ` Keir Fraser
2013-10-11 7:12 ` Jan Beulich
2013-10-11 8:07 ` Keir Fraser
2013-10-11 9:02 ` Andrew Cooper
2013-10-11 9:32 ` Jan Beulich
2013-10-11 9:36 ` David Vrabel
2013-10-11 9:37 ` Jan Beulich
2013-10-11 12:20 ` Jan Beulich
2013-10-11 14:39 ` George Dunlap
2013-10-11 14:45 ` George Dunlap
2013-10-11 15:00 ` Processed: " xen
2013-10-11 10:36 ` George Dunlap
2013-10-11 6:37 ` Juergen Gross
2013-10-11 10:32 ` George Dunlap [this message]
2013-10-11 11:15 ` Dario Faggioli
2013-10-11 11:32 ` George Dunlap
2013-10-11 11:49 ` Dario Faggioli
2013-10-11 12:03 ` Jan Beulich
2013-10-11 11:47 ` Keir Fraser
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=5257D3D2.4020907@eu.citrix.com \
--to=george.dunlap@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=david.vrabel@citrix.com \
--cc=juergen.gross@ts.fujitsu.com \
--cc=xen-devel@lists.xen.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.