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