From nobody Mon Apr 29 07:58:00 2024 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 1527598418057761.5292881702637; Tue, 29 May 2018 05:53:38 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 78F8E30C3A1D; Tue, 29 May 2018 12:53:36 +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 307B817C4D; Tue, 29 May 2018 12:53:36 +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 D3DF24CA84; Tue, 29 May 2018 12:53:35 +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 w4TCrG4U013525 for ; Tue, 29 May 2018 08:53:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 13593202698A; Tue, 29 May 2018 12:53:16 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F85A2026988 for ; Tue, 29 May 2018 12:53:15 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 29 May 2018 14:53:14 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3] qemu: add support for vhost-vsock-pci 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 29 May 2018 12:53:37 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Create a new vsock endpoint by opening /dev/vhost-vsock, set the requested CID via ioctl (or assign a free one if auto=3D'yes'), pass the file descriptor to QEMU and build the command line. https://bugzilla.redhat.com/show_bug.cgi?id=3D1291851 Signed-off-by: J=C3=A1n Tomko --- Rebased version with all the ACKed squash-ins for patches 1-6 available at: git://repo.or.cz/libvirt/jtomko.git vsock-v3 http://repo.or.cz/libvirt/jtomko.git/shortlog/refs/heads/vsock-v3 src/qemu/qemu_alias.c | 16 +++++++++ src/qemu/qemu_command.c | 40 ++++++++++++++++++= ++++ src/qemu/qemu_domain.c | 5 +++ src/qemu/qemu_domain.h | 2 +- src/qemu/qemu_process.c | 35 +++++++++++++++++++ .../vhost-vsock-auto.x86_64-latest.args | 32 +++++++++++++++++ .../vhost-vsock.x86_64-latest.args | 32 +++++++++++++++++ tests/qemuxml2argvtest.c | 14 ++++++++ 8 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/vhost-vsock-auto.x86_64-latest.a= rgs create mode 100644 tests/qemuxml2argvdata/vhost-vsock.x86_64-latest.args diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index 578a33b284..89dec91ed1 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -533,6 +533,18 @@ qemuAssignDeviceInputAlias(virDomainDefPtr def, } =20 =20 +static int +qemuAssignDeviceVsockAlias(virDomainVsockDefPtr vsock) +{ + if (vsock->info.alias) + return 0; + if (VIR_STRDUP(vsock->info.alias, "vsock0") < 0) + return -1; + + return 0; +} + + int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) { @@ -629,6 +641,10 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCa= psPtr qemuCaps) if (qemuAssignDeviceMemoryAlias(NULL, def->mems[i], false) < 0) return -1; } + if (def->vsock) { + if (qemuAssignDeviceVsockAlias(def->vsock) < 0) + return -1; + } =20 return 0; } diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c7ff074e29..0b5ec4f2ba 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9912,6 +9912,42 @@ qemuBuildSeccompSandboxCommandLine(virCommandPtr cmd, } =20 =20 +static int +qemuBuildVsockCommandLine(virCommandPtr cmd, + virDomainDefPtr def, + virDomainVsockDefPtr vsock, + virQEMUCapsPtr qemuCaps) +{ + qemuDomainVsockPrivatePtr priv =3D (qemuDomainVsockPrivatePtr)vsock->p= rivateData; + const char *device =3D "vhost-vsock-pci"; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + char *devstr =3D NULL; + int ret =3D -1; + + virBufferAsprintf(&buf, "%s", device); + virBufferAsprintf(&buf, ",id=3D%s", vsock->info.alias); + virBufferAsprintf(&buf, ",guest-cid=3D%u", vsock->guest_cid); + virBufferAsprintf(&buf, ",vhostfd=3D%u", priv->vhostfd); + if (qemuBuildDeviceAddressStr(&buf, def, &vsock->info, qemuCaps) < 0) + goto cleanup; + + if (virBufferCheckError(&buf) < 0) + goto cleanup; + + devstr =3D virBufferContentAndReset(&buf); + + virCommandPassFD(cmd, priv->vhostfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT); + priv->vhostfd =3D -1; + virCommandAddArgList(cmd, "-device", devstr, NULL); + + ret =3D 0; + cleanup: + virBufferFreeAndReset(&buf); + VIR_FREE(devstr); + return ret; +} + + /* * Constructs a argv suitable for launching qemu with config defined * for a given virtual machine. @@ -10161,6 +10197,10 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, goto error; } =20 + if (def->vsock && + qemuBuildVsockCommandLine(cmd, def, def->vsock, qemuCaps) < 0) + goto error; + /* In some situations, eg. VFIO passthrough, QEMU might need to lock a * significant amount of memory, so we need to set the limit according= ly */ virCommandSetMaxMemLock(cmd, qemuDomainGetMemLockLimitBytes(def)); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 10f22b1cc2..2c51e4c0d8 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1160,6 +1160,8 @@ qemuDomainVsockPrivateNew(void) if (!(priv =3D virObjectNew(qemuDomainVsockPrivateClass))) return NULL; =20 + priv->vhostfd =3D -1; + return (virObjectPtr) priv; } =20 @@ -1167,6 +1169,9 @@ qemuDomainVsockPrivateNew(void) static void qemuDomainVsockPrivateDispose(void *obj ATTRIBUTE_UNUSED) { + qemuDomainVsockPrivatePtr priv =3D obj; + + VIR_FORCE_CLOSE(priv->vhostfd); } =20 =20 diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index f298ebf785..2e0f4df0fb 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -447,7 +447,7 @@ typedef qemuDomainVsockPrivate *qemuDomainVsockPrivateP= tr; struct _qemuDomainVsockPrivate { virObject parent; =20 - virTristateBool maybe; + int vhostfd; }; =20 =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 5f5759c9c8..30cc5904e0 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -79,6 +79,7 @@ #include "nwfilter_conf.h" #include "netdev_bandwidth_conf.h" #include "virresctrl.h" +#include "virvsock.h" =20 #define VIR_FROM_THIS VIR_FROM_QEMU =20 @@ -5947,6 +5948,36 @@ qemuProcessPrepareHostStorage(virQEMUDriverPtr drive= r, } =20 =20 +static int +qemuProcessOpenVhostVsock(virDomainVsockDefPtr vsock) +{ + qemuDomainVsockPrivatePtr priv =3D (qemuDomainVsockPrivatePtr)vsock->p= rivateData; + const char *vsock_path =3D "/dev/vhost-vsock"; + int fd; + + if ((fd =3D open(vsock_path, O_RDWR)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("unable to open vhost-vsock device")); + return -1; + } + + if (vsock->auto_cid =3D=3D VIR_TRISTATE_BOOL_YES) { + if (virVsockAcquireGuestCid(fd, &vsock->guest_cid) < 0) + goto error; + } else { + if (virVsockSetGuestCid(fd, vsock->guest_cid) < 0) + goto error; + } + + priv->vhostfd =3D fd; + return 0; + + error: + VIR_FORCE_CLOSE(fd); + return -1; +} + + /** * qemuProcessPrepareHost: * @driver: qemu driver @@ -5972,6 +6003,10 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver, if (qemuPrepareNVRAM(cfg, vm) < 0) goto cleanup; =20 + if (vm->def->vsock) { + if (qemuProcessOpenVhostVsock(vm->def->vsock) < 0) + goto cleanup; + } /* network devices must be "prepared" before hostdevs, because * setting up a network device might create a new hostdev that * will need to be setup. diff --git a/tests/qemuxml2argvdata/vhost-vsock-auto.x86_64-latest.args b/t= ests/qemuxml2argvdata/vhost-vsock-auto.x86_64-latest.args new file mode 100644 index 0000000000..dd9b60ba3e --- /dev/null +++ b/tests/qemuxml2argvdata/vhost-vsock-auto.x86_64-latest.args @@ -0,0 +1,32 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/home/test \ +USER=3Dtest \ +LOGNAME=3Dtest \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3Dtest,debug-threads=3Don \ +-S \ +-object secret,id=3DmasterKey0,format=3Draw,\ +file=3D/tmp/lib/domain--1-test/master-key.aes \ +-machine pc-i440fx-2.9,accel=3Dtcg,usb=3Doff,dump-guest-core=3Doff \ +-m 1024 \ +-realtime mlock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid bba65c0e-c049-934f-b6aa-4e2c0582acdf \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-test/monitor.so= ck,\ +server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-boot menu=3Don,strict=3Don \ +-device piix3-usb-uhci,id=3Dusb,bus=3Dpci.0,addr=3D0x1.0x2 \ +-device virtio-serial-pci,id=3Dvirtio-serial0,bus=3Dpci.0,addr=3D0x6 \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,\ +resourcecontrol=3Ddeny \ +-device vhost-vsock-pci,id=3Dvsock0,guest-cid=3D42,vhostfd=3D6789,bus=3Dpc= i.0,addr=3D0x2 \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvdata/vhost-vsock.x86_64-latest.args b/tests/= qemuxml2argvdata/vhost-vsock.x86_64-latest.args new file mode 100644 index 0000000000..907af8bb99 --- /dev/null +++ b/tests/qemuxml2argvdata/vhost-vsock.x86_64-latest.args @@ -0,0 +1,32 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/home/test \ +USER=3Dtest \ +LOGNAME=3Dtest \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3Dtest,debug-threads=3Don \ +-S \ +-object secret,id=3DmasterKey0,format=3Draw,\ +file=3D/tmp/lib/domain--1-test/master-key.aes \ +-machine pc-0.13,accel=3Dtcg,usb=3Doff,dump-guest-core=3Doff \ +-m 1024 \ +-realtime mlock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid bba65c0e-c049-934f-b6aa-4e2c0582acdf \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-test/monitor.so= ck,\ +server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-boot menu=3Don,strict=3Don \ +-device piix3-usb-uhci,id=3Dusb,bus=3Dpci.0,addr=3D0x1.0x2 \ +-device virtio-serial-pci,id=3Dvirtio-serial0,bus=3Dpci.0,addr=3D0x6 \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,\ +resourcecontrol=3Ddeny \ +-device vhost-vsock-pci,id=3Dvsock0,guest-cid=3D4,vhostfd=3D6789,bus=3Dpci= .0,addr=3D0x7 \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 2fe4390104..ddd2b88c0a 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -532,6 +532,17 @@ testCompareXMLToArgv(const void *data) } } =20 + if (vm->def->vsock) { + virDomainVsockDefPtr vsock =3D vm->def->vsock; + qemuDomainVsockPrivatePtr vsockPriv =3D + (qemuDomainVsockPrivatePtr)vsock->privateData; + + if (vsock->auto_cid =3D=3D VIR_TRISTATE_BOOL_YES) + vsock->guest_cid =3D 42; + + vsockPriv->vhostfd =3D 6789; + } + if (!(cmd =3D qemuProcessCreatePretendCmd(&driver, vm, migrateURI, (flags & FLAG_FIPS), false, VIR_QEMU_PROCESS_START_COLD)))= { @@ -2856,6 +2867,9 @@ mymain(void) QEMU_CAPS_DEVICE_VIRTIO_MOUSE_CCW, QEMU_CAPS_DEVICE_VIRTIO_TABLET_CCW); =20 + DO_TEST_CAPS_LATEST("vhost-vsock"); + DO_TEST_CAPS_LATEST("vhost-vsock-auto"); + if (getenv("LIBVIRT_SKIP_CLEANUP") =3D=3D NULL) virFileDeleteTree(fakerootdir); =20 --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list