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