From 12f78e5b82f76e18700bfc85d8d4d30345d88690 Mon Sep 17 00:00:00 2001 From: Bandan Das Date: Tue, 3 Dec 2013 20:05:12 +0100 Subject: 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 diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c index 9db7c77..bdeb0c3 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); @@ -1741,8 +1745,9 @@ static void reset_assigned_device(DeviceState *dev) static void assigned_realize(struct PCIDevice *pci_dev, Error **errp) { AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev); + AssignedDevice *adev; uint8_t e_intx; - int r; + int r, i = 0; Error *local_err = NULL; if (!kvm_enabled()) { @@ -1750,6 +1755,16 @@ static void assigned_realize(struct PCIDevice *pci_dev, Error **errp) goto exit_with_error; } + QLIST_FOREACH(adev, &devs, next) { + i++; + } + + if (i >= MAX_DEV_ASSIGN_CMDLINE) { + error_setg(&local_err, "pci-assign: Maximum supported assigned devices" + " (%d) already attached\n", MAX_DEV_ASSIGN_CMDLINE); + goto exit_with_error; + } + if (!dev->host.domain && !dev->host.bus && !dev->host.slot && !dev->host.function) { error_setg(&local_err, "no host device specified"); @@ -1819,6 +1834,7 @@ static void assigned_realize(struct PCIDevice *pci_dev, Error **errp) goto assigned_out; } + QLIST_INSERT_HEAD(&devs, dev, next); assigned_dev_load_option_rom(dev); return; @@ -1838,6 +1854,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); }