From nobody Sat Jul 5 00:35:50 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530106537039254.90868486941497; Wed, 27 Jun 2018 06:35:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 246D730C3400; Wed, 27 Jun 2018 13:35:35 +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 88330308240E; Wed, 27 Jun 2018 13:35:34 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D54CB18037EF; Wed, 27 Jun 2018 13:35:33 +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 w5RDZ7wq001572 for ; Wed, 27 Jun 2018 09:35:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 72E2820180EB; Wed, 27 Jun 2018 13:35:07 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id ECF742026D5B; Wed, 27 Jun 2018 13:35:06 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Wed, 27 Jun 2018 15:34:47 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v1 10/11] conf: Introduce new attribute 'display' 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 27 Jun 2018 13:35:36 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" QEMU 2.12 introduced a new type of display for mediated devices using vfio-pci backend which allows a mediated device to be used as a VGA compatible device as an alternative to an emulated video device. QEMU exposes this feature via a vfio device property 'display' with supported values 'on/off/auto' (default is 'off'). This patch adds the necessary bits to domain config handling in order to expose this feature. Since there's no convenient way for libvirt to come up with usable defaults for the display setting, simply because libvirt is not able to figure out which of the display implementations - dma-buf which requires OpenGL support vs vfio regions which doesn't need OpenGL (works with OpenGL enabled too) - the underlying mdev uses. Signed-off-by: Erik Skultety --- docs/formatdomain.html.in | 19 +++++- docs/schemas/domaincommon.rng | 5 ++ src/conf/domain_conf.c | 18 +++++- src/conf/domain_conf.h | 1 + src/qemu/qemu_domain.c | 71 ++++++++++++++++++= +++- .../hostdev-mdev-display-missing-graphics.xml | 35 +++++++++++ tests/qemuxml2argvdata/hostdev-mdev-display.xml | 39 ++++++++++++ .../hostdev-mdev-display-active.xml | 47 ++++++++++++++ .../hostdev-mdev-display-inactive.xml | 47 ++++++++++++++ tests/qemuxml2xmltest.c | 2 + 10 files changed, 279 insertions(+), 5 deletions(-) create mode 100644 tests/qemuxml2argvdata/hostdev-mdev-display-missing-gra= phics.xml create mode 100644 tests/qemuxml2argvdata/hostdev-mdev-display.xml create mode 100644 tests/qemuxml2xmloutdata/hostdev-mdev-display-active.xml create mode 100644 tests/qemuxml2xmloutdata/hostdev-mdev-display-inactive.= xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index c6ebd39bd9..f45eee6812 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -4502,9 +4502,22 @@ guest. Currently, model=3D'vfio-pci' and model=3D'vfio-ccw' (Since 4.4= .0) is supported. Refer MDEV to= create - a mediated device on the host. There are also some implications = on the - usage of guest's address type depending on the model - attribute, see the address element below. + a mediated device on the host. + Since 4.6.0 (QEMU 2.12) an optional + display attribute may be used to enable or disable + support for an accelerated remote desktop backed by a mediated + device (such as NVIDIA vGPU or Intel GVT-g) as an alternative to + emulated video devices. This attr= ibute + is limited to model=3D'vfio-pci' only. Supported va= lues + are either 'on' or 'off' (default is 'off'). It is required to u= se a + graphical framebuffer in order= to + use this attribute, currently only supported with VNC and Spice + graphics devices. +

+ Note: There are also some implications on the usage of guest's + address type depending on the model attribute, + see the address element below. +

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 4ad53d976b..1df479cda2 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -4590,6 +4590,11 @@ vfio-ccw + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6d399a198e..23d646cb63 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7651,6 +7651,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, char *rawio =3D NULL; char *backendStr =3D NULL; char *model =3D NULL; + char *display =3D NULL; int backend; int ret =3D -1; virDomainHostdevSubsysPCIPtr pcisrc =3D &def->source.subsys.u.pci; @@ -7670,6 +7671,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, sgio =3D virXMLPropString(node, "sgio"); rawio =3D virXMLPropString(node, "rawio"); model =3D virXMLPropString(node, "model"); + display =3D virXMLPropString(node, "display"); =20 /* @type is passed in from the caller rather than read from the * xml document, because it is specified in different places for @@ -7757,6 +7759,15 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, model); goto error; } + + if (display && + (mdevsrc->display =3D virTristateSwitchTypeFromString(display)= ) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("unknown value '%s' for attribute " + "'display'"), + display); + goto error; + } } =20 switch (def->source.subsys.type) { @@ -26574,9 +26585,14 @@ virDomainHostdevDefFormat(virBufferPtr buf, virTristateBoolTypeToString(scsisrc->rawio)); } =20 - if (def->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= MDEV) + if (def->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= MDEV) { virBufferAsprintf(buf, " model=3D'%s'", virMediatedDeviceModelTypeToString(mdevsrc->= model)); + if (mdevsrc->display > VIR_TRISTATE_SWITCH_ABSENT) + virBufferAsprintf(buf, " display=3D'%s'", + virTristateSwitchTypeToString(mdevsrc->d= isplay)); + } + } virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 99b5896391..6b21d2bf4c 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -382,6 +382,7 @@ typedef struct _virDomainHostdevSubsysMediatedDev virDo= mainHostdevSubsysMediated typedef virDomainHostdevSubsysMediatedDev *virDomainHostdevSubsysMediatedD= evPtr; struct _virDomainHostdevSubsysMediatedDev { int model; /* enum virMediatedDeviceModelType= */ + int display; /* virTristateSwitchType */ char uuidstr[VIR_UUID_STRING_BUFLEN]; /* mediated device's uuid stri= ng */ }; =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 948b9b7fd0..d624383c61 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -6127,6 +6127,72 @@ qemuDomainVsockDefPostParse(virDomainVsockDefPtr vso= ck) } =20 =20 +static int +qemuDomainHostdevMdevDefPostParse(const virDomainHostdevSubsysMediatedDev = *mdevsrc, + const virDomainDef *def) +{ + if (mdevsrc->display > VIR_TRISTATE_SWITCH_ABSENT && + mdevsrc->model !=3D VIR_MDEV_MODEL_TYPE_VFIO_PCI) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _(" attribute 'display' is only supported" + " with model=3D'vfio-pci'")); + + return -1; + } + + if (mdevsrc->display =3D=3D VIR_TRISTATE_SWITCH_ON) { + virDomainGraphicsDefPtr graphics =3D def->graphics[0]; + + if (def->ngraphics =3D=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("graphics device is needed for attribute valu= e " + "'display=3Don' in ")); + return -1; + } + + /* We're not able to tell whether an mdev needs OpenGL or not at t= he + * moment, so print a warning that an extra element might be + * necessary to be added. + */ + if (!graphics->gl || + graphics->gl->enable !=3D VIR_TRISTATE_BOOL_YES) { + VIR_WARN(" attribute 'display' may need the OpenGL to= " + "be enabled"); + } + } + + return 0; +} + + +static int +qemuDomainHostdevDefPostParse(const virDomainHostdevDef *hostdev, + const virDomainDef *def) +{ + const virDomainHostdevSubsysMediatedDev *mdevsrc; + + if (hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { + switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) { + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: + break; + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: + mdevsrc =3D &hostdev->source.subsys.u.mdev; + return qemuDomainHostdevMdevDefPostParse(mdevsrc, def); + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: + default: + virReportEnumRangeError(virDomainHostdevSubsysType, + hostdev->source.subsys.type); + return -1; + } + } + + return 0; +} + + static int qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, const virDomainDef *def, @@ -6177,11 +6243,14 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr = dev, ret =3D qemuDomainVsockDefPostParse(dev->data.vsock); break; =20 + case VIR_DOMAIN_DEVICE_HOSTDEV: + ret =3D qemuDomainHostdevDefPostParse(dev->data.hostdev, def); + break; + case VIR_DOMAIN_DEVICE_LEASE: case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: - case VIR_DOMAIN_DEVICE_HOSTDEV: case VIR_DOMAIN_DEVICE_WATCHDOG: case VIR_DOMAIN_DEVICE_GRAPHICS: case VIR_DOMAIN_DEVICE_HUB: diff --git a/tests/qemuxml2argvdata/hostdev-mdev-display-missing-graphics.x= ml b/tests/qemuxml2argvdata/hostdev-mdev-display-missing-graphics.xml new file mode 100644 index 0000000000..ea559a6444 --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-mdev-display-missing-graphics.xml @@ -0,0 +1,35 @@ + + QEMUGuest2 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + +

+ + + + + + + + +
+ + + + + diff --git a/tests/qemuxml2argvdata/hostdev-mdev-display.xml b/tests/qemuxm= l2argvdata/hostdev-mdev-display.xml new file mode 100644 index 0000000000..f5b3575c04 --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-mdev-display.xml @@ -0,0 +1,39 @@ + + QEMUGuest2 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + +
+ + + + + + + + + +
+ + + + + + diff --git a/tests/qemuxml2xmloutdata/hostdev-mdev-display-active.xml b/tes= ts/qemuxml2xmloutdata/hostdev-mdev-display-active.xml new file mode 100644 index 0000000000..63a1a00278 --- /dev/null +++ b/tests/qemuxml2xmloutdata/hostdev-mdev-display-active.xml @@ -0,0 +1,47 @@ + + QEMUGuest2 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + +
+ + +
+ + + +
+ + + + + + +