linux/drivers/xen
Matt Wilson d0b4d64aad xen/grant-table: correctly initialize grant table version 1
Commit 85ff6acb07 (xen/granttable: Grant
tables V2 implementation) changed the GREFS_PER_GRANT_FRAME macro from
a constant to a conditional expression. The expression depends on
grant_table_version being appropriately set. Unfortunately, at init
time grant_table_version will be 0. The GREFS_PER_GRANT_FRAME
conditional expression checks for "grant_table_version == 1", and
therefore returns the number of grant references per frame for v2.

This causes gnttab_init() to allocate fewer pages for gnttab_list, as
a frame can old half the number of v2 entries than v1 entries. After
gnttab_resume() is called, grant_table_version is appropriately
set. nr_init_grefs will then be miscalculated and gnttab_free_count
will hold a value larger than the actual number of free gref entries.

If a guest is heavily utilizing improperly initialized v1 grant
tables, memory corruption can occur. One common manifestation is
corruption of the vmalloc list, resulting in a poisoned pointer
derefrence when accessing /proc/meminfo or /proc/vmallocinfo:

[   40.770064] BUG: unable to handle kernel paging request at 0000200200001407
[   40.770083] IP: [<ffffffff811a6fb0>] get_vmalloc_info+0x70/0x110
[   40.770102] PGD 0
[   40.770107] Oops: 0000 [#1] SMP
[   40.770114] CPU 10

This patch introduces a static variable, grefs_per_grant_frame, to
cache the calculated value. gnttab_init() now calls
gnttab_request_version() early so that grant_table_version and
grefs_per_grant_frame can be appropriately set. A few BUG_ON()s have
been added to prevent this type of bug from reoccurring in the future.

Signed-off-by: Matt Wilson <msw@amazon.com>
Reviewed-and-Tested-by: Steven Noonan <snoonan@amazon.com>
Acked-by: Ian Campbell <Ian.Campbell@citrix.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Annie Li <annie.li@oracle.com>
Cc: xen-devel@lists.xen.org
Cc: linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org # v3.3 and newer
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
2013-01-15 15:56:55 -05:00
..
xen-pciback x86/xen : Fix the wrong check in pciback 2013-01-15 15:56:48 -05:00
xenbus xen/xenbus: Remove duplicate inclusion of asm/xen/hypervisor.h 2012-11-28 14:39:23 -05:00
xenfs userns: Convert xenfs to use kuid and kgid where appropriate 2012-09-21 03:13:06 -07:00
acpi.c xen/acpi/sleep: Enable ACPI sleep via the __acpi_os_prepare_sleep 2012-05-07 15:33:18 -04:00
balloon.c xen: balloon: allow PVMMU interfaces to be compiled out 2012-11-29 12:59:13 +00:00
biomerge.c xen: using EXPORT_SYMBOL requires including export.h 2012-01-18 15:37:49 -08:00
cpu_hotplug.c xen/bootup: During bootup suppress XENBUS: Unable to read cpu state 2012-02-03 16:05:30 -05:00
dbgp.c xen: dbgp: Fix warning when CONFIG_PCI is not enabled. 2012-10-19 15:19:37 -04:00
events.c xen: events: pirq_check_eoi_map is X86 specific 2012-10-19 15:17:53 -04:00
evtchn.c xen/event: Add reference counting to event channels 2011-11-21 17:14:48 -05:00
features.c
gntalloc.c mm: kill vma flag VM_RESERVED and mm->reserved_vm counter 2012-10-09 16:22:19 +09:00
gntdev.c mm: kill vma flag VM_RESERVED and mm->reserved_vm counter 2012-10-09 16:22:19 +09:00
grant-table.c xen/grant-table: correctly initialize grant table version 1 2013-01-15 15:56:55 -05:00
Kconfig xen: balloon: allow PVMMU interfaces to be compiled out 2012-11-29 12:59:13 +00:00
Makefile Merge branch 'arm-privcmd-for-3.8' of git://xenbits.xen.org/people/ianc/linux into stable/for-linus-3.8 2012-11-30 17:07:59 -05:00
manage.c xen/resume: Fix compile warnings. 2012-04-19 15:12:49 -04:00
mcelog.c xen/mce: add .poll method for mcelog device driver 2012-07-19 15:51:41 -04:00
pci.c xen/pci: Check for PCI bridge before using it. 2012-05-30 10:16:35 -04:00
pcpu.c xen/pcpu: Xen physical cpus online/offline sys interface 2012-07-19 15:51:39 -04:00
platform-pci.c Revert "xen PVonHVM: move shared_info to MMIO before kexec" 2012-08-16 13:05:25 -04:00
privcmd.c xen/privcmd: Relax access control in privcmd_ioctl_mmap 2013-01-11 12:40:00 -05:00
privcmd.h xen: Add privcmd device driver 2011-12-16 13:29:31 -05:00
swiotlb-xen.c Merge branch 'stable/late-swiotlb.v3.3' into stable/for-linus-3.7 2012-09-22 20:01:24 -04:00
sys-hypervisor.c xen: sysfs: fix build warning. 2012-10-19 15:17:51 -04:00
tmem.c xen/apic/xenbus/swiotlb/pcifront/grant/tmem: Make functions or variables static. 2012-08-21 14:50:03 -04:00
xen-acpi-pad.c xen/acpi: Move the xen_running_on_version_or_later function. 2012-11-28 14:39:31 -05:00
xen-acpi-processor.c cpuidle / ACPI : remove power from acpi_processor_cx structure 2012-09-05 15:13:48 +02:00
xen-balloon.c Features: 2012-03-22 20:16:14 -07:00
xen-selfballoon.c xen: Add selfballoning memory reservation tunable. 2012-05-21 10:52:53 -04:00
xencomm.c