cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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