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

357786
From dcf1c9f485cefd4dad8040efb9555f33a118074b 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)
357786
(cherry picked from commit 3cb35556dc7d994f203d732fe952f95fcdb03c0a)
357786
(cherry picked from commit 17e46c50515e8935c0f99a868fe07bd3c92a4586)
357786
(cherry picked from commit 726bd82965a9e1a58065a3226597b3c2bafdbf68)
357786
(cherry picked from commit efd8c5d78242c2e0892e165b75d2c8f1afb172a6)
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
357786
index b9bc6cd..34b9d19 100644
9bac43
--- a/hw/vfio/pci.c
9bac43
+++ b/hw/vfio/pci.c
357786
@@ -35,6 +35,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);
357786
@@ -2807,7 +2808,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