mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeremy Fitzhardinge <jeremy@goop.org>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: the arch/x86 maintainers <x86@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Xen-devel <xen-devel@lists.xensource.com>,
	Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Subject: [PATCH 02/24] xen: separate p2m allocation from setting
Date: Fri, 13 Mar 2009 01:11:38 -0700	[thread overview]
Message-ID: <1236931920-6861-3-git-send-email-jeremy@goop.org> (raw)
In-Reply-To: <1236931920-6861-1-git-send-email-jeremy@goop.org>

From: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>

When doing very early p2m setting, we need to separate setting
from allocation, so split things up accordingly.

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
---
 arch/x86/xen/mmu.c |   61 +++++++++++++++++++++++++++++++++++++--------------
 arch/x86/xen/mmu.h |    3 ++
 2 files changed, 47 insertions(+), 17 deletions(-)

diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
index eceff87..d534986 100644
--- a/arch/x86/xen/mmu.c
+++ b/arch/x86/xen/mmu.c
@@ -233,47 +233,74 @@ unsigned long get_phys_to_machine(unsigned long pfn)
 }
 EXPORT_SYMBOL_GPL(get_phys_to_machine);
 
-static void alloc_p2m(unsigned long **pp, unsigned long *mfnp)
+/* install a  new p2m_top page */
+bool install_p2mtop_page(unsigned long pfn, unsigned long *p)
 {
-	unsigned long *p;
+	unsigned topidx = p2m_top_index(pfn);
+	unsigned long **pfnp, *mfnp;
 	unsigned i;
 
-	p = (void *)__get_free_page(GFP_KERNEL | __GFP_NOFAIL);
-	BUG_ON(p == NULL);
+	pfnp = &p2m_top[topidx];
+	mfnp = &p2m_top_mfn[topidx];
 
 	for (i = 0; i < P2M_ENTRIES_PER_PAGE; i++)
 		p[i] = INVALID_P2M_ENTRY;
 
-	if (cmpxchg(pp, p2m_missing, p) != p2m_missing)
-		free_page((unsigned long)p);
-	else
+	if (cmpxchg(pfnp, p2m_missing, p) == p2m_missing) {
 		*mfnp = virt_to_mfn(p);
+		return true;
+	}
+
+	return false;
 }
 
-void set_phys_to_machine(unsigned long pfn, unsigned long mfn)
+static void alloc_p2m(unsigned long pfn)
 {
-	unsigned topidx, idx;
+	unsigned long *p;
 
-	if (unlikely(xen_feature(XENFEAT_auto_translated_physmap))) {
-		BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
-		return;
-	}
+	p = (void *)__get_free_page(GFP_KERNEL | __GFP_NOFAIL);
+	BUG_ON(p == NULL);
+
+	if (!install_p2mtop_page(pfn, p))
+		free_page((unsigned long)p);
+}
+
+/* Try to install p2m mapping; fail if intermediate bits missing */
+bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn)
+{
+	unsigned topidx, idx;
 
 	if (unlikely(pfn >= MAX_DOMAIN_PAGES)) {
 		BUG_ON(mfn != INVALID_P2M_ENTRY);
-		return;
+		return true;
 	}
 
 	topidx = p2m_top_index(pfn);
 	if (p2m_top[topidx] == p2m_missing) {
-		/* no need to allocate a page to store an invalid entry */
 		if (mfn == INVALID_P2M_ENTRY)
-			return;
-		alloc_p2m(&p2m_top[topidx], &p2m_top_mfn[topidx]);
+			return true;
+		return false;
 	}
 
 	idx = p2m_index(pfn);
 	p2m_top[topidx][idx] = mfn;
+
+	return true;
+}
+
+void set_phys_to_machine(unsigned long pfn, unsigned long mfn)
+{
+	if (unlikely(xen_feature(XENFEAT_auto_translated_physmap))) {
+		BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
+		return;
+	}
+
+	if (unlikely(!__set_phys_to_machine(pfn, mfn)))  {
+		alloc_p2m(pfn);
+
+		if (!__set_phys_to_machine(pfn, mfn))
+			BUG();
+	}
 }
 
 unsigned long arbitrary_virt_to_mfn(void *vaddr)
