Blame SOURCES/0013-vfio-cap-number-of-devices-that-can-be-assigned.patch

60061b
From e9ebc159a9acf108e1ec6f622be3f256cf14aba7 Mon Sep 17 00:00:00 2001
26ba25
From: Bandan Das <bsd@redhat.com>
26ba25
Date: Tue, 3 Dec 2013 20:05:13 +0100
26ba25
Subject: vfio: cap number of devices that can be assigned
26ba25
26ba25
RH-Author: Bandan Das <bsd@redhat.com>
26ba25
Message-id: <1386101113-31560-3-git-send-email-bsd@redhat.com>
26ba25
Patchwork-id: 55984
26ba25
O-Subject: [PATCH RHEL7 qemu-kvm v2 2/2] vfio: cap number of devices that can be assigned
26ba25
Bugzilla: 678368
26ba25
RH-Acked-by: Alex Williamson <alex.williamson@redhat.com>
26ba25
RH-Acked-by: Marcelo Tosatti <mtosatti@redhat.com>
26ba25
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
26ba25
26ba25
Go through all groups to get count of total number of devices
26ba25
active to enforce limit
26ba25
26ba25
Reasoning from Alex for the limit(32) - Assuming 3 slots per
26ba25
device, with 125 slots (number of memory slots for RHEL 7),
26ba25
we can support almost 40 devices and still have few slots left
26ba25
for other uses. Stepping down a bit, the number 32 arbitrarily
26ba25
matches the number of slots on a PCI bus and is also a nice power
26ba25
of two.
26ba25
26ba25
Signed-off-by: Bandan Das <bsd@redhat.com>
26ba25
26ba25
Rebase notes (2.8.0):
26ba25
- removed return value for vfio_realize (commit 1a22aca)
26ba25
26ba25
Merged patches (2.9.0):
26ba25
- 17eb774 vfio: Use error_setg when reporting max assigned device overshoot
26ba25
902636
 Merged patches (4.1.0-rc3):
902636
- 2b89558 vfio: increase the cap on number of assigned devices to 64
26ba25
---
902636
 hw/vfio/pci.c | 29 ++++++++++++++++++++++++++++-
902636
 hw/vfio/pci.h |  1 +
902636
 2 files changed, 29 insertions(+), 1 deletion(-)
26ba25
26ba25
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
60061b
index 7b45353ce2..eb725a3aee 100644
26ba25
--- a/hw/vfio/pci.c
26ba25
+++ b/hw/vfio/pci.c
60061b
@@ -45,6 +45,9 @@
26ba25
 
902636
 #define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug"
26ba25
 
902636
+/* RHEL only: Set once for the first assigned dev */
902636
+static uint16_t device_limit;
902636
+
26ba25
 static void vfio_disable_interrupts(VFIOPCIDevice *vdev);
26ba25
 static void vfio_mmap_set_enabled(VFIOPCIDevice *vdev, bool enabled);
902636
 
60061b
@@ -2807,9 +2810,30 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
26ba25
     ssize_t len;
26ba25
     struct stat st;
26ba25
     int groupid;
26ba25
-    int i, ret;
26ba25
+    int ret, i = 0;
902636
     bool is_mdev;
902636
 
902636
+    if (device_limit && device_limit != vdev->assigned_device_limit) {
902636
+            error_setg(errp, "Assigned device limit has been redefined. "
902636
+                       "Old:%d, New:%d",
902636
+                       device_limit, vdev->assigned_device_limit);
902636
+            return;
902636
+    } else {
902636
+        device_limit = vdev->assigned_device_limit;
902636
+    }
26ba25
+
26ba25
+    QLIST_FOREACH(group, &vfio_group_list, next) {
26ba25
+        QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
26ba25
+            i++;
26ba25
+        }
26ba25
+    }
26ba25
+
902636
+    if (i >= vdev->assigned_device_limit) {
26ba25
+        error_setg(errp, "Maximum supported vfio devices (%d) "
902636
+                     "already attached", vdev->assigned_device_limit);
26ba25
+        return;
26ba25
+    }
902636
+
26ba25
     if (!vdev->vbasedev.sysfsdev) {
26ba25
         if (!(~vdev->host.domain || ~vdev->host.bus ||
902636
               ~vdev->host.slot || ~vdev->host.function)) {
60061b
@@ -3246,6 +3270,9 @@ static Property vfio_pci_dev_properties[] = {
902636
     DEFINE_PROP_BOOL("x-no-kvm-msix", VFIOPCIDevice, no_kvm_msix, false),
902636
     DEFINE_PROP_BOOL("x-no-geforce-quirks", VFIOPCIDevice,
902636
                      no_geforce_quirks, false),
902636
+    /* RHEL only */
902636
+    DEFINE_PROP_UINT16("x-assigned-device-limit", VFIOPCIDevice,
902636
+                       assigned_device_limit, 64),
902636
     DEFINE_PROP_BOOL("x-no-kvm-ioeventfd", VFIOPCIDevice, no_kvm_ioeventfd,
902636
                      false),
902636
     DEFINE_PROP_BOOL("x-no-vfio-ioeventfd", VFIOPCIDevice, no_vfio_ioeventfd,
902636
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
60061b
index 64777516d1..e0fe6ca97e 100644
902636
--- a/hw/vfio/pci.h
902636
+++ b/hw/vfio/pci.h
60061b
@@ -139,6 +139,7 @@ struct VFIOPCIDevice {
902636
     EventNotifier err_notifier;
902636
     EventNotifier req_notifier;
902636
     int (*resetfn)(struct VFIOPCIDevice *);
902636
+    uint16_t assigned_device_limit;
902636
     uint32_t vendor_id;
902636
     uint32_t device_id;
902636
     uint32_t sub_vendor_id;
26ba25
-- 
60061b
2.27.0
26ba25