From nobody Fri Dec 19 18:46:29 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 1543501242252908.3072083284841; Thu, 29 Nov 2018 06:20:42 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id A4D667E9CB; Thu, 29 Nov 2018 14:20:37 +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 71AD3105705A; Thu, 29 Nov 2018 14:20:37 +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 0E3E73F606; Thu, 29 Nov 2018 14:20:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wATEKTCS004471 for ; Thu, 29 Nov 2018 09:20:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id 80CE561520; Thu, 29 Nov 2018 14:20:29 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4C255D777; Thu, 29 Nov 2018 14:20:28 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 29 Nov 2018 15:20:13 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v3 03/11] qemu: process: spice: Pick the first available DRM render node 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: , 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 29 Nov 2018 14:20:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Up until now, we formatted 'rendernode=3D' onto QEMU cmdline only if the user specified it in the XML, otherwise we let QEMU do it for us. This causes permission issues because by default the /dev/dri/renderDX permissions are as follows: crw-rw----. 1 root video There's literally no reason why it shouldn't be libvirt picking the DRM render node instead of QEMU, that way (and because we're using namespaces by default), we can safely relabel the device within the namespace. Signed-off-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_process.c | 22 +++++++++++++++- src/util/virutil.h | 2 +- .../graphics-spice-gl-no-rendernode.args | 25 +++++++++++++++++++ .../graphics-spice-gl-no-rendernode.xml | 24 ++++++++++++++++++ tests/qemuxml2argvmock.c | 9 +++++++ 5 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 tests/qemuxml2argvdata/graphics-spice-gl-no-rendernode.= args create mode 100644 tests/qemuxml2argvdata/graphics-spice-gl-no-rendernode.= xml diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 12d1fca0d4..feebdc7fdc 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4784,9 +4784,25 @@ qemuProcessGraphicsSetupListen(virQEMUDriverPtr driv= er, } =20 =20 +static int +qemuProcessGraphicsSetupRenderNode(virDomainGraphicsDefPtr graphics, + virQEMUCapsPtr qemuCaps) +{ + /* Don't bother picking a DRM node if QEMU doesn't support it. */ + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE_RENDERNODE)) + return 0; + + if (!(graphics->data.spice.rendernode =3D virHostGetDRMRenderNode())) + return -1; + + return 0; +} + + static int qemuProcessSetupGraphics(virQEMUDriverPtr driver, virDomainObjPtr vm, + virQEMUCapsPtr qemuCaps, unsigned int flags) { virDomainGraphicsDefPtr graphics; @@ -4797,6 +4813,10 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver, for (i =3D 0; i < vm->def->ngraphics; i++) { graphics =3D vm->def->graphics[i]; =20 + if (virDomainGraphicsNeedsRenderNode(graphics) && + qemuProcessGraphicsSetupRenderNode(graphics, qemuCaps) < 0) + goto cleanup; + if (qemuProcessGraphicsSetupListen(driver, graphics, vm) < 0) goto cleanup; } @@ -5953,7 +5973,7 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver, goto cleanup; =20 VIR_DEBUG("Setting graphics devices"); - if (qemuProcessSetupGraphics(driver, vm, flags) < 0) + if (qemuProcessSetupGraphics(driver, vm, priv->qemuCaps, flags) < 0) goto cleanup; =20 VIR_DEBUG("Create domain masterKey"); diff --git a/src/util/virutil.h b/src/util/virutil.h index 89bd21b148..588d779d10 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -222,7 +222,7 @@ unsigned long long virMemoryMaxValue(bool ulong) ATTRIB= UTE_NOINLINE; =20 bool virHostHasIOMMU(void); =20 -char *virHostGetDRMRenderNode(void); +char *virHostGetDRMRenderNode(void) ATTRIBUTE_NOINLINE; =20 /** * VIR_ASSIGN_IS_OVERFLOW: diff --git a/tests/qemuxml2argvdata/graphics-spice-gl-no-rendernode.args b/= tests/qemuxml2argvdata/graphics-spice-gl-no-rendernode.args new file mode 100644 index 0000000000..1b08811692 --- /dev/null +++ b/tests/qemuxml2argvdata/graphics-spice-gl-no-rendernode.args @@ -0,0 +1,25 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/home/test \ +USER=3Dtest \ +LOGNAME=3Dtest \ +QEMU_AUDIO_DRV=3Dspice \ +/usr/bin/qemu-system-i686 \ +-name QEMUGuest1 \ +-S \ +-machine pc,accel=3Dtcg,usb=3Doff,dump-guest-core=3Doff \ +-m 214 \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-QEMUGuest1/moni= tor.sock,\ +server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-usb \ +-spice port=3D0,gl=3Don,rendernode=3D/dev/dri/foo \ +-vga cirrus \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x3 diff --git a/tests/qemuxml2argvdata/graphics-spice-gl-no-rendernode.xml b/t= ests/qemuxml2argvdata/graphics-spice-gl-no-rendernode.xml new file mode 100644 index 0000000000..b48e7bc94e --- /dev/null +++ b/tests/qemuxml2argvdata/graphics-spice-gl-no-rendernode.xml @@ -0,0 +1,24 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + + + + + diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c index 79152d928e..a64cd955c4 100644 --- a/tests/qemuxml2argvmock.c +++ b/tests/qemuxml2argvmock.c @@ -184,6 +184,15 @@ virNetDevRunEthernetScript(const char *ifname ATTRIBUT= E_UNUSED, return 0; } =20 +char * +virHostGetDRMRenderNode(void) +{ + char *dst =3D NULL; + + ignore_value(VIR_STRDUP(dst, "/dev/dri/foo")); + return dst; +} + static void (*real_virCommandPassFD)(virCommandPtr cmd, int fd, unsigned i= nt flags); =20 static const int testCommandPassSafeFDs[] =3D { 1730, 1731 }; --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list