Skip to content

Commit 04414ba

Browse files
jgross1David Vrabel
authored andcommitted
xen: check pre-allocated page tables for conflict with memory map
Check whether the page tables built by the domain builder are at memory addresses which are in conflict with the target memory map. If this is the case just panic instead of running into problems later. Signed-off-by: Juergen Gross <jgross@suse.com> Acked-by: Konrad Rzeszutek Wilk <Konrad.wilk@oracle.com> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
1 parent 808fdb7 commit 04414ba

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎arch/x86/xen/mmu.c‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ static pud_t level3_user_vsyscall[PTRS_PER_PUD] __page_aligned_bss;
116116
DEFINE_PER_CPU(unsigned long, xen_cr3); /* cr3 stored as physaddr */
117117
DEFINE_PER_CPU(unsigned long, xen_current_cr3); /* actual vcpu cr3 */
118118

119+
static phys_addr_t xen_pt_base, xen_pt_size __initdata;
119120

120121
/*
121122
* Just beyond the highest usermode address. STACK_TOP_MAX has a
@@ -1998,7 +1999,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
19981999
check_pt_base(&pt_base, &pt_end, addr[i]);
19992000

20002001
/* Our (by three pages) smaller Xen pagetable that we are using */
2001-
memblock_reserve(PFN_PHYS(pt_base), (pt_end - pt_base) * PAGE_SIZE);
2002+
xen_pt_base = PFN_PHYS(pt_base);
2003+
xen_pt_size = (pt_end - pt_base) * PAGE_SIZE;
2004+
memblock_reserve(xen_pt_base, xen_pt_size);
20022005
/* protect xen_start_info */
20032006
memblock_reserve(__pa(xen_start_info), PAGE_SIZE);
20042007
/* Revector the xen_start_info */
@@ -2074,11 +2077,21 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
20742077
PFN_DOWN(__pa(initial_page_table)));
20752078
xen_write_cr3(__pa(initial_page_table));
20762079

2077-
memblock_reserve(__pa(xen_start_info->pt_base),
2078-
xen_start_info->nr_pt_frames * PAGE_SIZE);
2080+
xen_pt_base = __pa(xen_start_info->pt_base);
2081+
xen_pt_size = xen_start_info->nr_pt_frames * PAGE_SIZE;
2082+
2083+
memblock_reserve(xen_pt_base, xen_pt_size);
20792084
}
20802085
#endif /* CONFIG_X86_64 */
20812086

2087+
void __init xen_pt_check_e820(void)
2088+
{
2089+
if (xen_is_e820_reserved(xen_pt_base, xen_pt_size)) {
2090+
xen_raw_console_write("Xen hypervisor allocated page table memory conflicts with E820 map\n");
2091+
BUG();
2092+
}
2093+
}
2094+
20822095
static unsigned char dummy_mapping[PAGE_SIZE] __page_aligned_bss;
20832096

20842097
static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)

‎arch/x86/xen/setup.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,12 @@ char * __init xen_memory_setup(void)
802802
BUG();
803803
}
804804

805+
/*
806+
* Check for a conflict of the hypervisor supplied page tables with
807+
* the target E820 map.
808+
*/
809+
xen_pt_check_e820();
810+
805811
xen_reserve_xen_mfnlist();
806812

807813
/*

‎arch/x86/xen/xen-ops.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void xen_build_mfn_list_list(void);
3535
void xen_setup_machphys_mapping(void);
3636
void xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn);
3737
void xen_reserve_top(void);
38+
void __init xen_pt_check_e820(void);
3839

3940
void xen_mm_pin_all(void);
4041
void xen_mm_unpin_all(void);

0 commit comments

Comments
 (0)