77 lines
2.4 KiB
Diff
77 lines
2.4 KiB
Diff
From 0b8b44ec1fc3a0d17f13c07ac4c7351769a63300 Mon Sep 17 00:00:00 2001
|
|
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>
|
|
|
|
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
|
|
|
|
(cherry picked from commit 9fa3c9fc6dfcde76d80db1aa601b2d577f72ceec)
|
|
(cherry picked from commit 3cb35556dc7d994f203d732fe952f95fcdb03c0a)
|
|
---
|
|
hw/vfio/pci.c | 15 ++++++++++++++-
|
|
1 file changed, 14 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
|
|
index 6e0000c..d242c62 100644
|
|
--- a/hw/vfio/pci.c
|
|
+++ b/hw/vfio/pci.c
|
|
@@ -36,6 +36,7 @@
|
|
#include "qapi/error.h"
|
|
|
|
#define MSIX_CAP_LENGTH 12
|
|
+#define MAX_DEV_ASSIGN_CMDLINE 32
|
|
|
|
#define TYPE_VFIO_PCI "vfio-pci"
|
|
#define PCI_VFIO(obj) OBJECT_CHECK(VFIOPCIDevice, obj, TYPE_VFIO_PCI)
|
|
@@ -2811,9 +2812,21 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
|
|
ssize_t len;
|
|
struct stat st;
|
|
int groupid;
|
|
- int i, ret;
|
|
+ int ret, i = 0;
|
|
bool is_mdev;
|
|
|
|
+ QLIST_FOREACH(group, &vfio_group_list, next) {
|
|
+ QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
|
|
+ i++;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (i >= MAX_DEV_ASSIGN_CMDLINE) {
|
|
+ error_setg(errp, "Maximum supported vfio devices (%d) "
|
|
+ "already attached", MAX_DEV_ASSIGN_CMDLINE);
|
|
+ return;
|
|
+ }
|
|
+
|
|
if (!vdev->vbasedev.sysfsdev) {
|
|
if (!(~vdev->host.domain || ~vdev->host.bus ||
|
|
~vdev->host.slot || ~vdev->host.function)) {
|
|
--
|
|
1.8.3.1
|
|
|