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