vfio/ccw/pci: Allow devices to opt-in for ballooning
commit238e91728503d400e1c4e644e3a9b80f9e621682
authorAlex Williamson <alex.williamson@redhat.com>
Fri, 17 Aug 2018 15:27:16 +0000 (17 09:27 -0600)
committerAlex Williamson <alex.williamson@redhat.com>
Fri, 17 Aug 2018 15:27:16 +0000 (17 09:27 -0600)
treeab1e426f7787fc7ea16e1556c737d27a01afac6f
parentc65ee433153b5925e183a00ebf568e160077c694
vfio/ccw/pci: Allow devices to opt-in for ballooning

If a vfio assigned device makes use of a physical IOMMU, then memory
ballooning is necessarily inhibited due to the page pinning, lack of
page level granularity at the IOMMU, and sufficient notifiers to both
remove the page on balloon inflation and add it back on deflation.
However, not all devices are backed by a physical IOMMU.  In the case
of mediated devices, if a vendor driver is well synchronized with the
guest driver, such that only pages actively used by the guest driver
are pinned by the host mdev vendor driver, then there should be no
overlap between pages available for the balloon driver and pages
actively in use by the device.  Under these conditions, ballooning
should be safe.

vfio-ccw devices are always mediated devices and always operate under
the constraints above.  Therefore we can consider all vfio-ccw devices
as balloon compatible.

The situation is far from straightforward with vfio-pci.  These
devices can be physical devices with physical IOMMU backing or
mediated devices where it is unknown whether a physical IOMMU is in
use or whether the vendor driver is well synchronized to the working
set of the guest driver.  The safest approach is therefore to assume
all vfio-pci devices are incompatible with ballooning, but allow user
opt-in should they have further insight into mediated devices.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
hw/vfio/ccw.c
hw/vfio/common.c
hw/vfio/pci.c
hw/vfio/trace-events
include/hw/vfio/vfio-common.h