linux/arch/x86/xen
Stefano Stabellini 279b706bf8 x86,xen: introduce x86_init.mapping.pagetable_reserve
Introduce a new x86_init hook called pagetable_reserve that at the end
of init_memory_mapping is used to reserve a range of memory addresses for
the kernel pagetable pages we used and free the other ones.

On native it just calls memblock_x86_reserve_range while on xen it also
takes care of setting the spare memory previously allocated
for kernel pagetable pages from RO to RW, so that it can be used for
other purposes.

A detailed explanation of the reason why this hook is needed follows.

As a consequence of the commit:

commit 4b239f458c
Author: Yinghai Lu <yinghai@kernel.org>
Date:   Fri Dec 17 16:58:28 2010 -0800

    x86-64, mm: Put early page table high

at some point init_memory_mapping is going to reach the pagetable pages
area and map those pages too (mapping them as normal memory that falls
in the range of addresses passed to init_memory_mapping as argument).
Some of those pages are already pagetable pages (they are in the range
pgt_buf_start-pgt_buf_end) therefore they are going to be mapped RO and
everything is fine.
Some of these pages are not pagetable pages yet (they fall in the range
pgt_buf_end-pgt_buf_top; for example the page at pgt_buf_end) so they
are going to be mapped RW.  When these pages become pagetable pages and
are hooked into the pagetable, xen will find that the guest has already
a RW mapping of them somewhere and fail the operation.
The reason Xen requires pagetables to be RO is that the hypervisor needs
to verify that the pagetables are valid before using them. The validation
operations are called "pinning" (more details in arch/x86/xen/mmu.c).

In order to fix the issue we mark all the pages in the entire range
pgt_buf_start-pgt_buf_top as RO, however when the pagetable allocation
is completed only the range pgt_buf_start-pgt_buf_end is reserved by
init_memory_mapping. Hence the kernel is going to crash as soon as one
of the pages in the range pgt_buf_end-pgt_buf_top is reused (b/c those
ranges are RO).

For this reason we need a hook to reserve the kernel pagetable pages we
used and free the other ones so that they can be reused for other
purposes.
On native it just means calling memblock_x86_reserve_range, on Xen it
also means marking RW the pagetable pages that we allocated before but
that haven't been used before.

Another way to fix this is without using the hook is by adding a 'if
(xen_pv_domain)' in the 'init_memory_mapping' code and calling the Xen
counterpart, but that is just nasty.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Acked-by: H. Peter Anvin <hpa@zytor.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
2011-05-12 13:05:04 -04:00
..
Kconfig fix XEN_SAVE_RESTORE Kconfig dependencies 2011-04-11 22:54:48 +02:00
Makefile xen: move p2m handling to separate file 2011-01-11 14:31:07 -05:00
debugfs.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
debugfs.h
enlighten.c xen: Allow PV-OPS kernel to detect whether XSAVE is supported 2011-04-06 08:31:13 -04:00
grant-table.c
irq.c xen: fix non-ANSI function warning in irq.c 2011-01-20 14:52:13 -05:00
mmu.c x86,xen: introduce x86_init.mapping.pagetable_reserve 2011-05-12 13:05:04 -04:00
mmu.h xen: make install_p2mtop_page() static 2010-10-22 12:57:23 -07:00
multicalls.c
multicalls.h xen: Use this_cpu_ops 2010-12-17 15:07:19 +01:00
p2m.c xen: fix p2m section mismatches 2011-03-29 10:01:03 -04:00
pci-swiotlb-xen.c Merge branch 'stable/xen-pcifront-0.8.2' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen 2010-10-28 17:11:17 -07:00
platform-pci-unplug.c xen: unplug the emulated devices at resume time 2010-12-02 14:40:53 +00:00
setup.c xen: do not create the extra e820 region at an addr lower than 4G 2011-04-20 09:04:40 -04:00
smp.c xen: PV on HVM: support PV spinlocks and IPIs 2011-02-25 16:43:06 +00:00
spinlock.c xen: Use this_cpu_ops 2010-12-17 15:07:19 +01:00
suspend.c xen: suspend: add "arch" to pre/post suspend hooks 2011-02-25 16:43:12 +00:00
time.c xen/timer: Missing IRQF_NO_SUSPEND in timer code broke suspend. 2011-03-03 12:00:31 -05:00
vdso.h
xen-asm.S
xen-asm.h
xen-asm_32.S percpu: remove per_cpu__ prefix. 2009-10-29 22:34:15 +09:00
xen-asm_64.S xen: use iret for return from 64b kernel to 32b usermode 2009-12-03 11:14:54 -08:00
xen-head.S x86, asm: Cleanup unnecssary macros in asm-offsets.c 2011-02-25 16:37:32 -08:00
xen-ops.h xen: PV on HVM: support PV spinlocks and IPIs 2011-02-25 16:43:06 +00:00