thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

22c213
From de433da59448eaad4ac1b902d07d57b57f922aff Mon Sep 17 00:00:00 2001
22c213
From: Bandan Das <bsd@redhat.com>
22c213
Date: Tue, 3 Dec 2013 20:05:13 +0100
22c213
Subject: vfio: cap number of devices that can be assigned
22c213
22c213
RH-Author: Bandan Das <bsd@redhat.com>
22c213
Message-id: <1386101113-31560-3-git-send-email-bsd@redhat.com>
22c213
Patchwork-id: 55984
22c213
O-Subject: [PATCH RHEL7 qemu-kvm v2 2/2] vfio: cap number of devices that can be assigned
22c213
Bugzilla: 678368
22c213
RH-Acked-by: Alex Williamson <alex.williamson@redhat.com>
22c213
RH-Acked-by: Marcelo Tosatti <mtosatti@redhat.com>
22c213
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
22c213
22c213
Go through all groups to get count of total number of devices
22c213
active to enforce limit
22c213
22c213
Reasoning from Alex for the limit(32) - Assuming 3 slots per
22c213
device, with 125 slots (number of memory slots for RHEL 7),
22c213
we can support almost 40 devices and still have few slots left
22c213
for other uses. Stepping down a bit, the number 32 arbitrarily
22c213
matches the number of slots on a PCI bus and is also a nice power
22c213
of two.
22c213
22c213
Signed-off-by: Bandan Das <bsd@redhat.com>
22c213
22c213
Rebase notes (2.8.0):
22c213
- removed return value for vfio_realize (commit 1a22aca)
22c213
22c213
Merged patches (2.9.0):
22c213
- 17eb774 vfio: Use error_setg when reporting max assigned device overshoot
22c213
22c213
 Merged patches (4.1.0-rc3):
22c213
- 2b89558 vfio: increase the cap on number of assigned devices to 64
22c213
22c213
(cherry picked from commit 9fa3c9fc6dfcde76d80db1aa601b2d577f72ceec)
22c213
(cherry picked from commit 3cb35556dc7d994f203d732fe952f95fcdb03c0a)
22c213
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
22c213
---
22c213
 hw/vfio/pci.c | 29 ++++++++++++++++++++++++++++-
22c213
 hw/vfio/pci.h |  1 +
22c213
 2 files changed, 29 insertions(+), 1 deletion(-)
22c213
22c213
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
22c213
index c8534d3035..309535f306 100644
22c213
--- a/hw/vfio/pci.c
22c213
+++ b/hw/vfio/pci.c
22c213
@@ -47,6 +47,9 @@
22c213
 
22c213
 #define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug"
22c213
 
22c213
+/* RHEL only: Set once for the first assigned dev */
22c213
+static uint16_t device_limit;
22c213
+
22c213
 static void vfio_disable_interrupts(VFIOPCIDevice *vdev);
22c213
 static void vfio_mmap_set_enabled(VFIOPCIDevice *vdev, bool enabled);
22c213
 
22c213
@@ -2722,9 +2725,30 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
22c213
     ssize_t len;
22c213
     struct stat st;
22c213
     int groupid;
22c213
-    int i, ret;
22c213
+    int ret, i = 0;
22c213
     bool is_mdev;
22c213
 
22c213
+    if (device_limit && device_limit != vdev->assigned_device_limit) {
22c213
+            error_setg(errp, "Assigned device limit has been redefined. "
22c213
+                       "Old:%d, New:%d",
22c213
+                       device_limit, vdev->assigned_device_limit);
22c213
+            return;
22c213
+    } else {
22c213
+        device_limit = vdev->assigned_device_limit;
22c213
+    }
22c213
+
22c213
+    QLIST_FOREACH(group, &vfio_group_list, next) {
22c213
+        QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
22c213
+            i++;
22c213
+        }
22c213
+    }
22c213
+
22c213
+    if (i >= vdev->assigned_device_limit) {
22c213
+        error_setg(errp, "Maximum supported vfio devices (%d) "
22c213
+                     "already attached", vdev->assigned_device_limit);
22c213
+        return;
22c213
+    }
22c213
+
22c213
     if (!vdev->vbasedev.sysfsdev) {
22c213
         if (!(~vdev->host.domain || ~vdev->host.bus ||
22c213
               ~vdev->host.slot || ~vdev->host.function)) {
22c213
@@ -3167,6 +3191,9 @@ static Property vfio_pci_dev_properties[] = {
22c213
     DEFINE_PROP_BOOL("x-no-kvm-msix", VFIOPCIDevice, no_kvm_msix, false),
22c213
     DEFINE_PROP_BOOL("x-no-geforce-quirks", VFIOPCIDevice,
22c213
                      no_geforce_quirks, false),
22c213
+    /* RHEL only */
22c213
+    DEFINE_PROP_UINT16("x-assigned-device-limit", VFIOPCIDevice,
22c213
+                       assigned_device_limit, 64),
22c213
     DEFINE_PROP_BOOL("x-no-kvm-ioeventfd", VFIOPCIDevice, no_kvm_ioeventfd,
22c213
                      false),
22c213
     DEFINE_PROP_BOOL("x-no-vfio-ioeventfd", VFIOPCIDevice, no_vfio_ioeventfd,
22c213
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
22c213
index 35626cd63e..0cd4803aee 100644
22c213
--- a/hw/vfio/pci.h
22c213
+++ b/hw/vfio/pci.h
22c213
@@ -135,6 +135,7 @@ typedef struct VFIOPCIDevice {
22c213
     EventNotifier err_notifier;
22c213
     EventNotifier req_notifier;
22c213
     int (*resetfn)(struct VFIOPCIDevice *);
22c213
+    uint16_t assigned_device_limit;
22c213
     uint32_t vendor_id;
22c213
     uint32_t device_id;
22c213
     uint32_t sub_vendor_id;
22c213
-- 
22c213
2.21.0
22c213