|
|
b697b4 |
From 55dcef9d806aa530f10e3ca42eb24d52f850d674 Mon Sep 17 00:00:00 2001
|
|
|
a83cc2 |
From: Bandan Das <bsd@redhat.com>
|
|
|
a83cc2 |
Date: Tue, 3 Dec 2013 20:05:13 +0100
|
|
|
a83cc2 |
Subject: vfio: cap number of devices that can be assigned
|
|
|
a83cc2 |
|
|
|
a83cc2 |
RH-Author: Bandan Das <bsd@redhat.com>
|
|
|
a83cc2 |
Message-id: <1386101113-31560-3-git-send-email-bsd@redhat.com>
|
|
|
a83cc2 |
Patchwork-id: 55984
|
|
|
a83cc2 |
O-Subject: [PATCH RHEL7 qemu-kvm v2 2/2] vfio: cap number of devices that can be assigned
|
|
|
a83cc2 |
Bugzilla: 678368
|
|
|
a83cc2 |
RH-Acked-by: Alex Williamson <alex.williamson@redhat.com>
|
|
|
a83cc2 |
RH-Acked-by: Marcelo Tosatti <mtosatti@redhat.com>
|
|
|
a83cc2 |
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
a83cc2 |
|
|
|
a83cc2 |
Go through all groups to get count of total number of devices
|
|
|
a83cc2 |
active to enforce limit
|
|
|
a83cc2 |
|
|
|
a83cc2 |
Reasoning from Alex for the limit(32) - Assuming 3 slots per
|
|
|
a83cc2 |
device, with 125 slots (number of memory slots for RHEL 7),
|
|
|
a83cc2 |
we can support almost 40 devices and still have few slots left
|
|
|
a83cc2 |
for other uses. Stepping down a bit, the number 32 arbitrarily
|
|
|
a83cc2 |
matches the number of slots on a PCI bus and is also a nice power
|
|
|
a83cc2 |
of two.
|
|
|
a83cc2 |
|
|
|
77609c |
Count of slots increased to 509 later so we could increase limit
|
|
|
77609c |
to 64 as some usecases require more than 32 devices.
|
|
|
77609c |
|
|
|
a83cc2 |
Signed-off-by: Bandan Das <bsd@redhat.com>
|
|
|
a83cc2 |
---
|
|
|
a83cc2 |
hw/vfio/pci.c | 29 ++++++++++++++++++++++++++++-
|
|
|
a83cc2 |
hw/vfio/pci.h | 1 +
|
|
|
a83cc2 |
2 files changed, 29 insertions(+), 1 deletion(-)
|
|
|
a83cc2 |
|
|
|
a83cc2 |
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
|
|
|
b697b4 |
index 7b45353ce2..eb725a3aee 100644
|
|
|
a83cc2 |
--- a/hw/vfio/pci.c
|
|
|
a83cc2 |
+++ b/hw/vfio/pci.c
|
|
|
77609c |
@@ -45,6 +45,9 @@
|
|
|
a83cc2 |
|
|
|
a83cc2 |
#define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug"
|
|
|
a83cc2 |
|
|
|
a83cc2 |
+/* RHEL only: Set once for the first assigned dev */
|
|
|
a83cc2 |
+static uint16_t device_limit;
|
|
|
a83cc2 |
+
|
|
|
a83cc2 |
static void vfio_disable_interrupts(VFIOPCIDevice *vdev);
|
|
|
a83cc2 |
static void vfio_mmap_set_enabled(VFIOPCIDevice *vdev, bool enabled);
|
|
|
a83cc2 |
|
|
|
b697b4 |
@@ -2807,9 +2810,30 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
|
|
|
a83cc2 |
ssize_t len;
|
|
|
a83cc2 |
struct stat st;
|
|
|
a83cc2 |
int groupid;
|
|
|
a83cc2 |
- int i, ret;
|
|
|
a83cc2 |
+ int ret, i = 0;
|
|
|
a83cc2 |
bool is_mdev;
|
|
|
a83cc2 |
|
|
|
a83cc2 |
+ if (device_limit && device_limit != vdev->assigned_device_limit) {
|
|
|
a83cc2 |
+ error_setg(errp, "Assigned device limit has been redefined. "
|
|
|
a83cc2 |
+ "Old:%d, New:%d",
|
|
|
a83cc2 |
+ device_limit, vdev->assigned_device_limit);
|
|
|
a83cc2 |
+ return;
|
|
|
a83cc2 |
+ } else {
|
|
|
a83cc2 |
+ device_limit = vdev->assigned_device_limit;
|
|
|
a83cc2 |
+ }
|
|
|
a83cc2 |
+
|
|
|
a83cc2 |
+ QLIST_FOREACH(group, &vfio_group_list, next) {
|
|
|
a83cc2 |
+ QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
|
|
|
a83cc2 |
+ i++;
|
|
|
a83cc2 |
+ }
|
|
|
a83cc2 |
+ }
|
|
|
a83cc2 |
+
|
|
|
a83cc2 |
+ if (i >= vdev->assigned_device_limit) {
|
|
|
a83cc2 |
+ error_setg(errp, "Maximum supported vfio devices (%d) "
|
|
|
a83cc2 |
+ "already attached", vdev->assigned_device_limit);
|
|
|
a83cc2 |
+ return;
|
|
|
a83cc2 |
+ }
|
|
|
a83cc2 |
+
|
|
|
a83cc2 |
if (!vdev->vbasedev.sysfsdev) {
|
|
|
a83cc2 |
if (!(~vdev->host.domain || ~vdev->host.bus ||
|
|
|
a83cc2 |
~vdev->host.slot || ~vdev->host.function)) {
|
|
|
b697b4 |
@@ -3246,6 +3270,9 @@ static Property vfio_pci_dev_properties[] = {
|
|
|
a83cc2 |
DEFINE_PROP_BOOL("x-no-kvm-msix", VFIOPCIDevice, no_kvm_msix, false),
|
|
|
a83cc2 |
DEFINE_PROP_BOOL("x-no-geforce-quirks", VFIOPCIDevice,
|
|
|
a83cc2 |
no_geforce_quirks, false),
|
|
|
a83cc2 |
+ /* RHEL only */
|
|
|
a83cc2 |
+ DEFINE_PROP_UINT16("x-assigned-device-limit", VFIOPCIDevice,
|
|
|
a83cc2 |
+ assigned_device_limit, 64),
|
|
|
a83cc2 |
DEFINE_PROP_BOOL("x-no-kvm-ioeventfd", VFIOPCIDevice, no_kvm_ioeventfd,
|
|
|
a83cc2 |
false),
|
|
|
a83cc2 |
DEFINE_PROP_BOOL("x-no-vfio-ioeventfd", VFIOPCIDevice, no_vfio_ioeventfd,
|
|
|
a83cc2 |
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
|
|
|
a83cc2 |
index 64777516d1..e0fe6ca97e 100644
|
|
|
a83cc2 |
--- a/hw/vfio/pci.h
|
|
|
a83cc2 |
+++ b/hw/vfio/pci.h
|
|
|
a83cc2 |
@@ -139,6 +139,7 @@ struct VFIOPCIDevice {
|
|
|
a83cc2 |
EventNotifier err_notifier;
|
|
|
a83cc2 |
EventNotifier req_notifier;
|
|
|
a83cc2 |
int (*resetfn)(struct VFIOPCIDevice *);
|
|
|
a83cc2 |
+ uint16_t assigned_device_limit;
|
|
|
a83cc2 |
uint32_t vendor_id;
|
|
|
a83cc2 |
uint32_t device_id;
|
|
|
a83cc2 |
uint32_t sub_vendor_id;
|
|
|
a83cc2 |
--
|
|
|
a83cc2 |
2.27.0
|
|
|
a83cc2 |
|