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

4a2fec
From 3cb35556dc7d994f203d732fe952f95fcdb03c0a Mon Sep 17 00:00:00 2001
4a2fec
From: Bandan Das <bsd@redhat.com>
4a2fec
Date: Tue, 3 Dec 2013 20:05:13 +0100
4a2fec
Subject: vfio: cap number of devices that can be assigned
4a2fec
4a2fec
RH-Author: Bandan Das <bsd@redhat.com>
4a2fec
Message-id: <1386101113-31560-3-git-send-email-bsd@redhat.com>
4a2fec
Patchwork-id: 55984
4a2fec
O-Subject: [PATCH RHEL7 qemu-kvm v2 2/2] vfio: cap number of devices that can be assigned
4a2fec
Bugzilla: 678368
4a2fec
RH-Acked-by: Alex Williamson <alex.williamson@redhat.com>
4a2fec
RH-Acked-by: Marcelo Tosatti <mtosatti@redhat.com>
4a2fec
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
4a2fec
4a2fec
Go through all groups to get count of total number of devices
4a2fec
active to enforce limit
4a2fec
4a2fec
Reasoning from Alex for the limit(32) - Assuming 3 slots per
4a2fec
device, with 125 slots (number of memory slots for RHEL 7),
4a2fec
we can support almost 40 devices and still have few slots left
4a2fec
for other uses. Stepping down a bit, the number 32 arbitrarily
4a2fec
matches the number of slots on a PCI bus and is also a nice power
4a2fec
of two.
4a2fec
4a2fec
Signed-off-by: Bandan Das <bsd@redhat.com>
4a2fec
4a2fec
Rebase notes (2.8.0):
4a2fec
- removed return value for vfio_realize (commit 1a22aca)
4a2fec
4a2fec
Merged patches (2.9.0):
4a2fec
- 17eb774 vfio: Use error_setg when reporting max assigned device overshoot
4a2fec
4a2fec
(cherry picked from commit 9fa3c9fc6dfcde76d80db1aa601b2d577f72ceec)
4a2fec
---
4a2fec
 hw/vfio/pci.c | 15 ++++++++++++++-
4a2fec
 1 file changed, 14 insertions(+), 1 deletion(-)
4a2fec
4a2fec
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
4a2fec
index 31e1edf..f3f1ce6 100644
4a2fec
--- a/hw/vfio/pci.c
4a2fec
+++ b/hw/vfio/pci.c
4a2fec
@@ -34,6 +34,7 @@
4a2fec
 #include "qapi/error.h"
4a2fec
 
4a2fec
 #define MSIX_CAP_LENGTH 12
4a2fec
+#define MAX_DEV_ASSIGN_CMDLINE 32
4a2fec
 
4a2fec
 static void vfio_disable_interrupts(VFIOPCIDevice *vdev);
4a2fec
 static void vfio_mmap_set_enabled(VFIOPCIDevice *vdev, bool enabled);
4a2fec
@@ -2639,7 +2640,19 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
4a2fec
     ssize_t len;
4a2fec
     struct stat st;
4a2fec
     int groupid;
4a2fec
-    int i, ret;
4a2fec
+    int ret, i = 0;
4a2fec
+
4a2fec
+    QLIST_FOREACH(group, &vfio_group_list, next) {
4a2fec
+        QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
4a2fec
+            i++;
4a2fec
+        }
4a2fec
+    }
4a2fec
+
4a2fec
+    if (i >= MAX_DEV_ASSIGN_CMDLINE) {
4a2fec
+        error_setg(errp, "Maximum supported vfio devices (%d) "
4a2fec
+                     "already attached", MAX_DEV_ASSIGN_CMDLINE);
4a2fec
+        return;
4a2fec
+    }
4a2fec
 
4a2fec
     if (!vdev->vbasedev.sysfsdev) {
4a2fec
         if (!(~vdev->host.domain || ~vdev->host.bus ||
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec