From d700e88c39022f01065d704eca25a44183fc5807 Mon Sep 17 00:00:00 2001 From: Konrad Rzeszutek Wilk Date: Thu, 26 Jul 2012 12:00:56 -0400 Subject: [PATCH] xen/mmu: Recycle the Xen provided L4, L3, and L2 pages As we are not using them. We end up only using the L1 pagetables and grafting those to our page-tables. [v1: Per Stefano's suggestion squashed two commits] [v2: Per Stefano's suggestion simplified loop] [v3: Fix smatch warnings] [v4: Add more comments] Acked-by: Stefano Stabellini Signed-off-by: Konrad Rzeszutek Wilk (cherry picked from commit 488f046df922af992c1a718eff276529c0510885) Conflicts: arch/x86/xen/mmu.c --- arch/x86/xen/mmu.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c index af2c7e6258fc..4da2c850c649 100644 --- a/arch/x86/xen/mmu.c +++ b/arch/x86/xen/mmu.c @@ -1811,18 +1811,18 @@ static void convert_pfn_mfn(void *v) for (i = 0; i < PTRS_PER_PTE; i++) pte[i] = xen_make_pte(pte[i].pte); } -static __init check_pt_base(unsigned long *pt_base, unsigned long *pt_end, - unsigned long addr) +static void __init check_pt_base(unsigned long *pt_base, unsigned long *pt_end, + unsigned long addr) { - if (pt_base == PFN_DOWN(__pa(addr))) { + if (*pt_base == PFN_DOWN(__pa(addr))) { set_page_prot((void *)addr, PAGE_KERNEL); clear_page((void *)addr); - *pt_base++; + (*pt_base)++; } - if (pt_end == PFN_DOWN(__pa(addr))) { + if (*pt_end == PFN_DOWN(__pa(addr))) { set_page_prot((void *)addr, PAGE_KERNEL); clear_page((void *)addr); - *pt_end--; + (*pt_end)--; } } /* @@ -1851,7 +1851,7 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn) max_pfn_mapped = PFN_DOWN(__pa(xen_start_info->mfn_list)); pt_base = PFN_DOWN(__pa(xen_start_info->pt_base)); - pt_end = PFN_DOWN(__pa(xen_start_info->pt_base + (xen_start_info->nr_pt_frames * PAGE_SIZE))); + pt_end = pt_base + xen_start_info->nr_pt_frames; /* Zap identity mapping */ init_level4_pgt[0] = __pgd(0); @@ -1919,7 +1919,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn) /* We can't that easily rip out L3 and L2, as the Xen pagetables are * set out this way: [L4], [L1], [L2], [L3], [L1], [L1] ... for * the initial domain. For guests using the toolstack, they are in: - * [L4], [L3], [L2], [L1], [L1], order .. */ + * [L4], [L3], [L2], [L1], [L1], order .. So for dom0 we can only + * rip out the [L4] (pgd), but for guests we shave off three pages. + */ for (i = 0; i < ARRAY_SIZE(addr); i++) check_pt_base(&pt_base, &pt_end, addr[i]); -- 2.50.1