From: Keir Fraser <keir.xen@gmail.com>
To: Tim Deegan <tim@xen.org>, Andres Lagar Cavilla <andres@lagarcavilla.org>
Cc: Olaf Hering <olaf@aepfle.de>,
xen-devel@lists.xensource.com, zhen shi <bickys1986@gmail.com>,
Adin Scannell <adin@gridcentric.ca>
Subject: Re: Re: Re: mapping problems in xenpaging
Date: Mon, 10 Oct 2011 11:06:02 +0100 [thread overview]
Message-ID: <CAB8821A.2291B%keir.xen@gmail.com> (raw)
In-Reply-To: <20111010092111.GB31800@ocelot.phlegethon.org>
On 10/10/2011 10:21, "Tim Deegan" <tim@xen.org> wrote:
> At 21:20 -0400 on 09 Oct (1318195224), Andres Lagar Cavilla wrote:
>> I have a proposal. I'd like to hear from the list what they think.
>>
>> - 1. change p2m lock to a read/write lock
>> - 2. Make lookups (gfn_to_mfn_* family) take a read lock. All current
>> callers of p2m_lock will become write lockers.
>> - 3. Change the gfn_to_mfn_* family to get_page on the mfn obtained,
>> while holding the read lock.
>> - 4. Have all lookup callers put_page on the obtained mfn, once done.
>
> This seems like a step in the right direction, but if we're going to
> make this big an interface change there might be better interfaces to
> end up with.
>
> A few issues I can see with it:
> - p2m lookups are on some very performance-sensitive paths
> (e.g. multiple times in any pagetable walk or instruction emulation
> in a HVM guest) so adding the rwlock might have a noticeable impact.
If the read sections are short, may as well use a plain spinlock.
The best (but hard) way to make the locking cheaper is to work out a way to
use finer-grained locks (e.g., per-page / per-mapping) or avoid locks
altogether (e.g., RCU).
Multi-reader locks are rarely going to be a good choice in the hypervisor.
A good first step anyhow would be to make the p2m_ synchronisation correct,
and then optimise it. Sounds like that is hard enough. :-)
-- Keir
> - This fixes one class of races (page gets freed-to-xen underfoot) but
> leaves another one (gfn -> mfn map changes underfoot) untouched. In
> particular it doesn't solve the race where a foreign mapper
> gets a r/w map of what's meant to be a read-only frame.
>
> I think that to fix things properly we need to have some refcount
> associated with the p2m mapping itself. That would be taken by all
> lookups (or at least some - we could have a flag to the p2m lookup) and
> released as you suggest, but more importantly it would block all p2m changes
> while the count was raised. (I think that a least in the common case we
> could encode such a refcount using the existing typecount).
>
> One problem then is how to make all the callers of the p2m update
> functions handle failure, either by waiting (new deadlock risk?) or
> returning EAGAIN at the hypercall interface. Paths where the update
> isn't caused by an explicit request (like log-dirty and the mem-event
> rx-to-rw conversion) would be particularly tricky.
>
> More seriously, it introduces another round of the sort of priority
> inversion we already get with the existing refcounts - a foreign
> mapping, caused by a user-space program in another VM, could arbitrarily
> delay a p2m update (and so prevent a VCPU from making progress), without
> any mechanism to even request that the mapping be removed.
>
> Any ideas how to avoid that? Potentially with some extra bookkeeping on
> foreign mappings we could revoke or redirect them when the p2m changes.
> That would fit nicely with the abstraction in the interfaces where HVM
> domains' memory is always indexed by pfn. I can imagine it being quite
> tricky though.
>
>> I'm more wary that turning p2m locking into read/write will result in
>> code deadlocking itself: taking a read lock first and a write lock
>> later. Possibly the current rwlock implementation could be improved to
>> keep a cpumask of read-lockers, and provide an atomic "promote from
>> read to write" atomic operation (something along the lines of wait
>> until you're the only reader in the cpumask, and then cmpxchg(lock,
>> -1, WRITE_BIAS))
>
> I think that would deadlock if two cpus tried it at once.
>
> Tim.
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
next prev parent reply other threads:[~2011-10-10 10:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-10 1:20 Re: mapping problems in xenpaging Andres Lagar Cavilla
2011-10-10 9:21 ` Tim Deegan
2011-10-10 10:06 ` Keir Fraser [this message]
2011-10-10 19:31 ` Andres Lagar Cavilla
2011-10-11 6:04 ` Olaf Hering
2011-10-13 15:08 ` Tim Deegan
2011-10-10 19:17 ` Andres Lagar Cavilla
2011-10-13 15:02 ` Tim Deegan
2011-10-13 17:59 ` Andres Lagar Cavilla
2011-10-20 10:13 ` Tim Deegan
2011-10-20 14:54 ` Andres Lagar Cavilla
2011-10-20 15:31 ` Tim Deegan
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=CAB8821A.2291B%keir.xen@gmail.com \
--to=keir.xen@gmail.com \
--cc=adin@gridcentric.ca \
--cc=andres@lagarcavilla.org \
--cc=bickys1986@gmail.com \
--cc=olaf@aepfle.de \
--cc=tim@xen.org \
--cc=xen-devel@lists.xensource.com \
/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.