From nobody Mon Feb 9 17:05:04 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613030353; cv=none; d=zohomail.com; s=zohoarc; b=Hw6ukZ1DOCY9S6VV0HZ18wLNqJA0hiM9PoY1IG6NzJrIQNhdJeyUPgeIyMdLCNuUIFDhACQUkR4p6IKdO98Er1i65PzG8+gjcxarYH2QQ6zgZevcF2JDK8jvvwQ8TTJKeh10apnz4uypbswwUenr1Xq6lk2/GZCQyZOQI8q8/vU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613030353; h=Content-Type:Content-Transfer-Encoding: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=H81i7nF6gTSciw13tC31soFX6fR5c7t1QDixivOcoxc=; b=MEgfO1C5oG27JVbHuWnpC9hhvHG0s2FB2rRg9QWmo6pszrXXOI7nvFwEc7Opvqk8bzrlixUl2lzDC/mcCXWAgvlNrZ+XK1zTbT1qBnadvxfw4NCixu6dGfpYVi/riP8+PoolsoYlQbgnKNa+A9ZTV72GIF4rAVNyyIaKVZ3XF8g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613030353231227.9270824293909; Wed, 10 Feb 2021 23:59:13 -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-524-NOHf5gI3PGKArqVGklzaYg-1; Thu, 11 Feb 2021 02:57:57 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 84B46100A624; Thu, 11 Feb 2021 07:57:52 +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 5C2BC5C1BD; Thu, 11 Feb 2021 07:57:52 +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 1D65A4EE4D; Thu, 11 Feb 2021 07:57:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11B7vfMX022737 for ; Thu, 11 Feb 2021 02:57:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9AB415D9E8; Thu, 11 Feb 2021 07:57:41 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-48.phx2.redhat.com [10.3.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 531B55D9E3 for ; Thu, 11 Feb 2021 07:57:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613030352; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=H81i7nF6gTSciw13tC31soFX6fR5c7t1QDixivOcoxc=; b=C9yvWcIzGpVVKOrDCgVt6RVUH5U5sqszecCC+/Dy7xnxIDInY1BTsg61gNJEmyq85DZS4v hFV/qJ3GLLlLfrcScxrB0wf5MSxYUw6ZF6tnPj5j2+kSKePNZ5i8pKBY5kusXSHOwc0XtQ oSVU3CZxDKQuJ1A4r2DqhAoEjLipNWs= X-MC-Unique: NOHf5gI3PGKArqVGklzaYg-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 5/7] conf: parse/format element in plain Date: Thu, 11 Feb 2021 02:57:32 -0500 Message-Id: <20210211075734.340526-6-laine@redhat.com> In-Reply-To: <20210211075734.340526-1-laine@redhat.com> References: <20210211075734.340526-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The element in allows pairing two interfaces together as a simple "failover bond" network device in a guest. One of the devices will be the "transient" interface - it will be preferred for all network traffic when it is present, but may be removed when necessary, in particular during migration, when traffic will instead go through the other interface of the pair - the "persistent" interface. As it happens, in the QEMU implementation of this teaming pair (called "virtio failover" in QEMU) the transient interface is always a host network device assigned to the guest using VFIO (aka "hostdev"); the persistent interface is always an emulated virtio NIC. When support was initially added for , it was written to require that the transient/hostdev device be defined using ; this was done because the virtio failover implementation in QEMU and the virtio guest driver demands that the two interfaces in the pair have matching MAC addresses, and the only way libvirt can guarantee the MAC address of a hostdev network device is to use , whose main purpose is to configure the device's MAC address. (note that in turn requires that the network device be an SRIOV VF (Virtual Function), as that is the only type of network device whose MAC address we can set in a way that will survive the device's driver init in the guest). It has recently come up that some users are unable to use because they are running in a container environment where libvirt doesn't have the necessary privileges or resources to set the VF's MAC address (because setting the VF MAC is done via the same device's PF (Physical Function), and the PF is not exposed to libvirt's container. At the same time, they *are* able to set the VF's MAC address in advance of staring up libvirt in the container. So they could theoretically use the feature if libvirt just skipped the "setting the MAC address" part. Fortunately, that is *exactly* the difference between (a "hostdev VF") and (a "plain hostdev" - it could be *any PCI device; libvirt doesn't know what type of PCI device it is, and doesn't care). But what *is* still needed is for libvirt to provide a small bit of information on the commandline argument for the hostdev, telling QEMU that this device will be part of a team ("failover pair"), and the id of the other device in the pair. So, what we need to do is add support for the element to plain , and that is what this patch does. (actually, this patch adds parsing/formatting of the element in . The next patch will actually wire that into the qemu driver.) Signed-off-by: Laine Stump --- docs/formatdomain.rst | 51 +++++++++++++++ docs/schemas/domaincommon.rng | 3 + src/conf/domain_conf.c | 5 ++ src/conf/domain_conf.h | 1 + src/conf/domain_validate.c | 19 ++++++ .../net-virtio-teaming-hostdev.xml | 48 ++++++++++++++ .../net-virtio-teaming-hostdev.xml | 64 +++++++++++++++++++ tests/qemuxml2xmltest.c | 3 + 8 files changed, 194 insertions(+) create mode 100644 tests/qemuxml2argvdata/net-virtio-teaming-hostdev.xml create mode 100644 tests/qemuxml2xmloutdata/net-virtio-teaming-hostdev.xml diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 2493be595f..eafd6b3396 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -4837,6 +4837,22 @@ support in the hypervisor and the guest network driv= er). ... =20 +The second interface in this example is referencing a network that is +a pool of SRIOV VFs (i.e. a "hostdev network"). You could instead +directly reference an SRIOV VF device: + +:: + + ... + + +
+ + + + + ... + The ```` element required attribute ``type`` will be set to either ``"persistent"`` to indicate a device that should always be present in the domain, or ``"transient"`` to indicate a device that may periodically be @@ -4858,6 +4874,41 @@ once migration is completed; while migration is taki= ng place, network traffic will use the virtio NIC. (Of course the emulated virtio NIC and the hostde= v NIC must be connected to the same subnet for bonding to work properly). =20 +:since:`Since 7.1.0` The ```` element can also be added to a +plain ```` device. + +:: + + ... + + +
+ + + + + ... + +This device must be a network device, but not necessarily an SRIOV +VF. Using plain ```` rather than ```` or ```` is useful if the +device that will be assigned with VFIO is a standard NIC (not a VF) or +if libvirt doesn't have the necessary resources and privileges to set +the VF's MAC address (e.g. if libvirt is running unprivileged, or in a +container). This of course means that the user (or another +application) is responsible for setting the MAC address of the device +in a way such that it will survive guest driver initialization. For +standard NICs (i.e. not an SRIOV VF) this probably means that the +NIC's factory-programmed MAC address will need to be used for the +teaming pair (since any driver init in the guest will reset the MAC +back to factory). If it is an SRIOV VF, then its MAC address will need +to be set via the VF's PF, e.g. if you are going to use VF 2 of the PF +enp2s0f1, you would use something like this command: + +:: + + ip link set enp2s0f1 vf 2 mac 52:54:00:11:22:33 + NB1: Since you must know the alias name of the virtio NIC when configuring= the hostdev NIC, it will need to be manually set in the virtio NIC's configura= tion (as with all other manually set alias names, this means it must start with diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 31960fb7cf..e6de934456 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -5156,6 +5156,9 @@ + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3fe8517f39..8701136aa9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15015,6 +15015,9 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr x= mlopt, } } =20 + if (virDomainNetTeamingInfoParseXML(ctxt, &def->teaming) < 0) + goto error; + return def; =20 error: @@ -27433,6 +27436,8 @@ virDomainHostdevDefFormat(virBufferPtr buf, break; } =20 + virDomainNetTeamingInfoFormat(def->teaming, buf); + if (def->readonly) virBufferAddLit(buf, "\n"); if (def->shareable) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index fb695a212b..e263e6098b 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -354,6 +354,7 @@ struct _virDomainHostdevDef { virDomainHostdevCaps caps; } source; virDomainHostdevOrigStates origstates; + virDomainNetTeamingInfoPtr teaming; virDomainDeviceInfoPtr info; /* Guest address */ }; =20 diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 703946b3e5..b47ecba86b 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -1585,6 +1585,25 @@ virDomainHostdevDefValidate(const virDomainHostdevDe= f *hostdev) break; } } + + if (hostdev->teaming) { + if (hostdev->teaming->type !=3D VIR_DOMAIN_NET_TEAMING_TYPE_TRANSI= ENT) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("teaming hostdev devices must have type=3D'tr= ansient'")); + return -1; + } + if (!hostdev->teaming->persistent) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("missing required persistent attribute in hos= tdev teaming element")); + return -1; + } + if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS || + hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYP= E_PCI) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("teaming is only supported for pci hostdev de= vices")); + return -1; + } + } return 0; } =20 diff --git a/tests/qemuxml2argvdata/net-virtio-teaming-hostdev.xml b/tests/= qemuxml2argvdata/net-virtio-teaming-hostdev.xml new file mode 100644 index 0000000000..b176e66a00 --- /dev/null +++ b/tests/qemuxml2argvdata/net-virtio-teaming-hostdev.xml @@ -0,0 +1,48 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i386 + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + + + + + diff --git a/tests/qemuxml2xmloutdata/net-virtio-teaming-hostdev.xml b/test= s/qemuxml2xmloutdata/net-virtio-teaming-hostdev.xml new file mode 100644 index 0000000000..a7edab63bd --- /dev/null +++ b/tests/qemuxml2xmloutdata/net-virtio-teaming-hostdev.xml @@ -0,0 +1,64 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i386 + + + + +
+ + +
+ + + +
+ + + + + + +
+ + + + + + +
+ + + + + +
+ + +
+ + + +
+ + +
+ + +
+ + + diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index a00ebd7d76..5cd945f28f 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -438,6 +438,9 @@ mymain(void) DO_TEST("net-virtio-teaming-network", QEMU_CAPS_VIRTIO_NET_FAILOVER, QEMU_CAPS_DEVICE_VFIO_PCI); + DO_TEST("net-virtio-teaming-hostdev", + QEMU_CAPS_VIRTIO_NET_FAILOVER, + QEMU_CAPS_DEVICE_VFIO_PCI); DO_TEST_CAPS_LATEST("net-isolated-port"); DO_TEST("net-hostdev", NONE); DO_TEST("net-hostdev-bootorder", NONE); --=20 2.29.2