qemu-patch-raspberry4/hw/vfio
Alex Williamson 567d7d3e6b vfio/common: Work around kernel overflow bug in DMA unmap
A kernel bug was introduced in v4.15 via commit 71a7d3d78e3c which
adds a test for address space wrap-around in the vfio DMA unmap path.
Unfortunately due to overflow, the kernel detects an unmap of the last
page in the 64-bit address space as a wrap-around.  In QEMU, a Q35
guest with VT-d emulation and guest IOMMU enabled will attempt to make
such an unmap request during VM system reset, triggering an error:

  qemu-kvm: VFIO_UNMAP_DMA: -22
  qemu-kvm: vfio_dma_unmap(0x561f059948f0, 0xfef00000, 0xffffffff01100000) = -22 (Invalid argument)

Here the IOVA start address (0xfef00000) and the size parameter
(0xffffffff01100000) add to exactly 2^64, triggering the bug.  A
kernel fix is queued for the Linux v5.0 release to address this.

This patch implements a workaround to retry the unmap, excluding the
final page of the range when we detect an unmap failing which matches
the requirements for this issue.  This is expected to be a safe and
complete workaround as the VT-d address space does not extend to the
full 64-bit space and therefore the last page should never be mapped.

This workaround can be removed once all kernels with this bug are
sufficiently deprecated.

Link: https://bugzilla.redhat.com/show_bug.cgi?id=1662291
Reported-by: Pei Zhang <pezhang@redhat.com>
Debugged-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2019-02-21 21:07:03 -07:00
..
amd-xgbe.c vfio/platform: Make the vfio-platform device non-abstract 2018-10-15 10:52:09 -06:00
ap.c Clean up includes 2018-12-20 10:29:08 +01:00
calxeda-xgmac.c vfio/platform: Make the vfio-platform device non-abstract 2018-10-15 10:52:09 -06:00
ccw.c qemu-error: add {error, warn}_report_once_cond 2018-09-24 17:13:07 +02:00
common.c vfio/common: Work around kernel overflow bug in DMA unmap 2019-02-21 21:07:03 -07:00
display.c hw/vfio/display: add ramfb support 2018-10-15 10:52:09 -06:00
Makefile.objs hw/vfio/Makefile.objs: Create new CONFIG_* variables for VFIO core and PCI 2019-02-05 16:50:21 +01:00
pci-quirks.c vfio: Clean up error reporting after previous commit 2018-10-19 14:51:34 +02:00
pci.c trace: forbid use of %m in trace event format strings 2019-01-24 14:16:56 +00:00
pci.h hw/vfio/display: add ramfb support 2018-10-15 10:52:09 -06:00
platform.c vfio: Clean up error reporting after previous commit 2018-10-19 14:51:34 +02:00
spapr.c vfio/spapr: Allow backing bigger guest IOMMU pages with smaller physical pages 2018-08-21 14:28:45 +10:00
trace-events vfio/common: Work around kernel overflow bug in DMA unmap 2019-02-21 21:07:03 -07:00