qemu/hw/i386
Peter Xu 36d2d52bdb intel-iommu: send PSI always even if across PDEs
SECURITY IMPLICATION: without this patch, any guest with both assigned
device and a vIOMMU might encounter stale IO page mappings even if guest
has already unmapped the page, which may lead to guest memory
corruption.  The stale mappings will only be limited to the guest's own
memory range, so it should not affect the host memory or other guests on
the host.

During IOVA page table walking, there is a special case when the PSI
covers one whole PDE (Page Directory Entry, which contains 512 Page
Table Entries) or more.  In the past, we skip that entry and we don't
notify the IOMMU notifiers.  This is not correct.  We should send UNMAP
notification to registered UNMAP notifiers in this case.

For UNMAP only notifiers, this might cause IOTLBs cached in the devices
even if they were already invalid.  For MAP/UNMAP notifiers like
vfio-pci, this will cause stale page mappings.

This special case doesn't trigger often, but it is very easy to be
triggered by nested device assignments, since in that case we'll
possibly map the whole L2 guest RAM region into the device's IOVA
address space (several GBs at least), which is far bigger than normal
kernel driver usages of the device (tens of MBs normally).

Without this patch applied to L1 QEMU, nested device assignment to L2
guests will dump some errors like:

qemu-system-x86_64: VFIO_MAP_DMA: -17
qemu-system-x86_64: vfio_dma_map(0x557305420c30, 0xad000, 0x1000,
                    0x7f89a920d000) = -17 (File exists)

CC: QEMU Stable <qemu-stable@nongnu.org>
Acked-by: Jason Wang <jasowang@redhat.com>
[peterx: rewrite the commit message]
Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2018-05-23 17:33:57 +03:00
..
kvm x86/cpu: use standard-headers/asm-x86.kvm_para.h 2018-05-23 03:14:41 +03:00
xen xen: Use newly added dmops for mapping VGA memory 2018-04-26 16:29:51 +01:00
acpi-build.c pc: rename "hotplug memory" terminology to "device memory" 2018-05-07 10:00:02 -03:00
acpi-build.h Use scripts/clean-includes to drop redundant qemu/typedefs.h 2016-03-22 22:20:16 +01:00
amd_iommu.c x86_iommu: Move machine check to x86_iommu_realize() 2018-01-18 21:52:38 +02:00
amd_iommu.h amd_iommu: avoid needless includes in header file 2017-12-18 17:07:02 +03:00
intel_iommu.c intel-iommu: send PSI always even if across PDEs 2018-05-23 17:33:57 +03:00
intel_iommu_internal.h intel-iommu: Extend address width to 48 bits 2018-01-18 21:52:38 +02:00
kvmvapic.c mttcg/i386: Patch instruction using async_safe_* framework 2017-07-14 12:04:35 +02:00
Makefile.objs hw/i386: make IOMMUs configurable via default-configs/ 2018-03-12 16:12:46 +01:00
multiboot.c opts: don't silently truncate long option values 2018-05-09 00:13:39 +02:00
multiboot.h refer to FWCfgState explicitly 2013-06-02 18:14:02 +03:00
pc.c make sure that we aren't overwriting mc->get_hotplug_handler by accident 2018-05-10 18:10:56 +01:00
pc_piix.c pc: add 2.13 machine types 2018-05-15 11:33:33 -03:00
pc_q35.c pc: add 2.13 machine types 2018-05-15 11:33:33 -03:00
pc_sysfw.c target/i386: encrypt bios rom 2018-03-13 17:36:05 +01:00
trace-events hw/i386/vmport: replace fprintf() by trace events or LOG_UNIMP 2017-12-21 09:30:32 +01:00
vmmouse.c hw/input/i8042: Extract declarations from i386/pc.h into input/i8042.h 2018-03-12 16:12:48 +01:00
vmport.c hw/input/i8042: Extract declarations from i386/pc.h into input/i8042.h 2018-03-12 16:12:48 +01:00
x86-iommu.c x86_iommu: check if machine has PCI bus 2018-01-18 21:52:38 +02:00