[PATCH v3 3/6] img/app: add support for testing virtio-gpu

Alyssa Ross
2023-07-21T18:00:57Z

From: Alyssa Ross <alyssa.ross@unikie.com>

crosvm sadly doesn't support socket activation or readiness
notification, hence the sleep loop here.

Signed-off-by: Alyssa Ross <alyssa.ross@unikie.com>
Signed-off-by: Alyssa Ross <hi@alyssa.is>
---
img/app/Makefile | 13 ++++++++++++-
img/app/shell.nix | 2 +-
lib/common.mk | 2 ++
3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/img/app/Makefile b/img/app/Makefile
index 1ea0d66..0742440 100644
--- a/img/app/Makefile
+++ b/img/app/Makefile
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: EUPL-1.2+
# SPDX-FileCopyrightText: 2021-2023 Alyssa Ross <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2022 Unikie

include ../../lib/common.mk

@@ -77,6 +78,15 @@ build/etc/s6-rc: $(VM_S6_RC_FILES)
s6-rc-compile $@ $$dir; \
exit=$$?; rm -r $$dir; exit $$exit

+start-vhost-user-gpu:
+ rm -f build/vhost-user-gpu.sock
+ $(CROSVM_DEVICE_GPU) \
+ --socket build/vhost-user-gpu.sock \
+ --wayland-sock "$$XDG_RUNTIME_DIR/$$WAYLAND_DISPLAY" \
+ --params '{"context-types":"cross-domain"}' &
+ while ! [ -S build/vhost-user-gpu.sock ] && sleep .1; do :; done
+.PHONY: start-vhost-user-gpu
+
start-virtiofsd:
mkdir -p build
$(S6_IPCSERVER_SOCKETBINDER) -B build/virtiofsd.sock \
@@ -100,7 +110,7 @@ run-qemu: $(imgdir)/appvm/blk/root.img start-virtiofsd
-device virtconsole,chardev=virtiocon0
.PHONY: run-qemu

-run-cloud-hypervisor: $(imgdir)/appvm/blk/root.img start-virtiofsd
+run-cloud-hypervisor: $(imgdir)/appvm/blk/root.img start-vhost-user-gpu start-virtiofsd
rm -f build/vmm.sock
@../../scripts/run-cloud-hypervisor.sh \
--api-socket path=build/vmm.sock \
@@ -108,6 +118,7 @@ run-cloud-hypervisor: $(imgdir)/appvm/blk/root.img start-virtiofsd
--disk path=$(imgdir)/appvm/blk/root.img,readonly=on \
--disk path=$(RUN_IMG),readonly=on \
--fs tag=virtiofs0,socket=build/virtiofsd.sock \
+ --gpu socket=build/vhost-user-gpu.sock \
--kernel $(KERNEL) \
--cmdline "root=PARTLABEL=root" \
--console tty \
diff --git a/img/app/shell.nix b/img/app/shell.nix
index ba75fcc..0c94f1d 100644
--- a/img/app/shell.nix
+++ b/img/app/shell.nix
@@ -15,7 +15,7 @@ with config.pkgs;
# so we have to list virtiofsd first.
virtiofsd

- cloud-hypervisor execline jq qemu_kvm reuse s6
+ cloud-hypervisor crosvm execline jq qemu_kvm reuse s6
];

runDef = import run { inherit config; };
diff --git a/lib/common.mk b/lib/common.mk
index e32fecb..81754b9 100644
--- a/lib/common.mk
+++ b/lib/common.mk
@@ -11,6 +11,8 @@ QEMU_KVM = qemu-kvm
BACKGROUND = background
CPIO = cpio
CPIOFLAGS = --reproducible -R +0:+0 -H newc
+CROSVM = crosvm
+CROSVM_DEVICE_GPU = $(CROSVM) device gpu
MCOPY = mcopy
MKFS_FAT = mkfs.fat
MMD = mmd
--
2.40.1