thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-pci-assign-cap-number-of-devices-that-can-be-assigne.patch

9ae3a8
From 53d1ae3ef3ed6959596813e75678fcb4f2aa30c0 Mon Sep 17 00:00:00 2001
9ae3a8
Message-Id: <53d1ae3ef3ed6959596813e75678fcb4f2aa30c0.1387382496.git.minovotn@redhat.com>
9ae3a8
In-Reply-To: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
9ae3a8
References: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
9ae3a8
From: Bandan Das <bsd@redhat.com>
9ae3a8
Date: Tue, 3 Dec 2013 20:05:12 +0100
9ae3a8
Subject: [PATCH 43/46] pci-assign: cap number of devices that can be assigned
9ae3a8
9ae3a8
RH-Author: Bandan Das <bsd@redhat.com>
9ae3a8
Message-id: <1386101113-31560-2-git-send-email-bsd@redhat.com>
9ae3a8
Patchwork-id: 55983
9ae3a8
O-Subject: [PATCH RHEL7 qemu-kvm v2 1/2] pci-assign: cap number of devices that can be assigned
9ae3a8
Bugzilla: 678368
9ae3a8
RH-Acked-by: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
RH-Acked-by: Marcelo Tosatti <mtosatti@redhat.com>
9ae3a8
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
9ae3a8
Legacy device assignment is not supported for RHEL7, nevertheless,
9ae3a8
it makes sense to enforce the limit here was well in case we need
9ae3a8
to support it in the future. Note that 8 is the limit enforced on
9ae3a8
RHEL 6, RHEL 5 too has a static limit of 8 assigned devices.
9ae3a8
9ae3a8
Signed-off-by: Bandan Das <bsd@redhat.com>
9ae3a8
---
9ae3a8
 hw/i386/kvm/pci-assign.c | 19 ++++++++++++++++++-
9ae3a8
 1 file changed, 18 insertions(+), 1 deletion(-)
9ae3a8
9ae3a8
Signed-off-by: Michal Novotny <minovotn@redhat.com>
9ae3a8
---
9ae3a8
 hw/i386/kvm/pci-assign.c | 19 ++++++++++++++++++-
9ae3a8
 1 file changed, 18 insertions(+), 1 deletion(-)
9ae3a8
9ae3a8
diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
9ae3a8
index 7060605..4a05c0f 100644
9ae3a8
--- a/hw/i386/kvm/pci-assign.c
9ae3a8
+++ b/hw/i386/kvm/pci-assign.c
9ae3a8
@@ -139,8 +139,12 @@ typedef struct AssignedDevice {
9ae3a8
     MemoryRegion mmio;
9ae3a8
     char *configfd_name;
9ae3a8
     int32_t bootindex;
9ae3a8
+    QLIST_ENTRY(AssignedDevice) next;
9ae3a8
 } AssignedDevice;
9ae3a8
 
9ae3a8
+#define MAX_DEV_ASSIGN_CMDLINE 8
9ae3a8
+static QLIST_HEAD(, AssignedDevice) devs = QLIST_HEAD_INITIALIZER(devs);
9ae3a8
+
9ae3a8
 static void assigned_dev_update_irq_routing(PCIDevice *dev);
9ae3a8
 
9ae3a8
 static void assigned_dev_load_option_rom(AssignedDevice *dev);
9ae3a8
@@ -1733,14 +1737,25 @@ static void reset_assigned_device(DeviceState *dev)
9ae3a8
 static int assigned_initfn(struct PCIDevice *pci_dev)
9ae3a8
 {
9ae3a8
     AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
9ae3a8
+    AssignedDevice *adev;
9ae3a8
     uint8_t e_intx;
9ae3a8
-    int r;
9ae3a8
+    int r, i = 0;
9ae3a8
 
9ae3a8
     if (!kvm_enabled()) {
9ae3a8
         error_report("pci-assign: error: requires KVM support");
9ae3a8
         return -1;
9ae3a8
     }
9ae3a8
 
9ae3a8
+    QLIST_FOREACH(adev, &devs, next) {
9ae3a8
+        i++;
9ae3a8
+    }
9ae3a8
+
9ae3a8
+    if (i >= MAX_DEV_ASSIGN_CMDLINE) {
9ae3a8
+        error_report("pci-assign: Maximum supported assigned devices (%d) "
9ae3a8
+                     "already attached\n", MAX_DEV_ASSIGN_CMDLINE);
9ae3a8
+        return -1;
9ae3a8
+    }
9ae3a8
+
9ae3a8
     if (!dev->host.domain && !dev->host.bus && !dev->host.slot &&
9ae3a8
         !dev->host.function) {
9ae3a8
         error_report("pci-assign: error: no host device specified");
9ae3a8
@@ -1810,6 +1825,7 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
9ae3a8
         goto assigned_out;
9ae3a8
     }
9ae3a8
 
9ae3a8
+    QLIST_INSERT_HEAD(&devs, dev, next);
9ae3a8
     assigned_dev_load_option_rom(dev);
9ae3a8
 
9ae3a8
     add_boot_device_path(dev->bootindex, &pci_dev->qdev, NULL);
9ae3a8
@@ -1827,6 +1843,7 @@ static void assigned_exitfn(struct PCIDevice *pci_dev)
9ae3a8
 {
9ae3a8
     AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
9ae3a8
 
9ae3a8
+    QLIST_REMOVE(dev, next);
9ae3a8
     deassign_device(dev);
9ae3a8
     free_assigned_device(dev);
9ae3a8
 }
9ae3a8
-- 
9ae3a8
1.7.11.7
9ae3a8