From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009158; cv=none; d=zohomail.com; s=zohoarc; b=FK2Pi8HFIFNs+eoXcW0E37XHovGEAsVWeRw5+QXy0ecaSM/Vb8CpvWS/VdzqV7/fzZgfLjNMXEIAFl6LvkuyfM3LUIeNvvqRgLSPv+amNCSxXPpc763nOpCi++y4VBz7iyen4F1r35Krh022HKhttMoX6Rc0RdpJ/+XUGH6rTUE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009158; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rqmCTOhMcmZw6KYqwvaKr4Cz6BVm264h5D90siwqZTY=; b=YB36ssWj2sFOvqmtuPrwyqjQ9QDb01g1zA06k7mri7SFJlf/s2k1gwAVHMIafcz6GNZNVEaUkdPDR+uNJ1MN0jtqMjORZWXfaqo3zKpWIcqMyikSXe0ngUR0pvvoDtMKI+uy6AFmdP9WDc0DlY/KS4DPWgZjKg0eXTAeVKmnlrk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 159000915871739.8544305600293; Wed, 20 May 2020 14:12:38 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-410-zXeFeNxVNciFTkOZYmjAeA-1; Wed, 20 May 2020 17:12:33 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D0DC21855A1F; Wed, 20 May 2020 21:12:27 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AE2C25D9CD; Wed, 20 May 2020 21:12:27 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 81AF24EE4A; Wed, 20 May 2020 21:12:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCAlZ002004 for ; Wed, 20 May 2020 17:12:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5AB2C2029F61; Wed, 20 May 2020 21:12:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5436C202696C for ; Wed, 20 May 2020 21:12:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 333C9811E7A for ; Wed, 20 May 2020 21:12:08 +0000 (UTC) Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-413-y3gm5nj4P4KbjEYB_UC1aA-1; Wed, 20 May 2020 17:12:06 -0400 Received: by mail-qk1-f195.google.com with SMTP id n14so5134461qke.8 for ; Wed, 20 May 2020 14:12:05 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009157; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rqmCTOhMcmZw6KYqwvaKr4Cz6BVm264h5D90siwqZTY=; b=H4zkeimGSGowW3BVccS94fz8cF94Z+5L60ilTrZqHP2askedw2GNc8GgMSSCrvLod0n2VR gjNJIymViCCzJmtd50H77icqYbxvwMC7qK3wy+hHgNksy+1aEz0de5nxKCDPVbA8ndg91S 33fLUgfZLU4g3elAtJWPqDUDOxDE0Fw= X-MC-Unique: zXeFeNxVNciFTkOZYmjAeA-1 X-MC-Unique: y3gm5nj4P4KbjEYB_UC1aA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rqmCTOhMcmZw6KYqwvaKr4Cz6BVm264h5D90siwqZTY=; b=DTNRDYgwXYltzS+GG/n4fuMQhlNr6DUNhQbVMU/3Ipl7/xpt77JSD2/XmhkPOqoyay L3UAvgrhTPyVwo9ZeR5NDaYyFiTLFfITH8NWvfiUGBaPlC+xGJ+AmIypeFcgDq4lKp1M sWpU7z2sYcEUvBjG85CJKLiJSim6up/RP6Z289Za7HBWxs5B1CKtp5TbnmCzpUU4jKYr zgpPgPiXXYu5V5h32A7IAl6bMj6QacqVLIgdyYTQ3j1q/ykVIO0otBUsVa3jke6imoYM PHajVbXfZSonw4MYC4JLuWR7iT2q/luI15EUlDt7opDhkrul0lgM1xcnQtmFV15X2mzn cdkQ== X-Gm-Message-State: AOAM533d9XGiJy79YM/qqSxg4fhoNftbckWZrQnDFJF6oVWnO+HztwU4 4AHm44vbzemAdP4RwcjyzfLrK7Jd X-Google-Smtp-Source: ABdhPJy1Jr/GvjhCBH+SmQx7AGc8fy4f0vrkmNG25kBmu1jry8gX7UliGJvbAajdDQW8APTYte9Iqg== X-Received: by 2002:a37:57c5:: with SMTP id l188mr3160367qkb.273.1590009124946; Wed, 20 May 2020 14:12:04 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 01/21] qemu: address: Separate the slots into multiple aggregates Date: Wed, 20 May 2020 18:11:23 -0300 Message-Id: <20200520211143.2980117-2-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat Today's aggregate flag with the slot being true for pcie-root-ports is not enough as there will more number of aggregates depending on the number of Multifunction PCI cards assigned to the domain. The aggregate is changed to unsigned int. Zero means Not Applicable, 1 is reserved for the pcie-root-ports and >=3D 2 for the the PCI Multifunction cards(coming..). Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/conf/device_conf.h | 1 + src/conf/domain_addr.c | 46 +++++++++++++------ src/conf/domain_addr.h | 38 +++++++-------- src/qemu/qemu_domain_address.c | 84 ++++++++++++++++++++++++++++------ src/qemu/qemu_domain_address.h | 9 ++++ 5 files changed, 128 insertions(+), 50 deletions(-) diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index d7395f2201..cc1707c1d1 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -169,6 +169,7 @@ struct _virDomainDeviceInfo { */ int pciAddrExtFlags; /* enum virDomainPCIAddressExtensionFlags */ char *loadparm; + unsigned int aggregateSlotIdx; /* Used when the aggregate flag is set = */ =20 /* PCI devices will only be automatically placed on a PCI bus * that shares the same isolation group */ diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 8623e79daf..5c8fc62725 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -297,7 +297,7 @@ virDomainPCIControllerModelToConnectType(virDomainContr= ollerModelPCI model) return VIR_PCI_CONNECT_TYPE_PCIE_TO_PCI_BRIDGE; =20 case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT_PORT: - return VIR_PCI_CONNECT_TYPE_PCIE_ROOT_PORT | VIR_PCI_CONNECT_AGGRE= GATE_SLOT; + return VIR_PCI_CONNECT_TYPE_PCIE_ROOT_PORT; =20 case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_UPSTREAM_PORT: return VIR_PCI_CONNECT_TYPE_PCIE_SWITCH_UPSTREAM_PORT; @@ -843,6 +843,7 @@ virDomainPCIAddressReserveAddrInternal(virDomainPCIAddr= essSetPtr addrs, virPCIDeviceAddressPtr addr, virDomainPCIConnectFlags flags, unsigned int isolationGroup, + unsigned int aggregateSlotIdx, bool fromConfig) { g_autofree char *addrStr =3D NULL; @@ -874,9 +875,14 @@ virDomainPCIAddressReserveAddrInternal(virDomainPCIAdd= ressSetPtr addrs, * the device it's being reserved for can aggregate multiples on a * slot, set the slot's aggregate flag. */ - if (!bus->slot[addr->slot].functions && - flags & VIR_PCI_CONNECT_AGGREGATE_SLOT) { - bus->slot[addr->slot].aggregate =3D true; + if (!bus->slot[addr->slot].functions && aggregateSlotIdx > 0) { + bus->slot[addr->slot].aggregateSlotIdx =3D aggregateSlotIdx; + } else if (bus->slot[addr->slot].aggregateSlotIdx !=3D + aggregateSlotIdx && fromConfig) { + bus->slot[addr->slot].aggregateSlotIdx =3D 0; + VIR_DEBUG("PCI functions of %.4x:%.2x is aggregated to slot %u" + "because of user assigned address %s", + addr->domain, addr->bus, aggregateSlotIdx, addrStr); } =20 if (virDomainPCIAddressBusIsEmpty(bus) && !bus->isolationGroupLocked) { @@ -901,8 +907,8 @@ virDomainPCIAddressReserveAddrInternal(virDomainPCIAddr= essSetPtr addrs, =20 /* mark the requested function as reserved */ bus->slot[addr->slot].functions |=3D (1 << addr->function); - VIR_DEBUG("Reserving PCI address %s (aggregate=3D'%s')", addrStr, - bus->slot[addr->slot].aggregate ? "true" : "false"); + VIR_DEBUG("Reserving PCI address %s (aggregateSlotIdx=3D'%d')", + addrStr, bus->slot[addr->slot].aggregateSlotIdx); =20 return 0; } @@ -912,10 +918,12 @@ int virDomainPCIAddressReserveAddr(virDomainPCIAddressSetPtr addrs, virPCIDeviceAddressPtr addr, virDomainPCIConnectFlags flags, - unsigned int isolationGroup) + unsigned int isolationGroup, + unsigned int aggregateSlotIdx) { return virDomainPCIAddressReserveAddrInternal(addrs, addr, flags, - isolationGroup, true); + isolationGroup, + aggregateSlotIdx, true); } =20 int @@ -956,6 +964,7 @@ virDomainPCIAddressEnsureAddr(virDomainPCIAddressSetPtr= addrs, =20 if (virDomainPCIAddressReserveAddrInternal(addrs, &dev->addr.pci, flags, dev->isolationGr= oup, + dev->aggregateSlotIdx, true) < 0) { return -1; } @@ -1112,6 +1121,7 @@ virDomainPCIAddressSetFree(virDomainPCIAddressSetPtr = addrs) static int virDomainPCIAddressFindUnusedFunctionOnBus(virDomainPCIAddressBusPtr bus, virPCIDeviceAddressPtr searchAd= dr, + unsigned int aggregateSlotIdx, int function, virDomainPCIConnectFlags flags, bool *found) @@ -1134,8 +1144,8 @@ virDomainPCIAddressFindUnusedFunctionOnBus(virDomainP= CIAddressBusPtr bus, break; } =20 - if (flags & VIR_PCI_CONNECT_AGGREGATE_SLOT && - bus->slot[searchAddr->slot].aggregate) { + if (bus->slot[searchAddr->slot].aggregateSlotIdx > 0 && + bus->slot[searchAddr->slot].aggregateSlotIdx =3D=3D aggreg= ateSlotIdx) { /* slot and device are okay with aggregating devices */ if ((bus->slot[searchAddr->slot].functions & (1 << searchAddr->function)) =3D=3D 0) { @@ -1176,6 +1186,7 @@ virDomainPCIAddressGetNextAddr(virDomainPCIAddressSet= Ptr addrs, virPCIDeviceAddressPtr next_addr, virDomainPCIConnectFlags flags, unsigned int isolationGroup, + unsigned int aggregateSlotIdx, int function) { virPCIDeviceAddress a =3D { 0 }; @@ -1204,7 +1215,9 @@ virDomainPCIAddressGetNextAddr(virDomainPCIAddressSet= Ptr addrs, =20 a.slot =3D bus->minSlot; =20 - if (virDomainPCIAddressFindUnusedFunctionOnBus(bus, &a, function, + if (virDomainPCIAddressFindUnusedFunctionOnBus(bus, &a, + aggregateSlotIdx, + function, flags, &found) < 0)= { return -1; } @@ -1228,7 +1241,9 @@ virDomainPCIAddressGetNextAddr(virDomainPCIAddressSet= Ptr addrs, =20 a.slot =3D bus->minSlot; =20 - if (virDomainPCIAddressFindUnusedFunctionOnBus(bus, &a, function, + if (virDomainPCIAddressFindUnusedFunctionOnBus(bus, &a, + aggregateSlotIdx, + function, flags, &found) < 0)= { return -1; } @@ -1286,12 +1301,13 @@ virDomainPCIAddressReserveNextAddr(virDomainPCIAddr= essSetPtr addrs, { virPCIDeviceAddress addr; =20 - if (virDomainPCIAddressGetNextAddr(addrs, &addr, flags, - dev->isolationGroup, function) < 0) + if (virDomainPCIAddressGetNextAddr(addrs, &addr, flags, dev->isolation= Group, + dev->aggregateSlotIdx, function) < = 0) return -1; =20 if (virDomainPCIAddressReserveAddrInternal(addrs, &addr, flags, - dev->isolationGroup, false)= < 0) + dev->isolationGroup, + dev->aggregateSlotIdx, fals= e) < 0) return -1; =20 addr.extFlags =3D dev->addr.pci.extFlags; diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index c1363c1490..ddcff36e51 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -35,24 +35,19 @@ typedef enum { VIR_PCI_CONNECT_AUTOASSIGN =3D 1 << 0, /* okay to autoassign a device = to this controller */ VIR_PCI_CONNECT_HOTPLUGGABLE =3D 1 << 1, /* is hotplug needed/supporte= d */ =20 - /* set for devices that can share a single slot in auto-assignment - * (by assigning one device to each of the 8 functions on the slot) - */ - VIR_PCI_CONNECT_AGGREGATE_SLOT =3D 1 << 2, - /* kinds of devices as a bitmap so they can be combined (some PCI * controllers permit connecting multiple types of devices) */ - VIR_PCI_CONNECT_TYPE_PCI_DEVICE =3D 1 << 3, - VIR_PCI_CONNECT_TYPE_PCIE_DEVICE =3D 1 << 4, - VIR_PCI_CONNECT_TYPE_PCIE_ROOT_PORT =3D 1 << 5, - VIR_PCI_CONNECT_TYPE_PCIE_SWITCH_UPSTREAM_PORT =3D 1 << 6, - VIR_PCI_CONNECT_TYPE_PCIE_SWITCH_DOWNSTREAM_PORT =3D 1 << 7, - VIR_PCI_CONNECT_TYPE_DMI_TO_PCI_BRIDGE =3D 1 << 8, - VIR_PCI_CONNECT_TYPE_PCI_EXPANDER_BUS =3D 1 << 9, - VIR_PCI_CONNECT_TYPE_PCIE_EXPANDER_BUS =3D 1 << 10, - VIR_PCI_CONNECT_TYPE_PCI_BRIDGE =3D 1 << 11, - VIR_PCI_CONNECT_TYPE_PCIE_TO_PCI_BRIDGE =3D 1 << 12, + VIR_PCI_CONNECT_TYPE_PCI_DEVICE =3D 1 << 2, + VIR_PCI_CONNECT_TYPE_PCIE_DEVICE =3D 1 << 3, + VIR_PCI_CONNECT_TYPE_PCIE_ROOT_PORT =3D 1 << 4, + VIR_PCI_CONNECT_TYPE_PCIE_SWITCH_UPSTREAM_PORT =3D 1 << 5, + VIR_PCI_CONNECT_TYPE_PCIE_SWITCH_DOWNSTREAM_PORT =3D 1 << 6, + VIR_PCI_CONNECT_TYPE_DMI_TO_PCI_BRIDGE =3D 1 << 7, + VIR_PCI_CONNECT_TYPE_PCI_EXPANDER_BUS =3D 1 << 8, + VIR_PCI_CONNECT_TYPE_PCIE_EXPANDER_BUS =3D 1 << 9, + VIR_PCI_CONNECT_TYPE_PCI_BRIDGE =3D 1 << 10, + VIR_PCI_CONNECT_TYPE_PCIE_TO_PCI_BRIDGE =3D 1 << 11, } virDomainPCIConnectFlags; =20 /* a combination of all bits that describe the type of connections @@ -86,12 +81,12 @@ typedef struct { */ uint8_t functions; =20 - /* aggregate is true if this slot has only devices with - * VIR_PCI_CONNECT_AGGREGATE assigned to its functions (meaning - * that other devices with the same flags could also be - * auto-assigned to the other functions) + /* aggregate is greater than zero if this slot has only devices with + * VIR_PCI_CONNECT_AGGREGATE assigned to its functions and + * that other devices with the same aggregateSlotIdx could also be + * auto-assigned to the other functions on this slot) */ - bool aggregate; + unsigned int aggregateSlotIdx; } virDomainPCIAddressSlot; =20 typedef struct { @@ -170,7 +165,8 @@ int virDomainPCIAddressExtensionReserveNextAddr(virDoma= inPCIAddressSetPtr addrs, int virDomainPCIAddressReserveAddr(virDomainPCIAddressSetPtr addrs, virPCIDeviceAddressPtr addr, virDomainPCIConnectFlags flags, - unsigned int isolationGroup) + unsigned int isolationGroup, + unsigned int agregateSlotIdx) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 int virDomainPCIAddressReserveNextAddr(virDomainPCIAddressSetPtr addrs, diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 07431343ed..f86c85eaa9 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -24,6 +24,7 @@ #include "qemu_domain_address.h" #include "qemu_domain.h" #include "viralloc.h" +#include "virhostdev.h" #include "virerror.h" #include "virlog.h" =20 @@ -1419,6 +1420,54 @@ qemuDomainSetupIsolationGroups(virDomainDefPtr def) } =20 =20 +void +qemuDomainSetDeviceSlotAggregateIdx(virDomainDefPtr def G_GNUC_UNUSED, + virDomainDeviceDefPtr dev) +{ + virDomainDeviceInfoPtr info =3D virDomainDeviceGetInfo(dev); + + if (!info) + return; + + info->aggregateSlotIdx =3D 0; + + if (dev->type =3D=3D VIR_DOMAIN_DEVICE_CONTROLLER) { + virDomainControllerDefPtr cont =3D dev->data.controller; + if (cont->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI && + cont->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT_PORT)= { + info->aggregateSlotIdx =3D 1; + } + } + + return; +} + + +static int +qemuDomainFillDeviceSlotAggregationIter(virDomainDefPtr def, + virDomainDeviceDefPtr dev, + virDomainDeviceInfoPtr info G_GNUC= _UNUSED, + void *opaque G_GNUC_UNUSED) +{ + qemuDomainSetDeviceSlotAggregateIdx(def, dev); + + return 0; +} + + +static int +qemuDomainSetupSlotAggregation(virDomainDefPtr def) +{ + if (virDomainDeviceInfoIterate(def, + qemuDomainFillDeviceSlotAggregationIter, + NULL) < 0) { + return -1; + } + + return 0; +} + + /** * qemuDomainFillDevicePCIConnectFlags: * @@ -1590,7 +1639,8 @@ qemuDomainCollectPCIAddress(virDomainDefPtr def G_GNU= C_UNUSED, =20 if (virDomainPCIAddressReserveAddr(addrs, addr, info->pciConnectFlags, - info->isolationGroup) < 0) { + info->isolationGroup, + info->aggregateSlotIdx) < 0) { return -1; } =20 @@ -1787,7 +1837,7 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr= def, continue; } if (addrs->nbuses && - virDomainPCIAddressReserveAddr(addrs, &cont->info.addr.pci, fl= ags, 0) < 0) + virDomainPCIAddressReserveAddr(addrs, &cont->info.addr.pci, fl= ags, 0, 0) < 0) return -1; } =20 @@ -1796,11 +1846,11 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefP= tr def, memset(&tmp_addr, 0, sizeof(tmp_addr)); tmp_addr.slot =3D 1; /* ISA Bridge at 00:01.0 */ - if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0) < 0) + if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0, 0) = < 0) return -1; /* Bridge at 00:01.3 */ tmp_addr.function =3D 3; - if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0) < 0) + if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0, 0) = < 0) return -1; } =20 @@ -1841,7 +1891,7 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr= def, return -1; } } else { - if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags= , 0) < 0) + if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags= , 0, 0) < 0) return -1; primaryVideo->info.addr.pci =3D tmp_addr; primaryVideo->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE= _PCI; @@ -1864,7 +1914,7 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr= def, VIR_DEBUG("PCI address 0:0:2.0 in use, future addition of a vi= deo" " device will not be possible without manual" " intervention"); - } else if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags,= 0) < 0) { + } else if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags,= 0, 0) < 0) { return -1; } } @@ -1934,7 +1984,7 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr d= ef, assign =3D true; } if (assign) { - if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, f= lags, 0) < 0) + if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, f= lags, 0, 0) < 0) return -1; =20 cont->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; @@ -1957,7 +2007,7 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr d= ef, memset(&tmp_addr, 0, sizeof(tmp_addr)); tmp_addr.slot =3D 0x1E; if (!virDomainPCIAddressSlotInUse(addrs, &tmp_addr)) { - if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, f= lags, 0) < 0) + if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, f= lags, 0, 0) < 0) return -1; =20 cont->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; @@ -1981,12 +2031,12 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr= def, tmp_addr.slot =3D 0x1F; tmp_addr.function =3D 0; tmp_addr.multi =3D VIR_TRISTATE_SWITCH_ON; - if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0) < 0) + if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0, 0) = < 0) return -1; =20 tmp_addr.function =3D 3; tmp_addr.multi =3D VIR_TRISTATE_SWITCH_ABSENT; - if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0) < 0) + if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0, 0) = < 0) return -1; } =20 @@ -2023,7 +2073,7 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr d= ef, return -1; } } else { - if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags= , 0) < 0) + if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags= , 0, 0) < 0) return -1; primaryVideo->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE= _PCI; primaryVideo->info.addr.pci =3D tmp_addr; @@ -2049,7 +2099,7 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr d= ef, " device will not be possible without manual" " intervention"); virResetLastError(); - } else if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags,= 0) < 0) { + } else if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags,= 0, 0) < 0) { return -1; } } @@ -2070,7 +2120,7 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr d= ef, !virDeviceInfoPCIAddressIsWanted(&sound->info)) { continue; } - if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0)= < 0) + if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0,= 0) < 0) return -1; =20 sound->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; @@ -2272,7 +2322,8 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def, /* Reserve this function on the slot we found */ if (virDomainPCIAddressReserveAddr(addrs, &addr, cont->info.pciConnectFl= ags, - cont->info.isolationGro= up) < 0) { + cont->info.isolationGro= up, + cont->info.aggregateSlo= tIdx) < 0) { return -1; } =20 @@ -2646,6 +2697,9 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, if (qemuDomainSetupIsolationGroups(def) < 0) goto cleanup; =20 + if (qemuDomainSetupSlotAggregation(def) < 0) + goto cleanup; + if (nbuses > 0) { /* 1st pass to figure out how many PCI bridges we need */ if (!(addrs =3D qemuDomainPCIAddressSetCreate(def, qemuCaps, nbuse= s, true))) @@ -2766,6 +2820,7 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, dev.data.controller =3D def->controllers[contIndex]; /* set connect flags so it will be properly addressed */ qemuDomainFillDevicePCIConnectFlags(def, &dev, qemuCaps, drive= r); + qemuDomainSetDeviceSlotAggregateIdx(def, &dev); =20 /* Reserve an address for the controller. pci-root and pcie-ro= ot * controllers don't plug into any other PCI controller, hence @@ -3239,6 +3294,7 @@ qemuDomainEnsurePCIAddress(virDomainObjPtr obj, return 0; =20 qemuDomainFillDevicePCIConnectFlags(obj->def, dev, priv->qemuCaps, dri= ver); + qemuDomainSetDeviceSlotAggregateIdx(obj->def, dev); =20 qemuDomainFillDevicePCIExtensionFlags(dev, info, priv->qemuCaps); =20 diff --git a/src/qemu/qemu_domain_address.h b/src/qemu/qemu_domain_address.h index 7ef3308246..198f813595 100644 --- a/src/qemu/qemu_domain_address.h +++ b/src/qemu/qemu_domain_address.h @@ -53,6 +53,15 @@ void qemuDomainFillDeviceIsolationGroup(virDomainDefPtr = def, virDomainDeviceDefPtr dev) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 +void +qemuDomainSetDeviceSlotAggregateIdx(virDomainDefPtr def, + virDomainDeviceDefPtr dev); + +int +qemuDomainDefDeviceFindSlotAggregateIdx(virDomainDefPtr def, + virDomainDeviceDefPtr dev); + + void qemuDomainReleaseDeviceAddress(virDomainObjPtr vm, virDomainDeviceInfoPtr info); =20 --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009145; cv=none; d=zohomail.com; s=zohoarc; b=JWUZPYmoXQ/7wntet1gEP6ZYKnyNNfd5YJ8G9AcFAwFB0/+L2pchWIjOhta/CQirS4qxWv0il5robxMo8d2NRGf/UabkJT0SfsAVb5w9+QtiNEz7G/v+lxa3raoYo/1f46Mx7muDpiog8CXtysDQe83W+6r5vA3LY8SwvX+7ndA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009145; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EO9NydjIAYLyq/t6nIZozvEQJQm0gWEq0rGRIgFYvSY=; b=Kl7+YE1a6XTHCZrjkCpGLJmySY++Iblca0X2Uwab4F13mom9jQ1YQ9lHWf5p0GHu0mWnmwFSZudOtwP+cj4FGJPtjzYkoEO5/njZyyZCtzgdzlwyIdll3zAnQfNXwu+VtFV0CNI2pB8qnCYyl0BhoYAL94zDi28EYmH602pTjjI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1590009145486275.934237376071; Wed, 20 May 2020 14:12:25 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-467-N17VEHvDPH2wyWc37tEJuQ-1; Wed, 20 May 2020 17:12:21 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E9730BFC6; Wed, 20 May 2020 21:12:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 703C65D9CC; Wed, 20 May 2020 21:12:15 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6DCC84EE28; Wed, 20 May 2020 21:12:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCCmp002016 for ; Wed, 20 May 2020 17:12:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 59E392166BA3; Wed, 20 May 2020 21:12:12 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 558872166BA2 for ; Wed, 20 May 2020 21:12:10 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 64E0E80067A for ; Wed, 20 May 2020 21:12:10 +0000 (UTC) Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-99-hKYgnWCcNJaWxQEmr0oq4Q-1; Wed, 20 May 2020 17:12:08 -0400 Received: by mail-qt1-f194.google.com with SMTP id d7so3781810qtn.11 for ; Wed, 20 May 2020 14:12:07 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009144; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EO9NydjIAYLyq/t6nIZozvEQJQm0gWEq0rGRIgFYvSY=; b=BEi0KIjdTMMQzI/w6DGsya6jQWhSU2qFUmgVSku4pUkge6uNvsAQTiU2u3yI5ZGMO5MNLX bmQ31yDSwvMXwc6T9dMb4/0WepxfKgBSBdbaRWMIjWT8bcqHNVs/WEqOfrIRaJLaUH3PlW iiFCrytX5vPpAmH9MJJKofwm5m7AvXE= X-MC-Unique: N17VEHvDPH2wyWc37tEJuQ-1 X-MC-Unique: hKYgnWCcNJaWxQEmr0oq4Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EO9NydjIAYLyq/t6nIZozvEQJQm0gWEq0rGRIgFYvSY=; b=lLbzGbVgXAWqMHcztOwM+liYHZOj1K1jGN77QPxgdfJj5HZ+sAReiGG7mxraG6typV 4PyitxjDWU9FfIpZ0eSBxhTWL5NDZuFEVekB2f0gDC/I21+g6y6RsoK0uJEaz1G3gXY3 JMdf+gK5QKdcJzQEegytaHiPBphdbd85c51SJjnrvFgfqBMx3YuPi/ssm3MYU/uyfqXm 6BuFqqx0nUwpObrHyVZKc6K727uybT4QYgtjSLTTGaC0m+Jrv0wP0GgMiKNsLrLQnDSK k1WI8AtICUKNnTBemCAaXZ91hYYgNPegrKYdkOCLSrZMZFu9S56gaIjnIIuZolcYckCZ 9fzQ== X-Gm-Message-State: AOAM530MheELpfqV/9dbe7YLrQGOPoFuwwTinsG0KP+p1qPIOE3ioskR ps/7ik1fC6GZnL25DOXbYax/aWsm X-Google-Smtp-Source: ABdhPJzt1HJ3OpzSFl7XwPOcVPMGf2wAW27ke4d5SNeJj7O2O6LuFW96h3vj1CLV8YJcK3cNgV5eXA== X-Received: by 2002:ac8:36c7:: with SMTP id b7mr7540144qtc.269.1590009127219; Wed, 20 May 2020 14:12:07 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 02/21] utils: PCI multifunction detection helpers Date: Wed, 20 May 2020 18:11:24 -0300 Message-Id: <20200520211143.2980117-3-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This patch introduces two helpers that will be used in the next patches, virPCIDeviceIsMultifunction() and virHostdevIsPCIMultifunctionDevice(). Signed-off-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 31 +++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 3 +++ src/libvirt_private.syms | 2 ++ src/util/virpci.c | 17 +++++++++++++++++ src/util/virpci.h | 2 ++ 5 files changed, 55 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c201fc901d..0d289fbab5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -32659,3 +32659,34 @@ virHostdevIsVFIODevice(const virDomainHostdevDef *= hostdev) hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= PCI && hostdev->source.subsys.u.pci.backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI= _BACKEND_VFIO; } + + +/** + * virHostdevIsPCIMultifunctionDevice + * @hostdev: host device to check + * + * Returns true if @hostdev is a PCI Multifunction device, false otherwise. + */ +bool +virHostdevIsPCIMultifunctionDevice(virDomainHostdevDefPtr hostdev) +{ + g_autoptr(virPCIDevice) pciDev =3D NULL; + virDomainHostdevSubsysPCIPtr pcisrc =3D &hostdev->source.subsys.u.pci; + + if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS || + hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PC= I) + return false; + + /* Libvirt should be able to perform all the operations in + * virPCIDeviceNew() even if it's running unprivileged, so if this + * fails, the device apparently doesn't currently exist on the host. + * Since we can't speculate, assume this device is not multifunction. + */ + pciDev =3D virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus, + pcisrc->addr.slot, pcisrc->addr.function); + + if (!pciDev) + return false; + + return virPCIDeviceIsMultifunction(pciDev); +} diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ddc75d8de2..e6d3e04109 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3840,3 +3840,6 @@ virHostdevIsMdevDevice(const virDomainHostdevDef *hos= tdev) bool virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev) ATTRIBUTE_NONNULL(1); +bool +virHostdevIsPCIMultifunctionDevice(virDomainHostdevDefPtr hostdev) + ATTRIBUTE_NONNULL(1); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fd04fcece3..c143264382 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -723,6 +723,7 @@ virDomainEventWatchdogNewFromObj; virDomainQemuMonitorEventNew; virDomainQemuMonitorEventStateRegisterID; virHostdevIsMdevDevice; +virHostdevIsPCIMultifunctionDevice; virHostdevIsSCSIDevice; virHostdevIsVFIODevice; =20 @@ -2794,6 +2795,7 @@ virPCIDeviceGetUnbindFromStub; virPCIDeviceGetUsedBy; virPCIDeviceHasPCIExpressLink; virPCIDeviceIsAssignable; +virPCIDeviceIsMultifunction; virPCIDeviceIsPCIExpress; virPCIDeviceListAdd; virPCIDeviceListAddCopy; diff --git a/src/util/virpci.c b/src/util/virpci.c index 6c7e6bbcab..82e86456c4 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2837,6 +2837,23 @@ int virPCIGetHeaderType(virPCIDevicePtr dev, int *hd= rType) } =20 =20 +bool +virPCIDeviceIsMultifunction(virPCIDevicePtr dev) +{ + int fd; + uint8_t type; + + if ((fd =3D virPCIDeviceConfigOpen(dev)) < 0) + return -1; + + type =3D virPCIDeviceRead8(dev, fd, PCI_HEADER_TYPE); + + virPCIDeviceConfigClose(dev, fd); + + return type & PCI_HEADER_TYPE_MULTI; +} + + void virPCIEDeviceInfoFree(virPCIEDeviceInfoPtr dev) { diff --git a/src/util/virpci.h b/src/util/virpci.h index f16d23614a..64a9109d9b 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -270,6 +270,8 @@ int virPCIDeviceGetLinkCapSta(virPCIDevicePtr dev, =20 int virPCIGetHeaderType(virPCIDevicePtr dev, int *hdrType); =20 +bool virPCIDeviceIsMultifunction(virPCIDevicePtr dev); + void virPCIEDeviceInfoFree(virPCIEDeviceInfoPtr dev); =20 ssize_t virPCIGetMdevTypes(const char *sysfspath, --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009158; cv=none; d=zohomail.com; s=zohoarc; b=St3MHzB6syng5I0L8FLH9UeXULgw3utV2PaPgJZy8YCaja40UR4WXlp2rmMBUbyH4DPHY43nfb9vzVi8d/DRp+DzSvqGTFAvphMZ+4RXyexIu+n+4SWj2wMSmwhsilClbo1vwvka/kyD89qlLFBTv9FrjQSTPmuR1QDKUOjF3Ow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009158; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OwfOhI0MHIRadxqA+fjtZM+TsEyvsgIiwMsq7Kwudbg=; b=XZYk3Q8L7rylAwJ5gqaUFAYW0mvhmLfOflLtVX2AhUCBrmEaT0LDR88Aep+LuDya4upoNYwpPb4eILy4irgqNl+NiK+dG8M0lTAhGFFLOt9n4nbSC7Uoor4CAhRPdtKluIB8xupMLOifdj/iGsx3rlRRLcOhDEKMXVK97rebuvw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1590009158477755.5292746811172; Wed, 20 May 2020 14:12:38 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-46-rpc_U0-BPD2U0PQob5j_Ig-1; Wed, 20 May 2020 17:12:34 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0878487300F; Wed, 20 May 2020 21:12:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D98C64EEC3; Wed, 20 May 2020 21:12:27 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A9E64180BACF; Wed, 20 May 2020 21:12:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCEZP002031 for ; Wed, 20 May 2020 17:12:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id C35355AB85; Wed, 20 May 2020 21:12:14 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B8F3511317 for ; Wed, 20 May 2020 21:12:12 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BCA22185A78B for ; Wed, 20 May 2020 21:12:12 +0000 (UTC) Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-162-Y2BO2vtWPbyyI52NG3NEkg-1; Wed, 20 May 2020 17:12:10 -0400 Received: by mail-qt1-f193.google.com with SMTP id z18so3840794qto.2 for ; Wed, 20 May 2020 14:12:10 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009157; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=OwfOhI0MHIRadxqA+fjtZM+TsEyvsgIiwMsq7Kwudbg=; b=KUpLdlHzC2NdvCIFBB7PZsrHChnYNRKylqF1uZlJDrV06hRsmvL0f+/9HvlL1aOXRePyKO 9MVcpcTQ5AHaZE0QZuyfqCzH4Kj5G79nVo76Y/mO9yylHocB3G5sUSX8WMoIx8CO0MOTJQ mJrAQytUoWgJvUiyO3Bbz7/UTYeoO1w= X-MC-Unique: rpc_U0-BPD2U0PQob5j_Ig-1 X-MC-Unique: Y2BO2vtWPbyyI52NG3NEkg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OwfOhI0MHIRadxqA+fjtZM+TsEyvsgIiwMsq7Kwudbg=; b=F7jpME9uR2OUGNMPpqc19L1cxaXgmVBotpuViEvDkC0G8DxihW3VeakNA5+NPWHvwW KZcI5Gvw3/QcUwx4wYAAd+RXVaFFq9FNg9b31/eGI7XwVNwUhzcqeZ6OmvdFeaRjgu6p jFvOGdlIUuxdTHuqVVg259JEOa0jb47mSWa/QwCKaWIvLvNYzXhf/wjlZtQAUpKjExRr K1xG9ahdR7RStDzxuih8wriFyGH9K/CHUwG4/OZfXkYfVluWMWSKXHqaTuKRLwniuWi0 uNoATHiL8PedeuG2Ph+KzWUcymWJarsJG7yS8JijJoI43EV0DpSvmI88JQxdZpBZm1Wr sS9A== X-Gm-Message-State: AOAM5306z1uOHwMqrnJrVPmB3dAxv/yDekOhWB6t7J9ZDAqXbTrtN+Cv A7i5jpwgbG4nqXU9GxIfgo2zODSh X-Google-Smtp-Source: ABdhPJyylfLVPM4Jw1GexCckwm6rlfMLFO8EjEOho8wwnYahyQ4cjN06FPQ56FB0HzedamUdMR9XsA== X-Received: by 2002:ac8:7586:: with SMTP id s6mr6853908qtq.96.1590009129660; Wed, 20 May 2020 14:12:09 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 03/21] virhostdev: Introduce virHostdevPCIDevicesBelongToSameSlot Date: Wed, 20 May 2020 18:11:25 -0300 Message-Id: <20200520211143.2980117-4-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/virhostdev.c | 29 +++++++++++++++++++++++++++++ src/hypervisor/virhostdev.h | 2 ++ src/libvirt_private.syms | 1 + 3 files changed, 32 insertions(+) diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index 9017cc3be8..03e0c5b470 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -312,6 +312,35 @@ virHostdevIsVirtualFunction(virDomainHostdevDefPtr hos= tdev) } =20 =20 +bool +virHostdevPCIDevicesBelongToSameSlot(virDomainHostdevDefPtr dev1, + virDomainHostdevDefPtr dev2) +{ + virPCIDeviceAddressPtr devAddr1 =3D NULL, devAddr2 =3D NULL; + + if (!dev1 || !dev2) + return false; + + devAddr1 =3D &dev1->source.subsys.u.pci.addr; + devAddr2 =3D &dev2->source.subsys.u.pci.addr; + if ((devAddr1->domain !=3D devAddr2->domain) || + (devAddr1->bus !=3D devAddr2->bus) || + (devAddr1->slot !=3D devAddr2->slot) || + (virPCIDeviceAddressEqual(devAddr1, devAddr2))) { + return false; + } + + /* The Virtual Functions have multifunction false even though they hav= e same + * domain:bus:slot as the Physical function. They are to be treated + * like non-multifunction devices + */ + if (virHostdevIsVirtualFunction(dev1) || virHostdevIsVirtualFunction(d= ev2)) + return false; + + return true; +} + + static int virHostdevNetDevice(virDomainHostdevDefPtr hostdev, int pfNetDevIdx, diff --git a/src/hypervisor/virhostdev.h b/src/hypervisor/virhostdev.h index 811bda40ed..84515d83fd 100644 --- a/src/hypervisor/virhostdev.h +++ b/src/hypervisor/virhostdev.h @@ -202,6 +202,8 @@ int virHostdevPCINodeDeviceReAttach(virHostdevManagerPt= r mgr, int virHostdevPCINodeDeviceReset(virHostdevManagerPtr mgr, virPCIDevicePtr pci) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); +bool virHostdevPCIDevicesBelongToSameSlot(virDomainHostdevDefPtr dev1, + virDomainHostdevDefPtr dev2); =20 int virHostdevPrepareOneNVMeDevice(virHostdevManagerPtr hostdev_mgr, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c143264382..e74174ffbd 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -726,6 +726,7 @@ virHostdevIsMdevDevice; virHostdevIsPCIMultifunctionDevice; virHostdevIsSCSIDevice; virHostdevIsVFIODevice; +virHostdevPCIDevicesBelongToSameSlot; =20 =20 # conf/domain_nwfilter.h --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009162; cv=none; d=zohomail.com; s=zohoarc; b=FoRmltRpNXNtStVxoRejeRngU2/UREl4EwnrYTwOEBYLhBrD/pz1EDqQ3AfRJJ+vUu3TuwdHC/XY5kqc6uUrbzfKTEupA4DWH+S/VXfwn6D85RGfG/N/laHLgzEpx/YBGwqc/7RW6I50HqLFOm5f38b3nYVvgtEJ+00/Mh6Pk/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009162; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=d38x1/1Cl1Qccrx7vhQM4LXsQcfdwz0bmB42n9Lbh0Q=; b=fNxvHHu2TJBKCrn58BhyNKPS4H/BZbdhGALr0/21a4zCRHspQZ8eTrpYeDIXVl4EEzFzQy6aItsnEjkIuBV/lRyPt64MJIj6NBb7yaU/FaCP7FFdjkyqv+SaJvAvcJa2vI8R/IlN+6TdpmY4kXPdWcKokBGwVeqNKTc2ihg53AE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1590009162950971.235271170148; Wed, 20 May 2020 14:12:42 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-328-YKrne5LoPoeznRpLuIfYBA-1; Wed, 20 May 2020 17:12:37 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4DF483631B; Wed, 20 May 2020 21:12:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 286695D9CC; Wed, 20 May 2020 21:12:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E0E8A1809563; Wed, 20 May 2020 21:12:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCHA6002050 for ; Wed, 20 May 2020 17:12:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 779F410031E4; Wed, 20 May 2020 21:12:17 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 56D151007A45 for ; Wed, 20 May 2020 21:12:17 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B87CD811E7A for ; Wed, 20 May 2020 21:12:16 +0000 (UTC) Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-98-o3BVGmVvOQi6UNtsY1NDmw-1; Wed, 20 May 2020 17:12:13 -0400 Received: by mail-qk1-f196.google.com with SMTP id i14so5112459qka.10 for ; Wed, 20 May 2020 14:12:12 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009161; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=d38x1/1Cl1Qccrx7vhQM4LXsQcfdwz0bmB42n9Lbh0Q=; b=Reuu+jqv0+L2pFiXwe8cQiMqApuLEzqx/Pe0fms68/y01GUiv+r9O3U4sBlPlJPB9Lcu2s M2a7KzOenY7y820BU+LN7y/Rtr/ydQP+vc+YGYUEE09KwH5eahkQXI1MTwEoI9eoZayuSs NbdJPnzDz0H4AU/++5785VWqDPgVQ9U= X-MC-Unique: YKrne5LoPoeznRpLuIfYBA-1 X-MC-Unique: o3BVGmVvOQi6UNtsY1NDmw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=d38x1/1Cl1Qccrx7vhQM4LXsQcfdwz0bmB42n9Lbh0Q=; b=srytsSFGNHjPTKCtE2jvwnhB71l+C8qOKoMNCZRPXqKFRpaiz4JuP4aDUoaVdsFKe1 EjvZ7TMpoYOwA2qq9FAMRcpiPLMwdTxbW5TSy3Of0x/VIlLBm29cbfJmZmH/ptSrtNIG E2otiy69/XHvEeB9CX01k6akRW14Hv6eMQmlmI1LWnINsHcZ56k4t1ZLXS3kF9ymFIve jGp86iQYRCIJzrN8ebygnAdBv7AN/Jktl5IHJfChVJu5V7SAurkEVX0u7Afx0L1j+8eF /+8qQeVu6YOqq9Ac04sqOB0ZYkgm1sNo3vaUdv8uWnpthvrOAUo+CFCn+GJC9Kea0vl6 Sutg== X-Gm-Message-State: AOAM533qAU2+KxbdWswZrM4fSOy6m8+NW+UJiqOSTysv8LrR/NhqEYvl vtzlGeVibr7oJrqJ2LOKule5DHiH X-Google-Smtp-Source: ABdhPJyF0e4cbB0GJFb4yApmTBTyX/f/7nfcuTzGkrOJXt9tj8ZCmiHgCx8lOYhI6DKemXjKXTrIeQ== X-Received: by 2002:a37:9dc2:: with SMTP id g185mr4030952qke.102.1590009131912; Wed, 20 May 2020 14:12:11 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 04/21] qemu: address: Enable auto addressing multifunction cards Date: Wed, 20 May 2020 18:11:26 -0300 Message-Id: <20200520211143.2980117-5-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat For existing domains using the primary function alone of a multifunction card, the card is still treated as a multifunction card. This is done to prevent hotplug of other functions when the primary function is already hotplugged. If the secondary functions are part of the xml without the primary function being part of the xml, this has never been supported. So, Libvirt doesn't consider this either as a multifunction card. Since we're now checking PCI headers via virHostdevIsPCIMultifunctionDevice(), changes in virpcitestdata files were required to allow the test suit to recognize the 0005:90:01.N test device as multifunction. Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_domain.h | 11 ++ src/qemu/qemu_domain_address.c | 150 +++++++++++++++++- tests/qemuhotplugtest.c | 1 + .../hostdev-pci-address-unassigned.args | 9 +- .../hostdev-pci-multifunction.args | 18 ++- .../hostdev-pci-multifunction.xml | 8 +- .../qemuxml2argvdata/pseries-hostdevs-1.args | 5 +- .../qemuxml2argvdata/pseries-hostdevs-3.args | 5 +- tests/qemuxml2argvtest.c | 6 +- .../hostdev-pci-address-unassigned.xml | 8 +- .../hostdev-pci-multifunction.xml | 24 +-- .../qemuxml2xmloutdata/pseries-hostdevs-1.xml | 4 +- .../qemuxml2xmloutdata/pseries-hostdevs-3.xml | 4 +- tests/virpcitestdata/0005-90-01.1.config | Bin 256 -> 256 bytes tests/virpcitestdata/0005-90-01.2.config | Bin 256 -> 256 bytes tests/virpcitestdata/0005-90-01.3.config | Bin 0 -> 256 bytes 16 files changed, 206 insertions(+), 47 deletions(-) create mode 100644 tests/virpcitestdata/0005-90-01.3.config diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 41d3f1561d..b601d52126 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -636,6 +636,17 @@ struct _qemuDomainSaveCookie { =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuDomainSaveCookie, virObjectUnref); =20 +typedef struct _qemuDomainPCIHostdevdata qemuDomainPCIHostdevdata; +typedef qemuDomainPCIHostdevdata *qemuDomainPCIHostdevDataPtr; +struct _qemuDomainPCIHostdevdata { + const virDomainDef *def; + virDomainPCIAddressSetPtr addrs; + virDomainHostdevDefPtr device; +}; + +typedef int (*virDomainPCIHostdevCallback)(qemuDomainPCIHostdevDataPtr dat= a, + virDomainHostdevDefPtr hostdev); + typedef struct _qemuDomainXmlNsDef qemuDomainXmlNsDef; typedef qemuDomainXmlNsDef *qemuDomainXmlNsDefPtr; struct _qemuDomainXmlNsDef { diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index f86c85eaa9..f431f4bb15 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1420,11 +1420,136 @@ qemuDomainSetupIsolationGroups(virDomainDefPtr def) } =20 =20 +#define PCI_MAX_BRIDGE_NUMBER 0xff +#define PCI_MAX_DEVICES 32 + + +/** + * qemuDomainPCIHostDevicesIter: + * @data - The data->device is the one which is called-back with for + * each hostdev + * cb() - callback to be called for each hostdev + * Return : + * If the callback for any of the hostdev fails, the Iter returns + * with the return value for that callback. + * Zero on success. + */ +static +int qemuDomainPCIHostDevicesIter(qemuDomainPCIHostdevDataPtr data, + virDomainPCIHostdevCallback cb) +{ + size_t i; + int ret =3D -1; + + /* Iterate through the PCI Hostdevices, the Mdev source is of type + * UUID, so skip that. */ + for (i =3D 0; i < data->def->nhostdevs; i++) { + virDomainHostdevSubsysPtr subsys =3D &data->def->hostdevs[i]->sour= ce.subsys; + virDomainHostdevDefPtr hostdev =3D data->def->hostdevs[i]; + if (data->device =3D=3D hostdev) + continue; + if (data->def->hostdevs[i]->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBS= YS) + continue; + if (subsys->type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI && + subsys->type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST && + (subsys->type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV && + subsys->u.mdev.model =3D=3D VIR_MDEV_MODEL_TYPE_VFIO_PCI)) { + continue; + } + + if ((ret =3D cb(data, hostdev)) !=3D 0) + return ret; + } + + return 0; +} + + + +static int +qemuDomainFindNextAggregationSlotIdxIter(virDomainDefPtr def G_GNUC_UNUSED, + virDomainDeviceDefPtr dev G_GNUC_= UNUSED, + virDomainDeviceInfoPtr info, + void *opaque) +{ + int *aggregationSlotIdx =3D opaque; + + if (info && info->aggregateSlotIdx =3D=3D *aggregationSlotIdx) + return -1; + + return 0; +} + + +static unsigned int +qemuDomainFindNextSlotAggregationIdx(virDomainDefPtr def) +{ + int aggregateSlotIdx =3D 2; + + while (aggregateSlotIdx < PCI_MAX_BRIDGE_NUMBER * PCI_MAX_DEVICES && + virDomainDeviceInfoIterate(def, + qemuDomainFindNextAggregationSlotIdx= Iter, + &aggregateSlotIdx) < 0) { + aggregateSlotIdx++; + } + + return aggregateSlotIdx; +} + + +static int +qemuDomainDefHostdevGetSlotAggregateIdx(qemuDomainPCIHostdevDataPtr data, + virDomainHostdevDefPtr hostdev) +{ + if (data->device && + virHostdevPCIDevicesBelongToSameSlot(data->device, hostdev)) { + if (hostdev->info->aggregateSlotIdx > 0) + return hostdev->info->aggregateSlotIdx; + } + + return 0; +} + +/** + * qemuDomainDefDeviceFindSlotAggregateIdx: + * @def : domain def + * @dev : Find the slot aggregate for the device if other + * functions are already part of the def and have + * a slot aggreate idx assigned. + * Return: + * -1: if not assigned. + * 0: If the device is not a hostdev or not a + * multifunction device. + * >0: If assigned a value; + **/ +int +qemuDomainDefDeviceFindSlotAggregateIdx(virDomainDefPtr def, + virDomainDeviceDefPtr dev) +{ + int aggregateSlotIdx =3D 0; + virDomainHostdevDefPtr hostdev =3D dev->data.hostdev; + qemuDomainPCIHostdevdata temp =3D {def, NULL, hostdev}; + + /* Only PCI host devices are subject to isolation */ + if (!virHostdevIsPCIMultifunctionDevice(hostdev)) + return 0; + + aggregateSlotIdx =3D qemuDomainPCIHostDevicesIter(&temp, + qemuDomainDefHostdevGe= tSlotAggregateIdx); + + if (aggregateSlotIdx > 0) + return aggregateSlotIdx; + + return -1; +} + + void -qemuDomainSetDeviceSlotAggregateIdx(virDomainDefPtr def G_GNUC_UNUSED, +qemuDomainSetDeviceSlotAggregateIdx(virDomainDefPtr def, virDomainDeviceDefPtr dev) { virDomainDeviceInfoPtr info =3D virDomainDeviceGetInfo(dev); + int aggregateSlotIdx =3D 0; =20 if (!info) return; @@ -1437,6 +1562,12 @@ qemuDomainSetDeviceSlotAggregateIdx(virDomainDefPtr = def G_GNUC_UNUSED, cont->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT_PORT)= { info->aggregateSlotIdx =3D 1; } + } else if (dev->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV) { + aggregateSlotIdx =3D qemuDomainDefDeviceFindSlotAggregateIdx(def, = dev); + if (aggregateSlotIdx > 0) + info->aggregateSlotIdx =3D aggregateSlotIdx; + else if (aggregateSlotIdx < 0) + info->aggregateSlotIdx =3D qemuDomainFindNextSlotAggregationId= x(def); } =20 return; @@ -2379,10 +2510,12 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def, =20 /* Host PCI devices */ for (i =3D 0; i < def->nhostdevs; i++) { - virDomainHostdevSubsysPtr subsys =3D &def->hostdevs[i]->source.sub= sys; - if (!virDeviceInfoPCIAddressIsWanted(def->hostdevs[i]->info)) + int function =3D 0; + virDomainHostdevDefPtr hostdev =3D def->hostdevs[i]; + virDomainHostdevSubsysPtr subsys =3D &hostdev->source.subsys; + if (!virDeviceInfoPCIAddressIsWanted(hostdev->info)) continue; - if (def->hostdevs[i]->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) + if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) continue; if (subsys->type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI && subsys->type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST && @@ -2396,9 +2529,14 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED) continue; =20 - if (qemuDomainPCIAddressReserveNextAddr(addrs, - def->hostdevs[i]->info) < = 0) + if (hostdev->info->aggregateSlotIdx > 1) + function =3D hostdev->source.subsys.u.pci.addr.function; + + if (virDomainPCIAddressReserveNextAddr(addrs, hostdev->info, + hostdev->info->pciConnectFl= ags, + function) < 0) { return -1; + } } =20 /* memballoon. the qemu driver only accepts virtio memballoon devices = */ diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index ba3fc4d814..57f64d191c 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -89,6 +89,7 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt, virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_SPICE_FILE_XFER_DISABLE); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_PR_MANAGER_HELPER); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_SCSI_BLOCK); + virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY); =20 if (qemuTestCapsCacheInsert(driver.qemuCapsCache, priv->qemuCaps) < 0) return -1; diff --git a/tests/qemuxml2argvdata/hostdev-pci-address-unassigned.args b/t= ests/qemuxml2argvdata/hostdev-pci-address-unassigned.args index 42fae17444..8e031c0f1f 100644 --- a/tests/qemuxml2argvdata/hostdev-pci-address-unassigned.args +++ b/tests/qemuxml2argvdata/hostdev-pci-address-unassigned.args @@ -25,7 +25,8 @@ server,nowait \ -no-shutdown \ -no-acpi \ -usb \ --device vfio-pci,host=3D0005:90:01.0,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x3 \ --device vfio-pci,host=3D0005:90:01.2,id=3Dhostdev2,bus=3Dpci.0,addr=3D0x4 \ --device vfio-pci,host=3D0005:90:01.3,id=3Dhostdev3,bus=3Dpci.0,addr=3D0x5 \ --device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x6 +-device vfio-pci,host=3D0005:90:01.0,id=3Dhostdev0,bus=3Dpci.0,multifuncti= on=3Don,\ +addr=3D0x3 \ +-device vfio-pci,host=3D0005:90:01.2,id=3Dhostdev2,bus=3Dpci.0,addr=3D0x3.= 0x2 \ +-device vfio-pci,host=3D0005:90:01.3,id=3Dhostdev3,bus=3Dpci.0,addr=3D0x3.= 0x3 \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x4 diff --git a/tests/qemuxml2argvdata/hostdev-pci-multifunction.args b/tests/= qemuxml2argvdata/hostdev-pci-multifunction.args index d8690c010b..3bf3629d48 100644 --- a/tests/qemuxml2argvdata/hostdev-pci-multifunction.args +++ b/tests/qemuxml2argvdata/hostdev-pci-multifunction.args @@ -25,11 +25,13 @@ server,nowait \ -no-shutdown \ -no-acpi \ -usb \ --device vfio-pci,host=3D0005:90:01.0,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x3 \ --device vfio-pci,host=3D0001:01:00.1,id=3Dhostdev1,bus=3Dpci.0,addr=3D0x4 \ --device vfio-pci,host=3D0001:01:00.0,id=3Dhostdev2,bus=3Dpci.0,addr=3D0x5 \ --device vfio-pci,host=3D0005:90:01.2,id=3Dhostdev3,bus=3Dpci.0,addr=3D0x6 \ --device vfio-pci,host=3D0005:90:01.3,id=3Dhostdev4,bus=3Dpci.0,addr=3D0x7 \ --device vfio-pci,host=3D0000:06:12.1,id=3Dhostdev5,bus=3Dpci.0,addr=3D0x8 \ --device vfio-pci,host=3D0000:06:12.2,id=3Dhostdev6,bus=3Dpci.0,addr=3D0x9 \ --device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0xa +-device vfio-pci,host=3D0005:90:01.0,id=3Dhostdev0,bus=3Dpci.0,multifuncti= on=3Don,\ +addr=3D0x3 \ +-device vfio-pci,host=3D0005:90:01.2,id=3Dhostdev1,bus=3Dpci.0,addr=3D0x3.= 0x2 \ +-device vfio-pci,host=3D0005:90:01.3,id=3Dhostdev2,bus=3Dpci.0,addr=3D0x3.= 0x3 \ +-device vfio-pci,host=3D0001:01:00.1,id=3Dhostdev3,bus=3Dpci.0,addr=3D0x4.= 0x1 \ +-device vfio-pci,host=3D0001:01:00.0,id=3Dhostdev4,bus=3Dpci.0,multifuncti= on=3Don,\ +addr=3D0x4 \ +-device vfio-pci,host=3D0000:06:12.1,id=3Dhostdev5,bus=3Dpci.0,addr=3D0x5 \ +-device vfio-pci,host=3D0000:06:12.2,id=3Dhostdev6,bus=3Dpci.0,addr=3D0x6 \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x7 diff --git a/tests/qemuxml2argvdata/hostdev-pci-multifunction.xml b/tests/q= emuxml2argvdata/hostdev-pci-multifunction.xml index 06c889c64d..a0af6c5a90 100644 --- a/tests/qemuxml2argvdata/hostdev-pci-multifunction.xml +++ b/tests/qemuxml2argvdata/hostdev-pci-multifunction.xml @@ -22,25 +22,25 @@ -
+
-
+
-
+
-
+
diff --git a/tests/qemuxml2argvdata/pseries-hostdevs-1.args b/tests/qemuxml= 2argvdata/pseries-hostdevs-1.args index 51ec025dce..d745f5bae6 100644 --- a/tests/qemuxml2argvdata/pseries-hostdevs-1.args +++ b/tests/qemuxml2argvdata/pseries-hostdevs-1.args @@ -26,5 +26,6 @@ server,nowait \ -device spapr-pci-host-bridge,index=3D1,id=3Dpci.1 \ -device spapr-pci-host-bridge,index=3D2,id=3Dpci.2 \ -device vfio-pci,host=3D0005:90:01.0,id=3Dhostdev0,bus=3Dpci.1.0,addr=3D0x= 1 \ --device vfio-pci,host=3D0001:01:00.0,id=3Dhostdev1,bus=3Dpci.2.0,addr=3D0x= 1 \ --device vfio-pci,host=3D0001:01:00.1,id=3Dhostdev2,bus=3Dpci.2.0,addr=3D0x2 +-device vfio-pci,host=3D0001:01:00.0,id=3Dhostdev1,bus=3Dpci.2.0,multifunc= tion=3Don,\ +addr=3D0x1 \ +-device vfio-pci,host=3D0001:01:00.1,id=3Dhostdev2,bus=3Dpci.2.0,addr=3D0x= 1.0x1 diff --git a/tests/qemuxml2argvdata/pseries-hostdevs-3.args b/tests/qemuxml= 2argvdata/pseries-hostdevs-3.args index 5820140065..d29b01f4d8 100644 --- a/tests/qemuxml2argvdata/pseries-hostdevs-3.args +++ b/tests/qemuxml2argvdata/pseries-hostdevs-3.args @@ -25,5 +25,6 @@ server,nowait \ -no-shutdown \ -device spapr-pci-host-bridge,index=3D1,id=3Dpci.1 \ -device spapr-pci-host-bridge,index=3D2,id=3Dpci.2 \ --device vfio-pci,host=3D0001:01:00.0,id=3Dhostdev0,bus=3Dpci.2.0,addr=3D0x= 1 \ --device vfio-pci,host=3D0001:01:00.1,id=3Dhostdev1,bus=3Dpci.2.0,addr=3D0x2 +-device vfio-pci,host=3D0001:01:00.0,id=3Dhostdev0,bus=3Dpci.2.0,multifunc= tion=3Don,\ +addr=3D0x1 \ +-device vfio-pci,host=3D0001:01:00.1,id=3Dhostdev1,bus=3Dpci.2.0,addr=3D0x= 1.0x1 diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 4f613e8f1a..df11669cd5 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1442,7 +1442,8 @@ mymain(void) =20 DO_TEST("hostdev-pci-multifunction", QEMU_CAPS_KVM, - QEMU_CAPS_DEVICE_VFIO_PCI); + QEMU_CAPS_DEVICE_VFIO_PCI, + QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY); =20 DO_TEST("hostdev-pci-address-unassigned", QEMU_CAPS_KVM, @@ -2033,14 +2034,17 @@ mymain(void) QEMU_CAPS_VIRTIO_SCSI); DO_TEST("pseries-hostdevs-1", QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE, + X_QEMU_CAPS_PCI_MULTIFUNCTION, QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_DEVICE_VFIO_PCI); DO_TEST("pseries-hostdevs-2", QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE, + X_QEMU_CAPS_PCI_MULTIFUNCTION, QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_DEVICE_VFIO_PCI); DO_TEST("pseries-hostdevs-3", QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE, + X_QEMU_CAPS_PCI_MULTIFUNCTION, QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_DEVICE_VFIO_PCI); =20 diff --git a/tests/qemuxml2xmloutdata/hostdev-pci-address-unassigned.xml b/= tests/qemuxml2xmloutdata/hostdev-pci-address-unassigned.xml index 2341e8432b..d6c26c3252 100644 --- a/tests/qemuxml2xmloutdata/hostdev-pci-address-unassigned.xml +++ b/tests/qemuxml2xmloutdata/hostdev-pci-address-unassigned.xml @@ -28,7 +28,7 @@
-
+
@@ -42,17 +42,17 @@
-
+
-
+
-
+
diff --git a/tests/qemuxml2xmloutdata/hostdev-pci-multifunction.xml b/tests= /qemuxml2xmloutdata/hostdev-pci-multifunction.xml index 52ed86e305..c40b2130df 100644 --- a/tests/qemuxml2xmloutdata/hostdev-pci-multifunction.xml +++ b/tests/qemuxml2xmloutdata/hostdev-pci-multifunction.xml @@ -28,52 +28,52 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/tests/qemuxml2xmloutdata/pseries-hostdevs-1.xml b/tests/qemuxm= l2xmloutdata/pseries-hostdevs-1.xml index e77a060a38..c09588de9d 100644 --- a/tests/qemuxml2xmloutdata/pseries-hostdevs-1.xml +++ b/tests/qemuxml2xmloutdata/pseries-hostdevs-1.xml @@ -40,14 +40,14 @@
-
+
-
+
diff --git a/tests/qemuxml2xmloutdata/pseries-hostdevs-3.xml b/tests/qemuxm= l2xmloutdata/pseries-hostdevs-3.xml index f91959b805..f01adf6d25 100644 --- a/tests/qemuxml2xmloutdata/pseries-hostdevs-3.xml +++ b/tests/qemuxml2xmloutdata/pseries-hostdevs-3.xml @@ -32,14 +32,14 @@
-
+
-
+
diff --git a/tests/virpcitestdata/0005-90-01.1.config b/tests/virpcitestdat= a/0005-90-01.1.config index beee76534041a7020c08ae9ac03d9a349c6ea12e..a60599bd342d3ebcdc7b8367ca3= 6ad337f602fde 100644 GIT binary patch delta 44 ycmZo*YG4vE7BFRCV-R3+7GUOK;Amg~f~JXq5)*X<85t+qEn;Cc-jFjfPzC^<7YL>R delta 39 ucmZo*YG4vE7BFRCV-R3+7GUOK;9y{25MXGU7$`AON05CJ=3D!Q7z5RUfCHEW5{!&mj0{Y5Fz#TaS&cX3;ByxM DCDjDB literal 256 zcmXpOc)-BMAi%_;z|6zo!oa|wz|aIFu>xbDS`csmlR$!5K#7rosSd`)Mk^@TV-u#E T7_0Gy9FS#<5E~CbCCJ=3D!Q7z5RUfCHEW5{!&mj0{Y5Fz#TaS&cX3;ByxM DCDjDB literal 0 HcmV?d00001 --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009154; cv=none; d=zohomail.com; s=zohoarc; b=NIhX05rk1yl3bZwdU6vkYG8Wx2Qo3Qga20+/aHWE3q/Jn2FJFM9/BEol81vQJXsOAd+c5YbqxGHZRR2jv54CiNKVS7yi30gTdPNOMWPcGs7XPDVcgRSMCL7QRMqhvpRTEHKW3ZbHNPfi7nA5/qHe1gBeKW+q5B3zQiWKQ8OiiTw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009154; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wlmAsbYOSMGS7S/xQLFAQVmqiawUbNmgnHkR4NC/UUc=; b=QkLLxA5tKIZk3an9Adi8C2XSGSl3UhVmlB8+srPbYqMGcTbkFzk03CYHyY5wJ+/Tq3GD9z8ISjhS3UZBV/6iWt/Uvc9h909aXHtDyaGZBayoRX77V/6Px35e2J/fiohm1AB09Wn7hxPOFfxtz/3IVrg8qMFT0j2ClQgrckfqz3g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1590009154982895.8999776839999; Wed, 20 May 2020 14:12:34 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-28-EcTcmLu2PIucE4N6t-h2LA-1; Wed, 20 May 2020 17:12:30 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B30DF1005512; Wed, 20 May 2020 21:12:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 912D860CC0; Wed, 20 May 2020 21:12:23 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CDFE61809563; Wed, 20 May 2020 21:12:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCHd0002049 for ; Wed, 20 May 2020 17:12:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5CE1B5AB7A; Wed, 20 May 2020 21:12:17 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4031E5AB85 for ; Wed, 20 May 2020 21:12:17 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0FFD08ECB1A for ; Wed, 20 May 2020 21:12:17 +0000 (UTC) Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-59-x2f4S4_OPn-JR0rih1bZ7Q-1; Wed, 20 May 2020 17:12:14 -0400 Received: by mail-qk1-f196.google.com with SMTP id s1so5133166qkf.9 for ; Wed, 20 May 2020 14:12:14 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009153; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=wlmAsbYOSMGS7S/xQLFAQVmqiawUbNmgnHkR4NC/UUc=; b=Vw9ehoQFD8rg+Zw2jEf/SMx32bL4+qWpR4ofMfg2jKEj07Y2NZ6ga723MpifwtVtj5o9m0 orN+mVDKrpCeWuJSvGhdmbZ3YcTo7T2JeE4B0PsFy6PFpOpJW1ivpQPwAywZCfmg0svCCU oZcpY0miV1AzN+6KV4ymE/PtTDDfmKE= X-MC-Unique: EcTcmLu2PIucE4N6t-h2LA-1 X-MC-Unique: x2f4S4_OPn-JR0rih1bZ7Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wlmAsbYOSMGS7S/xQLFAQVmqiawUbNmgnHkR4NC/UUc=; b=Oj60GA6KUnuEdNntudJJuisrT5z9NEr+tgg95rjUUZ6SGhBLdxV2DzxioqtLeJeyyg /QpCfzXS9xQkTuso6kt0wQHrbadopR8S5jpMbJUpiKModdTzoUxePYSwDEomEyoYws2E uuX3j416SDBd61XGYe+pK10xchZfLcn3vpDHUteFEhvaIyWFz5WpLIA/W+MWstlpJF4n UOzCmJ/kzIK+vyh+H5GJm08FB+ydmoDJwywi+cs2CspZy4b1EmDa9twHb+pu2IBVJlVi QioWHhgGoNCJ+d74WK+Qlleh260dfN4PwTCbnIg9fgzbJz8YtLC/pwev9RvbkNyW0vaV sUXw== X-Gm-Message-State: AOAM532HMCmJPWMM2sqzr/ojhLSNgmFixjFcVgNvXjJbPK+RtXXmFJg+ pK+znXYAhVALblUYDWeDGw5ISoO+ X-Google-Smtp-Source: ABdhPJy2WpxFQ8k0aRR614tXP9y8jpLDtNdEFSlKBwLj7rq+avlvhfO+2pbLHR9ORdVSaTu7qV2V8Q== X-Received: by 2002:a37:7904:: with SMTP id u4mr6785666qkc.297.1590009133951; Wed, 20 May 2020 14:12:13 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 05/21] conf: qemu: validate multifunction hostdevice domain configs Date: Wed, 20 May 2020 18:11:27 -0300 Message-Id: <20200520211143.2980117-6-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat It is invalid to have secondary functions without the primary functions part of the domain. Prevents new domain define, but existing ones would not vanish. Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_domain_address.c | 1 - src/qemu/qemu_domain_address.h | 4 ++ src/qemu/qemu_validate.c | 56 +++++++++++++++++++ .../hostdev-pci-no-primary-function.xml | 23 ++++++++ .../hostdev-pci-validate.args | 30 ++++++++++ .../qemuxml2argvdata/hostdev-pci-validate.xml | 29 ++++++++++ tests/qemuxml2argvtest.c | 8 +++ 7 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/hostdev-pci-no-primary-function.= xml create mode 100644 tests/qemuxml2argvdata/hostdev-pci-validate.args create mode 100644 tests/qemuxml2argvdata/hostdev-pci-validate.xml diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index f431f4bb15..05ef4de100 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1434,7 +1434,6 @@ qemuDomainSetupIsolationGroups(virDomainDefPtr def) * with the return value for that callback. * Zero on success. */ -static int qemuDomainPCIHostDevicesIter(qemuDomainPCIHostdevDataPtr data, virDomainPCIHostdevCallback cb) { diff --git a/src/qemu/qemu_domain_address.h b/src/qemu/qemu_domain_address.h index 198f813595..8d51456f5b 100644 --- a/src/qemu/qemu_domain_address.h +++ b/src/qemu/qemu_domain_address.h @@ -25,6 +25,7 @@ #include "domain_conf.h" #include "qemu_conf.h" #include "qemu_capabilities.h" +#include "qemu_domain.h" =20 int qemuDomainGetSCSIControllerModel(const virDomainDef *def, const virDomainControllerDef *cont, @@ -57,6 +58,9 @@ void qemuDomainSetDeviceSlotAggregateIdx(virDomainDefPtr def, virDomainDeviceDefPtr dev); =20 +int qemuDomainPCIHostDevicesIter(qemuDomainPCIHostdevDataPtr data, + virDomainPCIHostdevCallback cb); + int qemuDomainDefDeviceFindSlotAggregateIdx(virDomainDefPtr def, virDomainDeviceDefPtr dev); diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 584d1375b8..956e3daf7d 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -762,6 +762,59 @@ qemuValidateDefGetVcpuHotplugGranularity(const virDoma= inDef *def) } =20 =20 +static int +qemuValidatePCIHostdevIsPrimaryFunction(qemuDomainPCIHostdevDataPtr data, + virDomainHostdevDefPtr hostdev) +{ + if (!data->device || !hostdev) + return 0; + + if ((hostdev->source.subsys.u.pci.addr.function =3D=3D 0) && + (virHostdevPCIDevicesBelongToSameSlot(data->device, hostdev))) + return 1; + + return 0; +} + + +static int qemuValidateDomainDefPCIMultifunctionHostdev(qemuDomainPCIHostd= evDataPtr data, + virDomainHostdevDe= fPtr hostdev) +{ + qemuDomainPCIHostdevdata hostdevIterData =3D {data->def, NULL, hostdev= }; + + if (!virHostdevIsPCIMultifunctionDevice(hostdev) || + hostdev->source.subsys.u.pci.addr.function =3D=3D 0) + return 0; + + /* If the device is non-zero function but its Primary function is not + * part of the domain, error out. + */ + if (!qemuDomainPCIHostDevicesIter(&hostdevIterData, + qemuValidatePCIHostdevIsPrimaryFunct= ion)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Secondary functions of a PCI multifunction card " + "cannot be assigned to a domain without the " + "Primary function.")); + return -1; + } + + return 0; +} + + +static int qemuValidateDomainDefPCIHostdevs(const virDomainDef *def) +{ + qemuDomainPCIHostdevdata hostdevdata =3D {def, NULL, NULL}; + + if (qemuDomainPCIHostDevicesIter(&hostdevdata, + qemuValidateDomainDefPCIMultifunction= Hostdev)) { + return -1; + } + + return 0; +} + + int qemuValidateDomainDef(const virDomainDef *def, void *opaque) @@ -966,6 +1019,9 @@ qemuValidateDomainDef(const virDomainDef *def, if (qemuValidateDomainDefConsole(def, qemuCaps) < 0) return -1; =20 + if (qemuValidateDomainDefPCIHostdevs(def) < 0) + return -1; + if (cfg->vncTLS && cfg->vncTLSx509secretUUID && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_TLS_CREDS_X509)) { for (i =3D 0; i < def->ngraphics; i++) { diff --git a/tests/qemuxml2argvdata/hostdev-pci-no-primary-function.xml b/t= ests/qemuxml2argvdata/hostdev-pci-no-primary-function.xml new file mode 100644 index 0000000000..9cd844bbe7 --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-pci-no-primary-function.xml @@ -0,0 +1,23 @@ + + delete + 583a8e8e-f0ce-4f53-89ab-092862148b25 + 262144 + 4 + + hvm + + + /usr/bin/qemu-system-x86_64 + + + + + + + + +
+ + + + diff --git a/tests/qemuxml2argvdata/hostdev-pci-validate.args b/tests/qemux= ml2argvdata/hostdev-pci-validate.args new file mode 100644 index 0000000000..2a8508991e --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-pci-validate.args @@ -0,0 +1,30 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-delete \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-delete/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-delete/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/domain--1-delete/.config \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-x86_64 \ +-name delete \ +-S \ +-machine pc,accel=3Dkvm,usb=3Doff,dump-guest-core=3Doff \ +-m 256 \ +-realtime mlock=3Doff \ +-smp 4,sockets=3D4,cores=3D1,threads=3D1 \ +-uuid 583a8e8e-f0ce-4f53-89ab-092862148b25 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-delete/monitor.= sock,\ +server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-usb \ +-device vfio-pci,host=3D0000:06:12.1,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x3 \ +-device vfio-pci,host=3D0000:06:12.2,id=3Dhostdev1,bus=3Dpci.0,addr=3D0x4 \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x5 diff --git a/tests/qemuxml2argvdata/hostdev-pci-validate.xml b/tests/qemuxm= l2argvdata/hostdev-pci-validate.xml new file mode 100644 index 0000000000..54797c2dda --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-pci-validate.xml @@ -0,0 +1,29 @@ + + delete + 583a8e8e-f0ce-4f53-89ab-092862148b25 + 262144 + 4 + + hvm + + + /usr/bin/qemu-system-x86_64 + + + + + + + + +
+ + + + + +
+ + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index df11669cd5..84e8157e17 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1714,6 +1714,14 @@ mymain(void) QEMU_CAPS_DEVICE_VFIO_PCI); DO_TEST("hostdev-vfio-multidomain", QEMU_CAPS_DEVICE_VFIO_PCI); + DO_TEST("hostdev-pci-validate", + QEMU_CAPS_KVM, + X_QEMU_CAPS_NODEFCONFIG, X_QEMU_CAPS_HOST_PCI_MULTIDOMAIN, + QEMU_CAPS_DEVICE_VFIO_PCI); + DO_TEST_PARSE_ERROR("hostdev-pci-no-primary-function", + QEMU_CAPS_KVM, + X_QEMU_CAPS_NODEFCONFIG, X_QEMU_CAPS_HOST_PCI_MULTIDOMAIN, + QEMU_CAPS_DEVICE_VFIO_PCI); DO_TEST("hostdev-mdev-precreated", QEMU_CAPS_DEVICE_VFIO_PCI); DO_TEST_PARSE_ERROR("hostdev-mdev-src-address-invalid", --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009159; cv=none; d=zohomail.com; s=zohoarc; b=TlupgUTZnLYRNNelp37snYkff3H6VwAOWb0hNJFTlmhAWi7w//sMfaP1Yz0MVw3+V7vIIkhDOgs5NTzFCtlQjxyzr9HMHri5aAhO2IweVAa6OAPOziLuhCD0Y+N4i+ckINkRa1Rri9PrjhxsJ+FroQwUK1TVJYtZQupVOjfNpz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009159; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qEpTkn1ZFz7YwGnqpAwyChnVE6OXFw4Qa66MfP1Jsas=; b=XixdlymEY04GnYLyuouQwi1j9tdiSQ5ZZiPhBI+B2sdnmoPzZlaZWP/+BlmzhsAWU3PutHZ+3PNCL/w0/DykuxyZ33/WRXRuymFYp72Z4RHE4e7GE8Ky2nkwnR/1MYIZpPiG6lKtpUNc2iQ6buvMaad91TDsyjtZlc/f4Tdn3Y4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1590009159689814.2925767612559; Wed, 20 May 2020 14:12:39 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-403-g96b8XLhP8Ow9wsx3owl_g-1; Wed, 20 May 2020 17:12:36 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 60E1F83DC10; Wed, 20 May 2020 21:12:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F5C179597; Wed, 20 May 2020 21:12:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0CE191809557; Wed, 20 May 2020 21:12:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCLk7002070 for ; Wed, 20 May 2020 17:12:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id A14B45AB85; Wed, 20 May 2020 21:12:21 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8F19811317 for ; Wed, 20 May 2020 21:12:21 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A87738316F2 for ; Wed, 20 May 2020 21:12:20 +0000 (UTC) Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-341-3GQVv4rBNbqwBQpRQRZowA-1; Wed, 20 May 2020 17:12:17 -0400 Received: by mail-qt1-f193.google.com with SMTP id n22so3766802qtv.12 for ; Wed, 20 May 2020 14:12:16 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009158; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=qEpTkn1ZFz7YwGnqpAwyChnVE6OXFw4Qa66MfP1Jsas=; b=GZ6O1kKgG4eAh0oqBrrjnikX4TSX/TLGv9gFm0g380zYGwtM1lRZpjrHS5h3e/xz70Mk4Z ev+5AleLIDCb0XE0P2J6/nOPcobiT78saRXDFH5R2L2NQQOVQXmq6i8wqQkdc5WOgXVy6h blxTMCwI/97bA5yqpIHh1mrvNsfVitA= X-MC-Unique: g96b8XLhP8Ow9wsx3owl_g-1 X-MC-Unique: 3GQVv4rBNbqwBQpRQRZowA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qEpTkn1ZFz7YwGnqpAwyChnVE6OXFw4Qa66MfP1Jsas=; b=Wt4gAzcaLVb3qHPB6UYx3XgJ2kfLgOdwFRqBRoEvt/eL/XXE7t2eMLXaLOuU+hREb/ UcdF9lAf64bAxS1pvsBd+FjqIm2waoWb4yOFS22JNfsOdV7xdZY6QJ+KV1jCXmH237Gb hd9QjmpZJw26AGXdzhGxd8w617HY2WAfrSoH6gcF0U2iHtYgwTW62cOR27uYenHWS/a3 xqvi49icyH85xpOSPnin56RjnSfatTwtS6v6ZdFFBFMYlnOuduAaJIkrkLp4b3O3cOZ3 UJsUEXR2qTqzegp7ecGo0HOUJgqodlfFb+8qgpdYpFsfIbnHg6EehtFWEp/DpXZatbf6 yGFA== X-Gm-Message-State: AOAM530VhB2I5GUbEWrO2JDaNajUoaWOCE5TF1Uyl3cLGxdAlnPqWmpJ 5wwfasqCnNpv32HGx43zJnu4+1hd X-Google-Smtp-Source: ABdhPJy2mKMDz9lBk1sWD21S9rpYId7lx570NlJd+qKifOxviOtVARYcLVJSAUKBEB1h95zbyf/1+w== X-Received: by 2002:ac8:6f28:: with SMTP id i8mr7459663qtv.163.1590009136270; Wed, 20 May 2020 14:12:16 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 06/21] conf: Add helper to get active functions of a slot of domain Date: Wed, 20 May 2020 18:11:28 -0300 Message-Id: <20200520211143.2980117-7-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat In some cases it may be better to have a bitmap representing the state of individual functions rather than iterating the definition. The new helper creates a bitmap representing the state from the domain definition. Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 27 +++++++++++++++++++++++++++ src/conf/domain_conf.h | 3 +++ src/libvirt_private.syms | 1 + 3 files changed, 31 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0d289fbab5..fcd390ace4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -17315,6 +17315,33 @@ virDomainHostdevFind(virDomainDefPtr def, return *found ? i : -1; } =20 +#define PCI_MAX_SLOT_FUNCTIONS 8 +/** + * virDomainDefHostdevGetPCIOnlineFunctionMap: + * @def: domain definition + * @aggrSlotIdx: slot aggregation index + * Returns a bitmap representing state of individual functions of a slot. + */ +virBitmapPtr +virDomainDefHostdevGetPCIOnlineFunctionMap(virDomainDefPtr def, + int aggrSlotIdx) +{ + size_t i; + virBitmapPtr ret =3D NULL; + + if (!(ret =3D virBitmapNew(PCI_MAX_SLOT_FUNCTIONS))) + return NULL; + + for (i =3D 0; i < def->nhostdevs; i++) { + size_t function =3D def->hostdevs[i]->source.subsys.u.pci.addr.fun= ction; + + if (def->hostdevs[i]->info->aggregateSlotIdx =3D=3D aggrSlotIdx) + ignore_value(virBitmapSetBit(ret, function)); + } + + return ret; +} + static bool virDomainDiskControllerMatch(int controller_type, int disk_bus) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e6d3e04109..634865842a 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3315,6 +3315,9 @@ virDomainHostdevDefPtr virDomainHostdevRemove(virDomainDefPtr def, size_t i); int virDomainHostdevFind(virDomainDefPtr def, virDomainHostdevDefPtr match, virDomainHostdevDefPtr *found); +virBitmapPtr virDomainDefHostdevGetPCIOnlineFunctionMap(virDomainDefPtr de= f, + int aggrSlotIdx); + =20 virDomainGraphicsListenDefPtr virDomainGraphicsGetListen(virDomainGraphicsDefPtr def, size_t i); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index e74174ffbd..323291367f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -323,6 +323,7 @@ virDomainDefHasOldStyleUEFI; virDomainDefHasUSB; virDomainDefHasVcpusOffline; virDomainDefHasVFIOHostdev; +virDomainDefHostdevGetPCIOnlineFunctionMap; virDomainDefLifecycleActionAllowed; virDomainDefMaybeAddController; virDomainDefMaybeAddInput; --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009160; cv=none; d=zohomail.com; s=zohoarc; b=AZtphb1Lu/70WZsAGii+AgEHwsXSpcgqfqtjoEjquUq5uYW/AzR9k7VDpHcagxUE3+URsQqFzwAXQNCMb1ni/bvrknXt0gHfCZmkukeAzBwE00fwJ6zf6YHD3IYqEV2zN2ksYs1TZlgiqpM3JUBxAWMC10qSVvILh/Z/Ft/hoPA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009160; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YoFaFMCbZPYEQe7eVujJUMXB+UUIv/9Y+Hb0J78OMt4=; b=CatWmEM2fNZh340fyGPy58CnpwFmixtC+79fvcpqRvDoX41lR76mBoEuuujpbFZD3bcH62JAifbCWyR6zWdudqeUWrP27ebTqBebLS/nmll1yUKO0GSU8slHJ+h+nOEo6114Qo6hHXjLxC/DqbsAQ/Mk50ZyvyzwsWcOW+3kv4E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1590009160716642.8574989991479; Wed, 20 May 2020 14:12:40 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-156-K0Nr6jrTMhyDjbTo8G7ZRA-1; Wed, 20 May 2020 17:12:34 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 203DD1855A0B; Wed, 20 May 2020 21:12:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F41AA5D9CC; Wed, 20 May 2020 21:12:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C974054D00; Wed, 20 May 2020 21:12:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCMwE002076 for ; Wed, 20 May 2020 17:12:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id B9D6B5AB7A; Wed, 20 May 2020 21:12:22 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A456263537 for ; Wed, 20 May 2020 21:12:22 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A5298007D0 for ; Wed, 20 May 2020 21:12:21 +0000 (UTC) Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-10-NOsT237KPpi5ice9ilmQ2g-1; Wed, 20 May 2020 17:12:19 -0400 Received: by mail-qt1-f193.google.com with SMTP id d7so3782177qtn.11 for ; Wed, 20 May 2020 14:12:18 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009159; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=YoFaFMCbZPYEQe7eVujJUMXB+UUIv/9Y+Hb0J78OMt4=; b=ZUbNmkO7CTG6QzML9/czM9BJcHQl8fnqJVUupwyBYDrNmcmdyN4sIeKS4yGU9HLxpyB5JS HlY/GBaeTy3xeQE7JSujLvDYAPZaRBSNh0A6SToU81EN/cPlP3e9jrfCI3Z6svQNiKW977 tnrr92L0vmu3HWHJd85nwiDenxmGbF0= X-MC-Unique: K0Nr6jrTMhyDjbTo8G7ZRA-1 X-MC-Unique: NOsT237KPpi5ice9ilmQ2g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YoFaFMCbZPYEQe7eVujJUMXB+UUIv/9Y+Hb0J78OMt4=; b=b/Cp+SsHPpHZkthVY46Ynw9k03G2Lb6Pdbj2Er2LO4Vn3gJgugVBsrzdO/2PuQgKIx As2x/GenLI0FCfqZRZ+r2hUwb8KOh6gT45QZ84iSEkz8uTcyynWkc9nGexvWc9QokEU/ 7R1hBJHNbjae2PVbF1YmWtvWEUw50rkcbCD3qxPuq6d/WzgooE9ianX4fhaOKbZbCT48 7TdqCEnrXS3MaVQOYNat4WJqYANaibEW/zPRYDLNtx+MA/iEbf2UoH69mh51igH6Isbc ZWBMkBCj3Vv+3EyK8L6VV2Bzi2ogYFY0eRwdU04Nymmd3iN+VwvOBBern8lB0xGxUWCK 2Umw== X-Gm-Message-State: AOAM530fZ6HK3op+frwzx1J1iD4IzBYGlNzzqtlNTS0WYpGf/VQAxVfG NUKPi1N0em9ZKK7IBeYRturBtyTn X-Google-Smtp-Source: ABdhPJwweYll5Hcrut8G94b1oXVMbTCw4mAZkEOy3MUS6wznMiOSccvq4xNM92wCJt8oHb68EuLtog== X-Received: by 2002:aed:2ce4:: with SMTP id g91mr7636131qtd.22.1590009138294; Wed, 20 May 2020 14:12:18 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 07/21] qemu: hostdev: Move the hostdev preparation to a separate function Date: Wed, 20 May 2020 18:11:29 -0300 Message-Id: <20200520211143.2980117-8-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat No functional change. Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_hotplug.c | 80 ++++++++++++++++++++++++++--------------- src/qemu/qemu_hotplug.h | 5 +++ 2 files changed, 56 insertions(+), 29 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 3571dead89..172747b2e2 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1014,6 +1014,55 @@ qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPt= r driver, } =20 =20 +int qemuDomainAttachPCIHostDevicePrepare(virQEMUDriverPtr driver, + virDomainDefPtr def, + virDomainHostdevDefPtr hostdev, + virQEMUCapsPtr qemuCaps) +{ + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + unsigned int flags =3D 0; + int backend; + + if (!cfg->relaxedACS) + flags |=3D VIR_HOSTDEV_STRICT_ACS_CHECK; + if (qemuHostdevPreparePCIDevices(driver, def->name, def->uuid, + &hostdev, 1, qemuCaps, flags) < 0) + return -1; + + /* this could have been changed by qemuHostdevPreparePCIDevices */ + backend =3D hostdev->source.subsys.u.pci.backend; + + switch ((virDomainHostdevSubsysPCIBackendType) backend) { + case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO: + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("VFIO PCI device assignment is not " + "supported by this version of qemu")); + goto error; + } + break; + + case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT: + case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM: + break; + + case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN: + case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_LAST: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("QEMU does not support device assignment mode '%s= '"), + virDomainHostdevSubsysPCIBackendTypeToString(backen= d)); + goto error; + break; + } + + return 0; + + error: + qemuHostdevReAttachPCIDevices(driver, def->name, &hostdev, 1); + return -1; +} + + static int qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -1557,44 +1606,17 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driv= er, bool teardowndevice =3D false; bool teardownmemlock =3D false; int backend; - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); - unsigned int flags =3D 0; =20 if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0) return -1; =20 - if (!cfg->relaxedACS) - flags |=3D VIR_HOSTDEV_STRICT_ACS_CHECK; - if (qemuHostdevPreparePCIDevices(driver, vm->def->name, vm->def->uuid, - &hostdev, 1, priv->qemuCaps, flags) <= 0) + if (qemuDomainAttachPCIHostDevicePrepare(driver, vm->def, + hostdev, priv->qemuCaps) < 0) return -1; =20 /* this could have been changed by qemuHostdevPreparePCIDevices */ backend =3D hostdev->source.subsys.u.pci.backend; =20 - switch ((virDomainHostdevSubsysPCIBackendType)backend) { - case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO: - if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("VFIO PCI device assignment is not " - "supported by this version of qemu")); - goto error; - } - break; - - case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT: - case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM: - break; - - case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN: - case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_LAST: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("QEMU does not support device assignment mode '%s= '"), - virDomainHostdevSubsysPCIBackendTypeToString(backen= d)); - goto error; - break; - } - if (qemuDomainAdjustMaxMemLockHostdev(vm, hostdev) < 0) goto error; teardownmemlock =3D true; diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 4a49e04a15..9df4a4e5f7 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -122,6 +122,11 @@ void qemuDomainRemoveVcpuAlias(virQEMUDriverPtr driver, virDomainObjPtr vm, const char *alias); =20 +int qemuDomainAttachPCIHostDevicePrepare(virQEMUDriverPtr driver, + virDomainDefPtr def, + virDomainHostdevDefPtr dev, + virQEMUCapsPtr qemuCaps); + int qemuDomainChrInsert(virDomainDefPtr vmdef, virDomainChrDefPtr chr); --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009166; cv=none; d=zohomail.com; s=zohoarc; b=ORLC+kgcX4i0krHCyb6fkBkAs0slgDCzFXvs6JAa9YnhX6fcJrJ4/5Je+5ghcXzLHf2SRNsnu5EZJP+SPgmcYNRN5shjPCBGejLaKigM3xTT1TdZo6guRXHq4uFgGC+bAumJTt6/P9LMxoClLwhbcUzY4Ae6IoCpGasAx2XFwUE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009166; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HZg+jNXn2hKagSTvB7tClGOq5bCtB0Aca+8y+NS++2A=; b=VcpByMLfmnGtwerTg4dE/OtpuLUTttFXLF53MFOzSHl4oht8FmLiDGLDOHE5QS1YBnInDijE6bQ//2HuD1QyAje2t5G7ckVTQl35VjPVssb6FJ/ObRDE55SPo0yE5N032KEts0+KH3YZ9rVND4zD6oEJ8ArLCHmE0XML7st5jyg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 159000916643970.60231665608433; Wed, 20 May 2020 14:12:46 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-361-vCGtjbsdNQioBc2-rEFFcA-1; Wed, 20 May 2020 17:12:40 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B3B6118A0765; Wed, 20 May 2020 21:12:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 952A15D9CC; Wed, 20 May 2020 21:12:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 67B711800433; Wed, 20 May 2020 21:12:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCOIA002086 for ; Wed, 20 May 2020 17:12:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5848A1000DA7; Wed, 20 May 2020 21:12:24 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5376A10D17BF for ; Wed, 20 May 2020 21:12:24 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2FE978A5E4C for ; Wed, 20 May 2020 21:12:24 +0000 (UTC) Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-71-SV6LTCSlNo-xPCPB_dTrbg-1; Wed, 20 May 2020 17:12:21 -0400 Received: by mail-qk1-f196.google.com with SMTP id s1so5133538qkf.9 for ; Wed, 20 May 2020 14:12:21 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009165; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HZg+jNXn2hKagSTvB7tClGOq5bCtB0Aca+8y+NS++2A=; b=aoW3Y5WUL7BuOxEkAfp053wQC9NIzLOrg4XR7S4baKqYxURIMylIhBNIMvGeAfTImEQ/N/ i+NePUXyvuS+XsYenZQmN19VRdYH77lK2m/E3asa9L2/W6Esw3bwIe2msUdMEMaDx/LaHo ZDQ9BrcyxzL6CfxVvsFCTEch3tHKBe4= X-MC-Unique: vCGtjbsdNQioBc2-rEFFcA-1 X-MC-Unique: SV6LTCSlNo-xPCPB_dTrbg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HZg+jNXn2hKagSTvB7tClGOq5bCtB0Aca+8y+NS++2A=; b=cqgWzWC4g1Ris1cK2NbUXgFhMx9OtXXFcZrMJFVRyMwQcH2yz1kGy/0UStaDlg1upe 394aTdKcWfCUW0vAK0YvE4I0+/HdmZyu7ZdUpeNJlGjci/Bwlj4HSz5IqFyz1DcXxVFr 1zsuj0LkbefBvneA/eQtqwygSxduR1B6LYiKnIJrfcOyPhScSoMWkOfGRxWQLcG08rtd smbkEzQKlsJPEq3w9YP9c6H/GXpUtwPYKn++qzNkTjtcsK/N6d1VEkRCOA0we92vTKW9 vT137ec08gOfJKH6HyodVOFEC36gzRvxgwcdGpwjtWdfIYjcM4zMeC1YMsUKUJRv3TuG VI0A== X-Gm-Message-State: AOAM533YYe2HfsFn5UP7n+6bbCo8kryO1Dv4hyYM73LVC6PuYn2q1d90 QOktnxX4qmnryHCZvDhNEbCz57ZY X-Google-Smtp-Source: ABdhPJzb2aGLJjv35No2YEw4ojXYMMZ7YUUHuyUF5GocW/ZRUiv1EnfWhRDsM1RCKnw7LQltEw2suw== X-Received: by 2002:ae9:e319:: with SMTP id v25mr6625678qkf.311.1590009140789; Wed, 20 May 2020 14:12:20 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 08/21] qemu: hotplug: Move the detach of PCI device to the beginning of live hotplug Date: Wed, 20 May 2020 18:11:30 -0300 Message-Id: <20200520211143.2980117-9-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat The hostdevices are the only devices which have dependencies outside of themselves such that, other functions of the PCI card should also have been detached from host driver before attempting the hotplug. This patch moves the detach to the beginning of the hotplug so that the following patch can detach all functions first before attempting to hotplug any. We don't need to move the detach for net devices using SRIOV as all SRIOV devices are single function devices and can be independently detached as usual. Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_hotplug.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 172747b2e2..d88a0922d4 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1222,6 +1222,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, g_autofree char *netdev_name =3D NULL; g_autoptr(virConnect) conn =3D NULL; virErrorPtr save_err =3D NULL; + virDomainHostdevDefPtr hostdev =3D NULL; =20 /* preallocate new slot for device */ if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets + 1) < 0) @@ -1252,9 +1253,18 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, * as a hostdev (the hostdev code will reach over into the * netdev-specific code as appropriate), then also added to * the nets list (see cleanup:) if successful. + * + * qemuDomainAttachHostDevice uses a connection to resolve + * a SCSI hostdev secret, which is not this case, so pass NULL. */ - ret =3D qemuDomainAttachHostDevice(driver, vm, - virDomainNetGetActualHostdev(net)= ); + hostdev =3D virDomainNetGetActualHostdev(net); + if (qemuDomainAttachPCIHostDevicePrepare(driver, vm->def, + hostdev, priv->qemuCaps) = < 0) + goto cleanup; + + if ((ret =3D qemuDomainAttachHostDevice(driver, vm, hostdev)) < 0) + qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev,= 1); + goto cleanup; } =20 @@ -1610,10 +1620,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr drive= r, if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0) return -1; =20 - if (qemuDomainAttachPCIHostDevicePrepare(driver, vm->def, - hostdev, priv->qemuCaps) < 0) - return -1; - /* this could have been changed by qemuHostdevPreparePCIDevices */ backend =3D hostdev->source.subsys.u.pci.backend; =20 @@ -1689,8 +1695,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver, if (releaseaddr) qemuDomainReleaseDeviceAddress(vm, info); =20 - qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1); - return -1; } =20 @@ -2929,6 +2933,8 @@ qemuDomainAttachHostDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; + if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("hotplug is not supported for hostdev mode '%s'"), @@ -2938,9 +2944,15 @@ qemuDomainAttachHostDevice(virQEMUDriverPtr driver, =20 switch (hostdev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: - if (qemuDomainAttachHostPCIDevice(driver, vm, - hostdev) < 0) + if (qemuDomainAttachPCIHostDevicePrepare(driver, vm->def, + hostdev, priv->qemuCaps) = < 0) return -1; + + if (qemuDomainAttachHostPCIDevice(driver, vm, hostdev) < 0) { + qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev,= 1); + return -1; + } + break; =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009165; cv=none; d=zohomail.com; s=zohoarc; b=DpRVV0j6uq4l6nx2ADKD2Cbhearafd/CIgj4xYpOFOBLRCIx6n4BYglvTUvSZdfMsv0g0q9643iaa65HmaxHMl9ZnzhPyKJVRmhDpueJd4Me2XC/oD9ZSUqYsUMpXT8JAtOl1+5Vu3DM0PR7aGi0EN+/mVU18BNeMVfe9Z8Rlu0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009165; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=O+CyqplIKBCRpfPd3Mhk9gTigKQmSePH+dBEL3sW+ok=; b=XOL7KWk9B5cFWJtRl5eYd1AQbMn3mwHXI1+9xkWC7GykrRfMJNpm0loVv9LUqodH8egcXXDMR86QMkmzM7COOfeH0ZikTRpeydgXEorjARwuB02DcS3YoViwE0Y4q3zc3eceC1HdwuZ0GnYw8HfCe1NcSQWPNN92xM/Wu0tE13Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1590009165367356.7628230757945; Wed, 20 May 2020 14:12:45 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-392-KRTKXTQPMOaqYh11qxExiA-1; Wed, 20 May 2020 17:12:41 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 09DC9835B45; Wed, 20 May 2020 21:12:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB6AA60C87; Wed, 20 May 2020 21:12:34 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id ABDC154D05; Wed, 20 May 2020 21:12:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCQFB002101 for ; Wed, 20 May 2020 17:12:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 890C22156A2E; Wed, 20 May 2020 21:12:26 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 755F62166BA3 for ; Wed, 20 May 2020 21:12:26 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3F8D78A5E4C for ; Wed, 20 May 2020 21:12:26 +0000 (UTC) Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-369-0HbLGBBLNC6o5C_BrhU_WA-1; Wed, 20 May 2020 17:12:23 -0400 Received: by mail-qt1-f193.google.com with SMTP id l1so3811988qtp.6 for ; Wed, 20 May 2020 14:12:23 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009164; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=O+CyqplIKBCRpfPd3Mhk9gTigKQmSePH+dBEL3sW+ok=; b=Puo4h9D7UWcsOyVq8vn4f6MjXzY2oNa0XV2alx9o1O91fJtgeyD3N19rtgsipNIjCYkMdB t1KIP0vMrdKdi69FYnkdQSzGyjFE8Bsd2Ymso3h2zTiZcp38ggXCpxounZLBP+6JgTwUld KM1XQxUVNRCCU/oERpi6vIJx2CLZgVI= X-MC-Unique: KRTKXTQPMOaqYh11qxExiA-1 X-MC-Unique: 0HbLGBBLNC6o5C_BrhU_WA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O+CyqplIKBCRpfPd3Mhk9gTigKQmSePH+dBEL3sW+ok=; b=n98VWAK7Bu29qgK0b9oBxpkCpjm5rdYBRIoIgplUeQyXtO77ohJU867728h4cAV3Is 35j/bVU3NcPKnbJbm4hOcRiq5s4jst4u7PzFvkCf01fNPzhMolI2d4ruxPKG+UhmBO14 gMn3Yu42TqBQQu07G2bInATImBOpDijgmf7VALlqpTazQJKVGX5oImrWl+DxtniLYAui V/NX4wfbyqKVNmqGeu6Ek4UU77qhcAOQY7bFM5iZ+t8fB2b8Z0vBeBaryaugSx4vKDgI f7uSPi9jCjthgFqrNnaTDeZTYBvYrjtf9/VnE8qRdioXMHEeuWCunIenVTLylM8bmnQT Sx9w== X-Gm-Message-State: AOAM532eni9avT7EhKrG1vG+5TwjBclKqCkLJQxrgRW13VAOUmice00P IMphvPFujHZIDeJFl93e1hJg85hf X-Google-Smtp-Source: ABdhPJzKbqvCrHMHnazhGE0YwpzLBiRW1/kbnPccvMVyCLQ4Jq6puyA37KChfi5lzJT0lqPgVya2cg== X-Received: by 2002:ac8:2db0:: with SMTP id p45mr7028200qta.354.1590009143033; Wed, 20 May 2020 14:12:23 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 09/21] qemu: hotplug: move assignment outside qemuDomainAttachHostPCIDevice Date: Wed, 20 May 2020 18:11:31 -0300 Message-Id: <20200520211143.2980117-10-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat No functional change. Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_hotplug.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index d88a0922d4..6991d7988c 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1605,12 +1605,9 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr drive= r, virDomainHostdevDefPtr hostdev) { qemuDomainObjPrivatePtr priv =3D vm->privateData; - virDomainDeviceDef dev =3D { VIR_DOMAIN_DEVICE_HOSTDEV, - { .hostdev =3D hostdev } }; virDomainDeviceInfoPtr info =3D hostdev->info; int ret; g_autofree char *devstr =3D NULL; - bool releaseaddr =3D false; bool teardowncgroup =3D false; bool teardownlabel =3D false; bool teardowndevice =3D false; @@ -1643,14 +1640,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr drive= r, if (qemuAssignDeviceHostdevAlias(vm->def, &info->alias, -1) < 0) goto error; =20 - if (qemuDomainIsPSeries(vm->def)) - /* Isolation groups are only relevant for pSeries guests */ - qemuDomainFillDeviceIsolationGroup(vm->def, &dev); - - if (qemuDomainEnsurePCIAddress(vm, &dev, driver) < 0) - goto error; - releaseaddr =3D true; - if (!virDomainObjIsActive(vm)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("guest unexpectedly quit during hotplug")); @@ -1692,9 +1681,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver, if (teardownmemlock && qemuDomainAdjustMaxMemLock(vm, false) < 0) VIR_WARN("Unable to reset maximum locked memory on hotplug fail"); =20 - if (releaseaddr) - qemuDomainReleaseDeviceAddress(vm, info); - return -1; } =20 @@ -2934,6 +2920,8 @@ qemuDomainAttachHostDevice(virQEMUDriverPtr driver, virDomainHostdevDefPtr hostdev) { qemuDomainObjPrivatePtr priv =3D vm->privateData; + virDomainDeviceDef dev =3D { VIR_DOMAIN_DEVICE_HOSTDEV, + { .hostdev =3D hostdev } }; =20 if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -2948,7 +2936,15 @@ qemuDomainAttachHostDevice(virQEMUDriverPtr driver, hostdev, priv->qemuCaps) = < 0) return -1; =20 + if (qemuDomainIsPSeries(vm->def)) + /* Isolation groups are only relevant for pSeries guests */ + qemuDomainFillDeviceIsolationGroup(vm->def, &dev); + + if (qemuDomainEnsurePCIAddress(vm, &dev, driver) < 0) + return -1; + if (qemuDomainAttachHostPCIDevice(driver, vm, hostdev) < 0) { + qemuDomainReleaseDeviceAddress(vm, hostdev->info); qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev,= 1); return -1; } --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009164; cv=none; d=zohomail.com; s=zohoarc; b=gNLHN88efjBQcGFTKkTgoe23PjyweD1KvhRMl7D9FeJ1LeMXdGMiF/rH7EHSJKQNRPsQ7WQdVGxwKYIp70WibuEMelVVFfWRQlMRbpNpkvMTc1KgtwV/ZYB5XVmUacQILwR+pn/L1SHZ3SdViPlP0XExRBvHvEMy5eO4CgUsIJM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009164; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cSXns3FCXVyGPdw/JuEyiJHDKK+ueQz1/I3DxE/3TkA=; b=CYD8gg3364oTaa1jAebYtlcfh3fpYSwod+Ehthbs1fWX0LezwMTBRSxRxelzIAdM06EcbF6XcVIlxQh6rnvffmzZkMu3mhrcY95Jz98ZnOdHHl0r41otKrKxwotaQljUAAxQMgRB8sgK52xU7hralMOOrz+/dBP/BVUQQdSRKes= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1590009164831982.7196344782188; Wed, 20 May 2020 14:12:44 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-51-oJgpJnO8Mu2IFKdfXyoLqQ-1; Wed, 20 May 2020 17:12:40 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D580835B40; Wed, 20 May 2020 21:12:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2E6865D9CC; Wed, 20 May 2020 21:12:34 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0079D180CB39; Wed, 20 May 2020 21:12:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCWZc002120 for ; Wed, 20 May 2020 17:12:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0309F10D17BE; Wed, 20 May 2020 21:12:32 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F2DB310031E4 for ; Wed, 20 May 2020 21:12:29 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1B6F6811768 for ; Wed, 20 May 2020 21:12:29 +0000 (UTC) Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-172-_azzrh0ROsS1aKq0JPBNuA-1; Wed, 20 May 2020 17:12:26 -0400 Received: by mail-qt1-f196.google.com with SMTP id x12so3793771qts.9 for ; Wed, 20 May 2020 14:12:26 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009163; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=cSXns3FCXVyGPdw/JuEyiJHDKK+ueQz1/I3DxE/3TkA=; b=WiPneyow4DY6/Yd1EP5HVg8VWGHp7G2BJKg/b3q1N6gYEq11Wk7aWBe7eWBcflgwiy53Kc 4gMy9o1/n44KG4vR9ePdP2dGG5AkVyK2q9SRWGoljWyMAlUkVH8/h2V7or6p0qr/9XLTH6 yeJVnit4gTxLYZuBVboAxt4/4FFCVrk= X-MC-Unique: oJgpJnO8Mu2IFKdfXyoLqQ-1 X-MC-Unique: _azzrh0ROsS1aKq0JPBNuA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cSXns3FCXVyGPdw/JuEyiJHDKK+ueQz1/I3DxE/3TkA=; b=kXrPL34sH2wTs4HmVOmHjoLzoOp5U8sl7emUz48j84uwOOIhMSdBWzH5ITSQQdb7fY 2Gjx8CzCLADfuNlbUodSslg9IyJKjcwSSc5Db5kqExcsoc5tc/9HfesiGadXY+CFjlr0 xCtSGzislskrf6z8CzQkBWKT+1zkls8bP07CToamh4iFF2QqZh/XZgCF8fAZkMugeS6I R+KRgUWbL4KeXGkL55cG3BseRrvw2XA1+LlX+zNK4v8nVLRyXFUwzDUdy3rYEWe4IEbO ApKlHd5aCETElX0nmXpZXBog/Vj3o1S1iNSV9KiEaSG+JP/hfH9NSJg503+GfeHFLtiO R9aw== X-Gm-Message-State: AOAM533cgfgmmO6MdprWlH3hqrsv1RuWqgQ5Hm34L9ca+tKv/0OwVkoC H1uDZ24s0au22XJz/9n1+eIE2t3G X-Google-Smtp-Source: ABdhPJxsemfBL4M/PqqZahDDx9x7xEwmF4FhD0/6aDHGHvyeD5vHKBQ2WKogmftt1eBGCODbCgYLog== X-Received: by 2002:ac8:7591:: with SMTP id s17mr7266726qtq.17.1590009145861; Wed, 20 May 2020 14:12:25 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 10/21] Introduce virDomainDeviceDefParseXMLMany Date: Wed, 20 May 2020 18:11:32 -0300 Message-Id: <20200520211143.2980117-11-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat virDomainDeviceDefParseXMLMany will be used to parse '' XML elements that will be used to supply multiple hostdevs for hotplug/unplug. The idea is to parse each dev individually, by calling the same code that already handles it today. The result is returned in a new virDomainDeviceDefListPtr pointer type, which is an array of device definitions. This idea of calling existing functions to handles a single device definition in a loop is the central idea of how PCI multifunction hotplug and hotunplug is implemented in the next patches. Roughly speaking, we'll use virDomainDeviceDefListPtr lists to call (almost) the same hotplug/unplug mechanics we have today for each hostdev in the list. Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 166 +++++++++++++++++++++++++++++++++++---- src/conf/domain_conf.h | 32 ++++++++ src/libvirt_private.syms | 5 ++ 3 files changed, 189 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fcd390ace4..4c74ee7229 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1351,6 +1351,90 @@ virDomainXMLOptionDispose(void *obj) (xmlopt->config.privFree)(xmlopt->config.priv); } =20 +/* virDomainDeviceDefListAddCopy - add a *copy* of the device to this list= */ +static int +virDomainDeviceDefListAddCopy(virDomainDeviceDefListPtr list, + virDomainDeviceDefPtr dev, + virDomainDeviceDefListDataPtr data, + void *parseOpaque) +{ + virDomainDeviceDefPtr copy =3D virDomainDeviceDefCopy(dev, + data->def, + data->xmlopt, + parseOpaque); + + if (!copy) + return -1; + + if (VIR_APPEND_ELEMENT(list->devs, list->count, copy) < 0) { + virDomainDeviceDefFree(copy); + return -1; + } + + return 0; +} + +void virDomainDeviceDefListFree(virDomainDeviceDefListPtr list) +{ + size_t i; + + if (!list) + return; + for (i =3D 0; i < list->count; i++) + virDomainDeviceDefFree(list->devs[i]); + VIR_FREE(list->devs); +} + +void virDomainDeviceDefListFreeShallow(virDomainDeviceDefListPtr list) +{ + size_t i; + + if (!list) + return; + for (i =3D 0; i < list->count; i++) + VIR_FREE(list->devs[i]); +} + + +/* virDomainDeviceDefListIter - Iterate through the list with the callback= */ +int +virDomainDeviceDefListIterate(virDomainDeviceDefListPtr list, + virDomainDeviceDefListIterCallback cb, + void *data) +{ + size_t i; + + for (i =3D 0; i < list->count; i++) + if (cb(list->devs[i], data)) + return -1; + + return 0; +} + +virDomainDeviceDefListPtr +virDomainDeviceDefListCopy(virDomainDeviceDefListPtr list, + virDomainDeviceDefListDataPtr data, + void *parseOpaque) +{ + size_t i; + virDomainDeviceDefListPtr devlist =3D NULL; + + if (list && (VIR_ALLOC(devlist) < 0)) + goto cleanup; + + for (i =3D 0; i < list->count; i++) { + if (virDomainDeviceDefListAddCopy(devlist, list->devs[i], + data, parseOpaque) < 0) + goto cleanup; + } + + return devlist; + cleanup: + virDomainDeviceDefListFree(devlist); + return NULL; +} + + /** * virDomainKeyWrapCipherDefParseXML: * @@ -16873,23 +16957,17 @@ virDomainVsockDefParseXML(virDomainXMLOptionPtr x= mlopt, return g_steal_pointer(&vsock); } =20 -virDomainDeviceDefPtr -virDomainDeviceDefParse(const char *xmlStr, - const virDomainDef *def, - virDomainXMLOptionPtr xmlopt, - void *parseOpaque, - unsigned int flags) + +static virDomainDeviceDefPtr +virDomainDeviceDefParseXML(xmlNodePtr node, + const virDomainDef *def, + virDomainXMLOptionPtr xmlopt, + xmlXPathContextPtr ctxt, + void *parseOpaque, + unsigned int flags) { - g_autoptr(xmlDoc) xml =3D NULL; - xmlNodePtr node; - g_autoptr(xmlXPathContext) ctxt =3D NULL; g_autoptr(virDomainDeviceDef) dev =3D NULL; =20 - if (!(xml =3D virXMLParseStringCtxt(xmlStr, _("(device_definition)"), = &ctxt))) - return NULL; - - node =3D ctxt->node; - if (VIR_ALLOC(dev) < 0) return NULL; =20 @@ -17046,6 +17124,29 @@ virDomainDeviceDefParse(const char *xmlStr, } =20 =20 +virDomainDeviceDefPtr +virDomainDeviceDefParse(const char *xmlStr, + const virDomainDef *def, + virDomainXMLOptionPtr xmlopt, + void *parseOpaque, + unsigned int flags) +{ + g_autoptr(xmlDoc) xml =3D NULL; + xmlNodePtr node; + g_autoptr(xmlXPathContext) ctxt =3D NULL; + virDomainDeviceDefPtr dev =3D NULL; + + if (!(xml =3D virXMLParseStringCtxt(xmlStr, _("(device_definition)"), = &ctxt))) + return NULL; + + node =3D ctxt->node; + + dev =3D virDomainDeviceDefParseXML(node, def, xmlopt, ctxt, parseOpaqu= e, flags); + + return dev; + } + + virDomainDiskDefPtr virDomainDiskDefParse(const char *xmlStr, virDomainXMLOptionPtr xmlopt, @@ -32365,6 +32466,43 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefP= tr def) return 0; } =20 +virDomainDeviceDefListPtr +virDomainDeviceDefParseXMLMany(const char *xml, + const virDomainDef *def, + virDomainXMLOptionPtr xmlopt, + void *parseOpaque, + unsigned int flags) +{ + g_autoptr(xmlXPathContext) ctxt =3D NULL; + g_autoptr(xmlDoc) xmlPtr =3D NULL; + xmlNodePtr node, root; + virDomainDeviceDefPtr dev =3D NULL; + virDomainDeviceDefListPtr devlist; + + if (!(xmlPtr =3D virXMLParseStringCtxt(xml, _("(device_definition)"), = &ctxt))) + return NULL; + + if (VIR_ALLOC(devlist) < 0) + return NULL; + + root =3D xmlDocGetRootElement(xmlPtr); + node =3D root->children; + while (node) { + if (node->type =3D=3D XML_ELEMENT_NODE) { + dev =3D virDomainDeviceDefParseXML(node, def, xmlopt, ctxt, + parseOpaque, flags); + if (VIR_APPEND_ELEMENT(devlist->devs, devlist->count, dev) < 0= ) { + virDomainDeviceDefFree(dev); + virDomainDeviceDefListFree(devlist); + return NULL; + } + dev =3D NULL; + } + node =3D node->next; + } + + return devlist; +} =20 /** * virDomainDiskGetDetectZeroesMode: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 634865842a..e31fac8a4a 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2748,6 +2748,33 @@ typedef enum { typedef int (*virDomainDefPostParseBasicCallback)(virDomainDefPtr def, void *opaque); =20 +typedef struct _virDomainDeviceDefListData virDomainDeviceDefListData; +typedef virDomainDeviceDefListData *virDomainDeviceDefListDataPtr; +struct _virDomainDeviceDefListData { + const virDomainDef *def; + virDomainXMLOptionPtr xmlopt; +}; + +struct virDomainDeviceDefList { + virDomainDeviceDefPtr *devs; + size_t count; +}; +typedef struct virDomainDeviceDefList *virDomainDeviceDefListPtr; + +typedef int (*virDomainDeviceDefListIterCallback)(virDomainDeviceDefPtr de= v, + void *opaque); +int virDomainDeviceDefListIterate(virDomainDeviceDefListPtr devlist, + virDomainDeviceDefListIterCallback cb, + void *data); +virDomainDeviceDefListPtr +virDomainDeviceDefListCopy(virDomainDeviceDefListPtr list, + virDomainDeviceDefListDataPtr data, + void *parseOpaque); + +void virDomainDeviceDefListFree(virDomainDeviceDefListPtr list); +void virDomainDeviceDefListFreeShallow(virDomainDeviceDefListPtr list); + + /* Called once after everything else has been parsed, for adjusting * overall domain defaults. * @parseOpaque is opaque data passed by virDomainDefParse* caller, @@ -3155,6 +3182,11 @@ virDomainDeviceDefPtr virDomainDeviceDefParse(const = char *xmlStr, virDomainXMLOptionPtr xmlopt, void *parseOpaque, unsigned int flags); +virDomainDeviceDefListPtr virDomainDeviceDefParseXMLMany(const char *xmlSt= r, + const virDomainDe= f *def, + virDomainXMLOptio= nPtr xmlopt, + void *parseOpaque, + unsigned int flag= s); virDomainDiskDefPtr virDomainDiskDefParse(const char *xmlStr, virDomainXMLOptionPtr xmlopt, unsigned int flags); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 323291367f..29c6ac8e5e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -343,7 +343,12 @@ virDomainDeleteConfig; virDomainDeviceAliasIsUserAlias; virDomainDeviceDefCopy; virDomainDeviceDefFree; +virDomainDeviceDefListCopy; +virDomainDeviceDefListFree; +virDomainDeviceDefListFreeShallow; +virDomainDeviceDefListIterate; virDomainDeviceDefParse; +virDomainDeviceDefParseXMLMany; virDomainDeviceFindSCSIController; virDomainDeviceGetInfo; virDomainDeviceInfoIterate; --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009166; cv=none; d=zohomail.com; s=zohoarc; b=iLDXoZlWzEdEsJZS4JOmSebOEbO3sRDh527v2zvBS5FLeKqHNd8zoWfgzQFYn2EWONg1nISUTxlNZfFEwjziJg0zdDYnFdi0aWkAewkXTDIQHieifZKZwltvhT8jxxilWi3NHt2g2fpJo3GVfHrnHHfj187H9sTtptisjdlbMLk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009166; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Tx8JZWl3WZom+eyi2ciowItd+wi/sfs24bsNhE5xSUg=; b=kz3796ZdJ4dg320JmLSVetydFehvG8Mq+Fd2QSk4SzlN65pawzwX9IG3N5kkVS1VNZt5mqRza2FwiRVDPaO8PWt3ZmZPrSCCf1YypnNzh4cspCyKGXexK019D93J3Rj0bLmOxwtTMPu6YthxIoJA1SGc/zK675jOiYlVUFxF3ak= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1590009166650904.3471884209672; Wed, 20 May 2020 14:12:46 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-113-XiUvLq-JOGi3lVwEetJtEw-1; Wed, 20 May 2020 17:12:42 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B957464AD4; Wed, 20 May 2020 21:12:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 98E0482E7E; Wed, 20 May 2020 21:12:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6AA6C180530A; Wed, 20 May 2020 21:12:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCZfG002159 for ; Wed, 20 May 2020 17:12:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 870322157F25; Wed, 20 May 2020 21:12:35 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 82FD62166BA2 for ; Wed, 20 May 2020 21:12:31 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 69CF2800296 for ; Wed, 20 May 2020 21:12:31 +0000 (UTC) Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-400-focS_L-ONGeJsXlrEo6sHA-1; Wed, 20 May 2020 17:12:28 -0400 Received: by mail-qt1-f170.google.com with SMTP id a23so3851835qto.1 for ; Wed, 20 May 2020 14:12:28 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009165; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Tx8JZWl3WZom+eyi2ciowItd+wi/sfs24bsNhE5xSUg=; b=Y1gsiACAlrYJFmn7i4FDvoZDCIdAqW7IUbC3nLKDwuFx8mTD/J+ha1gj46LBSZQ7xeSdOm X6eRLbub7Ie0rE74BcY6bFZroeMEEwI9ALtaKWUm29pUIxMKVZ+I1m/WpiZIrSUdmP2tVE WmaUDWvp9y3of95+Lr5u5Y35f3LWcQg= X-MC-Unique: XiUvLq-JOGi3lVwEetJtEw-1 X-MC-Unique: focS_L-ONGeJsXlrEo6sHA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Tx8JZWl3WZom+eyi2ciowItd+wi/sfs24bsNhE5xSUg=; b=oeBNF/m9l/QBMED3IwHdorJYAGNrnap7qLmVbBEfnDI3hUUlQ/2LMflPHwY+2ymSZe uA1BDSkpVfkI9LE6yU5hF1s8189/ZwQOLtOwgXkIogrnszIUs1vYX0pQdh/kirmw3Nj/ XBvezcLiP3yNAH9uPHOOS8CXzt8IofZRC1YN/67yk310xpPHFHaDgJBPgx0nTcGzUJfM wgbe/4TQy679gR4dtzBv2bycpidEEpS7evEdggBsWHvD1IkC7hk6YpeZqs1ck1IcZjvJ yo36Wfm6tw5pi0DozGFnudz4xJiD3n9UicC2shUixX74vqjsPcZiL0uYyAgxBiBN/RIv ZqPA== X-Gm-Message-State: AOAM532ycacM/i7dHokodXOYFsqL8pXJbjSJz4r6vm+D47ogEl1YlnZy 0JeMq/pDvZdNkl/z6JskGBfaLGyT X-Google-Smtp-Source: ABdhPJyAq4tCVTt0CwfKTGrVTL4ltESqujXADtJfibQF68uah5Du602/YUMY1y3HJKmlq3gcW5ptgA== X-Received: by 2002:ac8:6f5a:: with SMTP id n26mr7882172qtv.303.1590009148075; Wed, 20 May 2020 14:12:28 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 11/21] Introduce qemuDomainDeviceParseXMLMany Date: Wed, 20 May 2020 18:11:33 -0300 Message-Id: <20200520211143.2980117-12-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_domain.c | 74 ++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 7 ++++ 2 files changed, 81 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d5e3d1a3cc..0471a37803 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -13391,6 +13391,80 @@ qemuProcessEventFree(struct qemuProcessEvent *even= t) } =20 =20 +static bool isPCIMultifunctionDeviceXML(const char *xml) +{ + xmlDocPtr xmlptr; + + if (!(xmlptr =3D virXMLParse(NULL, xml, _("(device_definition)")))) { + /* We report error anyway later */ + return false; + } + + return STREQ((const char *)(xmlDocGetRootElement(xmlptr))->name, "devic= es"); +} + +static +int qemuDomainValidateMultifunctionDeviceList(virDomainDeviceDefListPtr de= vlist) +{ + size_t i; + + for (i =3D 0; i < devlist->count; i++) { + virDomainDeviceInfoPtr info =3D virDomainDeviceGetInfo(devlist->de= vs[i]); + + if (info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && + info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { + return -1; + } + + if (devlist->devs[i]->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV) { + virDomainHostdevDefPtr hostdev =3D devlist->devs[i]->data.hostd= ev; + + if (hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_= TYPE_PCI) + return -1; + } + } + + return 0; +} + + +virDomainDeviceDefListPtr +qemuDomainDeviceParseXMLMany(const char *xml, + virDomainDeviceDefListDataPtr data, + void *parseOpaque, + unsigned int parse_flags) +{ + virDomainDeviceDefListPtr devlist =3D NULL; + + if (isPCIMultifunctionDeviceXML(xml)) { + if (!(devlist =3D virDomainDeviceDefParseXMLMany(xml, data->def, + data->xmlopt, + parseOpaque, + parse_flags))) + return NULL; + + if (qemuDomainValidateMultifunctionDeviceList(devlist) < 0) + goto cleanup; + } else { + virDomainDeviceDefPtr dev =3D virDomainDeviceDefParse(xml, data->d= ef, + data->xmlopt, + parseOpaque, + parse_flags); + if (!dev || VIR_ALLOC(devlist) < 0) + return NULL; + + if (VIR_APPEND_ELEMENT(devlist->devs, devlist->count, dev) < 0) + goto cleanup; + } + + return devlist; + + cleanup: + virDomainDeviceDefListFree(devlist); + return NULL; +} + + char * qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivatePtr priv) { diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index b601d52126..31c843de96 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1291,6 +1291,13 @@ qemuDomainNVRAMPathGenerate(virQEMUDriverConfigPtr c= fg, virDomainEventSuspendedDetailType qemuDomainPausedReasonToSuspendedEvent(virDomainPausedReason reason); =20 + +virDomainDeviceDefListPtr +qemuDomainDeviceParseXMLMany(const char *xml, + virDomainDeviceDefListDataPtr data, + void *parseOpaque, + unsigned int parse_flags); + int qemuDomainValidateActualNetDef(const virDomainNetDef *net, virQEMUCapsPtr qemuCaps); --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009169; cv=none; d=zohomail.com; s=zohoarc; b=QLVE6HTUC0+JFhOnVAJd7B1XMbLoKtp1SRIZql3Sk4zGhiF6BNbth0MjrjxIeDO6G+AQDfRjql4ymyV72CG+0w/LmBR3IBnEbz5etek4lTikojiwNQkRNx3pKteMvr0POsX+x7WHr3DJ/pPvHHwvPQrBZNYi/u5fOPfVeAh5GyE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009169; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tqUDLt0jIR+ntZF41ECOCut3Tk6wzy+MM1ncEHVB0hs=; b=n9Wawfm6sYi+2opF5BgrXiuqGEVPNHFwersrzj/MHnQtpV/aNplUElXUd6Xr53Ruuf4RqN8SsD0aCqh5+XBHWMX7fOxfwVjisKZ8PbaSjorMDKBiV9/aB8lQOTwt40Cm6TufxgmOvV8CE/Xyho3UYaTi/qMZJwwln+zTU11aRmw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1590009169483474.31368970416906; Wed, 20 May 2020 14:12:49 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-234-e0lJ_VUNNQGn9coGUBa8IA-1; Wed, 20 May 2020 17:12:45 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EC9C8800688; Wed, 20 May 2020 21:12:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CC43C2C7B9; Wed, 20 May 2020 21:12:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9F98B54D0B; Wed, 20 May 2020 21:12:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCaJL002182 for ; Wed, 20 May 2020 17:12:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 677D35AB85; Wed, 20 May 2020 21:12:36 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 63AAE11317 for ; Wed, 20 May 2020 21:12:34 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5F27B8ECB0C for ; Wed, 20 May 2020 21:12:34 +0000 (UTC) Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-352-LL4GtTToMpeVeG2VhDbFLw-1; Wed, 20 May 2020 17:12:30 -0400 Received: by mail-qk1-f193.google.com with SMTP id i5so5090653qkl.12 for ; Wed, 20 May 2020 14:12:30 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009168; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=tqUDLt0jIR+ntZF41ECOCut3Tk6wzy+MM1ncEHVB0hs=; b=Pwr+VC/8EAcj+8R60rVU/l8AtNc9g7YfE8NaYWCElSiAlFLqyfR6pvNFnvFLdnneCaW6lY fZPmgyVSwLkLtiZpj9et+QTOaZwwFLOINMS/SWpzpWpWBmT8FKktTIZzIiVgfOdCxqzzuN lpKpSHXA0mxY6ZdaMt7zd4O1QLv0+dY= X-MC-Unique: e0lJ_VUNNQGn9coGUBa8IA-1 X-MC-Unique: LL4GtTToMpeVeG2VhDbFLw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tqUDLt0jIR+ntZF41ECOCut3Tk6wzy+MM1ncEHVB0hs=; b=GUlut+QHOuMpatBUA8LiuH18G6Q4idGec+nQv22VJ5eputjVVQEguZMwLiPXnEwB6h rNkUX4Y/CTe4sKseqWL6/DUTYDtwNePYlpAOBf9evNs0W/nE6q/3oCxK+zisLycM46fy qzg/SvOqcyh0MSwOSVDiVPX+BelIgq0iGSA+3p8jiZQ1rhGGq2mLth0E5QdDdPaD6/di PzeJPVhnpJjVzRCvafRjMYeAqU3t09C8hFzWbrumZ/8FqkllzowBecZzdAWfje0e9ocr 43NlrK+xoJv3DlZgSF5GlQRy/JrezkBh1KPT3bP+GY+sDp11KlPyJXlt/EG2V+YiQ4qm hssQ== X-Gm-Message-State: AOAM531L3UnD8jZWbA/GjZmmwr8izPkj4J70XkmyUGPcl8MUYiU8hb74 6ySECF7S/3g8D053han909LD5PWW X-Google-Smtp-Source: ABdhPJxXqtAjMqLg6LORuz/WAnRQi+LwSQQyhVpZNZcLT8jnRLef8wBv46wekfZrPfshhwff94IEgQ== X-Received: by 2002:a37:9e06:: with SMTP id h6mr6680553qke.400.1590009149962; Wed, 20 May 2020 14:12:29 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 12/21] qemu: refactor qemuDomain[Attach|Detach]DeviceConfig Date: Wed, 20 May 2020 18:11:34 -0300 Message-Id: <20200520211143.2980117-13-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat This helps calling the routines with a list of devices. Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_driver.c | 45 +++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index dd9ae30bb5..43a3ffea99 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8117,11 +8117,8 @@ qemuCheckDiskConfigAgainstDomain(const virDomainDef = *def, =20 =20 static int -qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef, - virDomainDeviceDefPtr dev, - virQEMUCapsPtr qemuCaps, - unsigned int parse_flags, - virDomainXMLOptionPtr xmlopt) +qemuDomainAttachDeviceConfigInternal(virDomainDefPtr vmdef, + virDomainDeviceDefPtr dev) { virDomainDiskDefPtr disk; virDomainNetDefPtr net; @@ -8316,19 +8313,35 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef, return -1; } =20 - if (virDomainDefPostParse(vmdef, parse_flags, xmlopt, qemuCaps) < 0) - return -1; - return 0; } =20 =20 static int -qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef, +qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev, virQEMUCapsPtr qemuCaps, unsigned int parse_flags, virDomainXMLOptionPtr xmlopt) +{ + if (virDomainDefCompatibleDevice(vmdef, dev, NULL, + VIR_DOMAIN_DEVICE_ACTION_ATTACH, + false) < 0) + return -1; + + if (qemuDomainAttachDeviceConfigInternal(vmdef, dev)) + return -1; + + if (virDomainDefPostParse(vmdef, parse_flags, xmlopt, qemuCaps) < 0) + return -1; + + return 0; +} + + +static int +qemuDomainDetachDeviceConfigInternal(virDomainDefPtr vmdef, + virDomainDeviceDefPtr dev) { virDomainDiskDefPtr disk, det_disk; virDomainNetDefPtr net; @@ -8518,6 +8531,20 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef, return -1; } =20 + return 0; +} + + +static int +qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef, + virDomainDeviceDefPtr dev, + virQEMUCapsPtr qemuCaps, + unsigned int parse_flags, + virDomainXMLOptionPtr xmlopt) +{ + if (qemuDomainDetachDeviceConfigInternal(vmdef, dev)) + return -1; + if (virDomainDefPostParse(vmdef, parse_flags, xmlopt, qemuCaps) < 0) return -1; =20 --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009172; cv=none; d=zohomail.com; s=zohoarc; b=CSEbx8iJCp7hemvKcLcmXcy7Yo8rxVqc/o+AUaPWNhubvqqm5zexco8FaECat3V47kGv6SuuQvArEwoLu9/7Mjv1B4luLkDaXvrKx9FNWLo/A28JOShgEOHGzQYe6QxaSUTNMfqfpD00pYFFWMPbatJP0Ml6SEX8nCNDXqxk5j8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009172; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1lRiLwD0+c2KyAT8GgUgQybyYpH0KtMawoNbzHrT1nw=; b=WhgEi8LC6RKzDDjOzYOj8RucaM1aljZ7DjMXUQbcu6XI1nynjnbCGXLkUw8dWblcTGsSS21RCQyuvugk8m6nj1N2zbhGxJ1r3Pg94AW0ka1RQ0g/6HXaj0eyfeJwtpC3YeSWWj2lyNd4hQGOrZ+bhQnkWc0Z8UQTA0M37MYp6v0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1590009172047563.7814144308829; Wed, 20 May 2020 14:12:52 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-58-olti7cL0MKWw8JbEmm86vA-1; Wed, 20 May 2020 17:12:46 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4C45C835B46; Wed, 20 May 2020 21:12:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2DF4F797EF; Wed, 20 May 2020 21:12:40 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id F2D8A54D0E; Wed, 20 May 2020 21:12:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCbiu002190 for ; Wed, 20 May 2020 17:12:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 04A00202696C; Wed, 20 May 2020 21:12:37 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 007732026DFD for ; Wed, 20 May 2020 21:12:34 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CF89E811768 for ; Wed, 20 May 2020 21:12:34 +0000 (UTC) Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-113-dXJyTSgNMQGjqnIyW_Vevg-1; Wed, 20 May 2020 17:12:32 -0400 Received: by mail-qk1-f196.google.com with SMTP id s1so5134120qkf.9 for ; Wed, 20 May 2020 14:12:32 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009170; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=1lRiLwD0+c2KyAT8GgUgQybyYpH0KtMawoNbzHrT1nw=; b=ZoAzJ+/iEohDNt9+MwOctvltD6Vikd1/YIRcICGtno6VxSxK9rWnMhdh+uzCJpTrkEFO+E 2FF3i9KcLOyLvvTiako7y9NtJ/DwKatHH19b9TvBoFI76adyGfpJ/i1yHVnYOa+O2lVjJ2 AGVM0brH1I/kXf3vwkgiRyrzhgWiNxw= X-MC-Unique: olti7cL0MKWw8JbEmm86vA-1 X-MC-Unique: dXJyTSgNMQGjqnIyW_Vevg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1lRiLwD0+c2KyAT8GgUgQybyYpH0KtMawoNbzHrT1nw=; b=BGfAaYcsS3TDzFSCCALF3i/eA+uRlTP/yY6feU1m8oQDqOFPBbbB6buGBzX/uOlVMc WkPqYFjtkMYhEE8oa/qmotDJWM+bmCdlmkJgPjO1JqEBp18szzCHK30vctkxcoze9SUW XO8kYyjmwKe/TgdTGFYShIfDCqtp6uhrDIwITh3c+7D4/IE5fvZIMm0ZPhdNxOaqVpdZ 7PK0Dr7iD9WUd/A3Vq1t4/nCnFORGaEey+Pu4Y/V4GxJHtjizd5qJ0ZMXaEje7/NNkBK K1BcgPuPAS2y418m8NELKv5o5nDpRqI/80QH2lYMHBNtfv2olTYINwlrNTG0Ksbv42Ug xcBg== X-Gm-Message-State: AOAM5339YYeELB4QawOeKNV/joNe+BSfYkj6fjf3PPk/zBZLZon6koHi MubC6SeD2cAk39KWYyZ+eWxxUDul X-Google-Smtp-Source: ABdhPJwNTqm+yuQgB9kGkITumInzjHnPHtfCeMdb5P8YaQHV7xg0Ebz+JwIbZ3+9xRBzNuGQh2e8ww== X-Received: by 2002:a37:61cf:: with SMTP id v198mr6664304qkb.54.1590009151705; Wed, 20 May 2020 14:12:31 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 13/21] qemu: refactor qemuDomain[Attach|Detach]DeviceLive Date: Wed, 20 May 2020 18:11:35 -0300 Message-Id: <20200520211143.2980117-14-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat Helps calling multiple time per device. Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_driver.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 43a3ffea99..f880a5d6cf 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7824,9 +7824,9 @@ qemuDomainUndefine(virDomainPtr dom) } =20 static int -qemuDomainAttachDeviceLive(virDomainObjPtr vm, - virDomainDeviceDefPtr dev, - virQEMUDriverPtr driver) +qemuDomainAttachDeviceLiveInternal(virDomainObjPtr vm, + virDomainDeviceDefPtr dev, + virQEMUDriverPtr driver) { int ret =3D -1; const char *alias =3D NULL; @@ -7972,13 +7972,28 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, virObjectEventStateQueue(driver->domainEventState, event); } =20 + return ret; +} + +static int +qemuDomainAttachDeviceLive(virDomainObjPtr vm, + virDomainDeviceDefPtr dev, + virQEMUDriverPtr driver) +{ + int ret =3D -1; + + if (virDomainDefCompatibleDevice(vm->def, dev, NULL, + VIR_DOMAIN_DEVICE_ACTION_ATTACH, + false) < 0) + return -1; + + ret =3D qemuDomainAttachDeviceLiveInternal(vm, dev, driver); if (ret =3D=3D 0) ret =3D qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE= ); =20 return ret; } =20 - static int qemuDomainChangeDiskLive(virDomainObjPtr vm, virDomainDeviceDefPtr dev, --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009171; cv=none; d=zohomail.com; s=zohoarc; b=gmGxoOsBct5Tgl7ibyJ9vvzJsDQUnP/xXm4VRJXl7GAHGFmvLAEKXKbnyoRAZnTEIV8IlMj/dAHvGzWoGk6065wcxSyqAk1trFZqjNBqoafAi15H5OqLK85i0jGGjfsaKmZ0qafpIVFr+bQCOfaWy2aaAE/xtEIAqV6EHdRu0Z0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009171; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/T17Avh4IKuJ83nvtjPNzDBaVIA8sZ8JCmRVqGjKq8s=; b=AHgn8nT+TG02l1PqL7A9bFh4lKjEwQfNn+Gp3/tzGYmA8flsYeJjg0oPyfMXhgO7q/yymEBv6V9WZhqh2T0uf1qVhMLpMmwAW9PUZTtuf+o24+6S3aXJRhZ9eVVAVsdMaBGf2oqplP2x1v5sWbIPq/dB9ih0KwXNa9Mi3O1FHOk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1590009171216144.75711434512596; Wed, 20 May 2020 14:12:51 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-422-M4lasOqFNgmrPwwMvV-Trg-1; Wed, 20 May 2020 17:12:46 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B1D228018A2; Wed, 20 May 2020 21:12:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8EC3248D7E; Wed, 20 May 2020 21:12:40 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6043E180530E; Wed, 20 May 2020 21:12:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCb0P002198 for ; Wed, 20 May 2020 17:12:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5E02B2166BA3; Wed, 20 May 2020 21:12:37 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5A1FC2156A2E for ; Wed, 20 May 2020 21:12:37 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 387818007D4 for ; Wed, 20 May 2020 21:12:37 +0000 (UTC) Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-353-Gg0a--2EPxywKOTvLY4wyA-1; Wed, 20 May 2020 17:12:34 -0400 Received: by mail-qk1-f193.google.com with SMTP id 142so5159798qkl.6 for ; Wed, 20 May 2020 14:12:34 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009169; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=/T17Avh4IKuJ83nvtjPNzDBaVIA8sZ8JCmRVqGjKq8s=; b=YuCYDYszchL6TDr92Zt/i07uMokmoudq7cyW9E0/TQbALJXQEPuT2ksPWyqWJ+HwrAIFGk jrymdtZ6+9uLwDPz/5qUO6febZWTLxkc2zAdpcMFmtgcdTMTSBfuC/KyEb9SLtDZvl6aVy 9d2ft2wU7C2RYbj8r87ES5VFzQDldbg= X-MC-Unique: M4lasOqFNgmrPwwMvV-Trg-1 X-MC-Unique: Gg0a--2EPxywKOTvLY4wyA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/T17Avh4IKuJ83nvtjPNzDBaVIA8sZ8JCmRVqGjKq8s=; b=F9UWBWp6LmoGzPFigaW7aVnBxhM6oTyUtguqJwfM3i/QvIimq9odDQA/TxVy7g7AOo eS3Xq3B6xnwobXFPf8cRoxVrj9RcwM1O9guDYeZG1M5TKFpmy381sNCyU43m3aHC3UjZ zNRTCLT+L2Hx1tUll2tS3Heu+Upi4jwWEy2hyaNSqVl2gN1DeBUe9K7aQnKVIIsO0+T2 snc629T7qBUGWeTIKQO2vS85exe5zMtSeyzRVls/m/gKEzASz0y5rWeEcNGrsx+WzTnS 1SCZpVtTfjonn8x0DaXsPQuiWvledhORrwYnse4vFEDL1AfsuLq+PI+4OIznX5p9rdDj 8LzA== X-Gm-Message-State: AOAM531+m8D4TV1DczbrjRtbk2kC1yQphX3/+RrkYTmYUiE4rrKI2Zkc FBOtaS6XmQbHyhgnw9Ax1ucRgL3V X-Google-Smtp-Source: ABdhPJwWjft69W7OrHhlZRuyLD+Y1bi/W2Wzq1ZEfenyBQmlX6mQeNFfclwRjbPR/SLF0TE2NDzy/A== X-Received: by 2002:a05:620a:1524:: with SMTP id n4mr6949823qkk.490.1590009153988; Wed, 20 May 2020 14:12:33 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 14/21] qemu: hotplug: Queue and wait for multiple devices Date: Wed, 20 May 2020 18:11:36 -0300 Message-Id: <20200520211143.2980117-15-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat With multifunction devices, multiple delete requests are sent to qemu and all the requests should be queued up. Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_domain.h | 3 ++- src/qemu/qemu_hotplug.c | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 31c843de96..4fab1360f6 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -244,7 +244,8 @@ typedef enum { typedef struct _qemuDomainUnpluggingDevice qemuDomainUnpluggingDevice; typedef qemuDomainUnpluggingDevice *qemuDomainUnpluggingDevicePtr; struct _qemuDomainUnpluggingDevice { - const char *alias; + const char **aliases; + size_t naliases; qemuDomainUnpluggingDeviceStatus status; bool eventSeen; /* True if DEVICE_DELETED event arrived. */ }; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 6991d7988c..b9946e8b8e 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5134,13 +5134,19 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver, =20 static void qemuDomainMarkDeviceAliasForRemoval(virDomainObjPtr vm, - const char *alias) + const char *alias, + bool fresh) { qemuDomainObjPrivatePtr priv =3D vm->privateData; =20 - memset(&priv->unplug, 0, sizeof(priv->unplug)); + if (fresh) + memset(&priv->unplug, 0, sizeof(priv->unplug)); + + if (VIR_REALLOC_N(priv->unplug.aliases, priv->unplug.naliases + 1) < 0) + return; + + priv->unplug.aliases[priv->unplug.naliases++] =3D alias; =20 - priv->unplug.alias =3D alias; } =20 =20 @@ -5149,7 +5155,7 @@ qemuDomainMarkDeviceForRemoval(virDomainObjPtr vm, virDomainDeviceInfoPtr info) =20 { - qemuDomainMarkDeviceAliasForRemoval(vm, info->alias); + qemuDomainMarkDeviceAliasForRemoval(vm, info->alias, true); } =20 =20 @@ -5157,7 +5163,9 @@ static void qemuDomainResetDeviceRemoval(virDomainObjPtr vm) { qemuDomainObjPrivatePtr priv =3D vm->privateData; - priv->unplug.alias =3D NULL; + priv->unplug.aliases =3D NULL; + VIR_FREE(priv->unplug.aliases); + priv->unplug.naliases =3D 0; priv->unplug.eventSeen =3D false; } =20 @@ -5192,13 +5200,14 @@ qemuDomainWaitForDeviceRemoval(virDomainObjPtr vm) return 1; until +=3D qemuDomainGetUnplugTimeout(vm); =20 - while (priv->unplug.alias) { + /* All devices should get released around same time*/ + while (priv->unplug.naliases) { if ((rc =3D virDomainObjWaitUntil(vm, until)) =3D=3D 1) return 0; =20 if (rc < 0) { VIR_WARN("Failed to wait on unplug condition for domain '%s' " - "device '%s'", vm->def->name, priv->unplug.alias); + "device '%s'", vm->def->name, priv->unplug.aliases[0]= ); return 1; } } @@ -5224,14 +5233,16 @@ qemuDomainSignalDeviceRemoval(virDomainObjPtr vm, qemuDomainUnpluggingDeviceStatus status) { qemuDomainObjPrivatePtr priv =3D vm->privateData; + size_t i; =20 - if (STREQ_NULLABLE(priv->unplug.alias, devAlias)) { - VIR_DEBUG("Removal of device '%s' continues in waiting thread", de= vAlias); - qemuDomainResetDeviceRemoval(vm); - priv->unplug.status =3D status; - priv->unplug.eventSeen =3D true; - virDomainObjBroadcast(vm); - return true; + for (i =3D 0; i < priv->unplug.naliases; i++) { + if (STREQ_NULLABLE(priv->unplug.aliases[i], devAlias)) { + VIR_DEBUG("Removal of device '%s' continues in waiting thread"= , devAlias); + VIR_DELETE_ELEMENT(priv->unplug.aliases, i, priv->unplug.nalia= ses); + priv->unplug.status =3D status; + virDomainObjBroadcast(vm); + return true; + } } return false; } @@ -6075,7 +6086,7 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver, return -1; } =20 - qemuDomainMarkDeviceAliasForRemoval(vm, vcpupriv->alias); + qemuDomainMarkDeviceAliasForRemoval(vm, vcpupriv->alias, true); =20 if (qemuDomainDeleteDevice(vm, vcpupriv->alias) < 0) { if (virDomainObjIsActive(vm)) --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009224; cv=none; d=zohomail.com; s=zohoarc; b=fhm+P0AFJwfekerjMVq/puYM7KegNj9dCiNrNYRv0g7tleM4QuLHFGXZhi6BxitXWYqtgBDN3HkI9wesWzTPXZrtolx298Dxja+gu5fbntSeD9u7zkTnUCl1ucjqbi7k286CaZAA2oZRH0e9iRpGYHsLCghy5r5iE6ph1K1xciQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009224; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=81yRvNHlW6r9fn5/gJ0y0T2myfbLvzHknFtjnI0GRRE=; b=OL7FVL08kcpIUJ89y2Tx+XgVxxQJ8V/XrdybId4ypIixB2awnkLR+evpOPDVyS9dK6HwkHOJFYcTrikw+QVLs0wDGsWMnhagLfMTBuS3BhlY5Ah2Fdcip4Ne24Ys1tuhlhQoa2jn+6e/zjtstPMIsBmiLJee1pPIzhu93rG/cjY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1590009224536122.00271191383672; Wed, 20 May 2020 14:13:44 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-228-zbvNrqmZPFeVieSEZVXscg-1; Wed, 20 May 2020 17:13:40 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 35DA21B18BE3; Wed, 20 May 2020 21:13:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1776879596; Wed, 20 May 2020 21:13:33 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DABC61809547; Wed, 20 May 2020 21:13:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCeui002232 for ; Wed, 20 May 2020 17:12:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0B4481000DA7; Wed, 20 May 2020 21:12:40 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0733A1007A46 for ; Wed, 20 May 2020 21:12:40 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E28B4811E77 for ; Wed, 20 May 2020 21:12:39 +0000 (UTC) Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-384-0jzd51RBOXizNSRBiEZPrQ-1; Wed, 20 May 2020 17:12:36 -0400 Received: by mail-qk1-f195.google.com with SMTP id f83so5083264qke.13 for ; Wed, 20 May 2020 14:12:36 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009223; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=81yRvNHlW6r9fn5/gJ0y0T2myfbLvzHknFtjnI0GRRE=; b=TgkVd9aFxO0DTI1gmuCrD3hD7PRDRtNfmE3xezvwn0oZLR+tOXYgStW6owcr/THisvtMgY 7Ol1SKLOvSJLNJFVes94Ct2BLaNk949KIoGRrfZSZ8Yopy8ws3O/tKeptOP40OhQQa5r8A roj5z8zPorul8oUIT3VGHDMpgw52dpo= X-MC-Unique: zbvNrqmZPFeVieSEZVXscg-1 X-MC-Unique: 0jzd51RBOXizNSRBiEZPrQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=81yRvNHlW6r9fn5/gJ0y0T2myfbLvzHknFtjnI0GRRE=; b=PRkye0ukmXS8ujgITHiGXpBxqSx+puikwO+yPQedUOngGDxqvD74A2QlHI4BP7AKG3 gBUhrDtwgjNrxj6L1Wn/Q/sA96J3CSxvzYq6tf2iOkxt/bcRApsek9+C90zkPUcMUUh0 UNfQzUsoihtJed0Ht7e+t2IZM9/RrrqrvOHEVSncGlKvpwZW+2fL/HYsVCXrZXtBsiIw 5YJhTqAXNN4W6qKD6MHh0KnutglWm/TrO1Qm6XOVxZOpA86ZIC0AfeYcO/YRY4dI21sH HwfPqZp2mW1HlOjkC/AtAUE5MJHjuMSoXSt189Qj9Oc5bn/k3LcScDQDVycHES60wN7N 0huA== X-Gm-Message-State: AOAM532iz10fW/vpF3a6Ya46C2/dm0eFo+QH2UBE0fSqdDEB0pN0hbhw YM6khLXTyzkDddzZi6g8PD7MElTp X-Google-Smtp-Source: ABdhPJxIeRdug3iw+b0Vc9EXopStbeH4D2ztEuWymV0woLdLVu21f1ln5aBKiRN/wHFuK9sKc6u8DA== X-Received: by 2002:a37:8786:: with SMTP id j128mr6865790qkd.63.1590009156039; Wed, 20 May 2020 14:12:36 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 15/21] domain: addr: Introduce virDomainPCIAddressEnsureMultifunctionAddress Date: Wed, 20 May 2020 18:11:37 -0300 Message-Id: <20200520211143.2980117-16-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/conf/device_conf.h | 6 +++ src/conf/domain_addr.c | 84 +++++++++++++++++++++++++++++++++++++++- src/conf/domain_addr.h | 5 +++ src/libvirt_private.syms | 1 + src/util/virpci.h | 2 + 5 files changed, 96 insertions(+), 2 deletions(-) diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index cc1707c1d1..e7d8e2539f 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -182,6 +182,12 @@ struct _virDomainDeviceInfo { bool isolationGroupLocked; }; =20 +typedef struct _virDomainPCIMultifunctionAddressInfo virDomainPCIMultifunc= tionAddressInfo; +typedef virDomainPCIMultifunctionAddressInfo *virDomainPCIMultifunctionAdd= ressInfoPtr; +struct _virDomainPCIMultifunctionAddressInfo { + virDomainDeviceInfoPtr infos[VIR_PCI_MAX_FUNCTIONS]; +}; + void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info); void virDomainDeviceInfoFree(virDomainDeviceInfoPtr info); =20 diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 5c8fc62725..0a1c9ce142 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -21,11 +21,12 @@ =20 #include =20 +#include "device_conf.h" +#include "domain_addr.h" #include "viralloc.h" +#include "virhashcode.h" #include "virlog.h" #include "virstring.h" -#include "domain_addr.h" -#include "virhashcode.h" =20 #define VIR_FROM_THIS VIR_FROM_DOMAIN =20 @@ -990,6 +991,85 @@ virDomainPCIAddressExtensionReleaseAddr(virDomainPCIAd= dressSetPtr addrs, } =20 =20 +int +virDomainPCIAddressEnsureMultifunctionAddress(virDomainPCIAddressSetPtr ad= drs, + virDomainPCIMultifunctionAdd= ressInfoPtr pcicard) +{ + size_t i; + int ret =3D 0; + virPCIDeviceAddressPtr addr1 =3D NULL, addr2 =3D NULL; + virDomainDeviceInfoPtr dev =3D NULL; + + if (!pcicard->infos[0]) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Function-Zero missing on the slot")); + return -1; + } + + /* If the address is given by the user, make sure they belong + * to same slot */ + for (i =3D 0; i < VIR_PCI_MAX_FUNCTIONS; i++) { + g_autofree char *addrStr =3D NULL; + dev =3D pcicard->infos[i]; + + if (dev && !dev->pciConnectFlags) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Not a PCI Multifunction device.")); + return -1; + } + if (dev && virDeviceInfoPCIAddressIsPresent(dev)) { + /* Pick one and compare against rest of the user given */ + addr1 =3D addr1 ? addr1 : &dev->addr.pci; + addr2 =3D &dev->addr.pci; + + if (!(addrStr =3D virPCIDeviceAddressAsString(addr2))) + return -1; + + if (!virDomainPCIAddressValidate(addrs, addr2, addrStr, + dev->pciConnectFlags, true)) + return -1; + + if (!(addr1->domain =3D=3D addr2->domain && addr1->bus =3D=3D = addr2->bus && + addr1->slot =3D=3D addr2->slot)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Addresses belong to different PCI slots= ")); + return -1; + } + } + } + + /* Reserve all the user given addresses. */ + for (i =3D 0; i < VIR_PCI_MAX_FUNCTIONS; i++) { + dev =3D pcicard->infos[i]; + if (dev && virDeviceInfoPCIAddressIsPresent(dev)) { + ret =3D virDomainPCIAddressReserveAddrInternal(addrs, &dev->ad= dr.pci, + dev->pciConnectFl= ags, + dev->isolationGro= up, + dev->aggregateSlo= tIdx, + true); + if (ret < 0) + return ret; + } + } + + /* If the user has not given addresses, start with function zero */ + for (i =3D 0; i < VIR_PCI_MAX_FUNCTIONS; i++) { + dev =3D pcicard->infos[i]; + if (dev && !virDeviceInfoPCIAddressIsPresent(dev)) { + ret =3D virDomainPCIAddressReserveNextAddr(addrs, dev, + dev->pciConnectFlags,= i); + if (ret < 0) + return ret; + } + } + + /* Set multi on overriding what user has set. */ + pcicard->infos[0]->addr.pci.multi =3D VIR_TRISTATE_SWITCH_ON; + + return 0; +} + + void virDomainPCIAddressReleaseAddr(virDomainPCIAddressSetPtr addrs, virPCIDeviceAddressPtr addr) diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index ddcff36e51..e3c1293e1d 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -180,6 +180,11 @@ int virDomainPCIAddressEnsureAddr(virDomainPCIAddressS= etPtr addrs, virDomainPCIConnectFlags flags) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 +int +virDomainPCIAddressEnsureMultifunctionAddress(virDomainPCIAddressSetPtr ad= drs, + virDomainPCIMultifunctionAdd= ressInfoPtr pcicard) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + void virDomainPCIAddressReleaseAddr(virDomainPCIAddressSetPtr addrs, virPCIDeviceAddressPtr addr) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 29c6ac8e5e..99afe20294 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -148,6 +148,7 @@ virDomainCCWAddressSetFree; virDomainPCIAddressBusIsFullyReserved; virDomainPCIAddressBusSetModel; virDomainPCIAddressEnsureAddr; +virDomainPCIAddressEnsureMultifunctionAddress; virDomainPCIAddressExtensionReleaseAddr; virDomainPCIAddressExtensionReserveAddr; virDomainPCIAddressExtensionReserveNextAddr; diff --git a/src/util/virpci.h b/src/util/virpci.h index 64a9109d9b..8f20e31b43 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -25,6 +25,8 @@ #include "virobject.h" #include "virenum.h" =20 +#define VIR_PCI_MAX_FUNCTIONS 8 + typedef struct _virPCIDevice virPCIDevice; typedef virPCIDevice *virPCIDevicePtr; typedef struct _virPCIDeviceAddress virPCIDeviceAddress; --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009309; cv=none; d=zohomail.com; s=zohoarc; b=nUEVtSfsA+FagcNlbTeLYV0bbI/rxHS5onoipR5ME9sUXis99Wy//l+q9s5KOCU8krX43otBG/Y6ESzTuORkdQF/10Gc7deztSthTlQ2LRvDQtAjnjkRbj9wG2VxIgp7gmx4LTuF+EPOoUrPewYUdOG4XDbDjQZ4ISE80ifE/40= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009309; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SLNm4AzskS+jEoyCs0+WyFm2d/sN72XedfwEuvWJtiE=; b=UeNAZEd2nkU/g1GMWwk4BB7qhwRS6jpFhZMv73X/VhyvxTkzQR7W+08PNA+6xCYc8A/G3E1dUewAPJGS8KGjkfJqKFB9mc/HW40nig+QkQhKwxCKLA7oBymPzXGLEWDz6h76Y5yfQRB7ttCSDao9morleuFhkvHFfPeB6XKic+U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1590009309583160.9841884924116; Wed, 20 May 2020 14:15:09 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-293-6PprPDNDO2yVO5B9SpmPKA-1; Wed, 20 May 2020 17:15:04 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 18626474; Wed, 20 May 2020 21:14:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EC6AC7959C; Wed, 20 May 2020 21:14:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BF32C180CB39; Wed, 20 May 2020 21:14:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCgRh002255 for ; Wed, 20 May 2020 17:12:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6AAB42166BA3; Wed, 20 May 2020 21:12:42 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6681D2166BA2 for ; Wed, 20 May 2020 21:12:42 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 42C60800296 for ; Wed, 20 May 2020 21:12:42 +0000 (UTC) Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-356-yqC7xuErN4y6lgqDiU0BoA-1; Wed, 20 May 2020 17:12:40 -0400 Received: by mail-qk1-f193.google.com with SMTP id m11so5186651qka.4 for ; Wed, 20 May 2020 14:12:39 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009308; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=SLNm4AzskS+jEoyCs0+WyFm2d/sN72XedfwEuvWJtiE=; b=aXvjSa42+5OHS4YTf3gUS1Wo2eAdeIRCiqvkqDGNp3Rp2ctH65kU8i/bLH7W0V3Wr2gARG jaMsLvEVT/UkdF/N8xDsqnFAjogXbbmu1IpzbIr4qErgacfBPP5L2/gkOUa4g3BGGb7zGP woXPTx2AVEPFGRodu+b17b4UcLlWrfM= X-MC-Unique: 6PprPDNDO2yVO5B9SpmPKA-1 X-MC-Unique: yqC7xuErN4y6lgqDiU0BoA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SLNm4AzskS+jEoyCs0+WyFm2d/sN72XedfwEuvWJtiE=; b=S26BaQAlkrAEGrrVjR6HDH4DCdjEeVtbfaApHVL0vvI/3y+61sNXfl06/VrjX/T68g 9/lHAFj25GgSZOsQPiN9eojeDRwvHkCsQHdn0+jjl7ctpcsLbKcVyyq9NFAZfDUd2D+M MguJ6MzuxoKsxRvNqf6pMiuhDq2NjL8zB5SiIOWp79xjYPgZ2RIcQD68TYdON2yqBFdl fojqNTVl5cx6h7lCBy58qzMk77VxBWuKAyQcgKwQS3oXAe0nYdIinWkGAv/VaLu3pnon xgawGnJTPI3qdvgX044i+TaLsuxyt0kVfG2VtNMxfkHUY/rIoWml577Hdv7pJb7Wn33x SCYw== X-Gm-Message-State: AOAM533oOnegqQTP5JmNG4eHvzYkypFMLQAPf1sIftbpIJ7T09bjBWTp kYvBCSkGorDCkT13JdLqqe0Iy8DQ X-Google-Smtp-Source: ABdhPJzyzTYP4WOMQGBb8dzAzWObvdbket7i1Sf216reyksKv2XyleSsiDsAOkypLJuScTwd216wJw== X-Received: by 2002:a37:9f44:: with SMTP id i65mr1067085qke.103.1590009158685; Wed, 20 May 2020 14:12:38 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 16/21] qemu: hotplug: Implement multifunction device hotplug Date: Wed, 20 May 2020 18:11:38 -0300 Message-Id: <20200520211143.2980117-17-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat The support to allow multifunction device hotplug consists of using virDomainDeviceDefListPtr lists instead of single virDomainDeviceDefPtr device definitions in both qemuDomainAttachDeviceConfig() and qemuDomainAttachDeviceLive(). In AttachDeviceConfig() the same existing single device code is ran for all devs in the list. AttachDeviceLive() will verify if the list has size =3D 1 (meaning it is a single device attach) and redirect the code to the regular single dev attach procedure. If list size > 1, we'll execute a new specialized function called qemuDomainAttachMultifunctionDevice(), which is prepared to handle the nuances of this type of hotplug. The changes in both AttachDeviceLive() and AttachDeviceConfig() implied in changes to be made in qemuDomainAttachDeviceLiveAndConfig(), which is now handling a device list instead of a single device. No changes in regular device hotplug mechanics were made. Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_domain_address.c | 74 +++++++++++ src/qemu/qemu_domain_address.h | 4 + src/qemu/qemu_driver.c | 119 +++++++++++------- src/qemu/qemu_hotplug.c | 86 +++++++++++++ src/qemu/qemu_hotplug.h | 4 + tests/qemuhotplugtest.c | 39 ++++-- ...emuhotplug-multifunction-hostdev-pci-2.xml | 14 +++ .../qemuhotplug-multifunction-hostdev-pci.xml | 26 ++++ ...ug-base-live+multifunction-hostdev-pci.xml | 82 ++++++++++++ ...-base-live+multifunction-hostdev-pci-2.xml | 59 +++++++++ ...es-base-live+multifunction-hostdev-pci.xml | 69 ++++++++++ 11 files changed, 524 insertions(+), 52 deletions(-) create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-multifunction-= hostdev-pci-2.xml create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-multifunction-= hostdev-pci.xml create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-live+mult= ifunction-hostdev-pci.xml create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-pseries-base-l= ive+multifunction-hostdev-pci-2.xml create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-pseries-base-l= ive+multifunction-hostdev-pci.xml diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 05ef4de100..94d91a5daf 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -23,6 +23,7 @@ =20 #include "qemu_domain_address.h" #include "qemu_domain.h" +#include "domain_conf.h" #include "viralloc.h" #include "virhostdev.h" #include "virerror.h" @@ -3439,6 +3440,79 @@ qemuDomainEnsurePCIAddress(virDomainObjPtr obj, info->pciConnectFlags); } =20 + +int +qemuDomainPCIMultifunctionHostdevEnsurePCIAddresses(virDomainObjPtr vm, + virDomainDeviceDefList= Ptr devlist, + virQEMUDriverPtr drive= r) +{ + int ret =3D -1, aggrslotidx =3D 0; + virBitmapPtr slotmap =3D NULL; + size_t i; + qemuDomainObjPrivatePtr priv =3D vm->privateData; + virDomainPCIMultifunctionAddressInfoPtr devinfos =3D NULL; + + if (devlist->count > VIR_PCI_MAX_FUNCTIONS) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("More devices per slot found")); + return -1; + } + + for (i =3D 0; i < devlist->count; i++) + qemuDomainFillDevicePCIConnectFlags(vm->def, devlist->devs[i], + priv->qemuCaps, driver); + + if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + devlist->cou= nt) < 0) + return -1; + + /* Temporarily add the devices to the domain def to get the + * next aggregateIdx */ + for (i =3D 0; i < devlist->count; i++) + vm->def->hostdevs[vm->def->nhostdevs++] =3D devlist->devs[i]->data= .hostdev; + + for (i =3D 0; i < devlist->count; i++) { + virDomainHostdevDefPtr hostdev =3D devlist->devs[i]->data.hostdev; + + if (qemuDomainIsPSeries(vm->def)) + /* Isolation groups are only relevant for pSeries guests */ + qemuDomainFillDeviceIsolationGroup(vm->def, devlist->devs[i]); + + qemuDomainSetDeviceSlotAggregateIdx(vm->def, devlist->devs[i]); + aggrslotidx =3D aggrslotidx ? aggrslotidx : hostdev->info->aggrega= teSlotIdx; + + if (aggrslotidx !=3D hostdev->info->aggregateSlotIdx) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Devices belong to different PCI slots")); + return -1; + } + } + + for (i =3D 0; i < devlist->count; i++) + vm->def->hostdevs[--(vm->def->nhostdevs)] =3D NULL; + + slotmap =3D virDomainDefHostdevGetPCIOnlineFunctionMap(vm->def, aggrsl= otidx); + if (!virBitmapIsAllClear(slotmap)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("Device already assigned to guest")); + return -1; + } + + if (VIR_ALLOC(devinfos) < 0) + return -1; + + for (i =3D 0; i < devlist->count; i++) { + virDomainHostdevDefPtr hostdev =3D devlist->devs[i]->data.hostdev; + virPCIDeviceAddress addr =3D hostdev->source.subsys.u.pci.addr; + + devinfos->infos[addr.function] =3D hostdev->info; + } + + ret =3D virDomainPCIAddressEnsureMultifunctionAddress(priv->pciaddrs, = devinfos); + VIR_FREE(devinfos); + return ret; +} + + void qemuDomainReleaseDeviceAddress(virDomainObjPtr vm, virDomainDeviceInfoPtr info) diff --git a/src/qemu/qemu_domain_address.h b/src/qemu/qemu_domain_address.h index 8d51456f5b..b9ba577001 100644 --- a/src/qemu/qemu_domain_address.h +++ b/src/qemu/qemu_domain_address.h @@ -50,6 +50,10 @@ int qemuDomainEnsurePCIAddress(virDomainObjPtr obj, virQEMUDriverPtr driver) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); =20 +int qemuDomainPCIMultifunctionHostdevEnsurePCIAddresses(virDomainObjPtr ob= j, + virDomainDeviceDef= ListPtr devlist, + virQEMUDriverPtr d= river); + void qemuDomainFillDeviceIsolationGroup(virDomainDefPtr def, virDomainDeviceDefPtr dev) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f880a5d6cf..3217d93a73 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7977,17 +7977,28 @@ qemuDomainAttachDeviceLiveInternal(virDomainObjPtr = vm, =20 static int qemuDomainAttachDeviceLive(virDomainObjPtr vm, - virDomainDeviceDefPtr dev, + virDomainDeviceDefListPtr devlist, virQEMUDriverPtr driver) { int ret =3D -1; + size_t i; =20 - if (virDomainDefCompatibleDevice(vm->def, dev, NULL, - VIR_DOMAIN_DEVICE_ACTION_ATTACH, - false) < 0) - return -1; + for (i =3D 0; i < devlist->count; i++) + if (virDomainDefCompatibleDevice(vm->def, devlist->devs[i], NULL, + VIR_DOMAIN_DEVICE_ACTION_ATTACH, + false) < 0) + return ret; + + if (devlist->count > 1) { + ret =3D qemuDomainAttachMultifunctionDevice(vm, devlist, driver); + if (ret =3D=3D 0) { + for (i =3D 0; i < devlist->count; i++) + devlist->devs[i]->data.hostdev =3D NULL; + } + } else if (devlist->count =3D=3D 1) { + ret =3D qemuDomainAttachDeviceLiveInternal(vm, devlist->devs[0], d= river); + } =20 - ret =3D qemuDomainAttachDeviceLiveInternal(vm, dev, driver); if (ret =3D=3D 0) ret =3D qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE= ); =20 @@ -8334,18 +8345,24 @@ qemuDomainAttachDeviceConfigInternal(virDomainDefPt= r vmdef, =20 static int qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef, - virDomainDeviceDefPtr dev, + virDomainDeviceDefListPtr devlist, virQEMUCapsPtr qemuCaps, unsigned int parse_flags, virDomainXMLOptionPtr xmlopt) { - if (virDomainDefCompatibleDevice(vmdef, dev, NULL, - VIR_DOMAIN_DEVICE_ACTION_ATTACH, - false) < 0) - return -1; + size_t i; =20 - if (qemuDomainAttachDeviceConfigInternal(vmdef, dev)) - return -1; + for (i =3D 0; i < devlist->count; i++) { + if (virDomainDefCompatibleDevice(vmdef, devlist->devs[i], NULL, + VIR_DOMAIN_DEVICE_ACTION_ATTACH, + false) < 0) + return -1; + } + + for (i =3D 0; i < devlist->count; i++) { + if (qemuDomainAttachDeviceConfigInternal(vmdef, devlist->devs[i])) + return -1; + } =20 if (virDomainDefPostParse(vmdef, parse_flags, xmlopt, qemuCaps) < 0) return -1; @@ -8711,9 +8728,14 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr = vm, qemuDomainObjPrivatePtr priv =3D vm->privateData; virDomainDefPtr vmdef =3D NULL; g_autoptr(virQEMUDriverConfig) cfg =3D NULL; - virDomainDeviceDefPtr devConf =3D NULL; - virDomainDeviceDef devConfSave =3D { 0 }; + virDomainDeviceDefPtr devConfSave =3D NULL; virDomainDeviceDefPtr devLive =3D NULL; + virDomainDeviceDefListPtr devListConf =3D NULL; + virDomainDeviceDefListPtr devListConfSave =3D NULL; + virDomainDeviceDefListPtr devListLive =3D NULL; + virDomainDeviceDefListData data =3D {.def =3D vm->def, + .xmlopt =3D driver->xmlopt}; + size_t i; int ret =3D -1; unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_ABI_UPDATE; @@ -8732,52 +8754,58 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr= vm, if (!vmdef) goto cleanup; =20 - if (!(devConf =3D virDomainDeviceDefParse(xml, vmdef, - driver->xmlopt, priv->qemu= Caps, - parse_flags))) + devListConf =3D qemuDomainDeviceParseXMLMany(xml, &data, priv->qem= uCaps, + parse_flags); + if (!devListConf) goto cleanup; =20 /* - * devConf will be NULLed out by + * devListConf will be NULLed out by * qemuDomainAttachDeviceConfig(), so save it for later use by * qemuDomainAttachDeviceLiveAndConfigHomogenize() */ - devConfSave =3D *devConf; - - if (virDomainDeviceValidateAliasForHotplug(vm, devConf, - VIR_DOMAIN_AFFECT_CONFI= G) < 0) - goto cleanup; + if (flags & VIR_DOMAIN_AFFECT_LIVE) { + devListConfSave =3D virDomainDeviceDefListCopy(devListConf, + &data, + priv->qemuCaps); + if (!devListConfSave) + goto cleanup; + } =20 - if (virDomainDefCompatibleDevice(vmdef, devConf, NULL, - VIR_DOMAIN_DEVICE_ACTION_ATTACH, - false) < 0) - goto cleanup; + for (i =3D 0; i < devListConf->count; i++) { + if (virDomainDeviceValidateAliasForHotplug(vm, + devListConf->devs[i= ], + flags) < 0) + goto cleanup; + } =20 - if (qemuDomainAttachDeviceConfig(vmdef, devConf, priv->qemuCaps, + if (qemuDomainAttachDeviceConfig(vmdef, devListConf, priv->qemuCap= s, parse_flags, driver->xmlopt) < 0) goto cleanup; } =20 if (flags & VIR_DOMAIN_AFFECT_LIVE) { - if (!(devLive =3D virDomainDeviceDefParse(xml, vm->def, - driver->xmlopt, priv->qemu= Caps, - parse_flags))) + devListLive =3D qemuDomainDeviceParseXMLMany(xml, &data, priv->qem= uCaps, + parse_flags); + if (!devListLive) goto cleanup; =20 - if (flags & VIR_DOMAIN_AFFECT_CONFIG) - qemuDomainAttachDeviceLiveAndConfigHomogenize(&devConfSave, de= vLive); + for (i =3D 0; i < devListLive->count; i++) { + devLive =3D devListLive->devs[i]; =20 - if (virDomainDeviceValidateAliasForHotplug(vm, devLive, - VIR_DOMAIN_AFFECT_LIVE)= < 0) - goto cleanup; + if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + devConfSave =3D devListConfSave->devs[i]; + qemuDomainAttachDeviceLiveAndConfigHomogenize(devConfSave, + devLive); + } =20 - if (virDomainDefCompatibleDevice(vm->def, devLive, NULL, - VIR_DOMAIN_DEVICE_ACTION_ATTACH, - true) < 0) - goto cleanup; + if (virDomainDeviceValidateAliasForHotplug(vm, devLive, + VIR_DOMAIN_AFFECT_L= IVE) < 0) + goto cleanup; + } =20 - if (qemuDomainAttachDeviceLive(vm, devLive, driver) < 0) + if (qemuDomainAttachDeviceLive(vm, devListLive, driver) < 0) goto cleanup; /* * update domain status forcibly because the domain status may be @@ -8800,8 +8828,11 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr = vm, ret =3D 0; cleanup: virDomainDefFree(vmdef); - virDomainDeviceDefFree(devConf); - virDomainDeviceDefFree(devLive); + devConfSave =3D NULL; + devLive =3D NULL; + virDomainDeviceDefListFree(devListConf); + virDomainDeviceDefListFree(devListConfSave); + virDomainDeviceDefListFree(devListLive); =20 return ret; } diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index b9946e8b8e..a6c520ec1b 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1685,6 +1685,92 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr drive= r, } =20 =20 +static int +qemuiHostdevPCIMultifunctionDevicesListSort(const void *p1, + const void *p2) +{ + virDomainDeviceDefPtr a =3D *(virDomainDeviceDefPtr *) p1; + virDomainDeviceDefPtr b =3D *(virDomainDeviceDefPtr *) p2; + virPCIDeviceAddressPtr addr1 =3D &a->data.hostdev->source.subsys.u.pci= .addr; + virPCIDeviceAddressPtr addr2 =3D &b->data.hostdev->source.subsys.u.pci= .addr; + + return addr1->function - addr2->function; +} + + +int +qemuDomainAttachMultifunctionDevice(virDomainObjPtr vm, + virDomainDeviceDefListPtr devlist, + virQEMUDriverPtr driver) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + size_t i, d, h =3D devlist->count; + int ret =3D -1; + char *alias; + virObjectEventPtr event; + virDomainHostdevDefPtr hostdev; + + qsort(devlist->devs, devlist->count, sizeof(*devlist->devs), + qemuiHostdevPCIMultifunctionDevicesListSort); + + if (qemuDomainPCIMultifunctionHostdevEnsurePCIAddresses(vm, devlist, + driver) < 0) + return -1; + + for (d =3D 0; d < devlist->count; d++) { + hostdev =3D devlist->devs[d]->data.hostdev; + + if (qemuDomainAttachPCIHostDevicePrepare(driver, vm->def, hostdev, + priv->qemuCaps) < 0) + goto cleanup; + } + + /* Hotplug all functions, and Primary at last */ + for (h =3D devlist->count; h > 0; h--) { + /* The functions need not be contiguous, as a card may be sold with + * minimal functionality and then install the additional functions= on + * purchase into any of the daughter-card connectors. + */ + hostdev =3D devlist->devs[h-1]->data.hostdev; + + ret =3D qemuDomainAttachHostPCIDevice(driver, vm, hostdev); + if (ret) + goto release; + + alias =3D hostdev->info->alias; + hostdev =3D NULL; + + event =3D virDomainEventDeviceAddedNewFromObj(vm, alias); + virObjectEventStateQueue(driver->domainEventState, event); + } + + release: + /* Release addresses for the device which are not hotplugged. + */ + for (i =3D 0; i < h; i++) + qemuDomainReleaseDeviceAddress(vm, devlist->devs[i]->data.hostdev-= >info); + + cleanup: + /* If none are actually hotplugged and just detached from the + * host driver reattach the devices to host driver. + * + * If one of the hotplug failed, those which are already hotplugged ca= nnot + * be unplugged as they are released by qemu only on guest reboot even + * if we issue device_del on them. + * So, dont attempt to reattach any of them. + * NB: Let them be in the guest as they are not used anyway without + * function-zero? + */ + if (d > 0 && h =3D=3D devlist->count) { + for (i =3D 0; i < d; i++) + qemuHostdevReAttachPCIDevices(driver, vm->def->name, + &devlist->devs[i]->data.hostdev,= 1); + } + + return ret; +} + + void qemuDomainDelTLSObjects(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 9df4a4e5f7..b62528a6d9 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -126,6 +126,10 @@ int qemuDomainAttachPCIHostDevicePrepare(virQEMUDriver= Ptr driver, virDomainDefPtr def, virDomainHostdevDefPtr dev, virQEMUCapsPtr qemuCaps); +int +qemuDomainAttachMultifunctionDevice(virDomainObjPtr vm, + virDomainDeviceDefListPtr devlist, + virQEMUDriverPtr driver); =20 int qemuDomainChrInsert(virDomainDefPtr vmdef, diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 57f64d191c..32d186ef73 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -90,6 +90,7 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt, virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_PR_MANAGER_HELPER); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_SCSI_BLOCK); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY); + virQEMUCapsSet(priv->qemuCaps, X_QEMU_CAPS_PCI_MULTIFUNCTION); =20 if (qemuTestCapsCacheInsert(driver.qemuCapsCache, priv->qemuCaps) < 0) return -1; @@ -118,9 +119,14 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt, =20 static int testQemuHotplugAttach(virDomainObjPtr vm, - virDomainDeviceDefPtr dev) + virDomainDeviceDefListPtr devlist) { int ret =3D -1; + virDomainDeviceDefPtr dev; + + if (devlist->count > 1) + return qemuDomainAttachMultifunctionDevice(vm, devlist, &driver); + dev =3D devlist->devs[0]; =20 switch (dev->type) { case VIR_DOMAIN_DEVICE_DISK: @@ -245,7 +251,9 @@ testQemuHotplug(const void *data) bool keep =3D test->keep; unsigned int device_parse_flags =3D 0; virDomainObjPtr vm =3D NULL; - virDomainDeviceDefPtr dev =3D NULL; + virDomainDeviceDefPtr dev =3D NULL; /* temporary */ + virDomainDeviceDefListPtr devlist =3D NULL; + virDomainDeviceDefListData listdata; virCapsPtr caps =3D NULL; qemuMonitorTestPtr test_mon =3D NULL; qemuDomainObjPrivatePtr priv =3D NULL; @@ -283,11 +291,15 @@ testQemuHotplug(const void *data) if (test->action =3D=3D ATTACH) device_parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE; =20 - if (!(dev =3D virDomainDeviceDefParse(device_xml, vm->def, - driver.xmlopt, NULL, - device_parse_flags))) + listdata.def =3D vm->def; + listdata.xmlopt =3D driver.xmlopt; + devlist =3D qemuDomainDeviceParseXMLMany(device_xml, &listdata, NULL, + device_parse_flags); + if (!devlist) goto cleanup; =20 + dev =3D devlist->devs[0]; /* temporary */ + /* Now is the best time to feed the spoofed monitor with predefined * replies. */ if (!(test_mon =3D qemuMonitorTestNew(driver.xmlopt, vm, &driver, @@ -316,11 +328,11 @@ testQemuHotplug(const void *data) =20 switch (test->action) { case ATTACH: - ret =3D testQemuHotplugAttach(vm, dev); + ret =3D testQemuHotplugAttach(vm, devlist); if (ret =3D=3D 0) { /* vm->def stolen dev->data.* so we just need to free the dev * envelope */ - VIR_FREE(dev); + virDomainDeviceDefListFreeShallow(devlist); } if (ret =3D=3D 0 || fail) ret =3D testQemuHotplugCheckResult(vm, result_xml, @@ -356,7 +368,7 @@ testQemuHotplug(const void *data) virObjectUnref(vm); test->vm =3D NULL; } - virDomainDeviceDefFree(dev); + virDomainDeviceDefListFree(devlist); virObjectUnref(caps); qemuMonitorTestFree(test_mon); return ((ret < 0 && fail) || (!ret && !fail)) ? 0 : -1; @@ -840,6 +852,17 @@ mymain(void) "device_add", QMP_OK); DO_TEST_DETACH("pseries-base-live", "hostdev-pci", false, false, "device_del", QMP_DEVICE_DELETED("hostdev0") QMP_OK); + DO_TEST_ATTACH("base-live", "multifunction-hostdev-pci", false, false, + "device_add", QMP_OK, + "device_add", QMP_OK, + "device_add", QMP_OK, + "device_add", QMP_OK); + + qemuTestSetHostArch(&driver, VIR_ARCH_PPC64); + DO_TEST_ATTACH("pseries-base-live", "multifunction-hostdev-pci-2", fal= se, false, + "device_add", QMP_OK, + "device_add", QMP_OK); + qemuTestSetHostArch(&driver, VIR_ARCH_X86_64); =20 DO_TEST_ATTACH("base-live", "watchdog", false, true, "watchdog-set-action", QMP_OK, diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-multifunction-hostdev= -pci-2.xml b/tests/qemuhotplugtestdevices/qemuhotplug-multifunction-hostdev= -pci-2.xml new file mode 100644 index 0000000000..02e2236e5d --- /dev/null +++ b/tests/qemuhotplugtestdevices/qemuhotplug-multifunction-hostdev-pci-2.= xml @@ -0,0 +1,14 @@ + + + + +
+ + + + + +
+ + + diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-multifunction-hostdev= -pci.xml b/tests/qemuhotplugtestdevices/qemuhotplug-multifunction-hostdev-p= ci.xml new file mode 100644 index 0000000000..bef4be219f --- /dev/null +++ b/tests/qemuhotplugtestdevices/qemuhotplug-multifunction-hostdev-pci.xml @@ -0,0 +1,26 @@ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+multifuncti= on-hostdev-pci.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+mul= tifunction-hostdev-pci.xml new file mode 100644 index 0000000000..9dd04d3350 --- /dev/null +++ b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+multifunction-host= dev-pci.xml @@ -0,0 +1,82 @@ + + hotplug + d091ea82-29e6-2e34-3005-f02617b36e87 + 4194304 + 4194304 + 4 + + hvm + + + + + + + + + destroy + restart + restart + + /usr/bin/qemu-system-x86_64 + + +
+ + + +
+ + + +
+ + + + + + +
+ + + + + + + + + + +
+ + +
+ + + + +
+ + +
+ + + + +
+ + +
+ + + + +
+ + +
+ + + + + diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-pseries-base-live+mul= tifunction-hostdev-pci-2.xml b/tests/qemuhotplugtestdomains/qemuhotplug-pse= ries-base-live+multifunction-hostdev-pci-2.xml new file mode 100644 index 0000000000..f99c1b3741 --- /dev/null +++ b/tests/qemuhotplugtestdomains/qemuhotplug-pseries-base-live+multifunct= ion-hostdev-pci-2.xml @@ -0,0 +1,59 @@ + + hotplug + d091ea82-29e6-2e34-3005-f02617b36e87 + 4194304 + 4194304 + 4 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-ppc64 + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + + +
+ + +
+ + + + +
+ + +
+ + + + + + diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-pseries-base-live+mul= tifunction-hostdev-pci.xml b/tests/qemuhotplugtestdomains/qemuhotplug-pseri= es-base-live+multifunction-hostdev-pci.xml new file mode 100644 index 0000000000..9338d42e2e --- /dev/null +++ b/tests/qemuhotplugtestdomains/qemuhotplug-pseries-base-live+multifunct= ion-hostdev-pci.xml @@ -0,0 +1,69 @@ + + hotplug + d091ea82-29e6-2e34-3005-f02617b36e87 + 4194304 + 4194304 + 4 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-ppc64 + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + + +
+ + +
+ + + + +
+ + +
+ + + + +
+ + +
+ + + + + + + + --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009312; cv=none; d=zohomail.com; s=zohoarc; b=PYuG9kIILVSRQ6jLQJzavTYWUj5emeswa5FYlH8RL4/5pryeHhcV3zn0MC9t/vhNEtO4+pSkzKxwvyxDnErytZ+pIhrdljdxkhLdmvWm0ovv2xD6uvFslZf/cjBqzQwXX/HVBxL1XnW5nQ1S0NqvrPcI9C2ro7ADBiq+gXrKAvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009312; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=poSdcbzQKSdRWDxOewcD2oAfw5WfKnxqJKfQxlKYPQg=; b=aMe7Bp6L1yIFJ+lnHFXhNiJTUrGAJjjP6wiT8iz5dJIuE6yGJlCpD1uNoglbpIS1dsGe03kZARZupEhlrk9uEfSX4F1Vc25DZAkLOoZ36JG7Mdh9cmRKXKEQS3GUNUkoT2ONdXcLIHEb0NhfeFboyDJjnuNR3hZXBTdNuR+gDkQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1590009312067672.7780542654577; Wed, 20 May 2020 14:15:12 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-74-D9q3N3SiO3CNFhYxZIqAkA-1; Wed, 20 May 2020 17:15:06 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C822A0BE0; Wed, 20 May 2020 21:15:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 47EA560C84; Wed, 20 May 2020 21:15:01 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1950A54D01; Wed, 20 May 2020 21:15:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLChVS002271 for ; Wed, 20 May 2020 17:12:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9FF6463537; Wed, 20 May 2020 21:12:43 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9C21A8A4C4 for ; Wed, 20 May 2020 21:12:43 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 846978007D0 for ; Wed, 20 May 2020 21:12:43 +0000 (UTC) Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-264-UCgGj6VgNGuwkzM-2VSD-Q-1; Wed, 20 May 2020 17:12:41 -0400 Received: by mail-qk1-f195.google.com with SMTP id y22so5183758qki.3 for ; Wed, 20 May 2020 14:12:41 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009310; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=poSdcbzQKSdRWDxOewcD2oAfw5WfKnxqJKfQxlKYPQg=; b=BTgxMeQn1xTfXIArD3LcWvYmWjwx45jhK+ae3zLg9WD2M4LQSpTyeryW4N4J2RiZAv6taE MaghY52sMQ9WsL7LlMMg9FgnB9kHr0RXGoDa44DfP9XBhEbdzE6MuTh0SjiB9Q61dmpWUq p2tD2FmFNSycqZ2mhBGF8N0ODXxw6qo= X-MC-Unique: D9q3N3SiO3CNFhYxZIqAkA-1 X-MC-Unique: UCgGj6VgNGuwkzM-2VSD-Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=poSdcbzQKSdRWDxOewcD2oAfw5WfKnxqJKfQxlKYPQg=; b=FkMoIXzFj/VcntEiaAoRVPnPvA7KQomp+LcjWnIE/BSUH6ifLcHYkN/Yts+sBb3BId 4h5C5b5IsmUcaTII9EaIyZXqmNbz1Cvje1G81SHsTDVAQz+WqpkpFppFb4vHRSisjSxb 1XIVVeCW7CIkIrxo+eEjb5Ju45KVUSAKAPxecPn/RX9ERMktPTv2TPMVsTVfhXyhjnAx jl/9qKTFV/mxM/FBhuTtoayWD81rqVGwR24ZGfsxsY5by1t/JLUi9by3TuxBmNTRkafA yUan3DDyZAMXaTR9fNgqPXVYI2lJWmrlaLP47e7Cl6rR7z+eemcgbvlr+ecG++P94cwG 2CMg== X-Gm-Message-State: AOAM532qY9vdfMdkGqW50eVpZRwQy18Cqv5mSq2gvMYnz4gjd1RnZIf3 F+hQgDA1oktuy/bVimV/ak9UC51M X-Google-Smtp-Source: ABdhPJxNMuZ1c9Tl5QZwGXIovU6jxPm57V1DRG/A5ySeLVSoYpdHooqOPOQGcHfAfPbIuVxkKvmYvA== X-Received: by 2002:a37:7603:: with SMTP id r3mr6585253qkc.243.1590009160743; Wed, 20 May 2020 14:12:40 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 17/21] qemu: hotplug: Prevent updates to multifunction device Date: Wed, 20 May 2020 18:11:39 -0300 Message-Id: <20200520211143.2980117-18-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat PCI hostdevs once part of the domain can't be changed. Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_driver.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 3217d93a73..ce44a1455a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8889,6 +8889,8 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr d= om, virDomainObjPtr vm =3D NULL; qemuDomainObjPrivatePtr priv; virDomainDefPtr vmdef =3D NULL; + virDomainDeviceDefListPtr devlist; + virDomainDeviceDefListData data =3D {.xmlopt =3D driver->xmlopt}; virDomainDeviceDefPtr dev =3D NULL, dev_copy =3D NULL; bool force =3D (flags & VIR_DOMAIN_DEVICE_MODIFY_FORCE) !=3D 0; int ret =3D -1; @@ -8906,6 +8908,8 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr d= om, if (!(vm =3D qemuDomainObjFromDomain(dom))) goto cleanup; =20 + data.def =3D vm->def; + priv =3D vm->privateData; =20 if (virDomainUpdateDeviceFlagsEnsureACL(dom->conn, vm->def, flags) < 0) @@ -8921,12 +8925,20 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr= dom, !(flags & VIR_DOMAIN_AFFECT_LIVE)) parse_flags |=3D VIR_DOMAIN_DEF_PARSE_INACTIVE; =20 - dev =3D dev_copy =3D virDomainDeviceDefParse(xml, vm->def, - driver->xmlopt, priv->qemuCap= s, - parse_flags); - if (dev =3D=3D NULL) + + devlist =3D qemuDomainDeviceParseXMLMany(xml, &data, priv->qemuCaps, + parse_flags); + if (!devlist) goto endjob; =20 + if (devlist->count > 1) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("Update of multifunction devices is not supported= ")); + goto endjob; + } + + dev =3D dev_copy =3D devlist->devs[0]; + if (flags & VIR_DOMAIN_AFFECT_CONFIG && flags & VIR_DOMAIN_AFFECT_LIVE) { /* If we are affecting both CONFIG and LIVE --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009278; cv=none; d=zohomail.com; s=zohoarc; b=L8jthF5Kligd9FoHIwOmzflXL3VcxVnfL65I/5TQimDkqNHzpPX4dVOzX7oCqmhyu0gR4L8FwPbYZioRcOeTQbJzZwL80N+xgI3kZcVDz6zV/oVEr1MrlVoz4Yq3AmUlWK/N+OhvT663i5SN//uGkry/XtAwIapp8Tlk2IRQnX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009278; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ke4etmALym6Wo5GkDtFOywwZemXQZzn1hU5m0XPVi0k=; b=XyUu2aBRglRiu2phuQdK0QH28PH/bG9Ugs6puHg3O3Q/gF0RJDaVp1difXDV6bB2fM0m3WQB7esfEuivUAKi4dRNGd4s+32jacO7ixjTg2B9BvYE3OCJDRP5Vh0OIl4IgLbs4W0Wjcfecfd4sQgotxNDtQl/2zUAfuWz31DgiG4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1590009278432214.24982849632568; Wed, 20 May 2020 14:14:38 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-471-mtMSRRFNMyKaRuIoWLOq6A-1; Wed, 20 May 2020 17:14:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B2F08018A6; Wed, 20 May 2020 21:14:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5C0FA6E9EA; Wed, 20 May 2020 21:14:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2C49C180954D; Wed, 20 May 2020 21:14:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCoOM002368 for ; Wed, 20 May 2020 17:12:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8EBDC1007A45; Wed, 20 May 2020 21:12:50 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7177810D14F9 for ; Wed, 20 May 2020 21:12:46 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3E59C800294 for ; Wed, 20 May 2020 21:12:46 +0000 (UTC) Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-400-aoI4Da79ON6Gq3Bm68XYTw-1; Wed, 20 May 2020 17:12:43 -0400 Received: by mail-qk1-f193.google.com with SMTP id b6so5111461qkh.11 for ; Wed, 20 May 2020 14:12:43 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009277; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Ke4etmALym6Wo5GkDtFOywwZemXQZzn1hU5m0XPVi0k=; b=Rvk4IGZGbz4t2itMhxjyNgl5EW7h0iIykYz7/+9GCM/X0QybdMdac2lvni2ywf7HkQ8tHV psW1vjZ3cX+1RmozJKztf7mtM4p7r9m6ehbPJQGhdPkGe8VqSSVdmzh0rRMDUbjVfuxeKS aayfaS9ammRFusSJZZhTxbIFL3rFA1U= X-MC-Unique: mtMSRRFNMyKaRuIoWLOq6A-1 X-MC-Unique: aoI4Da79ON6Gq3Bm68XYTw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ke4etmALym6Wo5GkDtFOywwZemXQZzn1hU5m0XPVi0k=; b=BxGwzLZYLHR3fhM+LaiXQP4FSuIe4DBQS/3w37dOvCrwpRA6baPcp3nOhryYwL+qLa mUtNw1q+Rv+cl/BSqPdggF/9UqwSKVEsnHAwj1IbSTtzo/HMC2fkmwgBt2e8Hr2XN3nv F+masTZn0a43BWE0G1MVwRhv8CUx6L8QSi1U5JRGE5D0dKGtAcX3UwfzE4YIH9XJDzlh KKIyMUcqXAFPx12Wmzyq7OylDfT4SpS0gTs2vms7tpGMcAU9GyWwWgtGZfKOJOyJoZfI yhjYh98CJuoGmVscVP69v+5J9GGm4ePsEJ3N0eRcJKfpH6GSSF0/QYPMPxWupPuI8QXG HGeg== X-Gm-Message-State: AOAM532dBsfrdH52StAMEZZKxJMEo/nkTp+jHFgeG1SuoIpcZq17/HMh kZftwd6GgM6E87ISCqe7liiHscU3 X-Google-Smtp-Source: ABdhPJweejTLn71xwbs/GuNqjYbuJxcow5AfCID/5R/dO393gbdiUoOcoI4CV5HxgRUuqjk44OiFwA== X-Received: by 2002:a37:7904:: with SMTP id u4mr6787632qkc.297.1590009162845; Wed, 20 May 2020 14:12:42 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 18/21] qemu: hotplug: Implement multifunction device unplug Date: Wed, 20 May 2020 18:11:40 -0300 Message-Id: <20200520211143.2980117-19-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Shivaprasad G Bhat The same design ideas used in multifunction hotplug were used here as well. qemuDomainDetachDeviceConfig() was changed to accept a list of devices instead of a single device definition. qemuDomainDetachDeviceLiveAndConfig() was changed to handle device lists as well. For VIR_DOMAIN_AFFECT_LIVE, check if we're handling a single device unplug (devlist size =3D 1) and forward it to the regular qemuDomainDetachDeviceLive() function. Otherwise, a new qemuDomainDetachMultifunctionDevice() was added to handle the hot-unplug of multifunction devices. DetachMultifunctionDevice() is not considering the new multifunction unplug mechanics for the Pseries guest, present in QEMU 4.2 (the newest release ATM), to not break compatibility with older QEMU versions. This will be done properly in a later patch. Signed-off-by: Shivaprasad G Bhat Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_driver.c | 66 +++++++++++++++------- src/qemu/qemu_hotplug.c | 116 +++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_hotplug.h | 5 ++ src/qemu/qemu_validate.c | 2 +- src/qemu/qemu_validate.h | 1 + tests/qemuhotplugtest.c | 27 ++++++--- 6 files changed, 189 insertions(+), 28 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ce44a1455a..e7119fda8c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -50,6 +50,7 @@ #include "qemu_security.h" #include "qemu_checkpoint.h" #include "qemu_backup.h" +#include "qemu_validate.h" =20 #include "virerror.h" #include "virlog.h" @@ -8569,17 +8570,27 @@ qemuDomainDetachDeviceConfigInternal(virDomainDefPt= r vmdef, =20 static int qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef, - virDomainDeviceDefPtr dev, + virDomainDeviceDefListPtr devlist, virQEMUCapsPtr qemuCaps, unsigned int parse_flags, virDomainXMLOptionPtr xmlopt) { - if (qemuDomainDetachDeviceConfigInternal(vmdef, dev)) - return -1; + size_t i; + + for (i =3D 0; i < devlist->count; i++) { + if (qemuDomainDetachDeviceConfigInternal(vmdef, devlist->devs[i])) + return -1; + } =20 if (virDomainDefPostParse(vmdef, parse_flags, xmlopt, qemuCaps) < 0) return -1; =20 + /* Don't allow removing the primary function alone for a + * multifunction device (devlist->count greater than 1) + * leading to guest start failure later. */ + if (devlist->count > 1 && qemuValidateDomainDefPCIHostdevs(vmdef) < 0) + return -1; + return 0; } =20 @@ -9012,7 +9023,9 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr = driver, { qemuDomainObjPrivatePtr priv =3D vm->privateData; g_autoptr(virQEMUDriverConfig) cfg =3D NULL; - virDomainDeviceDefPtr dev =3D NULL, dev_copy =3D NULL; + virDomainDeviceDefListPtr devlist =3D NULL, devcopylist =3D NULL; + virDomainDeviceDefListData data =3D {.def =3D vm->def, + .xmlopt =3D driver->xmlopt}; unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE; virDomainDefPtr vmdef =3D NULL; int ret =3D -1; @@ -9026,11 +9039,11 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPt= r driver, !(flags & VIR_DOMAIN_AFFECT_LIVE)) parse_flags |=3D VIR_DOMAIN_DEF_PARSE_INACTIVE; =20 - dev =3D dev_copy =3D virDomainDeviceDefParse(xml, vm->def, - driver->xmlopt, priv->qemuCap= s, - parse_flags); - if (dev =3D=3D NULL) + devlist =3D qemuDomainDeviceParseXMLMany(xml, &data, + priv->qemuCaps, parse_flags); + if (!devlist) goto cleanup; + devcopylist =3D devlist; =20 if (flags & VIR_DOMAIN_AFFECT_CONFIG && flags & VIR_DOMAIN_AFFECT_LIVE) { @@ -9038,9 +9051,9 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr = driver, * create a deep copy of device as adding * to CONFIG takes one instance. */ - dev_copy =3D virDomainDeviceDefCopy(dev, vm->def, - driver->xmlopt, priv->qemuCaps); - if (!dev_copy) + devcopylist =3D virDomainDeviceDefListCopy(devlist, &data, + priv->qemuCaps); + if (!devcopylist) goto cleanup; } =20 @@ -9050,7 +9063,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr = driver, if (!vmdef) goto cleanup; =20 - if (qemuDomainDetachDeviceConfig(vmdef, dev, priv->qemuCaps, + if (qemuDomainDetachDeviceConfig(vmdef, devlist, priv->qemuCaps, parse_flags, driver->xmlopt) < 0) goto cleanup; @@ -9059,7 +9072,13 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr= driver, if (flags & VIR_DOMAIN_AFFECT_LIVE) { int rc; =20 - if ((rc =3D qemuDomainDetachDeviceLive(vm, dev_copy, driver, false= )) < 0) + if (devlist->count > 1) { + if ((rc =3D qemuDomainDetachMultifunctionDevice(vm, devlist, d= river)) < 0) + goto cleanup; + } else if ((rc =3D qemuDomainDetachDeviceLive(vm, + devcopylist->devs[0], + driver, + false)) < 0) goto cleanup; =20 if (rc =3D=3D 0 && qemuDomainUpdateDeviceList(driver, vm, QEMU_ASY= NC_JOB_NONE) < 0) @@ -9086,9 +9105,9 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr = driver, ret =3D 0; =20 cleanup: - if (dev !=3D dev_copy) - virDomainDeviceDefFree(dev_copy); - virDomainDeviceDefFree(dev); + if (devlist !=3D devcopylist) + virDomainDeviceDefListFree(devcopylist); + virDomainDeviceDefListFree(devlist); virDomainDefFree(vmdef); return ret; } @@ -9106,6 +9125,7 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDrive= rPtr driver, virDomainDefPtr persistentDef =3D NULL; virDomainDefPtr vmdef =3D NULL; unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE; + virDomainDeviceDefListPtr devlist =3D NULL; int ret =3D -1; =20 virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | @@ -9121,16 +9141,22 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDri= verPtr driver, goto cleanup; =20 if (persistentDef) { - virDomainDeviceDef dev; + virDomainDeviceDefPtr dev; =20 if (!(vmdef =3D virDomainObjCopyPersistentDef(vm, driver->xmlopt, priv->qemuCaps))) goto cleanup; =20 - if (virDomainDefFindDevice(vmdef, alias, &dev, true) < 0) + if (virDomainDefFindDevice(vmdef, alias, dev, true) < 0) + goto cleanup; + + if (VIR_ALLOC(devlist) < 0) goto cleanup; =20 - if (qemuDomainDetachDeviceConfig(vmdef, &dev, priv->qemuCaps, + if (VIR_APPEND_ELEMENT(devlist->devs, devlist->count, dev) < 0) + goto cleanup; + + if (qemuDomainDetachDeviceConfig(vmdef, devlist, priv->qemuCaps, parse_flags, driver->xmlopt) < 0) goto cleanup; } @@ -9159,6 +9185,8 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDrive= rPtr driver, ret =3D 0; cleanup: virDomainDefFree(vmdef); + virDomainDeviceDefListFree(devlist); + return ret; } =20 diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index a6c520ec1b..9d6671f4f6 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -6086,6 +6086,122 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, } =20 =20 +int +qemuDomainDetachMultifunctionDevice(virDomainObjPtr vm, + virDomainDeviceDefListPtr devlist, + virQEMUDriverPtr driver) +{ + size_t i; + int ret =3D -1; + g_autoptr(virBitmap) onlinemap =3D NULL; + virDomainHostdevDefPtr hostdev, detach =3D NULL; + virDomainHostdevSubsysPtr subsys =3D NULL; + int slotaggridx =3D 0; + virDomainHostdevSubsysPCIPtr pcisrc =3D NULL; + qemuDomainObjPrivatePtr priv =3D vm->privateData; + + qsort(devlist->devs, devlist->count, sizeof(*devlist->devs), + qemuiHostdevPCIMultifunctionDevicesListSort); + +#define FOR_EACH_DEV_IN_DEVLIST() \ + for (i =3D 0; i < devlist->count; i++) { \ + hostdev =3D devlist->devs[i]->data.hostdev; \ + subsys =3D &hostdev->source.subsys; \ + pcisrc =3D &subsys->u.pci; \ + virDomainHostdevFind(vm->def, hostdev, &detach); + + FOR_EACH_DEV_IN_DEVLIST() + if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("hot unplug is not supported for hostdev mode= '%s'"), + virDomainHostdevModeTypeToString(hostdev->mode)= ); + return -1; + } + } + + FOR_EACH_DEV_IN_DEVLIST() + if (!detach) { + virReportError(VIR_ERR_DEVICE_MISSING, + _("host pci device %.4x:%.2x:%.2x.%.1x not foun= d"), + pcisrc->addr.domain, pcisrc->addr.bus, + pcisrc->addr.slot, pcisrc->addr.function); + return -1; + } + } + + /* Check if the devices belong to same guest slot.*/ + FOR_EACH_DEV_IN_DEVLIST() + /* Pick one aggregateSlotIdx and compare against rest of them */ + slotaggridx =3D slotaggridx ? slotaggridx : detach->info->aggregat= eSlotIdx; + if (slotaggridx !=3D detach->info->aggregateSlotIdx) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("host pci device %.4x:%.2x:%.2x.%.1x does " + "not belong to same slot"), + pcisrc->addr.domain, + pcisrc->addr.bus, + pcisrc->addr.slot, + pcisrc->addr.function); + return -1; + } + } + + /* Check if the whole slot is being removed or not */ + onlinemap =3D virDomainDefHostdevGetPCIOnlineFunctionMap(vm->def, slot= aggridx); + FOR_EACH_DEV_IN_DEVLIST() + ignore_value(virBitmapClearBit(onlinemap, pcisrc->addr.function)); + } + + if (!virBitmapIsAllClear(onlinemap)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("hot unplug of partial PCI slot not allowed")); + return -1; + } + + /* Mark all aliases for removal */ + memset(&priv->unplug, 0, sizeof(priv->unplug)); + FOR_EACH_DEV_IN_DEVLIST() + if (qemuAssignDeviceHostdevAlias(vm->def, &detach->info->alias, -1= ) < 0) + goto reset; + + qemuDomainMarkDeviceAliasForRemoval(vm, detach->info->alias, false= ); + } + + qemuDomainObjEnterMonitor(driver, vm); + + /* must plug non-zero first, zero at last */ + for (i =3D devlist->count; i > 0; i--) { + hostdev =3D devlist->devs[i -1]->data.hostdev; + subsys =3D &hostdev->source.subsys; + pcisrc =3D &subsys->u.pci; + virDomainHostdevFind(vm->def, hostdev, &detach); + + if (qemuMonitorDelDevice(priv->mon, detach->info->alias) < 0) { + ignore_value(qemuDomainObjExitMonitor(driver, vm)); + if (virDomainObjIsActive(vm)) + virDomainAuditHostdev(vm, detach, "detach", false); + goto reset; + } + if (ARCH_IS_X86(vm->def->os.arch)) + break; /* deleting any one is enough! */ + } + + if (qemuDomainObjExitMonitor(driver, vm) < 0) + ret =3D -1; + + if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) { + FOR_EACH_DEV_IN_DEVLIST() + ret =3D qemuDomainRemoveHostDevice(driver, vm, detach); + } + } + reset: + qemuDomainResetDeviceRemoval(vm); + +#undef FOR_EACH_DEV_IN_DEVLIST + + return ret; +} + + static int qemuDomainRemoveVcpu(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index b62528a6d9..6e74473936 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -131,6 +131,11 @@ qemuDomainAttachMultifunctionDevice(virDomainObjPtr vm, virDomainDeviceDefListPtr devlist, virQEMUDriverPtr driver); =20 +int +qemuDomainDetachMultifunctionDevice(virDomainObjPtr vm, + virDomainDeviceDefListPtr devlist, + virQEMUDriverPtr driver); + int qemuDomainChrInsert(virDomainDefPtr vmdef, virDomainChrDefPtr chr); diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 956e3daf7d..b913ce2c5b 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -802,7 +802,7 @@ static int qemuValidateDomainDefPCIMultifunctionHostdev= (qemuDomainPCIHostdevData } =20 =20 -static int qemuValidateDomainDefPCIHostdevs(const virDomainDef *def) +int qemuValidateDomainDefPCIHostdevs(const virDomainDef *def) { qemuDomainPCIHostdevdata hostdevdata =3D {def, NULL, NULL}; =20 diff --git a/src/qemu/qemu_validate.h b/src/qemu/qemu_validate.h index acf7d26ce0..c6782066eb 100644 --- a/src/qemu/qemu_validate.h +++ b/src/qemu/qemu_validate.h @@ -33,3 +33,4 @@ int qemuValidateDomainDeviceDefDisk(const virDomainDiskDe= f *disk, int qemuValidateDomainDeviceDef(const virDomainDeviceDef *dev, const virDomainDef *def, void *opaque); +int qemuValidateDomainDefPCIHostdevs(const virDomainDef *def); diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 32d186ef73..175f3ffed8 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -158,10 +158,15 @@ testQemuHotplugAttach(virDomainObjPtr vm, =20 static int testQemuHotplugDetach(virDomainObjPtr vm, - virDomainDeviceDefPtr dev, + virDomainDeviceDefListPtr devlist, bool async) { int ret =3D -1; + virDomainDeviceDefPtr dev; + + if (devlist->count > 1) + return qemuDomainDetachMultifunctionDevice(vm, devlist, &driver); + dev =3D devlist->devs[0]; =20 switch (dev->type) { case VIR_DOMAIN_DEVICE_DISK: @@ -251,7 +256,6 @@ testQemuHotplug(const void *data) bool keep =3D test->keep; unsigned int device_parse_flags =3D 0; virDomainObjPtr vm =3D NULL; - virDomainDeviceDefPtr dev =3D NULL; /* temporary */ virDomainDeviceDefListPtr devlist =3D NULL; virDomainDeviceDefListData listdata; virCapsPtr caps =3D NULL; @@ -298,8 +302,6 @@ testQemuHotplug(const void *data) if (!devlist) goto cleanup; =20 - dev =3D devlist->devs[0]; /* temporary */ - /* Now is the best time to feed the spoofed monitor with predefined * replies. */ if (!(test_mon =3D qemuMonitorTestNew(driver.xmlopt, vm, &driver, @@ -340,14 +342,14 @@ testQemuHotplug(const void *data) break; =20 case DETACH: - ret =3D testQemuHotplugDetach(vm, dev, false); + ret =3D testQemuHotplugDetach(vm, devlist, false); if (ret =3D=3D 0 || fail) ret =3D testQemuHotplugCheckResult(vm, domain_xml, domain_filename, fail); break; =20 case UPDATE: - ret =3D testQemuHotplugUpdate(vm, dev); + ret =3D testQemuHotplugUpdate(vm, devlist->devs[0]); } =20 virObjectLock(priv->mon); @@ -852,16 +854,25 @@ mymain(void) "device_add", QMP_OK); DO_TEST_DETACH("pseries-base-live", "hostdev-pci", false, false, "device_del", QMP_DEVICE_DELETED("hostdev0") QMP_OK); - DO_TEST_ATTACH("base-live", "multifunction-hostdev-pci", false, false, + DO_TEST_ATTACH("base-live", "multifunction-hostdev-pci", false, true, "device_add", QMP_OK, "device_add", QMP_OK, "device_add", QMP_OK, "device_add", QMP_OK); + DO_TEST_DETACH("base-live", "multifunction-hostdev-pci", false, false, + "device_del", QMP_DEVICE_DELETED("hostdev3") + QMP_DEVICE_DELETED("hostdev2") + QMP_DEVICE_DELETED("hostdev1") + QMP_DEVICE_DELETED("hostdev0") QMP_OK); =20 qemuTestSetHostArch(&driver, VIR_ARCH_PPC64); - DO_TEST_ATTACH("pseries-base-live", "multifunction-hostdev-pci-2", fal= se, false, + DO_TEST_ATTACH("pseries-base-live", "multifunction-hostdev-pci-2", fal= se, true, "device_add", QMP_OK, "device_add", QMP_OK); + DO_TEST_DETACH("pseries-base-live", "multifunction-hostdev-pci-2", fal= se, false, + "device_del", QMP_OK, + "device_del", QMP_DEVICE_DELETED("hostdev1") + QMP_DEVICE_DELETED("hostdev0") QMP_OK); qemuTestSetHostArch(&driver, VIR_ARCH_X86_64); =20 DO_TEST_ATTACH("base-live", "watchdog", false, true, --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009231; cv=none; d=zohomail.com; s=zohoarc; b=EWdUKjKi3aqHuMsIQvvy1akJAHLvn6j35/epzmIGzDufkPvuYLtgry2tAIuMsQnMR3KqWItuOsj+0M5/4/3Nbv/vlYTsPl2hBefHxiu9ZjQGP6srhDDK62ThL1jQE+WlacudaI6O6pT09cxAxRk026nyChoKIfeLMPk2GehyII4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009231; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2PvWhjCQhm5pIdS/GwQ7oWZTpwlQpy+wSuzwTqpfzd4=; b=U6I17Mxu4bRO61BElHOalEFJP60lWTKkGCMnSzK2Tf9tfef+gWOp9qsVM4GHHJVNDHnUhCEgN6xTcpup6UnaYUQKqYeB/joQVLK8wmvIQ+3CDyN4LDiqxgnBgXdk8RYl3EiNPfxJEv496y+c2QffmcNLG/gZEtle9bvP/At+eBs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1590009231358194.08270845610798; Wed, 20 May 2020 14:13:51 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-313-jW9FLVowNd6myMplpZJeWQ-1; Wed, 20 May 2020 17:13:48 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 077CC1B18BCB; Wed, 20 May 2020 21:13:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D84FD2E18D; Wed, 20 May 2020 21:13:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id ACE9554D02; Wed, 20 May 2020 21:13:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCqpG002412 for ; Wed, 20 May 2020 17:12:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2EBEC2156A49; Wed, 20 May 2020 21:12:52 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0D41C2166BA2 for ; Wed, 20 May 2020 21:12:50 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0D5AF8007A4 for ; Wed, 20 May 2020 21:12:48 +0000 (UTC) Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-345-cHixD5SANq6rZwL3zYLoOQ-1; Wed, 20 May 2020 17:12:45 -0400 Received: by mail-qk1-f195.google.com with SMTP id z80so5211758qka.0 for ; Wed, 20 May 2020 14:12:45 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009230; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=2PvWhjCQhm5pIdS/GwQ7oWZTpwlQpy+wSuzwTqpfzd4=; b=MR5R7JTaminHr4Lvq2tPdnt72zyfDUF/Sjs2QOY6RmfW11b9KzaPt0AqOehl5Zy1efrLSL 8X8hfZ1oVHXdc1JfxDp2l6mLvN8g7RXTbyiJjPn1vEpBSG3YTyAQ5s97174Z6OQ5psSfCQ bQaoG+6+ef9guOtQ2jns96pet7x5MC0= X-MC-Unique: jW9FLVowNd6myMplpZJeWQ-1 X-MC-Unique: cHixD5SANq6rZwL3zYLoOQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2PvWhjCQhm5pIdS/GwQ7oWZTpwlQpy+wSuzwTqpfzd4=; b=m/9eXNSIqZEyOS5S7miAgMxIUtWmG310qEGMlSDSIV8dTvs3FgRu36uTC1pzbvEchu +KBAaDeQFQ3+9Ek0K6qTuPye3aptxfFDC4kZy3b5DmdQPnIf+5l4WxkDQERBFoWYAsE+ imKS/w8LKWgXekyP2rxs6ZlIBS8SiwnW77ajnJwxg9pbK6y13e2FZGfHWFV5p0SvzwO0 dL9KeXVs82i8ONm5f32oYtO+Kl+GuCdXWyp64YWeKizNE9QRYmZVN30Ae/ViGBNxzuCF ArSqmAXdm/w4MTAfC4zLsGNU+1nhLmltqHsAzL+5X2fSnnhqzMoexqGbjF0pPJEC2rmG Yuvg== X-Gm-Message-State: AOAM531hl6sGUyxfXcApa81S7Clo/G5DNYD6FvUY32EYsYABF/I/GERP 1vrluQcljy5K0PiD14oMKedQfjr6 X-Google-Smtp-Source: ABdhPJxsa9T4KHn8NRXSKV/iKO4N9GNCXbK/eOP3aedr0Bgfs1UgCYF7rJYtLuBjVDTL6YRj+DqJFQ== X-Received: by 2002:ae9:e895:: with SMTP id a143mr3097666qkg.359.1590009164642; Wed, 20 May 2020 14:12:44 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 19/21] qemu_hotplug.c: tune unplugTimeout for multifunction detach Date: Wed, 20 May 2020 18:11:41 -0300 Message-Id: <20200520211143.2980117-20-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In a multifunction hot-unplug, QEMU will unplug all the functions in a single detach operation, sequentially, triggered by the detach of function zero for Pseries guests or any function for x86 guests. This impacts the amount of timeout we're supposed to wait - an unplug operation with 4 hostdevs will naturally take longer than a single hostdev unplug. The previous existing timeout wasn't enough to handle this multifunction detach case, timing out the detach operation needlessly. This patch handles it by adding a new qemuDomainWaitForMultipleDeviceRemoval function that considers the number of naliases to be unplugged when calculating unplugTimeout. Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_hotplug.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 9d6671f4f6..23c7d57682 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5276,15 +5276,21 @@ qemuDomainGetUnplugTimeout(virDomainObjPtr vm) * - we failed to reliably wait for the event and thus use fallback b= ehavior */ static int -qemuDomainWaitForDeviceRemoval(virDomainObjPtr vm) +qemuDomainWaitForMultipleDeviceRemoval(virDomainObjPtr vm, + bool isMultiFunctionDevice) { qemuDomainObjPrivatePtr priv =3D vm->privateData; - unsigned long long until; + unsigned long long until, waitTime; int rc; =20 if (virTimeMillisNow(&until) < 0) return 1; - until +=3D qemuDomainGetUnplugTimeout(vm); + + waitTime =3D qemuDomainGetUnplugTimeout(vm); + if (isMultiFunctionDevice) + waitTime *=3D priv->unplug.naliases; + + until +=3D waitTime; =20 /* All devices should get released around same time*/ while (priv->unplug.naliases) { @@ -5307,6 +5313,17 @@ qemuDomainWaitForDeviceRemoval(virDomainObjPtr vm) return 1; } =20 +/* For a single device, call qemuDomainWaitForMultipleDeviceRemoval with + * isMultiFunctionDevice =3D false. + * + * Returns: same values as qemuDomainWaitForMultipleDeviceRemoval. + */ +static int +qemuDomainWaitForDeviceRemoval(virDomainObjPtr vm) +{ + return qemuDomainWaitForMultipleDeviceRemoval(vm, false); +} + /* Returns: * true there was a thread waiting for devAlias to be removed and this * thread will take care of finishing the removal @@ -6188,7 +6205,7 @@ qemuDomainDetachMultifunctionDevice(virDomainObjPtr v= m, if (qemuDomainObjExitMonitor(driver, vm) < 0) ret =3D -1; =20 - if ((ret =3D qemuDomainWaitForDeviceRemoval(vm)) =3D=3D 1) { + if ((ret =3D qemuDomainWaitForMultipleDeviceRemoval(vm, true)) =3D=3D = 1) { FOR_EACH_DEV_IN_DEVLIST() ret =3D qemuDomainRemoveHostDevice(driver, vm, detach); } --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009281; cv=none; d=zohomail.com; s=zohoarc; b=ZJVWrt6gxrsJ7Hb9aH5+5HDfPN5iza+IqdXZx/Zt9hWu/8f1vU59P7LDW4JjFcw3ciy5oIGHXSLGAr6c4v25lwC+X6QoqzmQlDne4sU2FUm9OuENgK7HwNOdJK7vgRJxj3KtPANa/yOW+q3BuogDSqoejUfiSbkZDeoc/6M7Wvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009281; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bvSROMO3qs++ful4yeS3EIWSz7tmzrR/rFMsi/Oe2Ek=; b=S/nAsv9L83y63g9A2zl9KFqeTiBkUK3nJz1x3Z39f1UZoiW1eLPYJcUO6QlHu+OtqUBa4oWCFLOHBRoNZ7xUOGTtYIWTdlgoeItcZazVu5aykt0Vt/0OuB+oO3WMcj4d91ungsdjEkF5xEnpm8I8ArI4NE1tERHwlPcyXcfSO7g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1590009281360708.7544860584173; Wed, 20 May 2020 14:14:41 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-28-QC6tsijNM-Co2H3ItUACAw-1; Wed, 20 May 2020 17:14:37 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4449AA0BD9; Wed, 20 May 2020 21:14:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 23078473BA; Wed, 20 May 2020 21:14:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E9C4D1809561; Wed, 20 May 2020 21:14:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCqJt002413 for ; Wed, 20 May 2020 17:12:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2ED352156A4A; Wed, 20 May 2020 21:12:52 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 170702157F25 for ; Wed, 20 May 2020 21:12:50 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 896D38316FE for ; Wed, 20 May 2020 21:12:49 +0000 (UTC) Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-242-AYeZ6OIOOhyMytEQJ5qDmg-1; Wed, 20 May 2020 17:12:47 -0400 Received: by mail-qt1-f193.google.com with SMTP id m44so3805104qtm.8 for ; Wed, 20 May 2020 14:12:47 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009279; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=bvSROMO3qs++ful4yeS3EIWSz7tmzrR/rFMsi/Oe2Ek=; b=Ii/4aoPS3BjZBk/+/Hn5wB6e+Eb15BadTTP7N8t2lchyw2LvcTNOVUWPu2TUVkATYUkmQX a5tZw8KTA537fy7pkh7V9tQSdGGkpHljv4E7Af0r1lF9bnmsh/XWhnMoQ8SunuwwYZpLzu UT0Kuw6K7QesrbXl1TARwc2ikGVvjFg= X-MC-Unique: QC6tsijNM-Co2H3ItUACAw-1 X-MC-Unique: AYeZ6OIOOhyMytEQJ5qDmg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bvSROMO3qs++ful4yeS3EIWSz7tmzrR/rFMsi/Oe2Ek=; b=qWz4HS45/xBokyQhW0NfJkk3iDZr0AcK0L/2PF67CxKnxu77CVj66EIqBzjZaALfln P4zoDG1WivZnsniDSBn6g1YULkDgh4EHF0y6mT+haYyiYpHJu1ZPJeEhV3rgqeti49/e 2Q2lumFOLJKVcA1fJN2j6eVc91iO8YdQrssBj0tDdSkF3oEGsQn5ch4mEO0q8SSfzNmP uWaERflLQRGyJpAFwVv45VUAkxRB/qUtYgxjC8KYgcXCAAlmOuL26eevFwW9kspJZk5n cK/opX6HUtkwexauL1nhUnkSXRW0awT9G3CfsvaZ+oHRuBSx+9ztzOvVOZ/NBYDCAld5 5iOA== X-Gm-Message-State: AOAM533IpKUu1siiUamUlo3san2KI6rhZCgILZ+ml7f9jCOIbCh4Rpbp E0iBmy6dFCEL2H3QqomIJ+OhjX+n X-Google-Smtp-Source: ABdhPJz7ofZ3wA2MivXx8lIrNrpO9SYW8zXotRDxNWASJKrx7HkEZmx68HKp4l50e+oBH5VfSoXsmw== X-Received: by 2002:ac8:5045:: with SMTP id h5mr7570213qtm.259.1590009166384; Wed, 20 May 2020 14:12:46 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 20/21] qemu_hotplug: do not hotplug/hotunplug 'unassigned' hostdevs Date: Wed, 20 May 2020 18:11:42 -0300 Message-Id: <20200520211143.2980117-21-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The new address type 'unassigned' allows for a hostdev to be managed by Libvirt, but not be assigned for guest usage. This can allow us to execute PCI multifunction hotplug, with managed mode, leaving non-zero functions unassigned. For hotplug and unplug, we'll skip unassigned devices when setting or evaluating aggregateSlotIdx and when we're about to execute device_add/device_del in QEMU. For hotplug we'll also skip adress assignment. For unplug we won't mark the device for removal since we won't be executing device_del on it. Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_domain.c | 1 + src/qemu/qemu_domain_address.c | 6 ++ src/qemu/qemu_hotplug.c | 16 ++++ tests/qemuhotplugtest.c | 9 ++ ...plug-multifunction-hostdev-pci-partial.xml | 27 ++++++ ...live+multifunction-hostdev-pci-partial.xml | 82 +++++++++++++++++++ 6 files changed, 141 insertions(+) create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-multifunction-= hostdev-pci-partial.xml create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-live+mult= ifunction-hostdev-pci-partial.xml diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 0471a37803..7bff50ca09 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -13412,6 +13412,7 @@ int qemuDomainValidateMultifunctionDeviceList(virDo= mainDeviceDefListPtr devlist) virDomainDeviceInfoPtr info =3D virDomainDeviceGetInfo(devlist->de= vs[i]); =20 if (info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && + info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED && info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { return -1; } diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 94d91a5daf..ebae69cc6d 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -3473,6 +3473,9 @@ qemuDomainPCIMultifunctionHostdevEnsurePCIAddresses(v= irDomainObjPtr vm, for (i =3D 0; i < devlist->count; i++) { virDomainHostdevDefPtr hostdev =3D devlist->devs[i]->data.hostdev; =20 + if (hostdev->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNAS= SIGNED) + continue; + if (qemuDomainIsPSeries(vm->def)) /* Isolation groups are only relevant for pSeries guests */ qemuDomainFillDeviceIsolationGroup(vm->def, devlist->devs[i]); @@ -3504,6 +3507,9 @@ qemuDomainPCIMultifunctionHostdevEnsurePCIAddresses(v= irDomainObjPtr vm, virDomainHostdevDefPtr hostdev =3D devlist->devs[i]->data.hostdev; virPCIDeviceAddress addr =3D hostdev->source.subsys.u.pci.addr; =20 + if (hostdev->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNAS= SIGNED) + continue; + devinfos->infos[addr.function] =3D hostdev->info; } =20 diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 23c7d57682..64dd69b923 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1646,6 +1646,13 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr drive= r, goto error; } =20 + /* For an unassigned hostdev, add it to the domain definition + * and return without hotplugging it to QEMU. */ + if (hostdev->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGN= ED) { + vm->def->hostdevs[vm->def->nhostdevs++] =3D hostdev; + return 0; + } + if (!(devstr =3D qemuBuildPCIHostdevDevStr(vm->def, hostdev, 0, priv->= qemuCaps))) goto error; =20 @@ -6148,6 +6155,9 @@ qemuDomainDetachMultifunctionDevice(virDomainObjPtr v= m, =20 /* Check if the devices belong to same guest slot.*/ FOR_EACH_DEV_IN_DEVLIST() + if (detach->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASS= IGNED) + continue; + /* Pick one aggregateSlotIdx and compare against rest of them */ slotaggridx =3D slotaggridx ? slotaggridx : detach->info->aggregat= eSlotIdx; if (slotaggridx !=3D detach->info->aggregateSlotIdx) { @@ -6180,6 +6190,9 @@ qemuDomainDetachMultifunctionDevice(virDomainObjPtr v= m, if (qemuAssignDeviceHostdevAlias(vm->def, &detach->info->alias, -1= ) < 0) goto reset; =20 + if (detach->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASS= IGNED) + continue; + qemuDomainMarkDeviceAliasForRemoval(vm, detach->info->alias, false= ); } =20 @@ -6192,6 +6205,9 @@ qemuDomainDetachMultifunctionDevice(virDomainObjPtr v= m, pcisrc =3D &subsys->u.pci; virDomainHostdevFind(vm->def, hostdev, &detach); =20 + if (detach->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASS= IGNED) + continue; + if (qemuMonitorDelDevice(priv->mon, detach->info->alias) < 0) { ignore_value(qemuDomainObjExitMonitor(driver, vm)); if (virDomainObjIsActive(vm)) diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 175f3ffed8..5e9d770cb1 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -865,6 +865,15 @@ mymain(void) QMP_DEVICE_DELETED("hostdev1") QMP_DEVICE_DELETED("hostdev0") QMP_OK); =20 + DO_TEST_ATTACH("base-live", "multifunction-hostdev-pci-partial", false= , true, + "device_add", QMP_OK, + "device_add", QMP_OK, + "device_add", QMP_OK); + DO_TEST_DETACH("base-live", "multifunction-hostdev-pci-partial", false= , false, + "device_del", QMP_DEVICE_DELETED("hostdev3") + QMP_DEVICE_DELETED("hostdev2") + QMP_DEVICE_DELETED("hostdev0") QMP_OK); + qemuTestSetHostArch(&driver, VIR_ARCH_PPC64); DO_TEST_ATTACH("pseries-base-live", "multifunction-hostdev-pci-2", fal= se, true, "device_add", QMP_OK, diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-multifunction-hostdev= -pci-partial.xml b/tests/qemuhotplugtestdevices/qemuhotplug-multifunction-h= ostdev-pci-partial.xml new file mode 100644 index 0000000000..5e01564d2b --- /dev/null +++ b/tests/qemuhotplugtestdevices/qemuhotplug-multifunction-hostdev-pci-pa= rtial.xml @@ -0,0 +1,27 @@ + + + + +
+ + + + + +
+ +
+ + + + +
+ + + + + +
+ + + diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+multifuncti= on-hostdev-pci-partial.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base-= live+multifunction-hostdev-pci-partial.xml new file mode 100644 index 0000000000..1808a0071e --- /dev/null +++ b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+multifunction-host= dev-pci-partial.xml @@ -0,0 +1,82 @@ + + hotplug + d091ea82-29e6-2e34-3005-f02617b36e87 + 4194304 + 4194304 + 4 + + hvm + + + + + + + + + destroy + restart + restart + + /usr/bin/qemu-system-x86_64 + + +
+ + + +
+ + + +
+ + + + + + +
+ + + + + + + + + + +
+ + +
+ + + + +
+ + +
+ + + + +
+ + +
+ + + + +
+ + +
+ + + + + --=20 2.26.2 From nobody Sat Apr 20 12:31:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590009229; cv=none; d=zohomail.com; s=zohoarc; b=iPV9HVHm4MqEc5tvFHMVvl4Q0xNiCkm2K1a4dIBdtTPIrWIvUd/XgFIfkjWH/BAOYr3o/xfSh84zQvt73mFoyW7SUjwGIID8QoA/qh8kvnT9MA8D0V2tr7PruC0IMy2GGEm+pXY7X3zlBwvhYnxIAo4c2grulS/Q8tpQCJ0VHqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590009229; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MkyOqom2mCSL8Jo0Fe4v9iZxSifpNTnfGK3/2VXG7pY=; b=OPtUIFPMjiaEK1MOuapLI/rz005tdrSMNqEpeLgirzHGsgqKWGXnxdGUmnEITG3wwKagkvd5kLB72iBS8fUXzmOi7Ujcssfs4/itV9y9yhwpwl4PxgrEXWPY3+1ImedEBPZ2pijz6Ksm0B4lu0Mk1l/xEVEz9WMYZdnIIECbFDM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1590009229857575.3001016151235; Wed, 20 May 2020 14:13:49 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-92-AiJSiX8MNTqfQyjD6WEoLQ-1; Wed, 20 May 2020 17:13:45 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AB948835B44; Wed, 20 May 2020 21:13:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8A63F5D9CC; Wed, 20 May 2020 21:13:40 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5A780180954D; Wed, 20 May 2020 21:13:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04KLCpR4002392 for ; Wed, 20 May 2020 17:12:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id BBFB810D17BF; Wed, 20 May 2020 21:12:51 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A616F10D17BE for ; Wed, 20 May 2020 21:12:51 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7B19C8ECB20 for ; Wed, 20 May 2020 21:12:51 +0000 (UTC) Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-394-Tnku9IQXM_ylHKMoCYXqhQ-1; Wed, 20 May 2020 17:12:49 -0400 Received: by mail-qt1-f195.google.com with SMTP id c24so3812047qtw.7 for ; Wed, 20 May 2020 14:12:49 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:fbf2:bc5e:c314:af31:7070]) by smtp.gmail.com with ESMTPSA id z14sm2992031qki.83.2020.05.20.14.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 14:12:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590009228; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=MkyOqom2mCSL8Jo0Fe4v9iZxSifpNTnfGK3/2VXG7pY=; b=aAQJHJmKjUbxQ0V3SauZv3vCerZ2RCb42pI8EIMR0/Tb8lw+eAAM51JVR2JG10IbC7TfgK //laKbnDQUYHvt2HSmmgpjCnjjRWFw4ZqfRtpfaRF3YcpZiGub2+3o734EQGfeRWcQuG8w 7dql41Gc0ECHEBBR1Zt2of1Zf1+TLt4= X-MC-Unique: AiJSiX8MNTqfQyjD6WEoLQ-1 X-MC-Unique: Tnku9IQXM_ylHKMoCYXqhQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MkyOqom2mCSL8Jo0Fe4v9iZxSifpNTnfGK3/2VXG7pY=; b=ikPnNHcl35SWTwHkmjA2PZ2nMM/6NCM+iGYDdB8ZSj6KXmVQi90XtFU4NJae1yYMxQ X91t8M1FuT7/sd2u+2dWIjWc/FF30KZX7hEyhl2eIKl6FIsNS58Ylq8DrsTLVzXGf6Ok ATbQLzEKpGgyzf++c6YOFO0FB5WLUE9Jz3W5RA7d7fsIxqoSqt57rrxPIwOJGz0q50zi r9nnm0Zoy9YmhrK/aJFyVbOhZCHBgp36zE6Ch4AjEZ4XLJ1vyHeCPwyAK9n6A+FZziOP g6XESQdfa59z+iXE69aMpbcYfQuU+yQxp1Fl/q8/8euLt4avMF+rrkPtTm9s9AWAbfL6 Fx+A== X-Gm-Message-State: AOAM532E9hj00RM+Ubh5AUEeGLqOfDULLM6XH9CasNAww2z0JxIFxMb2 G/Nq6vnOJhCqBtokzMCKSHcvFm2C X-Google-Smtp-Source: ABdhPJwlX9dfKuUP7J3EdXbq1s8MsmA4CGgEckcBAMbqLWuwSPbXiBdVu/uNWtapMtuSxn+zVHJh6A== X-Received: by 2002:ac8:8f7:: with SMTP id y52mr7638229qth.104.1590009168437; Wed, 20 May 2020 14:12:48 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 21/21] qemu_hotplug.c: use enhanced multifunction unplug if available Date: Wed, 20 May 2020 18:11:43 -0300 Message-Id: <20200520211143.2980117-22-danielhb413@gmail.com> In-Reply-To: <20200520211143.2980117-1-danielhb413@gmail.com> References: <20200520211143.2980117-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , sbhat@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" QEMU 4.2.0 introduced an enhanced version of the PCI multifunction hotunplug for the PSeries guest [1] where a single device_del of the function 0 will detach all the functions of the slot. The idea is to make this option similar to the behavior we already have on x86. This means that the unplug code in qemuDomainDetachMultifunctionDevice() can be simplified if the domain is running with QEMU 4.2.0 or newer. [1] https://github.com/qemu/qemu/commit/02a1536eee333123c7735cd36484da53b86= 0fbb7 Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_hotplug.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 64dd69b923..806dc98556 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -6123,6 +6123,7 @@ qemuDomainDetachMultifunctionDevice(virDomainObjPtr v= m, int slotaggridx =3D 0; virDomainHostdevSubsysPCIPtr pcisrc =3D NULL; qemuDomainObjPrivatePtr priv =3D vm->privateData; + int pSeriesEnhancedUnplugVersion; =20 qsort(devlist->devs, devlist->count, sizeof(*devlist->devs), qemuiHostdevPCIMultifunctionDevicesListSort); @@ -6198,15 +6199,16 @@ qemuDomainDetachMultifunctionDevice(virDomainObjPtr= vm, =20 qemuDomainObjEnterMonitor(driver, vm); =20 - /* must plug non-zero first, zero at last */ - for (i =3D devlist->count; i > 0; i--) { - hostdev =3D devlist->devs[i -1]->data.hostdev; - subsys =3D &hostdev->source.subsys; - pcisrc =3D &subsys->u.pci; - virDomainHostdevFind(vm->def, hostdev, &detach); + /* QEMU 4.2.0 introduced a new Pseries hotunplug mechanic, where + * the whole slot can be unplugged by hotunplugging function zero + * (see QEMU commit 02a1536eee for details). This makes it similar + * to what x86 does, as long as we hotunplug function zero first + * in all cases. */ + pSeriesEnhancedUnplugVersion =3D 4 * 1000000 + 2 * 1000; =20 - if (detach->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASS= IGNED) - continue; + if (virQEMUCapsGetVersion(priv->qemuCaps) >=3D pSeriesEnhancedUnplugVe= rsion) { + hostdev =3D devlist->devs[0]->data.hostdev; + virDomainHostdevFind(vm->def, hostdev, &detach); =20 if (qemuMonitorDelDevice(priv->mon, detach->info->alias) < 0) { ignore_value(qemuDomainObjExitMonitor(driver, vm)); @@ -6214,8 +6216,25 @@ qemuDomainDetachMultifunctionDevice(virDomainObjPtr = vm, virDomainAuditHostdev(vm, detach, "detach", false); goto reset; } - if (ARCH_IS_X86(vm->def->os.arch)) - break; /* deleting any one is enough! */ + } else { + /* We're running in an older QEMU, so we must plug non-zero first, + * zero at last. */ + for (i =3D devlist->count; i > 0; i--) { + hostdev =3D devlist->devs[i -1]->data.hostdev; + virDomainHostdevFind(vm->def, hostdev, &detach); + + if (detach->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_U= NASSIGNED) + continue; + + if (qemuMonitorDelDevice(priv->mon, detach->info->alias) < 0) { + ignore_value(qemuDomainObjExitMonitor(driver, vm)); + if (virDomainObjIsActive(vm)) + virDomainAuditHostdev(vm, detach, "detach", false); + goto reset; + } + if (ARCH_IS_X86(vm->def->os.arch)) + break; /* deleting any one is enough! */ + } } =20 if (qemuDomainObjExitMonitor(driver, vm) < 0) --=20 2.26.2