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

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