From nobody Fri Apr 26 12:52:13 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=1574775336; cv=none; d=zohomail.com; s=zohoarc; b=lJL15Wt/34yulaRIO/dYhH5RFIME9+jCKgokbJvB91F6IRIl/w2j8ZnJByOct6ipFsQsF9bQdCAkhX7EGMr2g6CmFXhNVeXPiqfOednEaSatFmTUUb2Qc8fvgo5Aooe1/qfPGbgA6/dgmN25T2GsuhFVSegmqs4C01KuMwPRVYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574775336; 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=Q+FZce6txMr4IvHzo5IpsGIIhSHiblBwuTeNut4HW+8=; b=FWOUS5S5563L1hkrsjfbL9zAoEkF6MRYjTHvvpygz+up+iTBEUT+7jXL+8WsmQluqyOlDBiE6H1H+x/PktCnidpbYx9uiRvKrfEYfIFwRjRRUD+9v46mAUOcPBIXjKljqutz/1JhNfdepS16d+wlCdD7CUK6d6XHxxoZItBBvXc= 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 1574775336507431.594756448403; Tue, 26 Nov 2019 05:35:36 -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-366-NPVK2K2lNK6wtWSbK4W8jQ-1; Tue, 26 Nov 2019 08:35:32 -0500 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 EC5BC1023146; Tue, 26 Nov 2019 13:35:27 +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 A72CC5D6D2; Tue, 26 Nov 2019 13:35: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 928351803C37; Tue, 26 Nov 2019 13:35:26 +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 xAQDYdX0004659 for ; Tue, 26 Nov 2019 08:34:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 24F5C11422D9; Tue, 26 Nov 2019 13:34:39 +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 2007910ABC9A for ; Tue, 26 Nov 2019 13:34:37 +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 59E468F250D for ; Tue, 26 Nov 2019 13:34:37 +0000 (UTC) Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-400-bZltpbF3PO2UF6DRNvVP8Q-1; Tue, 26 Nov 2019 08:34:33 -0500 Received: by mail-qk1-f194.google.com with SMTP id c124so11642001qkg.0; Tue, 26 Nov 2019 05:34:33 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:afb:97a3:bc66:755b:2f57]) by smtp.gmail.com with ESMTPSA id i41sm5931229qti.42.2019.11.26.05.34.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2019 05:34:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574775335; 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=Q+FZce6txMr4IvHzo5IpsGIIhSHiblBwuTeNut4HW+8=; b=A/M4WXd2OKTZeoCI2IgHEZeUpavSiduLFp5+glUNPOxyLNni7VX2dMC7imhNeNHPUJ7p// mtXoAQ7V9BT0khZ/Tp8w1Tl6dV1v5Ie7Jc1nmu9ojgLXZrOLVcnP1kYue8PeKJOUpSPNOJ QVkfw9/YFPsbFs0RRtRqeFm2oyzSsvo= 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=+F493HZyn1qOKMjRXpGw8xkEFfjtGS9Ok6JmrnlFdTw=; b=iibZULefz9LWvboHVP3890oWi9/w15jJFi8ylYPVh64hrh9ynmcIIYl+BU9L5dB/JW hGoc4rK+PXRVOBtcmtbUNwlYtMq1sjXfIlTS/WscX41WEDBYkrhXWPBymSQsiUvztus3 e+o+XZTzn1ESGlNDXOW46hLlNcAfysBUWUPMkP2SWxfrG1xqgS8UMJVq0OY2cfOxBv1W SO+d/+mlD1oW29bvrqNjn+7o3ByTxYTtQyZhqklHSXzMKwQvCZN9D1ESUt2pQD6aPLfb SlFhPJHKUU7ZylrKoKk+vrlXC6m5tKKwb/F1N/8rIDVHWx/FAwR2Rk+D6MXNsCNCEWeL 07/w== X-Gm-Message-State: APjAAAU0U5FAyJONt8m+PK4hpn9+7+O57iuTyO4n203H0BKczvGx4kg5 9HC5G4xpGC4NrBj0plXJ2qsruZM/ X-Google-Smtp-Source: APXvYqz/nAcc0TLlzAlDZcuFOheLnYxBvlHoA/a4ZOCCgqdLu/7hpJlGIMXyRjjxiiz1hZiDB5N9EQ== X-Received: by 2002:a05:620a:149b:: with SMTP id w27mr1872813qkj.37.1574775272701; Tue, 26 Nov 2019 05:34:32 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Tue, 26 Nov 2019 10:33:56 -0300 Message-Id: <20191126133401.1242133-2-danielhb413@gmail.com> In-Reply-To: <20191126133401.1242133-1-danielhb413@gmail.com> References: <20191126133401.1242133-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: bZltpbF3PO2UF6DRNvVP8Q-1 X-MC-Unique: NPVK2K2lNK6wtWSbK4W8jQ-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 xAQDYdX0004659 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , darkstego@gmail.com, laine@laine.org Subject: [libvirt] [PATCH v3 1/6] Introducing new address type='unassigned' for 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.15 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". This patch introduces a new address type called "unassigned" to handle this situation where 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. Next patch will use this new address type in the QEMU driver to avoid adding unassigned devices to the QEMU launch command line. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Cole Robinson --- docs/schemas/domaincommon.rng | 5 ++ src/conf/device_conf.c | 2 + src/conf/device_conf.h | 1 + src/conf/domain_conf.c | 7 ++- src/qemu/qemu_command.c | 1 + src/qemu/qemu_domain.c | 1 + src/qemu/qemu_domain_address.c | 5 ++ .../hostdev-pci-address-unassigned.xml | 42 ++++++++++++++ .../hostdev-pci-address-unassigned.xml | 58 +++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 10 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/hostdev-pci-address-unassigned.x= ml create mode 100644 tests/qemuxml2xmloutdata/hostdev-pci-address-unassigned= .xml diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index a83c9ae7a5..fa0e58f136 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -5463,6 +5463,11 @@ + + + unassigned + + diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index 4c57f0995f..4dbd5c1ac9 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -45,6 +45,7 @@ VIR_ENUM_IMPL(virDomainDeviceAddress, "virtio-mmio", "isa", "dimm", + "unassigned", ); =20 static int @@ -120,6 +121,7 @@ virDomainDeviceInfoAddressIsEqual(const virDomainDevice= Info *a, /* address types below don't have any specific data */ case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED: break; =20 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index d98fae775c..e091d7cfe2 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -45,6 +45,7 @@ typedef enum { VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM, + VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED, =20 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST } virDomainDeviceAddressType; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9580884747..52b6c40c44 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6286,9 +6286,11 @@ virDomainHostdevDefValidate(const virDomainHostdevDe= f *hostdev) switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: if (hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NO= NE && + hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UN= ASSIGNED && hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PC= I) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("PCI host devices must use 'pci' address = type")); + _("PCI host devices must use 'pci' or " + "'unassigned' address type")); return -1; } break; @@ -7307,6 +7309,7 @@ virDomainDeviceInfoFormat(virBufferPtr buf, =20 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST: break; } @@ -7507,6 +7510,7 @@ virDomainDeviceAddressParseXML(xmlNodePtr address, break; =20 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST: break; } @@ -21858,6 +21862,7 @@ virDomainDeviceInfoCheckABIStability(virDomainDevic= eInfoPtr src, case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST: break; } diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 3465d28b84..4935502e7b 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -461,6 +461,7 @@ qemuBuildVirtioDevStr(virBufferPtr buf, return -1; =20 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST: default: virReportEnumRangeError(virDomainDeviceAddressType, info->type); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index c233a4ba96..549d04742b 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7262,6 +7262,7 @@ qemuDomainDeviceDefValidateAddress(const virDomainDev= iceDef *dev, case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED: /* No validation for these address types yet */ break; =20 diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 605984f80f..b077240899 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -2313,6 +2313,11 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def, continue; } =20 + /* do not reserve address for info->type=3D'unassigned' */ + if (def->hostdevs[i]->info->type =3D=3D + VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED) + continue; + if (qemuDomainPCIAddressReserveNextAddr(addrs, def->hostdevs[i]->info) < = 0) goto error; diff --git a/tests/qemuxml2argvdata/hostdev-pci-address-unassigned.xml b/te= sts/qemuxml2argvdata/hostdev-pci-address-unassigned.xml new file mode 100644 index 0000000000..9a2685ca0e --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-pci-address-unassigned.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-unassigned.xml b/= tests/qemuxml2xmloutdata/hostdev-pci-address-unassigned.xml new file mode 100644 index 0000000000..2341e8432b --- /dev/null +++ b/tests/qemuxml2xmloutdata/hostdev-pci-address-unassigned.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 8b43f35f06..7c53d870d5 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -431,6 +431,7 @@ mymain(void) =20 DO_TEST("hostdev-usb-address", NONE); DO_TEST("hostdev-pci-address", NONE); + DO_TEST("hostdev-pci-address-unassigned", NONE); DO_TEST("hostdev-pci-multifunction", NONE); DO_TEST("hostdev-vfio", NONE); DO_TEST("hostdev-vfio-zpci", --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 12:52:13 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=1574775337; cv=none; d=zohomail.com; s=zohoarc; b=RJPZfuXj+qCNmHJMYHAtby8c//RQ2+p7oB4NxoOiPL95Yvbllljt/OJ5c90AjXJuTRgRHk1s1c+DKgUg9+KPGL25oqkGxjH3YlUxBYAnl4iY5h3i3pGzTU9OIGfE49Fn+Z+VvPaelq8TE5F1AkJ6rFyKngWroxJPzlboKF0n7Mw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574775337; 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=0nqzHBAcsagbaFkV66J5Afi2zBzBNHHaUY6bGrQkqH0=; b=jK2mxjqpT73xvdMYtehkbkYeexzqN6f6sOvcwS6BtqAMEjD8Z8qlufgLxYe5EKPkX8yIrbl4V5elMYqbpKXrEZ3fEeUxwZNKzOh3+WFVIhPBSQoGTY76Xp5kOsYgw82ZUoYzuXcoq/9SzqUE+tmlz0ilkPvKACdaVgxY9tCvmgs= 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 1574775337489614.1302432124204; Tue, 26 Nov 2019 05:35:37 -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-339-51Rs5neUPGGRdnzceBe6xQ-1; Tue, 26 Nov 2019 08:35:34 -0500 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 9A493189CF59; Tue, 26 Nov 2019 13:35:27 +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 5E3645D9D6; Tue, 26 Nov 2019 13:35: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 756971803C40; Tue, 26 Nov 2019 13:35:26 +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 xAQDYenL004683 for ; Tue, 26 Nov 2019 08:34:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id C718A11422D9; Tue, 26 Nov 2019 13:34:40 +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 C2F4210ABC9A for ; Tue, 26 Nov 2019 13:34:40 +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 AAC2E8F2502 for ; Tue, 26 Nov 2019 13:34:40 +0000 (UTC) Received: from mail-qv1-f68.google.com (mail-qv1-f68.google.com [209.85.219.68]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-168-Gipv334JNYSR3-mRv5YHyw-1; Tue, 26 Nov 2019 08:34:37 -0500 Received: by mail-qv1-f68.google.com with SMTP id d3so7239280qvs.11; Tue, 26 Nov 2019 05:34:36 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:afb:97a3:bc66:755b:2f57]) by smtp.gmail.com with ESMTPSA id i41sm5931229qti.42.2019.11.26.05.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2019 05:34:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574775336; 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=0nqzHBAcsagbaFkV66J5Afi2zBzBNHHaUY6bGrQkqH0=; b=WBdOnxtumcOR9Azie2mPmmaaQsnb4AQ4ZLWzxDtOau+aydpJg+hDH0cPjQbD+tAZOe6ahf pqu/orKQZsCpTBmUJlHqbg/LQ2cv0IjQ79I5QfG1DK0erD+EXHa1LTLeF5uohg/PI+0z0R gZe6+U0tfHdMWjadxcy66ClT0BiUlk8= 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=2fiNin7VDai0mSY0+UlTyJulCjQGpSFdEutcE4oMw+g=; b=nbeAqrzm8ZeBMFbZAmH/D1/AmGtH7WftC30APnK2qdCyRKdQGJHvylsxhN7o58po45 BnfqBuBbK/Ncozq0Lt9X94wUa3ni2yShKhJBjxY7QpY6DsnHuagjcx6G/7A25jOTHz18 5UPjAFObTeR6n0YEePFXJaDin3RENmIabC1kWLfnvCNhmypmnFQcChiJmhuDQE679eRr zAoj86dwkJF0YRuBZiD4JecAk9KiYT6erkZERU81qix+3hLEqNZtrXzoPYprsByRL6Tb USqyd5k8wKi3Wfx8kA7Czu48Aa/jdFHan2z6F5Srbyeij4SqhftPsojUzSSCeCw6Vh8V g8OA== X-Gm-Message-State: APjAAAWNcaTeoBZWXeLUqXtIOgclZwT1VNlUm9DOY2YxJCrKBEVfjPNJ PRr9t0LoY17milbjf6nXZ8A/Sfmg X-Google-Smtp-Source: APXvYqwSzD8GfePA0eR/j1qAVnVLRaY2+lQcqoFqbN71cYgTuQTZ88hMEWxJBtop230CKFWOYQjCDA== X-Received: by 2002:a05:6214:7d2:: with SMTP id bb18mr20717642qvb.35.1574775276233; Tue, 26 Nov 2019 05:34:36 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Tue, 26 Nov 2019 10:33:57 -0300 Message-Id: <20191126133401.1242133-3-danielhb413@gmail.com> In-Reply-To: <20191126133401.1242133-1-danielhb413@gmail.com> References: <20191126133401.1242133-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: Gipv334JNYSR3-mRv5YHyw-1 X-MC-Unique: 51Rs5neUPGGRdnzceBe6xQ-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 xAQDYenL004683 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , darkstego@gmail.com, laine@laine.org Subject: [libvirt] [PATCH v3 2/6] 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.14 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, by checking if dev->info->type is VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED, meaning that this device shouldn't be part of the actual guest launch and alias generation. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Cole Robinson --- src/qemu/qemu_alias.c | 6 ++++ src/qemu/qemu_command.c | 4 +++ .../hostdev-pci-address-unassigned.args | 31 +++++++++++++++++++ tests/qemuxml2argvtest.c | 4 +++ 4 files changed, 45 insertions(+) create mode 100644 tests/qemuxml2argvdata/hostdev-pci-address-unassigned.a= rgs diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index 93bdcb7548..6139f4c9fb 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 hostdevs that will not be + * assigned to the guest. */ + if (def->hostdevs[i]->info->type =3D=3D + VIR_DOMAIN_DEVICE_ADDRESS_TYPE_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 4935502e7b..124bdc2323 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5419,6 +5419,10 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd, } } =20 + /* Ignore unassigned devices */ + if (hostdev->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_U= NASSIGNED) + 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-unassigned.args b/t= ests/qemuxml2argvdata/hostdev-pci-address-unassigned.args new file mode 100644 index 0000000000..14fa3d6b37 --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-pci-address-unassigned.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 a2791d0460..5ee9c9b2dc 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-unassigned", + 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.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 12:52:13 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=1574775363; cv=none; d=zohomail.com; s=zohoarc; b=XgRkQFQhwnc8nDQrGUyjUvkPnyiSCiksFW9zCvd9QLei2hQB7X1mXXVe74O42wTm38YXbqE+BQztaj+lEWv87OMMVdBAWpPjF0zqEq6DM5iLsYJSrxSuUfcO7DvxqJb+0DdS79lbfJ9Y68UZ0oywvB0GzoXKsBAJuAgcDZW3Y1c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574775363; 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=bUjPFdWQrrwxueoVHK5TSKazSywhuE9d6JMAKwbQljY=; b=C4I3LnBKqdXe8eY45fl/wU5g2t7afFta/V8KcCh1bJWXzB0QlS3RJgIKpXgCvBpOW+2mSDglZiXDiVc2qcZYPBg42hdGkSLgCQKJEVTKnDl5ToroxdOgoH2zgxAw1ufZmI2U4wMB5OhKbhMTKq8nv6aYr0TqDU0rmulR4jzYYww= 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 1574775363398706.96332307349; Tue, 26 Nov 2019 05:36: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-142-A_wRvinBNCSB5Q4UW3j9pA-1; Tue, 26 Nov 2019 08:36:00 -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 7A06B8024E3; Tue, 26 Nov 2019 13:35: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 51265600CA; Tue, 26 Nov 2019 13:35: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 05D924E56D; Tue, 26 Nov 2019 13:35:55 +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 xAQDYlBx004742 for ; Tue, 26 Nov 2019 08:34:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id 178EB1C669; Tue, 26 Nov 2019 13:34:47 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 12A3EED16E for ; Tue, 26 Nov 2019 13:34:44 +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 92ED61022E93 for ; Tue, 26 Nov 2019 13:34:44 +0000 (UTC) Received: from mail-qv1-f66.google.com (mail-qv1-f66.google.com [209.85.219.66]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-175-KBZJglHZPeaT0qG1ge5ZIQ-1; Tue, 26 Nov 2019 08:34:40 -0500 Received: by mail-qv1-f66.google.com with SMTP id n4so7248953qvq.9; Tue, 26 Nov 2019 05:34:40 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:afb:97a3:bc66:755b:2f57]) by smtp.gmail.com with ESMTPSA id i41sm5931229qti.42.2019.11.26.05.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2019 05:34:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574775362; 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=bUjPFdWQrrwxueoVHK5TSKazSywhuE9d6JMAKwbQljY=; b=dJYuzIX+at6OE5oPm58cWVS87ER1vr3LvHivyawVdqwnu2Y6V15dhaYIgwwVvQL5rGFHQd H9DUGEAoEB6xXAkohdB9qCPqsOojl+SmR5wM5z62H6Z+CrWm04PoltWHO2GGcdp/FcRorX /nLUfkAfr/Eh3nAELrCyczZ5FUMS56Q= 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=tigpZ7TRbDUY1H9PSts/IrB7bb+O+VLwwyKhCEzkx2U=; b=FuRTr18mujmyJNbGo8UkCm1wwHEz6byROrRWuRLv6aoSmITzEstzeJurkL9zRv9Rap JMt910UoGdkQEVZwfzghYkO1oer99bM6hlvhnCE/OW66WxTOEtYZdRKqZo1A2R6nNWmr knSrL4G/sOgaegsu9V6P1M25WpXZQqQ+HjQArhRUwR9KhKfpdFhGOin9U//Yr1FKGMkW HPuTWUZERWmQFXS8bm39z0XlTJyul+SaItgZ+pWsT5FhYJjot9CYZ8wre2v4TRYg1Mwg CBp8GH1RUOZyDCYDTiYDkNU/BaK0w175neowulvnPsYr41Edl3mnr6/v7RvSn3ZAVwCg /riw== X-Gm-Message-State: APjAAAVljFOwGISmRo2Af0hhXrCxBP7GoT86vXduV1aa/8O/i+begVEl PvEYCs6qpAbT1x3fL1mGLCDs5gvG X-Google-Smtp-Source: APXvYqyvT8Tzu/2CQw5fWG+OR1RFs31DwBpM9MS/vpBz3UQnSaTk2Q9JfPuiuQTi6FX1IPbytsxTDQ== X-Received: by 2002:a05:6214:852:: with SMTP id dg18mr33432800qvb.8.1574775279980; Tue, 26 Nov 2019 05:34:39 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Tue, 26 Nov 2019 10:33:58 -0300 Message-Id: <20191126133401.1242133-4-danielhb413@gmail.com> In-Reply-To: <20191126133401.1242133-1-danielhb413@gmail.com> References: <20191126133401.1242133-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: KBZJglHZPeaT0qG1ge5ZIQ-1 X-MC-Unique: A_wRvinBNCSB5Q4UW3j9pA-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 xAQDYlBx004742 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , darkstego@gmail.com, laine@laine.org Subject: [libvirt] [PATCH v3 3/6] 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. This is an example of this newly added error condition when the domain does not declare all the PCI hostdevs of the same IOMMU: $ sudo ./run tools/virsh start multipci-coldplug-partial-fail error: Failed to start domain multipci-coldplug-partial-fail error: Requested operation is not valid: All devices of the same IOMMU grou= p 1 of the PCI device 0001:09:00.0 must belong to domain multipci-coldplug-partial= -fail $ Signed-off-by: Daniel Henrique Barboza Reviewed-by: Cole Robinson --- src/util/virhostdev.c | 64 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 39e6b8f49f..2e7885112f 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 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 12:52:13 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=1574775365; cv=none; d=zohomail.com; s=zohoarc; b=IR5aaAOMZp070By6pZuwBH6Qdc+p9nzX+oVMG9DrWBQ6VLLEFm7Yr8h7IyZsWRqepYBXzbQtn0swLZyeOU8GZ16BIwfvAzQTCGbiuvnoGpNa7C1f2Y7UPP3pHVMKaFra1EtP7O+j6exbBfr8JjZoGOCPYrhOIVPTmBPXKac6FO8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574775365; 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=1rOyTmRK9DQjX6snJcNAnF8yar4yNH9CDGw3y5xN+kk=; b=Sq2J4B9sJ4/GVBOIdm6RCE//vc2q/rIHpQcO+CsnlWDhX2opc+Wp/kId9qgq8062eUqAiKaOxOOMkHcA+ZRF2XosNq82hrxfKk883jpfEr/4IEqkOX8oFSQocwlXcJCvw3r5eBD6KvihYygA7ESuloJRu8qVS+gFczD5duVSq9Y= 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 1574775365738344.5178695494935; Tue, 26 Nov 2019 05:36:05 -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-405-Q06_zHqSMeW5zY5h7RDMhg-1; Tue, 26 Nov 2019 08:36:02 -0500 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 8262D1010C3E; Tue, 26 Nov 2019 13:35: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 51C795D6BE; Tue, 26 Nov 2019 13:35: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 0769E4E56E; Tue, 26 Nov 2019 13:35:55 +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 xAQDYkdl004727 for ; Tue, 26 Nov 2019 08:34:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3359111422D9; Tue, 26 Nov 2019 13:34:46 +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 2EFE310ABC9A for ; Tue, 26 Nov 2019 13:34:46 +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 1630618AE945 for ; Tue, 26 Nov 2019 13:34:46 +0000 (UTC) Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-390-YsmMA5HhMTuixqfF8uwgbg-1; Tue, 26 Nov 2019 08:34:43 -0500 Received: by mail-qt1-f175.google.com with SMTP id z22so543277qto.7; Tue, 26 Nov 2019 05:34:43 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:afb:97a3:bc66:755b:2f57]) by smtp.gmail.com with ESMTPSA id i41sm5931229qti.42.2019.11.26.05.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2019 05:34:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574775364; 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=1rOyTmRK9DQjX6snJcNAnF8yar4yNH9CDGw3y5xN+kk=; b=hLSH6J8yv9zEIQRK6hJR1BBKu7nd/4vJoNOA18l46HckSOFCtij38/WH2Dde/4N5RgyIeF ySI4/NZaIPecSJ/17kBqcB50ggtdcdLEJbBM2kPx04xVBS1cNI4EqE/BCoRA+wN3L7/0P4 m7Tnu8QZ1WLUCTFFa8q+Kwd4IWuwDo0= 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=KsOSxqI6B31jSLld/mCLR0wJ2aRMy0di4Hd+6DtsdZ0=; b=dibabDnyLG6VPJg4xhs7GeY+dPLjVCCoiFgXq+Tw3Cuqnk9lBuYZZpdIQ0hLOXHuZI g7NjGrSMN7mSbUa8wKJ60O7rBONOsIMOjW8Nwcf5atepq1K19FZjTdRhSP5LE3vnqTV7 0/gsPDQOVdj7JvJ1uN5h6WquwvF6Vkoyub+2oA+bCf0ZJP0snw7cX0HdS0D2fme9uKny EqGX3Fhjlgqvvej5E0AfRUtFj+7IgZxIKbbuxX46NqMZ5257RdU7fBsdA3YpicAf3IpM FAet0tOlbSD9Hwd0iUHLR3PaFndl0gyqdl6H27o3QdmE0ttrtB3vT/z5rcNF7t+pm65S 5n0A== X-Gm-Message-State: APjAAAUyGkCANQdNXoSsiRDVVi5nROEq9r87yzpziR+levEKby3fHKdW 15LlKUUSXPqwDa2v3rJSNBqslzPo X-Google-Smtp-Source: APXvYqzcBehM8pZGkykhPPJo0gkEayvkFNkDvKb9cXIBe/HSu3UZWc/x3MAEMQUGY2cnylU7m3iT/g== X-Received: by 2002:aed:2357:: with SMTP id i23mr35275876qtc.365.1574775283229; Tue, 26 Nov 2019 05:34:43 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Tue, 26 Nov 2019 10:33:59 -0300 Message-Id: <20191126133401.1242133-5-danielhb413@gmail.com> In-Reply-To: <20191126133401.1242133-1-danielhb413@gmail.com> References: <20191126133401.1242133-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: YsmMA5HhMTuixqfF8uwgbg-1 X-MC-Unique: Q06_zHqSMeW5zY5h7RDMhg-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 xAQDYkdl004727 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , darkstego@gmail.com, laine@laine.org Subject: [libvirt] [PATCH v3 4/6] 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.79 on 10.5.11.15 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 Reviewed-by: Cole Robinson --- docs/formatdomain.html.in | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 6df4a8b26e..7625265ba8 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -4148,6 +4148,20 @@ attributes: iobase and irq. Since 1.2.1 +
unassigned
+
For PCI hostdevs, <address type=3D'unassigned'/> + 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. Using this address type in such cases + will tell Libvirt that the device must not be assigned to the gues= t. + 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'unassigned'/> is an invalid ad= dress + type for all other device types. + Since 5.11.0 +
=20

