2024-09-10 06:42:37 +00:00
|
|
|
From 9813098fb73e899dd1d824f9c1e7e570a87b1771 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
|
2023-10-16 10:42:05 +00:00
|
|
|
Subject: vfio: cap number of devices that can be assigned
|
2018-10-14 17:48:54 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2021-09-02 06:44:51 +00:00
|
|
|
Count of slots increased to 509 later so we could increase limit
|
|
|
|
to 64 as some usecases require more than 32 devices.
|
|
|
|
|
2018-10-14 17:48:54 +00:00
|
|
|
Signed-off-by: Bandan Das <bsd@redhat.com>
|
|
|
|
---
|
2024-01-02 12:52:01 +00:00
|
|
|
hw/vfio/pci.c | 31 ++++++++++++++++++++++++++++++-
|
2019-08-15 04:45:41 +00:00
|
|
|
hw/vfio/pci.h | 1 +
|
2024-01-02 12:52:01 +00:00
|
|
|
2 files changed, 31 insertions(+), 1 deletion(-)
|
2018-10-14 17:48:54 +00:00
|
|
|
|
|
|
|
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
|
2024-09-10 06:42:37 +00:00
|
|
|
index 2407720c35..82a47edc89 100644
|
2018-10-14 17:48:54 +00:00
|
|
|
--- a/hw/vfio/pci.c
|
|
|
|
+++ b/hw/vfio/pci.c
|
2024-05-14 06:50:03 +00:00
|
|
|
@@ -50,6 +50,9 @@
|
2022-09-05 08:13:56 +00:00
|
|
|
/* Protected by BQL */
|
|
|
|
static KVMRouteChange vfio_route_change;
|
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);
|
2022-09-05 08:13:56 +00:00
|
|
|
static void vfio_msi_disable_common(VFIOPCIDevice *vdev);
|
2024-09-10 06:42:37 +00:00
|
|
|
@@ -2963,10 +2966,33 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
|
2024-05-14 06:50:03 +00:00
|
|
|
ERRP_GUARD();
|
2024-01-02 12:52:01 +00:00
|
|
|
VFIOPCIDevice *vdev = VFIO_PCI(pdev);
|
|
|
|
VFIODevice *vbasedev = &vdev->vbasedev;
|
2018-10-14 17:48:54 +00:00
|
|
|
- int i, ret;
|
|
|
|
+ int ret, i = 0;
|
2024-09-10 06:42:37 +00:00
|
|
|
+ VFIODevice *vbasedev_iter;
|
|
|
|
+ VFIOGroup *group;
|
2024-01-02 12:52:01 +00:00
|
|
|
char uuid[UUID_STR_LEN];
|
2024-09-10 06:42:37 +00:00
|
|
|
g_autofree char *name = NULL;
|
2018-11-29 12:09:34 +00:00
|
|
|
|
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
|
|
|
+
|
2024-05-14 06:50:03 +00:00
|
|
|
if (vbasedev->fd < 0 && !vbasedev->sysfsdev) {
|
2018-10-14 17:48:54 +00:00
|
|
|
if (!(~vdev->host.domain || ~vdev->host.bus ||
|
2018-11-29 12:09:34 +00:00
|
|
|
~vdev->host.slot || ~vdev->host.function)) {
|
2024-09-10 06:42:37 +00:00
|
|
|
@@ -3388,6 +3414,9 @@ static Property vfio_pci_dev_properties[] = {
|
2019-08-15 04:45:41 +00:00
|
|
|
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
|
2024-09-10 06:42:37 +00:00
|
|
|
index bf67df2fbc..0d3c93fb2e 100644
|
2019-08-15 04:45:41 +00:00
|
|
|
--- a/hw/vfio/pci.h
|
|
|
|
+++ b/hw/vfio/pci.h
|
2024-01-02 12:52:01 +00:00
|
|
|
@@ -142,6 +142,7 @@ struct VFIOPCIDevice {
|
2019-08-15 04:45:41 +00:00
|
|
|
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;
|
2023-10-16 10:42:05 +00:00
|
|
|
--
|
|
|
|
2.39.3
|
|
|
|
|