mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 16:53:55 -06:00
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>
This commit is contained in:
parent
c65ee43315
commit
238e917285
5 changed files with 59 additions and 2 deletions
|
@ -2804,12 +2804,13 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
|
|||
VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
|
||||
VFIODevice *vbasedev_iter;
|
||||
VFIOGroup *group;
|
||||
char *tmp, group_path[PATH_MAX], *group_name;
|
||||
char *tmp, *subsys, group_path[PATH_MAX], *group_name;
|
||||
Error *err = NULL;
|
||||
ssize_t len;
|
||||
struct stat st;
|
||||
int groupid;
|
||||
int i, ret;
|
||||
bool is_mdev;
|
||||
|
||||
if (!vdev->vbasedev.sysfsdev) {
|
||||
if (!(~vdev->host.domain || ~vdev->host.bus ||
|
||||
|
@ -2869,6 +2870,27 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Mediated devices *might* operate compatibly with memory ballooning, but
|
||||
* we cannot know for certain, it depends on whether the mdev vendor driver
|
||||
* stays in sync with the active working set of the guest driver. Prevent
|
||||
* the x-balloon-allowed option unless this is minimally an mdev device.
|
||||
*/
|
||||
tmp = g_strdup_printf("%s/subsystem", vdev->vbasedev.sysfsdev);
|
||||
subsys = realpath(tmp, NULL);
|
||||
g_free(tmp);
|
||||
is_mdev = (strcmp(subsys, "/sys/bus/mdev") == 0);
|
||||
free(subsys);
|
||||
|
||||
trace_vfio_mdev(vdev->vbasedev.name, is_mdev);
|
||||
|
||||
if (vdev->vbasedev.balloon_allowed && !is_mdev) {
|
||||
error_setg(errp, "x-balloon-allowed only potentially compatible "
|
||||
"with mdev devices");
|
||||
vfio_put_group(group);
|
||||
goto error;
|
||||
}
|
||||
|
||||
ret = vfio_get_device(group, vdev->vbasedev.name, &vdev->vbasedev, errp);
|
||||
if (ret) {
|
||||
vfio_put_group(group);
|
||||
|
@ -3170,6 +3192,8 @@ static Property vfio_pci_dev_properties[] = {
|
|||
DEFINE_PROP_BIT("x-igd-opregion", VFIOPCIDevice, features,
|
||||
VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT, false),
|
||||
DEFINE_PROP_BOOL("x-no-mmap", VFIOPCIDevice, vbasedev.no_mmap, false),
|
||||
DEFINE_PROP_BOOL("x-balloon-allowed", VFIOPCIDevice,
|
||||
vbasedev.balloon_allowed, false),
|
||||
DEFINE_PROP_BOOL("x-no-kvm-intx", VFIOPCIDevice, no_kvm_intx, false),
|
||||
DEFINE_PROP_BOOL("x-no-kvm-msi", VFIOPCIDevice, no_kvm_msi, false),
|
||||
DEFINE_PROP_BOOL("x-no-kvm-msix", VFIOPCIDevice, no_kvm_msix, false),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue