On Mon, 30 Jul 2018 17:14:37 -0600 Alex Williamson <alex.williamson@xxxxxxxxxx> wrote: > 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. I agree, that should be the case. For the upcoming vfio-ap devices? I'm not sure how much control there is over the pages that are used. > > 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@xxxxxxxxxx> > --- > hw/vfio/ccw.c | 9 +++++++++ > hw/vfio/common.c | 23 ++++++++++++++++++++++- > hw/vfio/pci.c | 26 +++++++++++++++++++++++++- > hw/vfio/trace-events | 1 + > include/hw/vfio/vfio-common.h | 2 ++ > 5 files changed, 59 insertions(+), 2 deletions(-) > > diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c > index 351b305e1ae7..40e7b5623e69 100644 > --- a/hw/vfio/ccw.c > +++ b/hw/vfio/ccw.c > @@ -349,6 +349,15 @@ static void vfio_ccw_get_device(VFIOGroup *group, VFIOCCWDevice *vcdev, > } > } > > + /* > + * All vfio-ccw devices are believed to operate compatibly with memory Better "to operate in a way compatible with memory ballooning"? > + * ballooning, ie. pages pinned in the host are in the current working > + * set of the guest driver and therefore never overlap with pages > + * available to the guest balloon driver. This needs to be set before > + * vfio_get_device() for vfio common to handle the balloon inhibitor. > + */ > + vcdev->vdev.balloon_allowed = true; > + > if (vfio_get_device(group, vcdev->cdev.mdevid, &vcdev->vdev, errp)) { > goto out_err; > }