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

115 lines
4.0 KiB
Diff
Raw Permalink Normal View History

2024-04-30 11:41:18 +00:00
From a27cfa0b407bd806ce389a7c69d0130bcfd35244 Mon Sep 17 00:00:00 2001
2022-05-17 08:38:02 +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.
Count of slots increased to 509 later so we could increase limit
to 64 as some usecases require more than 32 devices.
Signed-off-by: Bandan Das <bsd@redhat.com>
2024-04-30 11:41:18 +00:00
Rebase changes (231025):
- Update to upstream changes
2022-05-17 08:38:02 +00:00
---
2024-04-30 11:41:18 +00:00
hw/vfio/pci.c | 31 ++++++++++++++++++++++++++++++-
2022-05-17 08:38:02 +00:00
hw/vfio/pci.h | 1 +
2024-04-30 11:41:18 +00:00
2 files changed, 31 insertions(+), 1 deletion(-)
2022-05-17 08:38:02 +00:00
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
2024-04-30 11:41:18 +00:00
index c62c02f7b6..ec98080f28 100644
2022-05-17 08:38:02 +00:00
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
2023-05-09 05:17:27 +00:00
@@ -48,6 +48,9 @@
/* Protected by BQL */
static KVMRouteChange vfio_route_change;
2022-05-17 08:38:02 +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);
2023-05-09 05:17:27 +00:00
static void vfio_msi_disable_common(VFIOPCIDevice *vdev);
2024-04-30 11:41:18 +00:00
@@ -3076,14 +3079,37 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
{
VFIOPCIDevice *vdev = VFIO_PCI(pdev);
VFIODevice *vbasedev = &vdev->vbasedev;
+ VFIODevice *vbasedev_iter;
+ VFIOGroup *group;
char *tmp, *subsys;
Error *err = NULL;
2022-05-17 08:38:02 +00:00
struct stat st;
- int i, ret;
+ int ret, i = 0;
bool is_mdev;
2024-04-30 11:41:18 +00:00
char uuid[UUID_STR_LEN];
char *name;
2022-05-17 08:38:02 +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;
+ }
+
+ QLIST_FOREACH(group, &vfio_group_list, next) {
+ QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
+ i++;
+ }
+ }
+
+ if (i >= vdev->assigned_device_limit) {
+ error_setg(errp, "Maximum supported vfio devices (%d) "
+ "already attached", vdev->assigned_device_limit);
+ return;
+ }
+
2023-05-09 05:17:27 +00:00
if (!vbasedev->sysfsdev) {
2022-05-17 08:38:02 +00:00
if (!(~vdev->host.domain || ~vdev->host.bus ||
~vdev->host.slot || ~vdev->host.function)) {
2024-04-30 11:41:18 +00:00
@@ -3501,6 +3527,9 @@ static Property vfio_pci_dev_properties[] = {
2022-05-17 08:38:02 +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-04-30 11:41:18 +00:00
index fba8737ab2..eb74d9de2d 100644
2022-05-17 08:38:02 +00:00
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
2024-04-30 11:41:18 +00:00
@@ -142,6 +142,7 @@ struct VFIOPCIDevice {
2022-05-17 08:38:02 +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;
--
2024-04-30 11:41:18 +00:00
2.39.3
2022-05-17 08:38:02 +00:00