Virtio-related options

--=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 12:52:13 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=1574775376; cv=none; d=zohomail.com; s=zohoarc; b=PMBO4H+oN9gll36cMoce1Z601Oh9dJVcEGlZBOMmygI1NwTF+0H63g0Ox5ZudrjE7bu+bUBgdWYF+9J3Yppp0d/d/hvNenMKmKuAiWi7Nktc99RTT9LzfPHjXHEBlgQN99oGAFqhyXC7Ytx5rvZTBgyJmYMfc032xPq3kRtyNoU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574775376; 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=vvSSey/tlOw2zSGflLhg3k+gLOxb+cRnE0vHB4btnFI=; b=FTPg3srHZhT0hrBc9gk11T/NCQLq/2MQKgrj35WhBitV+jDpRfD4+i29LXEqjyQBfMnpXBC8LnVx1ZruT5JjI2GXhf6Y2WIkUjnGQDGFoR71MVxwRO2Cqcwc3oxNiIFzBuKCePtk3cs9IpGr/WgbysjsWJTOLDATW7+UgQRmmgY= 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 1574775376909329.8971385237553; Tue, 26 Nov 2019 05:36: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-27-bJS-wBY1Oh-4lSOFCpGbZg-1; Tue, 26 Nov 2019 08:36: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 A1197800C7B; Tue, 26 Nov 2019 13:36:05 +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 763031001B3F; Tue, 26 Nov 2019 13:36:05 +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 20FC418034EC; Tue, 26 Nov 2019 13:36:05 +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 xAQDYnit004753 for ; Tue, 26 Nov 2019 08:34:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id 898EBD95EB; Tue, 26 Nov 2019 13:34:49 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8546EED16E for ; Tue, 26 Nov 2019 13:34: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 6C6751022E93 for ; Tue, 26 Nov 2019 13:34:49 +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-207-1sazi78MMu6vs2EDan2d-Q-1; Tue, 26 Nov 2019 08:34:47 -0500 Received: by mail-qk1-f193.google.com with SMTP id m16so16035145qki.11; Tue, 26 Nov 2019 05:34:47 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:afb:97a3:bc66:755b:2f57]) by smtp.gmail.com with ESMTPSA id i41sm5931229qti.42.2019.11.26.05.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2019 05:34:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574775375; 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=vvSSey/tlOw2zSGflLhg3k+gLOxb+cRnE0vHB4btnFI=; b=QPNWzpgo/n+lOPdppOMhg1hxaHPMbx3eZThjLugMxAMtrsa5VSeARU6/dmSnma6Ht7PaQs V5FGMJL4cQ5MQjyXH8swmgYgQJnDo7wOcrV/keW8+tkD0P578S+sz6sxLZhe9wzEf2oSIX oMMDhLW1i8IFMgzmp9xVqghotltl1Oc= 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=IPmq3/DqMF2AtS3mGIUjgNXOWgyeHwADGwCdMmD7jxg=; b=Gr0WjIyeZmzVis6j+uZBPYPyztXfRE/8rsA4hoJwtEBEBmGkYYpdxR/rIKlv182fMP IOxfWVaonFvTV+AoiLfLYQIASVKvnlXs7644N6tylI1PTNvdEw/05OxweeoWe2pHNdD2 saXtju1zwiLbpDyHiIqu+ceCCkWo+7xnN7MMDFy1PuvMwJRaUf+FVFcFPdYaKt0sfsYO VLGoXi9qkvxTHA50eZu5kC/ZazPc+y9t7+IxEr3GTNvlqmu+IQ1hXq8vELck3IP5Jrc2 hDU5mvP4BPHOhy6gDoBpTZfNA1GXIrjpt+eOy7eEVPzeBo3qTjzuKVJLuS4bp4qdapzv Eknw== X-Gm-Message-State: APjAAAUhnatzAURwZ4xVDEj82AqyegFc1KhyBeS9iKRNk6fy8WvjW2yz y5DqcNy2pXSHGncTTAiSy0o6y56M X-Google-Smtp-Source: APXvYqya5xhhNPuMmtH+bBC4VvpacxtAvEhSu/6UyfaryzvPT0ZcfWs2RMtBU+bdxvofa2jaDbACPQ== X-Received: by 2002:a05:620a:1472:: with SMTP id j18mr27810270qkl.184.1574775286487; Tue, 26 Nov 2019 05:34:46 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Tue, 26 Nov 2019 10:34:00 -0300 Message-Id: <20191126133401.1242133-6-danielhb413@gmail.com> In-Reply-To: <20191126133401.1242133-1-danielhb413@gmail.com> References: <20191126133401.1242133-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: 1sazi78MMu6vs2EDan2d-Q-1 X-MC-Unique: bJS-wBY1Oh-4lSOFCpGbZg-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 xAQDYnit004753 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , darkstego@gmail.com, laine@laine.org Subject: [libvirt] [PATCH v3 5/6] utils: PCI multifunction detection helpers 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" This patch introduces two helpers that will be used in the next patch. One is virpci.c:virPCIDeviceIsMultifunction(), and the other is virhostdev.c:virHostdevIsPCIMultifunctionDevice(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: Cole Robinson --- src/libvirt_private.syms | 2 ++ src/util/virhostdev.c | 24 ++++++++++++++++++++++++ src/util/virhostdev.h | 3 +++ src/util/virpci.c | 17 +++++++++++++++++ src/util/virpci.h | 2 ++ 5 files changed, 48 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8fe0bf9365..345c9747e8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2137,6 +2137,7 @@ virHostCPUStatsAssign; # util/virhostdev.h virHostdevFindUSBDevice; virHostdevIsMdevDevice; +virHostdevIsPCIMultifunctionDevice; virHostdevIsSCSIDevice; virHostdevIsVFIODevice; virHostdevManagerGetDefault; @@ -2717,6 +2718,7 @@ virPCIDeviceGetUnbindFromStub; virPCIDeviceGetUsedBy; virPCIDeviceHasPCIExpressLink; virPCIDeviceIsAssignable; +virPCIDeviceIsMultifunction; virPCIDeviceIsPCIExpress; virPCIDeviceListAdd; virPCIDeviceListAddCopy; diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 2e7885112f..803daaa995 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -2251,3 +2251,27 @@ virHostdevUpdateActiveDomainDevices(virHostdevManage= rPtr mgr, =20 return 0; } + +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/util/virhostdev.h b/src/util/virhostdev.h index 2d61c21e9d..c5a1fdcf5e 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -194,6 +194,9 @@ bool virHostdevIsMdevDevice(const virDomainHostdevDef *hostdev) ATTRIBUTE_NONNULL(1); bool +virHostdevIsPCIMultifunctionDevice(virDomainHostdevDefPtr hostdev) + ATTRIBUTE_NONNULL(1); +bool virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev) ATTRIBUTE_NONNULL(1); =20 diff --git a/src/util/virpci.c b/src/util/virpci.c index 9bea5a20d0..840cca77fc 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2818,6 +2818,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 cfb4581edf..8f37636809 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -266,6 +266,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.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 12:52:13 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=1574775374; cv=none; d=zohomail.com; s=zohoarc; b=X/lHbcAN+JEv75QDx1zT/K/wRZMfPSCVyiAcuVCj9vTl5nHG46day1YUYJJKQG34SA0EGkkU6Cnmfrn7vh/3CaOKqgZ+myg3/J1VR0G4b8VNOsrFzeknxPX59/kVscMlhL2rJ9xMFjuVrFFhoJ6na5oj29L6hVAA3+tSqimee3E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574775374; 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=lcACWl59pAgv/xRod6EnVrabdeX2eyTlrLS11I0ZW50=; b=MZaShfTgEm5KneadOBUQVQ/KK3If4yKg1ZrvVRPehnVoS2CcNhnneIIzqvlmfJoBKLxCT92+CaZGF9Ae8o9IDJA9IedVD/tz1I9ME+jpRezCBUJ5xxvwnRPHwVAq6sOOd5pa8cqruAVitDoFwqczZHvH/PYIYhFY6LHEW/TNQLI= 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 1574775374003424.77858535059556; Tue, 26 Nov 2019 05:36:14 -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-44-j0RqseCyMVGs_OWaT_ApxA-1; Tue, 26 Nov 2019 08:36:10 -0500 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 B594A18B639C; Tue, 26 Nov 2019 13:36:05 +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 85E1E39F; Tue, 26 Nov 2019 13:36:05 +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 2D9B44E562; Tue, 26 Nov 2019 13:36:05 +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 xAQDYtNh004778 for ; Tue, 26 Nov 2019 08:34:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1E6012026D68; Tue, 26 Nov 2019 13:34:55 +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 1A0E62063205 for ; Tue, 26 Nov 2019 13:34:52 +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 CDDEA910449 for ; Tue, 26 Nov 2019 13:34:52 +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-229-VXx_nZFAODuaqi20eCL9Sg-1; Tue, 26 Nov 2019 08:34:50 -0500 Received: by mail-qk1-f195.google.com with SMTP id m125so16035206qkd.8; Tue, 26 Nov 2019 05:34:50 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:afb:97a3:bc66:755b:2f57]) by smtp.gmail.com with ESMTPSA id i41sm5931229qti.42.2019.11.26.05.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2019 05:34:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574775372; 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=lcACWl59pAgv/xRod6EnVrabdeX2eyTlrLS11I0ZW50=; b=VQBCYKEGZkQpaZarFe+NduRDwr4lUWyzwnOtMwZAXeBBOfx8g6fM/T0QCAJr3pKSRrdPKY 6K14XdGrZ5rX1EMXeS1WiL5pY4jc4KGzm34Fq/5WIOz/OCbzS++b4wrquDa6puFO3VpyO7 QKp8P+N1Jt1xQLxLHiX1KWP5Xnw3PyQ= 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=e3Tz1faBpGuNvgCangaOphUsYaqbxxeFxRUGLWSr/XA=; b=omfe4Ke6DbvIAuYjKbsz+uEzrmCEwU/PnRiwzYAMz/ERGy/8wdhjrme0NiGdbPJpke KlVO5QugVPzi6DrnhJ6xhIIwJHCPRpz9AExKEpNPrMP0kpntqoFN2YNDdnn6+BIstYWx sRjIuvORN47mvYkcaKH1hof1O3OZ+R/QMZtXPDLksSeLAxwfNuGxEac8ZAltkc4peWYV HnMUwaPfZACjAjuTxr5Db/Pi0MbQhrYwxjoEeda0oMkeP3S8ExaqlSKpxRFZnJZz4Gmu YOY7LFFSyUL+XHADnH5UpcciQLQsYIfSXa6HON/z6CbTaNWZ42XJmY9iUnP6ot/t/t6O nl+A== X-Gm-Message-State: APjAAAVqUI/n2zx17hr0j1eGDeFrwuSdWH9/Jq0TehrIHafPZCx1Xm4A MS2yvQN9lPZnVS8TexJlUB0FADQG X-Google-Smtp-Source: APXvYqxyVken7DdDNxpS2mNaBRkw0kpY9A8JJV7BgxR6LNkRXp169DAE2kf1fluXGnyrCqte+ORL5Q== X-Received: by 2002:a37:7482:: with SMTP id p124mr32856178qkc.348.1574775289965; Tue, 26 Nov 2019 05:34:49 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Tue, 26 Nov 2019 10:34:01 -0300 Message-Id: <20191126133401.1242133-7-danielhb413@gmail.com> In-Reply-To: <20191126133401.1242133-1-danielhb413@gmail.com> References: <20191126133401.1242133-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: VXx_nZFAODuaqi20eCL9Sg-1 X-MC-Unique: j0RqseCyMVGs_OWaT_ApxA-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id xAQDYtNh004778 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , darkstego@gmail.com, laine@laine.org Subject: [libvirt] [PATCH v3 6/6] domain_conf.c: don't allow function zero to be unassigned 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The recently added 'unassigned' address type for PCI hostdevs revealed an uncommon behavior in a Power 8 host with a Broadcom BCM5719 PCIe Multifunction card. With this setup, it is possible to passthrough the BCM5719 functions to the domain, but unassigning the function zero. This means that the guest is able to use non-zero functions of the device without having access to the function zero. This is the output of 'lspci' in this scenario where only function 2 is being assigned: $ lspci 0000:00:01.0 Unclassified device [00ff]: Red Hat, Inc Virtio memory balloon 0000:00:03.0 USB controller: Red Hat, Inc. QEMU XHCI Host Controller (rev 0= 1) 0000:00:04.0 SCSI storage controller: Red Hat, Inc Virtio block device 0001:00:01.2 Ethernet controller: Broadcom Limited NetXtreme BCM5719 Gigabi= t Ethernet PCIe (rev 01) $ More details can be read at [1]. In short, no other architecture is allowing this kind of behavior as PowerPC is displaying here. For x86, an extra 'pci=3Dpcie_scan_all' kernel option would be needed for the guest to find t= his device, while in PowerPC this wasn't needed. There's the question of compliance with the PCI 3.0 spec that Alex Williamson brought up in [2] that would be hurt if we allow this type of use. Allowing the zero function to be unassigned will also conflict with the logic use for hotplug/unplug of multifunction devices, which is a work in progress in Libvirt, since in both hotplug and unplug we rely on function zero to trigger the operation in QEM= U. With all these downsides, summed up with the fact that the only case we have proof where this might be a thing is a Power 8 host comboed with the BCM5719 card, let's forbid this kind of use in Libvirt altogether. [1] https://www.redhat.com/archives/libvir-list/2019-November/msg01099.html [2] https://www.redhat.com/archives/libvir-list/2019-November/msg01104.html Signed-off-by: Daniel Henrique Barboza Reviewed-by: Cole Robinson --- src/conf/domain_conf.c | 13 ++++++ ...pci-multifunction-zero-unassigned-fail.xml | 42 +++++++++++++++++++ tests/qemuxml2argvtest.c | 4 ++ tests/virpcimock.c | 9 ++-- 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 tests/qemuxml2argvdata/hostdev-pci-multifunction-zero-u= nassigned-fail.xml diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 52b6c40c44..270c70eafb 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15644,7 +15644,20 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr = xmlopt, | VIR_DOMAIN_DEF_PARSE_ALLOW_ROM) = < 0) goto error; } + if (def->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { + /* Do not allow function 0 of a PCI multifunction device to + * be unassigned */ + if (virHostdevIsPCIMultifunctionDevice(def)) { + if (def->info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNAS= SIGNED && + def->source.subsys.u.pci.addr.function =3D=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Function zero of PCI Multifunction devic= e " + "must always be assigned")); + goto error; + } + } + switch ((virDomainHostdevSubsysType) def->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: if (virXPathBoolean("boolean(./readonly)", ctxt)) diff --git a/tests/qemuxml2argvdata/hostdev-pci-multifunction-zero-unassign= ed-fail.xml b/tests/qemuxml2argvdata/hostdev-pci-multifunction-zero-unassig= ned-fail.xml new file mode 100644 index 0000000000..1abce3b2e7 --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-pci-multifunction-zero-unassigned-fail= .xml @@ -0,0 +1,42 @@ + + 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 5ee9c9b2dc..163664d913 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_PARSE_ERROR("hostdev-pci-multifunction-zero-unassigned-fail", + QEMU_CAPS_KVM, + QEMU_CAPS_DEVICE_VFIO_PCI); + DO_TEST("serial-file-log", QEMU_CAPS_CHARDEV_FILE_APPEND, QEMU_CAPS_DEVICE_ISA_SERIAL, diff --git a/tests/virpcimock.c b/tests/virpcimock.c index cd6ae1cff6..7be133d7a7 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -1000,9 +1000,12 @@ init_env(void) MAKE_PCI_DEVICE("0001:01:00.1", 0x8086, 0x105e, 5); MAKE_PCI_DEVICE("0005:80:00.0", 0x10b5, 0x8112, 6, .klass =3D 0x060400= ); MAKE_PCI_DEVICE("0005:90:01.0", 0x1033, 0x0035, 7); - MAKE_PCI_DEVICE("0005:90:01.1", 0x1033, 0x0035, 7); - MAKE_PCI_DEVICE("0005:90:01.2", 0x1033, 0x00e0, 7); - MAKE_PCI_DEVICE("0005:90:01.3", 0x1033, 0x00e0, 7); + MAKE_PCI_DEVICE("0005:90:01.1", 0x1033, 0x0035, 7, + .physfn =3D "0005:90:01.0"); /* Virtual Function */ + MAKE_PCI_DEVICE("0005:90:01.2", 0x1033, 0x00e0, 7, + .physfn =3D "0005:90:01.0"); /* Virtual Function */ + MAKE_PCI_DEVICE("0005:90:01.3", 0x1033, 0x00e0, 7, + .physfn =3D "0005:90:01.0"); /* Virtual Function */ MAKE_PCI_DEVICE("0000:0a:01.0", 0x8086, 0x0047, 8); MAKE_PCI_DEVICE("0000:0a:02.0", 0x8286, 0x0048, 8); MAKE_PCI_DEVICE("0000:0a:03.0", 0x8386, 0x0048, 8); --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list