cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

9ae3a8
From 4110ee428550f672ee1a1a73a634d5392bf9c55f Mon Sep 17 00:00:00 2001
9ae3a8
Message-Id: <4110ee428550f672ee1a1a73a634d5392bf9c55f.1387382496.git.minovotn@redhat.com>
9ae3a8
In-Reply-To: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
9ae3a8
References: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
9ae3a8
From: Bandan Das <bsd@redhat.com>
9ae3a8
Date: Tue, 3 Dec 2013 20:05:13 +0100
9ae3a8
Subject: [PATCH 44/46] vfio: cap number of devices that can be assigned
9ae3a8
9ae3a8
RH-Author: Bandan Das <bsd@redhat.com>
9ae3a8
Message-id: <1386101113-31560-3-git-send-email-bsd@redhat.com>
9ae3a8
Patchwork-id: 55984
9ae3a8
O-Subject: [PATCH RHEL7 qemu-kvm v2 2/2] vfio: cap number of devices that can be assigned
9ae3a8
Bugzilla: 678368
9ae3a8
RH-Acked-by: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
RH-Acked-by: Marcelo Tosatti <mtosatti@redhat.com>
9ae3a8
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
9ae3a8
Go through all groups to get count of total number of devices
9ae3a8
active to enforce limit
9ae3a8
9ae3a8
Reasoning from Alex for the limit(32) - Assuming 3 slots per
9ae3a8
device, with 125 slots (number of memory slots for RHEL 7),
9ae3a8
we can support almost 40 devices and still have few slots left
9ae3a8
for other uses. Stepping down a bit, the number 32 arbitrarily
9ae3a8
matches the number of slots on a PCI bus and is also a nice power
9ae3a8
of two.
9ae3a8
9ae3a8
Signed-off-by: Bandan Das <bsd@redhat.com>
9ae3a8
---
9ae3a8
 hw/misc/vfio.c | 15 ++++++++++++++-
9ae3a8
 1 file changed, 14 insertions(+), 1 deletion(-)
9ae3a8
9ae3a8
Signed-off-by: Michal Novotny <minovotn@redhat.com>
9ae3a8
---
9ae3a8
 hw/misc/vfio.c | 15 ++++++++++++++-
9ae3a8
 1 file changed, 14 insertions(+), 1 deletion(-)
9ae3a8
9ae3a8
diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
9ae3a8
index 250f96f..bd30130 100644
9ae3a8
--- a/hw/misc/vfio.c
9ae3a8
+++ b/hw/misc/vfio.c
9ae3a8
@@ -201,6 +201,7 @@ typedef struct VFIOGroup {
9ae3a8
 } VFIOGroup;
9ae3a8
 
9ae3a8
 #define MSIX_CAP_LENGTH 12
9ae3a8
+#define MAX_DEV_ASSIGN_CMDLINE 32
9ae3a8
 
9ae3a8
 static QLIST_HEAD(, VFIOContainer)
9ae3a8
     container_list = QLIST_HEAD_INITIALIZER(container_list);
9ae3a8
@@ -3557,7 +3558,19 @@ static int vfio_initfn(PCIDevice *pdev)
9ae3a8
     ssize_t len;
9ae3a8
     struct stat st;
9ae3a8
     int groupid;
9ae3a8
-    int ret;
9ae3a8
+    int ret, i = 0;
9ae3a8
+
9ae3a8
+    QLIST_FOREACH(group, &group_list, next) {
9ae3a8
+        QLIST_FOREACH(pvdev, &group->device_list, next) {
9ae3a8
+            i++;
9ae3a8
+        }
9ae3a8
+    }
9ae3a8
+
9ae3a8
+    if (i >= MAX_DEV_ASSIGN_CMDLINE) {
9ae3a8
+        error_report("vfio: Maximum supported vfio devices (%d) "
9ae3a8
+                     "already attached\n", MAX_DEV_ASSIGN_CMDLINE);
9ae3a8
+        return -1;
9ae3a8
+    }
9ae3a8
 
9ae3a8
     /* Check that the host device exists */
9ae3a8
     snprintf(path, sizeof(path),
9ae3a8
-- 
9ae3a8
1.7.11.7
9ae3a8