|
|
28f2e1 |
From e9ebc159a9acf108e1ec6f622be3f256cf14aba7 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 |
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
|
|
|
28f2e1 |
index 7b45353ce2..eb725a3aee 100644
|
|
|
22c213 |
--- a/hw/vfio/pci.c
|
|
|
22c213 |
+++ b/hw/vfio/pci.c
|
|
|
febaa2 |
@@ -45,6 +45,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 |
|
|
|
28f2e1 |
@@ -2807,9 +2810,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)) {
|
|
|
28f2e1 |
@@ -3246,6 +3270,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
|
|
|
febaa2 |
index 64777516d1..e0fe6ca97e 100644
|
|
|
22c213 |
--- a/hw/vfio/pci.h
|
|
|
22c213 |
+++ b/hw/vfio/pci.h
|
|
|
febaa2 |
@@ -139,6 +139,7 @@ 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 |
--
|
|
|
28f2e1 |
2.27.0
|
|
|
22c213 |
|