From nobody Fri May 16 10:26:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496419793789455.9827028516545; Fri, 2 Jun 2017 09:09:53 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id A2F8BC0587CB; Fri, 2 Jun 2017 16:09:51 +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 68EA64F9B4; Fri, 2 Jun 2017 16:09:51 +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 04E0D1869FFC; Fri, 2 Jun 2017 16:08:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v52G8UFO011700 for ; Fri, 2 Jun 2017 12:08:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id BC4067F468; Fri, 2 Jun 2017 16:08:30 +0000 (UTC) Received: from inaba.usersys.redhat.com (dhcp129-60.brq.redhat.com [10.34.129.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 45B8C8443E for ; Fri, 2 Jun 2017 16:08:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A2F8BC0587CB Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A2F8BC0587CB From: Andrea Bolognani To: libvir-list@redhat.com Date: Fri, 2 Jun 2017 18:07:51 +0200 Message-Id: <1496419671-7600-27-git-send-email-abologna@redhat.com> In-Reply-To: <1496419671-7600-1-git-send-email-abologna@redhat.com> References: <1496419671-7600-1-git-send-email-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 26/26] qemu: Isolate hostdevs on pSeries guests 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 02 Jun 2017 16:09:52 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" All the pieces are now in place, so we can finally start using isolation groups to achieve our initial goal, which is separating hostdevs from emulated PCI devices while keeping hostdevs that belong to the same host IOMMU group together. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1280542 --- src/qemu/qemu_domain_address.c | 79 ++++++++++++++++++= ++++ .../qemuxml2argv-pseries-hostdev.args | 8 ++- .../qemuxml2xmlout-pseries-hostdev.xml | 16 ++++- 3 files changed, 97 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 384d6fd..877ff90 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -901,6 +901,82 @@ qemuDomainFillAllPCIConnectFlags(virDomainDefPtr def, =20 =20 /** + * qemuDomainFillDeviceIsolationGroupIter: + * @def: domain definition + * @dev: device definition + * @info: device information + * @opaque: user data + * + * Fill isolation group information for a single device. + * + * You're not meant to call this directly, use + * qemuDomainFillAllIsolationGroups() instead. + * + * Return: 0 on success, <0 on failure + * */ +static int +qemuDomainFillDeviceIsolationGroupIter(virDomainDefPtr def, + virDomainDeviceDefPtr dev, + virDomainDeviceInfoPtr info, + void *opaque ATTRIBUTE_UNUSED) +{ + virDomainHostdevDefPtr hostdev; + virPCIDeviceAddressPtr hostAddr; + + /* Only pSeries guests care about isolation groups at the moment */ + if (!qemuDomainIsPSeries(def)) + return 0; + + /* Only hostdev... */ + if (dev->type !=3D VIR_DOMAIN_DEVICE_HOSTDEV) + return 0; + + hostdev =3D dev->data.hostdev; + + /* ... of the PCI kind need this extra information */ + if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS || + hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PC= I) { + return 0; + } + + hostAddr =3D &hostdev->source.subsys.u.pci.addr; + + /* The isolation group is simply the IOMMU group assigned by the host = */ + info->isolationGroup =3D virPCIDeviceAddressGetIOMMUGroupNum(hostAddr); + + if (info->isolationGroup < 0) { + VIR_WARN("Can't look up isolation group for device %04x:%02x:%02x.= %x", + hostAddr->domain, hostAddr->bus, + hostAddr->slot, hostAddr->function); + } else { + VIR_DEBUG("Isolation group for device %04x:%02x:%02x.%x is %d", + hostAddr->domain, hostAddr->bus, + hostAddr->slot, hostAddr->function, + info->isolationGroup); + } + + return info->isolationGroup; +} + + +/** + * qemuDomainFillAllIsolationGroups: + * @def: domain definition + * + * Fill isolation group information for all devices in @def. + * + * Return: 0 on success, <0 on failure + */ +static int +qemuDomainFillAllIsolationGroups(virDomainDefPtr def) +{ + return virDomainDeviceInfoIterate(def, + qemuDomainFillDeviceIsolationGroupIt= er, + NULL); +} + + +/** * qemuDomainFillDevicePCIConnectFlags: * * @def: the entire DomainDef @@ -2036,6 +2112,9 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, if (qemuDomainFillAllPCIConnectFlags(def, qemuCaps, driver) < 0) goto cleanup; =20 + if (qemuDomainFillAllIsolationGroups(def) < 0) + goto cleanup; + if (nbuses > 0) { /* 1st pass to figure out how many PCI bridges we need */ if (!(addrs =3D qemuDomainPCIAddressSetCreate(def, nbuses, true))) diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-hostdev.args b/tes= ts/qemuxml2argvdata/qemuxml2argv-pseries-hostdev.args index dbd2964..9630a83 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-hostdev.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-hostdev.args @@ -18,6 +18,8 @@ QEMU_AUDIO_DRV=3Dnone \ server,nowait \ -mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dreadline \ -boot c \ --device vfio-pci,host=3D0001:01:00.0,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x1 \ --device vfio-pci,host=3D0005:90:01.2,id=3Dhostdev1,bus=3Dpci.0,addr=3D0x2 \ --device vfio-pci,host=3D0001:01:00.1,id=3Dhostdev2,bus=3Dpci.0,addr=3D0x3 +-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.1.0,addr=3D0x= 1 \ +-device vfio-pci,host=3D0005:90:01.2,id=3Dhostdev1,bus=3Dpci.2.0,addr=3D0x= 1 \ +-device vfio-pci,host=3D0001:01:00.1,id=3Dhostdev2,bus=3Dpci.1.0,addr=3D0x2 diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-hostdev.xml b/= tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-hostdev.xml index a00c09c..7560661 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-hostdev.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-hostdev.xml @@ -19,26 +19,36 @@ + + + + 2 + + + + + 3 +
-
+
-
+
-
+
--=20 2.7.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list