diff --git a/arch/x86/xen/mmu.h b/arch/x86/xen/mmu.h
index 24d1b44..da73026 100644
--- a/arch/x86/xen/mmu.h
+++ b/arch/x86/xen/mmu.h
@@ -11,6 +11,9 @@ enum pt_level {
 };
 
 
+bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn);
+bool install_p2mtop_page(unsigned long pfn, unsigned long *p);
+
 void set_pte_mfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags);
 
 
-- 
1.6.0.6


  parent reply	other threads:[~2009-03-13  8:13 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-13  8:11 [GIT PULL] 2.6.30 Xen core updates Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 01/24] xen: disable preempt for leave_lazy_mmu Jeremy Fitzhardinge
2009-03-13  8:11 ` Jeremy Fitzhardinge [this message]
2009-03-13  8:11 ` [PATCH 03/24] xen: dynamically allocate p2m tables Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 04/24] xen: split construction of p2m mfn tables from registration Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 05/24] xen: clean up xen_load_gdt Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 06/24] xen: make xen_load_gdt simpler Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 07/24] xen: remove xen_load_gdt debug Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 08/24] xen: reserve i386 Xen pagetables Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 09/24] NULL noise: arch/x86/xen/smp.c Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 10/24] xen: mask XSAVE from cpuid Jeremy Fitzhardinge
2009-03-13  9:50   ` [Xen-devel] " Jan Beulich
2009-03-13 15:13     ` Jeremy Fitzhardinge
2009-03-15 18:45       ` H. Peter Anvin
2009-03-15 21:03         ` Jeremy Fitzhardinge
2009-03-15 22:47           ` Arjan van de Ven
2009-03-16  0:05             ` Jeremy Fitzhardinge
2009-03-16  0:09               ` Arjan van de Ven
2009-03-16  0:57                 ` H. Peter Anvin
2009-03-16 14:16                 ` Jan Beulich
2009-03-16 14:29                   ` Arjan van de Ven
2009-03-16 23:59                   ` Andi Kleen
2009-03-17  1:33                     ` H. Peter Anvin
2009-03-17 11:56                       ` Andi Kleen
2009-03-17 15:48                         ` H. Peter Anvin
2009-03-17 15:49                         ` Arjan van de Ven
2009-03-17 15:55                           ` Andi Kleen
2009-03-17  7:53                     ` Jan Beulich
2009-03-17 10:48                       ` Andi Kleen
2009-03-17 10:55                         ` Jan Beulich
2009-03-13  8:11 ` [PATCH 11/24] xen: add FIX_TEXT_POKE to fixmap Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 12/24] x86-64: remove PGE from must-have feature list Jeremy Fitzhardinge
2009-03-15 21:18   ` H. Peter Anvin
2009-03-15 21:25     ` Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 13/24] Xen: Add virt_to_pfn helper function Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 14/24] xen: add irq_from_evtchn Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 15/24] xen: add /dev/xen/evtchn driver Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 16/24] xen: export ioctl headers to userspace Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 17/24] xen/dev-evtchn: clean up locking in evtchn Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 18/24] xen: add "capabilities" file Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 19/24] xen: add /sys/hypervisor support Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 20/24] xen/sys/hypervisor: change writable_pt to features Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 21/24] xen: drop kexec bits from /sys/hypervisor since kexec isn't implemented yet Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 22/24] xen: remove suspend_cancel hook Jeremy Fitzhardinge
2009-03-13 10:08   ` [Xen-devel] " Jan Beulich
2009-03-13 15:17     ` Jeremy Fitzhardinge
2009-03-13  8:11 ` [PATCH 23/24] xen: use device model for suspending xenbus devices Jeremy Fitzhardinge
2009-03-13 10:09   ` [Xen-devel] [PATCH 23/24] xen: use device model for suspendingxenbus devices Jan Beulich
2009-03-13  8:12 ` [PATCH 24/24] xen/xenbus: export xenbus_dev_changed 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=1236931920-6861-3-git-send-email-jeremy@goop.org \
    --to=jeremy@goop.org \
    --cc=hpa@zytor.com \
    --cc=jeremy.fitzhardinge@citrix.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®