linux/arch/x86/xen
David Vrabel 0160676bba xen/p2m: check MFN is in range before using the m2p table
On hosts with more than 168 GB of memory, a 32-bit guest may attempt
to grant map an MFN that is error cannot lookup in its mapping of the
m2p table.  There is an m2p lookup as part of m2p_add_override() and
m2p_remove_override().  The lookup falls off the end of the mapped
portion of the m2p and (because the mapping is at the highest virtual
address) wraps around and the lookup causes a fault on what appears to
be a user space address.

do_page_fault() (thinking it's a fault to a userspace address), tries
to lock mm->mmap_sem.  If the gntdev device is used for the grant map,
m2p_add_override() is called from from gnttab_mmap() with mm->mmap_sem
already locked.  do_page_fault() then deadlocks.

The deadlock would most commonly occur when a 64-bit guest is started
and xenconsoled attempts to grant map its console ring.

Introduce mfn_to_pfn_no_overrides() which checks the MFN is within the
mapped portion of the m2p table before accessing the table and use
this in m2p_add_override(), m2p_remove_override(), and mfn_to_pfn()
(which already had the correct range check).

All faults caused by accessing the non-existant parts of the m2p are
thus within the kernel address space and exception_fixup() is called
without trying to lock mm->mmap_sem.

This means that for MFNs that are outside the mapped range of the m2p
then mfn_to_pfn() will always look in the m2p overrides.  This is
correct because it must be a foreign MFN (and the PFN in the m2p in
this case is only relevant for the other domain).

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@citrix.com>
Cc: Jan Beulich <JBeulich@suse.com>
--
v3: check for auto_translated_physmap in mfn_to_pfn_no_overrides()
v2: in mfn_to_pfn() look in m2p_overrides if the MFN is out of
    range as it's probably foreign.
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
2013-09-25 09:00:03 -04:00
..
apic.c
debugfs.c
debugfs.h
enlighten.c xen/spinlock: Fix locking path engaging too soon under PVHVM. 2013-09-09 12:06:16 -04:00
grant-table.c
irq.c x86/xen: disable premption when enabling local irqs 2013-08-20 10:02:03 -04:00
Kconfig
Makefile
mmu.c Merge branch 'x86-kaslr-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2013-04-30 08:37:24 -07:00
mmu.h
multicalls.c
multicalls.h
p2m.c xen/p2m: check MFN is in range before using the m2p table 2013-09-25 09:00:03 -04:00
pci-swiotlb-xen.c
platform-pci-unplug.c
setup.c Linux 3.11-rc7 2013-09-09 12:05:37 -04:00
smp.c xen/smp: Update pv_lock_ops functions before alternative code starts under PVHVM 2013-09-09 12:06:31 -04:00
smp.h xen: Clean up apic ipi interface 2013-05-29 09:04:21 -04:00
spinlock.c xen: Do not enable spinlocks before jump_label_init() has executed 2013-09-24 16:22:26 -04:00
suspend.c
time.c Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2013-07-06 14:09:38 -07:00
trace.c
vdso.h
vga.c
xen-asm_32.S
xen-asm_64.S
xen-asm.h
xen-asm.S
xen-head.S
xen-ops.h x86: delete __cpuinit usage from all x86 files 2013-07-14 19:36:56 -04:00