From nobody Mon Apr 29 10:22:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.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=1574374806; cv=none; d=zoho.com; s=zohoarc; b=LvEjG7+ygg51+TTpCF6GN14gpXvH+hbJzJDZdMKmm+1xP+V/vxfpvLBNzr3qhhPfuYZZtMCd2xYEmw6PmwnNeODUhknpu8okt/m0iwY8uavWSU6MiyXG6C1cM1ogmHKz1FfNkYNVUgJEgaHn9wYf2+9WGiTB45Ja8X0gpJ0vXuA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574374806; 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=bB1j56RxLaZJ3dhQd2KWPkF4iQzmXbT8DncRaFKQ+/4=; b=Ca08n2jnAmbAY5rBgynIo5WEGS1Z0/YC3VQlvhUN2g+Pj2nqE7kuKZuYJm4Ujd+LS82fAFdMoc6iy8iNS1sa0I8E7DCmHuZDh44uEpw3GHpu8SBlbWQWcvGqGQq/vcPqZrNJDswuAbgKeotEgOdWMEXTPLGZM//S8FblwkjtgXs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.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 1574374806735448.6860231175334; Thu, 21 Nov 2019 14:20:06 -0800 (PST) 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-263-ODgdHpBAO663J15fUasAEg-1; Thu, 21 Nov 2019 17:19:59 -0500 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 E932A107ACE3; Thu, 21 Nov 2019 22:19:47 +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 B4A437BF8F; Thu, 21 Nov 2019 22:19:47 +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 1BC9F1809567; Thu, 21 Nov 2019 22:19:47 +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 xALMJjPY026204 for ; Thu, 21 Nov 2019 17:19:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 91C9310551B2; Thu, 21 Nov 2019 22:19:45 +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 8CBC410551B0 for ; Thu, 21 Nov 2019 22:19:43 +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 BE68B8002FA for ; Thu, 21 Nov 2019 22:19: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-265-z3dVvHEqNyyJIF4c_flstg-1; Thu, 21 Nov 2019 17:19:41 -0500 Received: by mail-qk1-f195.google.com with SMTP id o17so4584515qko.6; Thu, 21 Nov 2019 14:19:41 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:afb:97a3:bc66:755b:2f57]) by smtp.gmail.com with ESMTPSA id v65sm2093513qkh.7.2019.11.21.14.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 14:19:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574374802; 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=bB1j56RxLaZJ3dhQd2KWPkF4iQzmXbT8DncRaFKQ+/4=; b=gWKGs9h9btfh6O97pr/j6mu05WI0v3HozyZfIyKDUTeCcCAAtIGWFklEsOcVD6CWpws6T7 2jvNrUio9UTQCmTb4PA1ayclPJvAMWIxJaa0ZqyBZF03vcIcGukifOCOcOT6qOYyGjfLaR XWHCOxadxh015w3PRKib8C4aDDrprP8= 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=DO3RbzvDQyVJyZMXmTSaJcw3ppfd3HtXe/GT28SdGGU=; b=DSMoMnuEBccBtmTdArPQ/L2JvMdztfqfFMgyxjjQ6hFn0aPwrG0VNUtcE3ImhrYMse PKoGMnyslZeaW5K/yIIq3H5jb+PaAcEs/FCgK4zUOJ6UsfollwX79VpO77kFlCZuFrh2 d5aZ7Ef9ZNz4NGLKfiroKHgKxhuB5/Rj5aL48KAe/23itlHuJojY9bJ/5sw9oToc0WFI 9zBb4H4Gt0AKVYAejf0EviCNG9CQoQXroByb4KiTLaZXxsQse7lhrRFF/iVKuex0yNkZ zlqMx7bA2D1joASCQiZ5qdf5rRgue8b3oHOQdrGuFOM0BvJbeg5IUN4rL8Ha4PzbiA1W ZyIQ== X-Gm-Message-State: APjAAAVY9w9AyRjLrKYdp0Yrj2xvy1NFn52jH8xg9fl75QUFS25g9auY 3sSLQU8/JQMLvR/lmVGF5MzZPMe/GyU= X-Google-Smtp-Source: APXvYqw6aGacQ42gcVGfpQqsqk/ZERCtwUJTqfTHVCDiHbrtaQMHOzWPuHbX6iCFirKG/a7LKYl0vw== X-Received: by 2002:a37:4ed7:: with SMTP id c206mr675849qkb.440.1574374780554; Thu, 21 Nov 2019 14:19:40 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Thu, 21 Nov 2019 19:19:14 -0300 Message-Id: <20191121221917.15969-2-danielhb413@gmail.com> In-Reply-To: <20191121221917.15969-1-danielhb413@gmail.com> References: <20191121221917.15969-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: z3dVvHEqNyyJIF4c_flstg-1 X-MC-Unique: ODgdHpBAO663J15fUasAEg-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id xALMJjPY026204 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , darkstego@gmail.com, laine@laine.org Subject: [libvirt] [PATCH v2 1/4] domain_conf: allow address type='none' to unassign PCI hostdevs 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Today, to use a PCI hostdev "A" in a domain, all PCI devices that belongs to the same IOMMU group must also be declared in the domain XML, meaning that all IOMMU devices are detached from the host and all of them are visible to the guest. The result is that the guest will have access to all devices, but this is not necessarily what the administrator wanted. If only the hostdev "A" was intended for guest usage, but hostdevs "B" and "C" happened to be in the same IOMMU group of "A", the guest will gain access to all 3 devices. This makes the administrator rely on alternative solutions, such as use all hostdevs with un-managed mode and detached all the IOMMU before the guest starts. If use un-managed mode is not an option, the only alternative left is an ACS patch to deny guest access to "B" and "C". Discussions made in [1] and [2] led to the approach implemented here. This patch builds upon the already existing VIR_DOMAIN_DEF_FORMAT_ADDRESS_NONE format to use it as a indication of whether a hostdev will be owned by a domain, but not visible to the guest OS. This allows the administrator to declare all the IOMMU while also choosing which hostdevs will be usable by the guest. This new mechanic applies to all PCI hostdevs, regardless of whether they are a PCI multifunction hostdev or not. Using
in any case other than a PCI hostdev will result in error. The use of a new 'unassigned' flag in virDomainHostdevDef makes it easier to distinguish between the case we're handling here versus the case in which a PCI hostdev has no
element. Both are interpreted as VIR_DOMAIN_DEF_FORMAT_ADDRESS_NONE in the existing code, thus reducing the logic to a flag makes it easier to handle this new use case. In the next patch we'll use the 'unassigned' flag to filter the hostdevs being initialized in the QEMU command line. [1] https://www.redhat.com/archives/libvir-list/2019-July/msg01175.html [2] https://www.redhat.com/archives/libvir-list/2019-October/msg00298.html Signed-off-by: Daniel Henrique Barboza --- docs/schemas/domaincommon.rng | 5 ++ src/conf/domain_conf.c | 56 ++++++++++++++++-- src/conf/domain_conf.h | 3 + src/qemu/qemu_domain_address.c | 6 ++ .../hostdev-pci-address-none.xml | 42 ++++++++++++++ .../hostdev-pci-address-none.xml | 58 +++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 7 files changed, 165 insertions(+), 6 deletions(-) create mode 100644 tests/qemuxml2argvdata/hostdev-pci-address-none.xml create mode 100644 tests/qemuxml2xmloutdata/hostdev-pci-address-none.xml diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index a83c9ae7a5..a9a3f2e2d1 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -5463,6 +5463,11 @@ + + + none + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 54d6ae297e..1bb24d2632 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7159,6 +7159,15 @@ virDomainDeviceInfoFormat(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); } =20 + /* Format
for un-assigned hostdevs */ + if (flags & VIR_DOMAIN_DEF_FORMAT_ADDRESS_NONE) { + virBufferAsprintf(&attrBuf, " type=3D'%s'", + virDomainDeviceAddressTypeToString(info->type)); + virXMLFormatElement(buf, "address", &attrBuf, &childBuf); + + return 0; + } + if (info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE || info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390) /* We're done here */ @@ -8129,7 +8138,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, virDomainHostdevDefPtr def, unsigned int flags) { - xmlNodePtr sourcenode; + xmlNodePtr sourcenode, addressnode; int backend; virDomainHostdevSubsysPCIPtr pcisrc =3D &def->source.subsys.u.pci; virDomainHostdevSubsysSCSIPtr scsisrc =3D &def->source.subsys.u.scsi; @@ -8280,6 +8289,28 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, def, flags) <= 0) return -1; =20 + /* @unassigned has meaning only for hostdev PCI devices. + *
has a special meaning in this case, + * telling the guest that this hostdev shouldn't be assigned + * by it. + * + * Note that both
and no
element + * declared implies in VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE + * through the code. This is why we can't simply check for + * VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE to set the @unassigned + * flag. + */ + def->unassigned =3D false; + + if ((addressnode =3D virXPathNode("./address", ctxt))) { + g_autofree char *address_type =3D virXMLPropString(addressnode, + "type"); + int typeFromString =3D virDomainDeviceAddressTypeFromString(ad= dress_type); + + if (typeFromString =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) + def->unassigned =3D true; + } + backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT; if ((backendStr =3D virXPathString("string(./driver/@name)", ctxt)= ) && (((backend =3D virDomainHostdevSubsysPCIBackendTypeFromString(= backendStr)) < 0) || @@ -15579,7 +15610,17 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr = xmlopt, } =20 if (def->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) { - if (virDomainDeviceInfoParseXML(xmlopt, node, def->info, + /* skip address parsing if we already know it is an un-assigned + * pci hostdev */ + bool skipParse =3D false; + + if (def->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && + def->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= PCI && + def->unassigned) + skipParse =3D true; + + if (!skipParse && + virDomainDeviceInfoParseXML(xmlopt, node, def->info, flags | VIR_DOMAIN_DEF_PARSE_ALLO= W_BOOT | VIR_DOMAIN_DEF_PARSE_ALLOW_ROM) = < 0) goto error; @@ -27082,6 +27123,7 @@ virDomainHostdevDefFormat(virBufferPtr buf, virDomainHostdevSubsysMediatedDevPtr mdevsrc =3D &def->source.subsys.u= .mdev; virDomainHostdevSubsysSCSIVHostPtr scsihostsrc =3D &def->source.subsys= .u.scsi_host; const char *type; + unsigned int formatFlags; =20 if (!mode) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -27165,11 +27207,13 @@ virDomainHostdevDefFormat(virBufferPtr buf, if (def->shareable) virBufferAddLit(buf, "\n"); =20 - if (virDomainDeviceInfoFormat(buf, def->info, - flags | VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT - | VIR_DOMAIN_DEF_FORMAT_ALLOW_ROM) < 0) { + formatFlags =3D flags | VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT + | VIR_DOMAIN_DEF_FORMAT_ALLOW_ROM; + if (def->unassigned) + formatFlags |=3D VIR_DOMAIN_DEF_FORMAT_ADDRESS_NONE; + + if (virDomainDeviceInfoFormat(buf, def->info, formatFlags) < 0) return -1; - } =20 virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 39fb42e29d..51851e3638 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -344,6 +344,7 @@ struct _virDomainHostdevDef { bool missing; bool readonly; bool shareable; + bool unassigned; union { virDomainHostdevSubsys subsys; virDomainHostdevCaps caps; @@ -3021,6 +3022,8 @@ typedef enum { VIR_DOMAIN_DEF_FORMAT_ALLOW_ROM =3D 1 << 6, VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT =3D 1 << 7, VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST =3D 1 << 8, + /* format address type=3D'none' for un-assigned PCI hostdevs */ + VIR_DOMAIN_DEF_FORMAT_ADDRESS_NONE =3D 1 << 9, } virDomainDefFormatFlags; =20 /* Use these flags to skip specific domain ABI consistency checks done diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 605984f80f..301a08197b 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -2313,6 +2313,12 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def, continue; } =20 + /* Do not assign an address to a hostdev that will not + * be assigned to the guest. + */ + if (def->hostdevs[i]->unassigned) + continue; + if (qemuDomainPCIAddressReserveNextAddr(addrs, def->hostdevs[i]->info) < = 0) goto error; diff --git a/tests/qemuxml2argvdata/hostdev-pci-address-none.xml b/tests/qe= muxml2argvdata/hostdev-pci-address-none.xml new file mode 100644 index 0000000000..63c9d4eef6 --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-pci-address-none.xml @@ -0,0 +1,42 @@ + + delete + 583a8e8e-f0ce-4f53-89ab-092862148b25 + 262144 + 4 + + hvm + + + /usr/bin/qemu-system-x86_64 + + + + + + + + +
+ + + + + +
+ +
+ + + + +
+ + + + + +
+ + + + diff --git a/tests/qemuxml2xmloutdata/hostdev-pci-address-none.xml b/tests/= qemuxml2xmloutdata/hostdev-pci-address-none.xml new file mode 100644 index 0000000000..08aa5323e4 --- /dev/null +++ b/tests/qemuxml2xmloutdata/hostdev-pci-address-none.xml @@ -0,0 +1,58 @@ + + delete + 583a8e8e-f0ce-4f53-89ab-092862148b25 + 262144 + 262144 + 4 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + +
+ + +
+ + + + + + + +
+ +
+ + + + +
+ +
+ + + + +
+ +
+ + + + +
+ +
+ + +
+ + + diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index ed53ddc8c6..039d5ac1ad 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -423,6 +423,7 @@ mymain(void) =20 DO_TEST("hostdev-usb-address", NONE); DO_TEST("hostdev-pci-address", NONE); + DO_TEST("hostdev-pci-address-none", NONE); DO_TEST("hostdev-pci-multifunction", NONE); DO_TEST("hostdev-vfio", NONE); DO_TEST("hostdev-vfio-zpci", --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 10:22:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.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=1574374803; cv=none; d=zoho.com; s=zohoarc; b=gZp6CKnOpHV+/h/1Xhbe2sc2EXFqtWkDIjrNxt2q730++Yf21wDAy2eLttzDG2oCu4mruo/QSROdDAlGe4SlHE0XWkGTxBmzbE2/lEx6sJ5mGJab5WW26h/viIpPeF75KAXrfjOQRFh4kqMis//dyYwrIDbKEacncA5oFb857Ro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574374803; 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=4HwesB1V7h0qwMO8xcr2m1Ntjyy24w/VvTIdyqOxTLo=; b=L2lVZbr3Jxe9fnP/yHmOz4Iq51c4N7r6OYDXBAnSgWz0v3HQo2uYkYsJpKV7A8bA4ANZiTG2gHHwgbdZ9iBVpw+USuEio8ckYT1fm09zXNNJAaUpkcw5qd3pxI/Xs2cYKqnpnA7ytngxSeD5zFVoPUsDMuexAR2+oSTUvoSQfAw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.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 15743748034661009.9912767544323; Thu, 21 Nov 2019 14:20:03 -0800 (PST) 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-60-dLoG6fabOK2ZaXxknDblGw-1; Thu, 21 Nov 2019 17:20:00 -0500 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 C169A800581; Thu, 21 Nov 2019 22:19:55 +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 971566E714; Thu, 21 Nov 2019 22:19:55 +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 4E8404E566; Thu, 21 Nov 2019 22:19:55 +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 xALMJmPF026216 for ; Thu, 21 Nov 2019 17:19:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3AEEC2157F41; Thu, 21 Nov 2019 22:19:48 +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 367DA2157F3E for ; Thu, 21 Nov 2019 22:19:46 +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 10C6680030F for ; Thu, 21 Nov 2019 22:19:46 +0000 (UTC) Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-103-ENEp_ASNMrC0nZQzzD3HWQ-1; Thu, 21 Nov 2019 17:19:44 -0500 Received: by mail-qk1-f172.google.com with SMTP id d13so4594032qko.3; Thu, 21 Nov 2019 14:19:43 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:afb:97a3:bc66:755b:2f57]) by smtp.gmail.com with ESMTPSA id v65sm2093513qkh.7.2019.11.21.14.19.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 14:19:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574374802; 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=4HwesB1V7h0qwMO8xcr2m1Ntjyy24w/VvTIdyqOxTLo=; b=fEvDS0MMHVfLjO5DZHkCTpYHbOK3h6hJ1PAJ5TGXMftRmJsRwD31rzDNdAm1emJF1471FR FtCTWoffDm3cTW+E4KfUgbNTtzv4GpUjRrQ1rxJJ35WO0RelplSI/xvzbnCQ6ZGvAST0Fq 89zBqZWC3fb1mxMG3wwLbEh0ibvMbtw= 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=LahG+ma4XWn6QQb02/6Yud80kIRdWlhVrrJEDcDFn8k=; b=asRaFc+Q0i2AimyOsemoOHlwUhstWDvUzPML3flBBPdb9pMJ3gpJIrBdlaG48trRBX ZhPe197B0nYIuRCTd3cXhvmfDgkNXtjirJQVTR8aTzR9/vwvFt8m7COmQZWVekqdM4Gd P8LWwAo4cAnKiCt0hqPfMcJhsI3TxmRXfj8ytaAXGPHBhdotQ9yEp0hDT69Mip0KrgZ3 WiznmAcr9fJiOnTC+gyHHzp7y7bJ8LsQzKqKktzf4fZbvOSUi0puEylFgIREcMfS8+vY YYcUsEzye1fs5Riyp4vyKpfARaw72RkQk1UlMsUrDgkwu6QMLmJRi0f9yc8mVJi0AZnO vqjg== X-Gm-Message-State: APjAAAUXY57SbORPCVMh8VvY913Yxl6a0T6Le1v0wRKOBLvlrWXpomir G+lngbQW4KJNTFqH4mlEeJcWtomDrqk= X-Google-Smtp-Source: APXvYqypxV8wo8HTUpAZst9iEo5ve3vo6Km+cQjnzmJ0uAmZVcdj8oVKvXCNv4tIszKwjsqiq5THyw== X-Received: by 2002:a37:4d89:: with SMTP id a131mr628462qkb.241.1574374783324; Thu, 21 Nov 2019 14:19:43 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Thu, 21 Nov 2019 19:19:15 -0300 Message-Id: <20191121221917.15969-3-danielhb413@gmail.com> In-Reply-To: <20191121221917.15969-1-danielhb413@gmail.com> References: <20191121221917.15969-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: ENEp_ASNMrC0nZQzzD3HWQ-1 X-MC-Unique: dLoG6fabOK2ZaXxknDblGw-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id xALMJmPF026216 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , darkstego@gmail.com, laine@laine.org Subject: [libvirt] [PATCH v2 2/4] qemu: handle unassigned PCI hostdevs in command line and alias 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Previous patch made it possible for the QEMU driver to check if a given PCI hostdev is unassigned=3Dtrue, meaning that this device shouldn't be part of the actual guest launch and alias generation. Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_alias.c | 6 ++++ src/qemu/qemu_command.c | 4 +++ .../hostdev-pci-address-none.args | 31 +++++++++++++++++++ tests/qemuxml2argvtest.c | 4 +++ 4 files changed, 45 insertions(+) create mode 100644 tests/qemuxml2argvdata/hostdev-pci-address-none.args diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index 93bdcb7548..8733db4cf5 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -603,6 +603,12 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCa= psPtr qemuCaps) return -1; } for (i =3D 0; i < def->nhostdevs; i++) { + /* do not assign alias for PCI multifunction hostdevs that + * will not be assigned to the guest. + */ + if (def->hostdevs[i]->unassigned) + continue; + /* we can't start assigning at 0, since netdevs may have used * up some hostdevN entries already. Also if the HostdevDef is * linked to a NetDef, they will share an info and the alias diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index ca1bd12594..d27ca39cbf 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5418,6 +5418,10 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd, } } =20 + /* Ignore unassigned devices */ + if (hostdev->unassigned) + continue; + unsigned int bootIndex =3D hostdev->info->bootIndex; =20 /* bootNet will be non-0 if boot order was set and no other diff --git a/tests/qemuxml2argvdata/hostdev-pci-address-none.args b/tests/q= emuxml2argvdata/hostdev-pci-address-none.args new file mode 100644 index 0000000000..14fa3d6b37 --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-pci-address-none.args @@ -0,0 +1,31 @@ +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=3D0005:90:01.0,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x3 \ +-device vfio-pci,host=3D0005:90:01.2,id=3Dhostdev1,bus=3Dpci.0,addr=3D0x4 \ +-device vfio-pci,host=3D0005:90:01.3,id=3Dhostdev2,bus=3Dpci.0,addr=3D0x5 \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x6 diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 07e711840d..ea9c440f5f 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1326,6 +1326,10 @@ mymain(void) QEMU_CAPS_KVM, QEMU_CAPS_DEVICE_VFIO_PCI); =20 + DO_TEST("hostdev-pci-address-none", + QEMU_CAPS_KVM, + QEMU_CAPS_DEVICE_VFIO_PCI); + DO_TEST("serial-file-log", QEMU_CAPS_CHARDEV_FILE_APPEND, QEMU_CAPS_DEVICE_ISA_SERIAL, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 10:22:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.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=1574374811; cv=none; d=zoho.com; s=zohoarc; b=kg/XB3GXh7R9PQ3+0CQYaqEnnwVlDtV12F+QRxa963pgNpX8YKkxw0Dwe7Cxp0HTVOqnnlRgyy1xFQauORZFrdL2uzvrAhfm8cSnZ+SWZpUhGvurwvDUgn3MpMDIBANpl7KHlL0IDqMBCmdSRYSJUpDmngBb/1ZHLlF9gzC2fS4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574374811; 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=UMRMMoe6WdCuWBMKO0AHVL7uOLkDhdQPsMpWdFY9ofE=; b=OrrMk5dkXCZNWLCnsv0efL8Rol+q7kSso1r2z0hk1craJ5oa1MWJfFfX3/X74G2YwKYfxdX8+GGwW1pFu0zcbz5Fs/hsdEPGFOnrUkD5Nou/whzFT2sUViFTrr8vlfpZCJuYvxqQHIIIrwoeSlJ+Xg8AtkT74cuMz6uy8m4n/u4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.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 1574374811562238.72789145616684; Thu, 21 Nov 2019 14:20:11 -0800 (PST) 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-265--_rpoErxOOC9g_q0q1yStg-1; Thu, 21 Nov 2019 17:20:06 -0500 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 8C72A10054E3; Thu, 21 Nov 2019 22:20:00 +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 605A57BF8F; Thu, 21 Nov 2019 22:20:00 +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 16DB218089CD; Thu, 21 Nov 2019 22:20:00 +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 xALMJnEp026224 for ; Thu, 21 Nov 2019 17:19:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4700D2157F41; Thu, 21 Nov 2019 22:19:49 +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 42B172157F3E for ; Thu, 21 Nov 2019 22:19:49 +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 17017185A78E for ; Thu, 21 Nov 2019 22:19:49 +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-397-YyGP--UvPVe6Z5lC0Y7bVQ-1; Thu, 21 Nov 2019 17:19:47 -0500 Received: by mail-qt1-f194.google.com with SMTP id t8so5545945qtc.6; Thu, 21 Nov 2019 14:19:47 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:afb:97a3:bc66:755b:2f57]) by smtp.gmail.com with ESMTPSA id v65sm2093513qkh.7.2019.11.21.14.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 14:19:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574374810; 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=UMRMMoe6WdCuWBMKO0AHVL7uOLkDhdQPsMpWdFY9ofE=; b=Cb22ERWinyjsFr3l9rQv5tO2s0kS3zjGWp75Cb+jmtxCuYG8cWwWXSnt+Fxsr23HVbctAe GR5DBR5Hmuni4PT/WaULznB7qlOoTDhYfCkcv8emjyhGjvlliczhU12qmfxRRSZmzX7ZBn AeEzMtdlMS1jS5sCh8a6ucfKAX5VOZQ= 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=PsehB47YJoUnqD/ADYTrQoDFrjLK4u7NHnujw8ANC5Y=; b=Py3dQm9/NIdqhmSb8teD3aS5ssu011WNv5H/Bobt1wo7U1wzTqAvTV7ZIGlC1tq7h8 RiqCa/+H4BR+m5VvMin3iksM5QrtaGeDp9N0zXZ3HOe/ltKwK3KNu5U8/x96lvyB0tMU WEcXQUOSIJpaYa0xLQIBBgXPe9STegpz+scHXApFEfOyBUCSOq4SuI7s/fZOzZBTWc5m LgLGTn3MvjVoCb9rsrqg923BPSkCrqShqMHs/52AuQkXT4T00BGn2+PpGugF23wfslVs UN8sskGymfXJIgcFcG9kGn6AEtQPw4wBUlerKk+gaRMRvvv16iAfuQUDCHbJTXaZL6fo k0wA== X-Gm-Message-State: APjAAAWJHolIv3q9Wq92AyoMdLoPkfrAn7Oa/Z7Os7UGHq82KbNMnAz5 WqNoXzBt1T0VY2T15s39KWtpXjjI3Zk= X-Google-Smtp-Source: APXvYqx0X1B4rh+RWXefLxQnU3jqEB7WueM/nYUruyhSl7mtqMlx3eo73VC8QyNY2uAkotDBKAphkw== X-Received: by 2002:ac8:6f66:: with SMTP id u6mr11197796qtv.72.1574374786327; Thu, 21 Nov 2019 14:19:46 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Thu, 21 Nov 2019 19:19:16 -0300 Message-Id: <20191121221917.15969-4-danielhb413@gmail.com> In-Reply-To: <20191121221917.15969-1-danielhb413@gmail.com> References: <20191121221917.15969-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: YyGP--UvPVe6Z5lC0Y7bVQ-1 X-MC-Unique: -_rpoErxOOC9g_q0q1yStg-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id xALMJnEp026224 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , darkstego@gmail.com, laine@laine.org Subject: [libvirt] [PATCH v2 3/4] virhostdev.c: check all IOMMU devs in virHostdevPreparePCIDevices 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" virHostdevPreparePCIDevices verifies if a PCI hostdev "A" is in use by another domain by checking the 'activePCIHostdevs' list. It also verifies if other domains are using any other hostdev that belongs to the same IOMMU of "A". This is not enough to cover all the cases. Suppose a PCI hostdev "B" that shares the IOMMU with "A". We are currently able to abort guest launch if "B" is being used by another domain, but if "B" is not being used by any domain, we'll proceed guest execution. What happens then is: if "A" is being used in managed mode, the guest will fail to launch because Libvirt didn't detach "B" from the host. If "A" is being used in un-managed mode, the guest might fail or succeed to launch depending on whether both "A" and "B" were detached manually prior to guest start. Libvirt is now able to deal with these scenarios in a homogeneous fashion, providing the same behavior for both managed and un-managed mode while allowing parcial assignment for both cases as well. This patch changes virHostdevPreparePCIDevices to check all the PCI hostdevs of the domain against all the PCI hostdevs of the IOMMU, failing to launch if the domain does not contain all the PCI hostdevs declared, in both managed and un-managed cases. After this patch, any existing domains that were using PCI hostdevs with un-managed mode, and were getting away with partial assignment without declaring all the IOMMU PCI hostdevs in the domain XML, will be forced to do so. The missing PCI hostdevs can be declared with "
" to keep them invisible to the guest, making the guest oblivious of this change. This is an annoyance for such domains, but the payoff is more consistency of behavior between managed and un-managed mode and more clarity on the domain XML, forcing the admin to declare all PCI hostdevs of the IOMMU and knowing exactly what will be detached from the host. Signed-off-by: Daniel Henrique Barboza --- src/util/virhostdev.c | 64 +++++++++++++++++-- ...ostdev-pci-multifunction-partial-fail.args | 31 +++++++++ ...hostdev-pci-multifunction-partial-fail.xml | 35 ++++++++++ tests/qemuxml2argvtest.c | 4 ++ 4 files changed, 127 insertions(+), 7 deletions(-) create mode 100644 tests/qemuxml2argvdata/hostdev-pci-multifunction-partia= l-fail.args create mode 100644 tests/qemuxml2argvdata/hostdev-pci-multifunction-partia= l-fail.xml diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 17eb290825..eff3ecb839 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -56,6 +56,13 @@ struct virHostdevIsPCINodeDeviceUsedData { bool usesVFIO; }; =20 +struct virHostdevIsAllIOMMUGroupUsedData { + virPCIDeviceListPtr pcidevs; + const char *domainName; + const char *deviceName; + int iommuGroup; +}; + /* This module makes heavy use of bookkeeping lists contained inside a * virHostdevManager instance to keep track of the devices' status. To make * it easy to spot potential ownership errors when moving devices from one @@ -111,6 +118,27 @@ static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceA= ddressPtr devAddr, void *o return 0; } =20 +static int virHostdevIsAllIOMMUGroupUsed(virPCIDeviceAddressPtr devAddr, v= oid *opaque) +{ + struct virHostdevIsAllIOMMUGroupUsedData *helperData =3D opaque; + virPCIDevicePtr actual; + + actual =3D virPCIDeviceListFindByIDs(helperData->pcidevs, + devAddr->domain, devAddr->bus, + devAddr->slot, devAddr->function); + if (actual) { + return 0; + } else { + virReportError(VIR_ERR_OPERATION_INVALID, + _("All devices of the same IOMMU group %d of " + "the PCI device %s must belong to domain %s"), + helperData->iommuGroup, + helperData->deviceName, + helperData->domainName); + return -1; + } +} + static int virHostdevManagerOnceInit(void) { if (!VIR_CLASS_NEW(virHostdevManager, virClassForObject())) @@ -724,9 +752,10 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, unsigned int flags) { g_autoptr(virPCIDeviceList) pcidevs =3D NULL; + g_autofree unsigned int *searchedIOMMUs =3D NULL; int last_processed_hostdev_vf =3D -1; - size_t i; - int ret =3D -1; + size_t i, j; + int ret =3D -1, nSearchedIOMMUs =3D 0; virPCIDeviceAddressPtr devAddr =3D NULL; =20 if (!nhostdevs) @@ -735,6 +764,8 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, if (!(pcidevs =3D virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs))) return -1; =20 + searchedIOMMUs =3D g_new0(unsigned int, virPCIDeviceListCount(pcidevs)= ); + virObjectLock(mgr->activePCIHostdevs); virObjectLock(mgr->inactivePCIHostdevs); =20 @@ -778,13 +809,32 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, goto cleanup; =20 /* VFIO devices belonging to same IOMMU group can't be - * shared across guests. Check if that's the case. */ + * shared across guests, and all of the must belong to the + * same domain. If a device isn't going to be assigned + * (flag unassigned is true) the guest will not use it, but + * the actual device must be detached together from the host + * anyway. */ if (usesVFIO) { - data.usesVFIO =3D true; - if (virPCIDeviceAddressIOMMUGroupIterate(devAddr, - virHostdevIsPCINodeDe= viceUsed, - &data) < 0) + int devIOMMUGroup =3D virPCIDeviceAddressGetIOMMUGroupNum(devA= ddr); + struct virHostdevIsAllIOMMUGroupUsedData helper =3D { + pcidevs, dom_name, virPCIDeviceGetName(pci), devIOMMUGroup= }; + bool alreadySearched =3D false; + + for (j =3D 0; j < nSearchedIOMMUs; j++) { + if (devIOMMUGroup =3D=3D searchedIOMMUs[j]) { + alreadySearched =3D true; + break; + } + } + + if (alreadySearched) + continue; + + if (virPCIDeviceAddressIOMMUGroupIterate( + devAddr, virHostdevIsAllIOMMUGroupUsed, &helper) < 0) goto cleanup; + + searchedIOMMUs[nSearchedIOMMUs++] =3D devIOMMUGroup; } } =20 diff --git a/tests/qemuxml2argvdata/hostdev-pci-multifunction-partial-fail.= args b/tests/qemuxml2argvdata/hostdev-pci-multifunction-partial-fail.args new file mode 100644 index 0000000000..4074968c84 --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-pci-multifunction-partial-fail.args @@ -0,0 +1,31 @@ +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=3D0005:90:01.0,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x3 \ +-device vfio-pci,host=3D0005:90:01.1,id=3Dhostdev1,bus=3Dpci.0,addr=3D0x4 \ +-device vfio-pci,host=3D0005:90:01.3,id=3Dhostdev2,bus=3Dpci.0,addr=3D0x5 \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x6 diff --git a/tests/qemuxml2argvdata/hostdev-pci-multifunction-partial-fail.= xml b/tests/qemuxml2argvdata/hostdev-pci-multifunction-partial-fail.xml new file mode 100644 index 0000000000..fc3e3bb520 --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-pci-multifunction-partial-fail.xml @@ -0,0 +1,35 @@ + + 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 ea9c440f5f..46a0ac15f0 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1330,6 +1330,10 @@ mymain(void) QEMU_CAPS_KVM, QEMU_CAPS_DEVICE_VFIO_PCI); =20 + DO_TEST("hostdev-pci-multifunction-partial-fail", + QEMU_CAPS_KVM, + QEMU_CAPS_DEVICE_VFIO_PCI); + DO_TEST("serial-file-log", QEMU_CAPS_CHARDEV_FILE_APPEND, QEMU_CAPS_DEVICE_ISA_SERIAL, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 10:22:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.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=1574374816; cv=none; d=zoho.com; s=zohoarc; b=bpZTYiQiLd+bHCFpetOIF4/GrvlzMMV8Bi1mSw77D+daHJpRb+nuAgNpMhyPTM1dZyMeg4SseSOKADsP+8khcLKtmE68YhESBs+kNVVEeJndzsh+kXDXDvcuEWzAKI7POnZGayMDxQjN9qU0xbP8UI3cvAIsnCJOLMS/u27j7AA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574374816; 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=x1jDB2mnoHIryaYpOH2PT85LuXv1QpCvrCxFvx4daQU=; b=O3Tshsj3JnOrsIQvBlCdGHLRNeQkakWo/elX5yGedVsh4xzsuek383d3tS0HoxoaXU6i1ikXCW6rsusGQpvJkf/HoiRGirU5X0qSyr9wKYr8FBcqw/p1kHCrJggAzlWYshDrYP/ljCgcCvQTJBw0Qo794Eqiu9S/RK7wdjoE4/0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.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 1574374816332281.1172245903464; Thu, 21 Nov 2019 14:20:16 -0800 (PST) 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-344-2DOmHngDMzq35n4dmXAWPQ-1; Thu, 21 Nov 2019 17:20:13 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 54633CF98B; Thu, 21 Nov 2019 22:20:08 +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 F28A810016E8; Thu, 21 Nov 2019 22:20:07 +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 72D4418089D0; Thu, 21 Nov 2019 22:20:07 +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 xALMJtkM026237 for ; Thu, 21 Nov 2019 17:19:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7A126F77D3; Thu, 21 Nov 2019 22:19:55 +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 7590BF9ABA for ; Thu, 21 Nov 2019 22:19:53 +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 5AC868007D9 for ; Thu, 21 Nov 2019 22:19:53 +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-114-MFazl9DaMdWJiPt2UJVZ7g-1; Thu, 21 Nov 2019 17:19:49 -0500 Received: by mail-qt1-f193.google.com with SMTP id o49so5535470qta.7; Thu, 21 Nov 2019 14:19:49 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:afb:97a3:bc66:755b:2f57]) by smtp.gmail.com with ESMTPSA id v65sm2093513qkh.7.2019.11.21.14.19.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 14:19:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574374815; 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=x1jDB2mnoHIryaYpOH2PT85LuXv1QpCvrCxFvx4daQU=; b=Rc+hH62FTpO2SMi4HCNPtEpojQf2iAvb0jykugRUCT/dli3zghJSuL1xDIVnqlf2h5+4vH 58tNVzKXUVs00ES9OjTsT6p1dFNqNEUVKz+exCKKdX4C1xQ8S8N+KuPm7sAOF64rWgujhK Ca8ZhpGKO/WabxyMFFNpJ1uJBLy3lTA= 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=g1ymERiMNhbA4PaBAD9KxOrzsyT5wrhXTE+l9oTK3Us=; b=anjXoPf4asGAZ2UAQfbkiDfJ4w7rZoEpeQbDzSb21wEk2JKk4ZCMxDSnTgHJYPcL5s exs5J251wVDqmcXjmrbNgPv0v1ZndJkEcL0gWz6q4tf0F0vJZMFaDOJqJfx6D1ijWPGa ybDalgxwO0W1zML5MUQwd9kjiKzpmFNDFQdLSX69hhDx+2oXg0QqbRSZgL9LPrachdI0 NUzC9Zye61fm6dFtGnz0Ev1rGPfFMF4vdsGM10Y5S0z1qp4KWq0sHz6Ykyi524R+kJPm DukWSfKsGe8RCZ3wgDRS5Unw01ccvP1F17WEtFHDALZvSXTWc7mQKuLIYOvyoVkEVnwB 3VyA== X-Gm-Message-State: APjAAAWf0arv+N7yd3qEun9Y20/nuCZgkqDEjQj6CtE5RW68E8yrdiAn 9EfpOFALy/+caTkvwV6iQXKCht9n39k= X-Google-Smtp-Source: APXvYqxZ7I22yRBhe/hFXoU3FxnuY7PJYqWyYGV1laz61Fvx09FvEnyyj/P19JB6l1GI5xmu6pHr5Q== X-Received: by 2002:aed:3b3b:: with SMTP id p56mr11271513qte.200.1574374789010; Thu, 21 Nov 2019 14:19:49 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Thu, 21 Nov 2019 19:19:17 -0300 Message-Id: <20191121221917.15969-5-danielhb413@gmail.com> In-Reply-To: <20191121221917.15969-1-danielhb413@gmail.com> References: <20191121221917.15969-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: MFazl9DaMdWJiPt2UJVZ7g-1 X-MC-Unique: 2DOmHngDMzq35n4dmXAWPQ-1 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id xALMJtkM026237 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , darkstego@gmail.com, laine@laine.org Subject: [libvirt] [PATCH v2 4/4] formatdomain.html.in: document
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.22 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Daniel Henrique Barboza --- docs/formatdomain.html.in | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index a1042a314c..65012aac88 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -4137,6 +4137,21 @@ attributes: iobase and irq. Since 1.2.1 +
none
+
For PCI hostdevs, <address type=3D'none'/> has + a special meaning. A PCI hostdev must be assigned to the domain + with all the devices of its IOMMU group. If the admin so chooses, + it is possible to filter which devices the guest OS will actually + see, while the Libvirt domain is retaining ownership of all the + devices of the IOMMU group. Passing address type none + in such cases will tell Libvirt that the device must not be + assigned to the guest. This avoids scenarios in which the admin + might be compelled to use a ACS patch to remove the device + from the guest. + <address type=3D'none'/> is an invalid address + type for all other device types. + Since 5.10.0 +
=20

Virtio-related options

--=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list