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

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