From: Jeremy Fitzhardinge <jeremy@goop.org>
To: Ian Campbell <Ian.Campbell@citrix.com>
Cc: Xen-devel <xen-devel@lists.xensource.com>
Subject: Re: xen.git branch reorg / success with 2.6.30-rc3 pv_ops dom0
Date: Wed, 22 Jul 2009 11:16:25 -0700 [thread overview]
Message-ID: <4A675779.1030403@goop.org> (raw)
In-Reply-To: <1244711914.27370.511.camel@zakaz.uk.xensource.com>
On 06/11/09 02:18, Ian Campbell wrote:
> Pasi, to validate the theory that you are seeing races between unpinning
> and kmap_atomic_pte can you give this biguglystick approach to solving
> it a go.
>
I gave up trying to solve this in any kind of clever way and just
decided to go with a slightly cleaned-up version of this patch.
Unfortunately, I don't think it actually solves the problem because it
doesn't prevent unpin from happening while the page is still kmapped; it
just ends up using the spinlock as a barrier to move the race around to
some timing which is presumably mostly avoids the problem.
In principle the fix is to take the lock in xen_kmap_atomic and release
it in xen_kunmap_atomic. Unfortunately this is pretty ugly and complex
because kmaps are 1) inherently per-cpu, and 2) there can be 2 levels of
kmapping at once. This means that we'd need 2 per-cpu locks to allow us
to hold these locks for the mapping duration without introducing
deadlocks. However unpin (and pin, in principle) need to take *all*
these locks to exclude kmap on all cpus.
This is total overkill, since we only really care about excluding kmap
and unpin from a given pagetable, which suggests that the locks should
be part of the mm rather than global. Unfortunately k(un)map_atomic_pte
don't get the mm of the pagetable they're trying to pin, and I don't
think we can assume its the current mm.
Another (pretty hideous) approach might be to make unpin check the state
of the KMAP_PTE[01] slots in each CPU's kmap fixmaps and see if a
mapping exists for a page that its currently unpinning. This also has
the problem of being inherently racy; if we unpin the page, there's
going to be a little window after the unpin and before the kmap pte
update (even if they're back-to-back batched hypercalls).
I guess we could have a global rw spinlock; kmap/unmap takes it for
reading, and so can be concurrent with all other kmaps, but pin/unpin
takes it for writing to exclude them. That would work, but runs the
risk of pin/unpin from being livelocked out (I don't think rwspins will
block new readers if there's a pending writer). Ugly, but its the only
thing I can think of which actually solves the problem.
Oh, crap, we don't have a kunmap_atomic_pte hook.
Thoughts? Am I overthinking this and missing something obvious?
(PS: avoid CONFIG_HIGHPTE)
J
> diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
> index 1729178..beeb8e8 100644
> --- a/arch/x86/xen/mmu.c
> +++ b/arch/x86/xen/mmu.c
> @@ -1145,9 +1145,12 @@ static int xen_unpin_page(struct mm_struct *mm, struct page *page,
> return 0; /* never need to flush on unpin */
> }
>
> +static DEFINE_SPINLOCK(hack_lock); /* Hack to sync unpin against kmap_atomic_pte */
> +
> /* Release a pagetables pages back as normal RW */
> static void __xen_pgd_unpin(struct mm_struct *mm, pgd_t *pgd)
> {
> + spin_lock(&hack_lock);
> xen_mc_batch();
>
> xen_do_pin(MMUEXT_UNPIN_TABLE, PFN_DOWN(__pa(pgd)));
> @@ -1173,6 +1176,7 @@ static void __xen_pgd_unpin(struct mm_struct *mm, pgd_t *pgd)
> __xen_pgd_walk(mm, pgd, xen_unpin_page, USER_LIMIT);
>
> xen_mc_issue(0);
> + spin_unlock(&hack_lock);
> }
>
> static void xen_pgd_unpin(struct mm_struct *mm)
> @@ -1521,6 +1525,9 @@ static void xen_pgd_free(struct mm_struct *mm, pgd_t *pgd)
> static void *xen_kmap_atomic_pte(struct page *page, enum km_type type)
> {
> pgprot_t prot = PAGE_KERNEL;
> + void *ret;
> +
> + spin_lock(&hack_lock);
>
> if (PagePinned(page))
> prot = PAGE_KERNEL_RO;
> @@ -1530,7 +1537,11 @@ static void *xen_kmap_atomic_pte(struct page *page, enum km_type type)
> page_to_pfn(page), type,
> (unsigned long)pgprot_val(prot) & _PAGE_RW ? "WRITE" : "READ");
>
> - return kmap_atomic_prot(page, type, prot);
> + ret = kmap_atomic_prot(page, type, prot);
> +
> + spin_unlock(&hack_lock);
> +
> + return ret;
> }
> #endif
>
>
>
>
next prev parent reply other threads:[~2009-07-22 18:16 UTC|newest]
Thread overview: 118+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-23 17:38 xen.git branch reorg Jeremy Fitzhardinge
2009-04-23 18:24 ` Pasi Kärkkäinen
2009-04-23 18:32 ` Jeremy Fitzhardinge
2009-04-25 11:54 ` xen.git branch reorg / crash with 2.6.30-rc3 pv_ops dom0 Pasi Kärkkäinen
2009-04-25 12:36 ` Pasi Kärkkäinen
2009-04-25 13:59 ` M A Young
2009-04-26 14:50 ` Pasi Kärkkäinen
2009-04-25 23:34 ` Jeremy Fitzhardinge
2009-04-26 14:51 ` Pasi Kärkkäinen
2009-04-26 18:38 ` Pasi Kärkkäinen
2009-04-27 19:33 ` Jeremy Fitzhardinge
2009-04-27 19:38 ` Pasi Kärkkäinen
[not found] ` <1240931113.22119.11.camel@zakaz.uk.xensource.com>
2009-04-28 15:22 ` Pasi Kärkkäinen
2009-04-28 15:41 ` Yum install xen on F10 Boris Derzhavets
2009-04-28 16:02 ` M A Young
2009-04-28 17:42 ` Boris Derzhavets
2009-04-28 19:33 ` Pasi Kärkkäinen
2009-04-28 19:40 ` Boris Derzhavets
2009-04-29 6:40 ` Boris Derzhavets
2009-05-01 9:13 ` Boris Derzhavets
2009-05-01 9:26 ` John Haxby
2009-05-01 10:51 ` Boris Derzhavets
2009-05-01 10:55 ` M A Young
2009-05-01 11:19 ` Boris Derzhavets
2009-04-28 17:38 ` Pasi Kärkkäinen
2009-04-28 16:25 ` xen.git branch reorg / crash with 2.6.30-rc3 pv_ops dom0 Jeremy Fitzhardinge
[not found] ` <1240939020.22119.15.camel@zakaz.uk.xensource.com>
2009-04-28 17:30 ` Jeremy Fitzhardinge
[not found] ` <1240989350.17173.2096.camel@localhost.localdomain>
2009-04-29 16:25 ` Jeremy Fitzhardinge
2009-05-01 9:58 ` Pasi Kärkkäinen
2009-05-01 18:35 ` Jeremy Fitzhardinge
2009-05-05 17:19 ` Pasi Kärkkäinen
2009-05-05 20:10 ` Jeremy Fitzhardinge
2009-05-06 18:54 ` xen.git branch reorg / success " Pasi Kärkkäinen
2009-05-06 21:51 ` Jeremy Fitzhardinge
2009-05-07 17:24 ` Pasi Kärkkäinen
2009-05-07 18:30 ` Jeremy Fitzhardinge
2009-05-07 18:46 ` Pasi Kärkkäinen
2009-05-14 11:11 ` xen.git branch reorg / success with 2.6.30-rc3 pv_ops dom0 / CONFIG_HIGHPTE problems Pasi Kärkkäinen
2009-05-15 22:48 ` Jeremy Fitzhardinge
2009-05-18 14:57 ` xen.git branch reorg / success with 2.6.30-rc3 pv_ops dom0 Ian Campbell
2009-05-18 17:06 ` Pasi Kärkkäinen
2009-05-18 17:17 ` Pasi Kärkkäinen
2009-05-18 17:39 ` Jeremy Fitzhardinge
2009-05-18 17:50 ` Pasi Kärkkäinen
2009-05-21 9:08 ` Ian Campbell
2009-05-22 8:06 ` Pasi Kärkkäinen
2009-06-04 20:26 ` Pasi Kärkkäinen
2009-06-04 20:30 ` Pasi Kärkkäinen
2009-06-05 10:20 ` Ian Campbell
2009-06-05 11:23 ` Pasi Kärkkäinen
2009-06-05 11:37 ` Ian Campbell
2009-06-05 13:38 ` Pasi Kärkkäinen
2009-06-05 13:52 ` Ian Campbell
2009-06-05 15:41 ` Pasi Kärkkäinen
2009-06-05 16:05 ` Ian Campbell
2009-06-05 16:12 ` Ian Campbell
2009-06-05 18:19 ` Pasi Kärkkäinen
2009-06-08 15:45 ` Ian Campbell
2009-06-08 16:00 ` Ian Campbell
2009-06-08 16:13 ` Pasi Kärkkäinen
2009-06-08 16:17 ` Ian Campbell
2009-06-08 16:21 ` Pasi Kärkkäinen
2009-06-08 17:05 ` Pasi Kärkkäinen
2009-06-08 19:11 ` Pasi Kärkkäinen
2009-06-09 14:53 ` Pasi Kärkkäinen
2009-06-09 15:37 ` Ian Campbell
2009-06-09 18:07 ` Pasi Kärkkäinen
2009-06-09 17:28 ` Jeremy Fitzhardinge
2009-06-11 9:02 ` Ian Campbell
2009-06-11 9:14 ` Pasi Kärkkäinen
2009-06-11 9:18 ` Ian Campbell
2009-06-11 9:18 ` Ian Campbell
2009-06-11 18:27 ` Pasi Kärkkäinen
2009-06-11 19:34 ` Pasi Kärkkäinen
2009-06-15 10:03 ` Ian Campbell
2009-06-15 10:21 ` Pasi Kärkkäinen
2009-06-16 10:35 ` Ian Campbell
2009-06-16 10:56 ` Pasi Kärkkäinen
2009-06-16 19:31 ` Jeremy Fitzhardinge
2009-06-29 21:23 ` Dulloor
2009-07-22 18:16 ` Jeremy Fitzhardinge [this message]
2009-06-11 15:18 ` Jeremy Fitzhardinge
2009-06-11 17:24 ` Pasi Kärkkäinen
2009-06-11 18:56 ` Jeremy Fitzhardinge
2009-06-11 19:02 ` Pasi Kärkkäinen
2009-06-11 19:23 ` Jeremy Fitzhardinge
2009-06-29 21:16 ` Pasi Kärkkäinen
2009-05-18 19:09 ` Pasi Kärkkäinen
2009-05-06 6:48 ` xen.git branch reorg / crash " Jiang, Yunhong
2009-05-06 7:40 ` Jiang, Yunhong
2009-05-06 15:54 ` Jeremy Fitzhardinge
2009-04-24 10:33 ` xen.git branch reorg Boris Derzhavets
2009-04-24 18:17 ` Jeremy Fitzhardinge
2009-04-24 18:50 ` Boris Derzhavets
2009-04-24 19:48 ` Jeremy Fitzhardinge
2009-04-24 22:39 ` Christophe Saout
2009-04-25 6:55 ` Boris Derzhavets
2009-04-25 7:03 ` Venefax
2009-04-25 8:35 ` Boris Derzhavets
2009-04-25 8:19 ` Pasi Kärkkäinen
2009-04-25 8:58 ` Boris Derzhavets
2009-04-25 9:22 ` Boris Derzhavets
[not found] ` <1240846534.29824.101.camel@zakaz.uk.xensource.com>
2009-04-27 19:46 ` Jeremy Fitzhardinge
2009-04-27 20:18 ` Christophe Saout
2009-04-24 18:56 ` Boris Derzhavets
2009-04-24 8:59 ` Alex Zeffertt
2009-04-27 15:44 ` Ian Campbell
2009-04-26 1:28 ` William Pitcock
2009-04-27 20:50 ` Jeremy Fitzhardinge
2009-04-27 21:07 ` William Pitcock
2009-04-27 23:48 ` Jeremy Fitzhardinge
2009-04-28 7:13 ` William Pitcock
2009-04-28 9:14 ` Boris Derzhavets
2009-04-28 14:51 ` William Pitcock
2009-04-28 15:01 ` Boris Derzhavets
2009-04-28 15:33 ` William Pitcock
2009-04-28 15:51 ` Boris Derzhavets
2009-04-28 16:28 ` Jeremy Fitzhardinge
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=4A675779.1030403@goop.org \
--to=jeremy@goop.org \
--cc=Ian.Campbell@citrix.com \
--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.