From: Jeremy Fitzhardinge <jeremy@goop.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: LKML <linux-kernel@vger.kernel.org>,
x86@kernel.org, Stephen Tweedie <sct@redhat.com>,
Eduardo Habkost <ehabkost@redhat.com>,
Mark McLoughlin <markmc@redhat.com>,
x86@kernel.org
Subject: [PATCH 44 of 55] xen: rework pgd_walk to deal with 32/64 bit
Date: Tue, 08 Jul 2008 15:07:06 -0700 [thread overview]
Message-ID: <ff719e4b56d5027b933f.1215554826@localhost> (raw)
In-Reply-To: <patchbomb.1215554782@localhost>
Rewrite pgd_walk to deal with 64-bit address spaces. There are two
notible features of 64-bit workspaces:
1. The physical address is only 48 bits wide, with the upper 16 bits
being sign extension; kernel addresses are negative, and userspace is
positive.
2. The Xen hypervisor mapping is at the negative-most address, just above
the sign-extension hole.
1. means that we can't easily use addresses when traversing the space,
since we must deal with sign extension. This rewrite expresses
everything in terms of pgd/pud/pmd indices, which means we don't need
to worry about the exact configuration of the virtual memory space.
This approach works equally well in 32-bit.
To deal with 2, assume the hole is between the uppermost userspace
address and PAGE_OFFSET. For 64-bit this skips the Xen mapping hole.
For 32-bit, the hole is zero-sized.
In all cases, the uppermost kernel address is FIXADDR_TOP.
A side-effect of this patch is that the upper boundary is actually
handled properly, exposing a long-standing bug in 32-bit, which failed
to pin kernel pmd page. The kernel pmd is not shared, and so must be
explicitly pinned, even though the kernel ptes are shared and don't
need pinning.
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
---
arch/x86/xen/mmu.c | 117 +++++++++++++++++++++++++++++++++-------------------
1 file changed, 76 insertions(+), 41 deletions(-)
diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
--- a/arch/x86/xen/mmu.c
+++ b/arch/x86/xen/mmu.c
@@ -44,6 +44,7 @@
#include <asm/pgtable.h>
#include <asm/tlbflush.h>
+#include <asm/fixmap.h>
#include <asm/mmu_context.h>
#include <asm/paravirt.h>
#include <asm/linkage.h>
@@ -491,77 +492,103 @@
#endif /* PAGETABLE_LEVELS == 4 */
/*
- (Yet another) pagetable walker. This one is intended for pinning a
- pagetable. This means that it walks a pagetable and calls the
- callback function on each page it finds making up the page table,
- at every level. It walks the entire pagetable, but it only bothers
- pinning pte pages which are below pte_limit. In the normal case
- this will be TASK_SIZE, but at boot we need to pin up to
- FIXADDR_TOP. But the important bit is that we don't pin beyond
- there, because then we start getting into Xen's ptes.
-*/
-static int pgd_walk(pgd_t *pgd_base, int (*func)(struct page *, enum pt_level),
+ * (Yet another) pagetable walker. This one is intended for pinning a
+ * pagetable. This means that it walks a pagetable and calls the
+ * callback function on each page it finds making up the page table,
+ * at every level. It walks the entire pagetable, but it only bothers
+ * pinning pte pages which are below limit. In the normal case this
+ * will be STACK_TOP_MAX, but at boot we need to pin up to
+ * FIXADDR_TOP.
+ *
+ * For 32-bit the important bit is that we don't pin beyond there,
+ * because then we start getting into Xen's ptes.
+ *
+ * For 64-bit, we must skip the Xen hole in the middle of the address
+ * space, just after the big x86-64 virtual hole.
+ */
+static int pgd_walk(pgd_t *pgd, int (*func)(struct page *, enum pt_level),
unsigned long limit)
{
- pgd_t *pgd = pgd_base;
int flush = 0;
- unsigned long addr = 0;
- unsigned long pgd_next;
+ unsigned hole_low, hole_high;
+ unsigned pgdidx_limit, pudidx_limit, pmdidx_limit;
+ unsigned pgdidx, pudidx, pmdidx;
- BUG_ON(limit > FIXADDR_TOP);
+ /* The limit is the last byte to be touched */
+ limit--;
+ BUG_ON(limit >= FIXADDR_TOP);
if (xen_feature(XENFEAT_auto_translated_physmap))
return 0;
- for (; addr != FIXADDR_TOP; pgd++, addr = pgd_next) {
+ /*
+ * 64-bit has a great big hole in the middle of the address
+ * space, which contains the Xen mappings. On 32-bit these
+ * will end up making a zero-sized hole and so is a no-op.
+ */
+ hole_low = pgd_index(STACK_TOP_MAX + PGDIR_SIZE - 1);
+ hole_high = pgd_index(PAGE_OFFSET);
+
+ pgdidx_limit = pgd_index(limit);
+#if PTRS_PER_PUD > 1
+ pudidx_limit = pud_index(limit);
+#else
+ pudidx_limit = 0;
+#endif
+#if PTRS_PER_PMD > 1
+ pmdidx_limit = pmd_index(limit);
+#else
+ pmdidx_limit = 0;
+#endif
+
+ flush |= (*func)(virt_to_page(pgd), PT_PGD);
+
+ for (pgdidx = 0; pgdidx <= pgdidx_limit; pgdidx++) {
pud_t *pud;
- unsigned long pud_limit, pud_next;
- pgd_next = pud_limit = pgd_addr_end(addr, FIXADDR_TOP);
-
- if (!pgd_val(*pgd))
+ if (pgdidx >= hole_low && pgdidx < hole_high)
continue;
- pud = pud_offset(pgd, 0);
+ if (!pgd_val(pgd[pgdidx]))
+ continue;
+
+ pud = pud_offset(&pgd[pgdidx], 0);
if (PTRS_PER_PUD > 1) /* not folded */
flush |= (*func)(virt_to_page(pud), PT_PUD);
- for (; addr != pud_limit; pud++, addr = pud_next) {
+ for (pudidx = 0; pudidx < PTRS_PER_PUD; pudidx++) {
pmd_t *pmd;
- unsigned long pmd_limit;
- pud_next = pud_addr_end(addr, pud_limit);
+ if (pgdidx == pgdidx_limit &&
+ pudidx > pudidx_limit)
+ goto out;
- if (pud_next < limit)
- pmd_limit = pud_next;
- else
- pmd_limit = limit;
-
- if (pud_none(*pud))
+ if (pud_none(pud[pudidx]))
continue;
- pmd = pmd_offset(pud, 0);
+ pmd = pmd_offset(&pud[pudidx], 0);
if (PTRS_PER_PMD > 1) /* not folded */
flush |= (*func)(virt_to_page(pmd), PT_PMD);
- for (; addr != pmd_limit; pmd++) {
- addr += (PAGE_SIZE * PTRS_PER_PTE);
- if ((pmd_limit-1) < (addr-1)) {
- addr = pmd_limit;
- break;
- }
+ for (pmdidx = 0; pmdidx < PTRS_PER_PMD; pmdidx++) {
+ struct page *pte;
- if (pmd_none(*pmd))
+ if (pgdidx == pgdidx_limit &&
+ pudidx == pudidx_limit &&
+ pmdidx > pmdidx_limit)
+ goto out;
+
+ if (pmd_none(pmd[pmdidx]))
continue;
- flush |= (*func)(pmd_page(*pmd), PT_PTE);
+ pte = pmd_page(pmd[pmdidx]);
+ flush |= (*func)(pte, PT_PTE);
}
}
}
-
- flush |= (*func)(virt_to_page(pgd_base), PT_PGD);
+out:
return flush;
}
@@ -650,6 +677,11 @@
xen_mc_batch();
}
+#ifdef CONFIG_X86_PAE
+ /* Need to make sure unshared kernel PMD is pinnable */
+ pin_page(virt_to_page(pgd_page(pgd[pgd_index(TASK_SIZE)])), PT_PMD);
+#endif
+
xen_do_pin(MMUEXT_PIN_L3_TABLE, PFN_DOWN(__pa(pgd)));
xen_mc_issue(0);
}
@@ -731,6 +763,10 @@
xen_do_pin(MMUEXT_UNPIN_TABLE, PFN_DOWN(__pa(pgd)));
+#ifdef CONFIG_X86_PAE
+ /* Need to make sure unshared kernel PMD is unpinned */
+ pin_page(virt_to_page(pgd_page(pgd[pgd_index(TASK_SIZE)])), PT_PMD);
+#endif
pgd_walk(pgd, unpin_page, TASK_SIZE);
xen_mc_issue(0);
@@ -750,7 +786,6 @@
list_for_each_entry(page, &pgd_list, lru) {
if (PageSavePinned(page)) {
BUG_ON(!PagePinned(page));
- printk("unpinning pinned %p\n", page_address(page));
xen_pgd_unpin((pgd_t *)page_address(page));
ClearPageSavePinned(page);
}
next prev parent reply other threads:[~2008-07-08 23:27 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-08 22:06 [PATCH 00 of 55] xen64: implement 64-bit Xen support Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 01 of 55] x86/paravirt: Call paravirt_pagetable_setup_{start, done} Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 02 of 55] pvops-64: call paravirt_post_allocator_init() on setup_arch() Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 03 of 55] x86_64: there's no need to preallocate level1_fixmap_pgt Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 04 of 55] x86: clean up formatting of __switch_to Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 05 of 55] x86: use __page_aligned_data/bss Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 06 of 55] x86_64: adjust exception frame in ia32entry Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 07 of 55] x86_64: unstatic get_local_pda Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 08 of 55] xen: print backtrace on multicall failure Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 09 of 55] xen-netfront: fix xennet_release_tx_bufs() Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 10 of 55] xen: add xen_arch_resume()/xen_timer_resume hook for ia64 support Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 11 of 55] xen: define set_pte from the outset Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 12 of 55] xen64: define asm/xen/interface for 64-bit Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 13 of 55] xen: make ELF notes work for 32 and 64 bit Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 14 of 55] xen: fix 64-bit hypercall variants Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 15 of 55] xen64: fix calls into hypercall page Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 16 of 55] xen64: add extra pv_mmu_ops Jeremy Fitzhardinge
2008-07-09 7:55 ` Mark McLoughlin
2008-07-09 8:02 ` Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 17 of 55] xen64: random ifdefs to mask out 32-bit only code Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 18 of 55] xen64: get active_mm from the pda Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 19 of 55] xen: move smp setup into smp.c Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 20 of 55] x86_64: add workaround for no %gs-based percpu Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 21 of 55] xen64: smp.c compile hacking Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 22 of 55] xen64: add xen-head code to head_64.S Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 23 of 55] xen64: add asm-offsets Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 24 of 55] xen64: add 64-bit assembler Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 25 of 55] xen64: use set_fixmap for shared_info structure Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 26 of 55] xen: cpu_detect is 32-bit only Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 27 of 55] xen64: add hypervisor callbacks for events, etc Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 28 of 55] xen64: early mapping setup Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 29 of 55] xen64: 64-bit starts using set_pte from very early Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 30 of 55] xen64: map an initial chunk of physical memory Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 31 of 55] xen32: create initial mappings like 64-bit Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 32 of 55] xen: fix truncation of machine address Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 33 of 55] xen64: use arbitrary_virt_to_machine for xen_set_pmd Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 34 of 55] xen: set num_processors Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 35 of 55] xen64: defer setting pagetable alloc/release ops Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 36 of 55] xen: use set_pte_vaddr Jeremy Fitzhardinge
2008-07-08 22:06 ` [PATCH 37 of 55] xen64: xen_write_idt_entry() and cvt_gate_to_trap() Jeremy Fitzhardinge
2008-07-08 22:07 ` [PATCH 38 of 55] xen64: deal with extra words Xen pushes onto exception frames Jeremy Fitzhardinge
2008-07-08 22:07 ` [PATCH 39 of 55] xen64: add pvop for swapgs Jeremy Fitzhardinge
2008-07-08 22:07 ` [PATCH 40 of 55] xen64: register callbacks in arch-independent way Jeremy Fitzhardinge
2008-07-08 22:07 ` [PATCH 41 of 55] xen64: add identity irq->vector map Jeremy Fitzhardinge
2008-07-08 22:07 ` [PATCH 42 of 55] Xen64: HYPERVISOR_set_segment_base() implementation Jeremy Fitzhardinge
2008-07-08 22:07 ` [PATCH 43 of 55] xen64: implement xen_load_gs_index() Jeremy Fitzhardinge
2008-07-08 22:07 ` Jeremy Fitzhardinge [this message]
2008-07-08 22:07 ` [PATCH 45 of 55] xen: make sure the kernel command line is right Jeremy Fitzhardinge
2008-07-08 22:07 ` [PATCH 46 of 55] xen: enable PM_SLEEP for CONFIG_XEN Jeremy Fitzhardinge
2008-07-08 22:07 ` [PATCH 47 of 55] xen64: implement failsafe callback Jeremy Fitzhardinge
2008-07-08 22:07 ` [PATCH 48 of 55] xen64: Clear %fs on xen_load_tls() Jeremy Fitzhardinge
2008-07-08 22:07 ` [PATCH 49 of 55] xen64: implement 64-bit update_descriptor Jeremy Fitzhardinge
2008-07-08 22:07 ` [PATCH 50 of 55] xen64: save lots of registers Jeremy Fitzhardinge
2008-07-08 22:07 ` [PATCH 51 of 55] xen64: allocate and manage user pagetables Jeremy Fitzhardinge
2008-07-08 22:07 ` [PATCH 52 of 55] xen64: set up syscall and sysenter entrypoints for 64-bit Jeremy Fitzhardinge
2008-07-08 22:07 ` [PATCH 53 of 55] xen64: set up userspace syscall patch Jeremy Fitzhardinge
2008-07-08 22:07 ` [PATCH 54 of 55] xen: implement Xen write_msr operation Jeremy Fitzhardinge
2008-07-08 22:07 ` [PATCH 55 of 55] xen: update Kconfig to allow 64-bit Xen Jeremy Fitzhardinge
2008-07-09 11:12 ` [PATCH 00 of 55] xen64: implement 64-bit Xen support Ingo Molnar
2008-07-09 11:16 ` [patch] power, xen64: fix PM_SLEEP build dependencies (was: Re: [PATCH 00 of 55] xen64: implement 64-bit Xen support) Ingo Molnar
2008-07-09 19:47 ` Ingo Molnar
2008-07-09 19:52 ` Ingo Molnar
2008-07-09 19:59 ` Rafael J. Wysocki
2008-07-09 20:02 ` Rafael J. Wysocki
2008-07-09 20:04 ` Ingo Molnar
2008-07-09 20:17 ` [patch] power, xen64: fix PM_SLEEP build dependencies Jeremy Fitzhardinge
2008-07-09 20:17 ` [patch] power, xen64: fix PM_SLEEP build dependencies (was: Re: [PATCH 00 of 55] xen64: implement 64-bit Xen support) Rafael J. Wysocki
2008-07-09 20:23 ` [patch] power, xen64: fix PM_SLEEP build dependencies Jeremy Fitzhardinge
2008-07-09 20:26 ` Ingo Molnar
2008-07-09 20:33 ` Rafael J. Wysocki
2008-07-09 20:39 ` Jeremy Fitzhardinge
2008-07-09 20:42 ` Ingo Molnar
2008-07-09 20:53 ` Rafael J. Wysocki
2008-07-09 20:23 ` [patch] power, xen64: fix PM_SLEEP build dependencies (was: Re: [PATCH 00 of 55] xen64: implement 64-bit Xen support) Ingo Molnar
2008-07-09 20:40 ` [patch] power, xen64: fix PM_SLEEP build dependencies Jeremy Fitzhardinge
2008-07-09 11:21 ` [patch] xen64: fix !HVC_XEN build dependency (was: Re: [PATCH 00 of 55] xen64: implement 64-bit Xen support) Ingo Molnar
2008-07-09 16:07 ` [patch] xen64: fix !HVC_XEN build dependency Jeremy Fitzhardinge
2008-07-09 11:47 ` [patch] xen64: fix build error on 32-bit + !HIGHMEM (was: Re: [PATCH 00 of 55] xen64: implement 64-bit Xen support) Ingo Molnar
2008-07-09 16:07 ` [patch] xen64: fix build error on 32-bit + !HIGHMEM Jeremy Fitzhardinge
2008-07-09 16:12 ` [PATCH 00 of 55] xen64: implement 64-bit Xen support 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=ff719e4b56d5027b933f.1215554826@localhost \
--to=jeremy@goop.org \
--cc=ehabkost@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=markmc@redhat.com \
--cc=mingo@elte.hu \
--cc=sct@redhat.com \
--cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox