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

26ba25
From caa475eb19e0e235920f15828c6879c4b64499a2 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
26ba25
(cherry picked from commit 9fa3c9fc6dfcde76d80db1aa601b2d577f72ceec)
26ba25
(cherry picked from commit 3cb35556dc7d994f203d732fe952f95fcdb03c0a)
26ba25
---
26ba25
 hw/vfio/pci.c | 15 ++++++++++++++-
26ba25
 1 file changed, 14 insertions(+), 1 deletion(-)
26ba25
26ba25
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
26ba25
index b9bc6cd..34b9d19 100644
26ba25
--- a/hw/vfio/pci.c
26ba25
+++ b/hw/vfio/pci.c
26ba25
@@ -35,6 +35,7 @@
26ba25
 #include "qapi/error.h"
26ba25
 
26ba25
 #define MSIX_CAP_LENGTH 12
26ba25
+#define MAX_DEV_ASSIGN_CMDLINE 32
26ba25
 
26ba25
 static void vfio_disable_interrupts(VFIOPCIDevice *vdev);
26ba25
 static void vfio_mmap_set_enabled(VFIOPCIDevice *vdev, bool enabled);
26ba25
@@ -2807,7 +2808,19 @@ 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;
26ba25
+
26ba25
+    QLIST_FOREACH(group, &vfio_group_list, next) {
26ba25
+        QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
26ba25
+            i++;
26ba25
+        }
26ba25
+    }
26ba25
+
26ba25
+    if (i >= MAX_DEV_ASSIGN_CMDLINE) {
26ba25
+        error_setg(errp, "Maximum supported vfio devices (%d) "
26ba25
+                     "already attached", MAX_DEV_ASSIGN_CMDLINE);
26ba25
+        return;
26ba25
+    }
26ba25
 
26ba25
     if (!vdev->vbasedev.sysfsdev) {
26ba25
         if (!(~vdev->host.domain || ~vdev->host.bus ||
26ba25
-- 
26ba25
1.8.3.1
26ba25