summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2024-04-24 15:19:39 +0200
committerAlyssa Ross <hi@alyssa.is>2024-05-29 09:16:51 +0200
commit6f1821fbd8025f53a81527bdd3fbca0b6df1fdb8 (patch)
treeb5b1a465463542532988c2368d1af5d836b96456
parent57a8921790aa4fd1d11c308d29991d5a18102730 (diff)
downloadspectrum-6f1821fbd8025f53a81527bdd3fbca0b6df1fdb8.tar
spectrum-6f1821fbd8025f53a81527bdd3fbca0b6df1fdb8.tar.gz
spectrum-6f1821fbd8025f53a81527bdd3fbca0b6df1fdb8.tar.bz2
spectrum-6f1821fbd8025f53a81527bdd3fbca0b6df1fdb8.tar.lz
spectrum-6f1821fbd8025f53a81527bdd3fbca0b6df1fdb8.tar.xz
spectrum-6f1821fbd8025f53a81527bdd3fbca0b6df1fdb8.tar.zst
spectrum-6f1821fbd8025f53a81527bdd3fbca0b6df1fdb8.zip
host/start-vmm: provide a VSOCK device to VMs
This will be used for communicating with the File Chooser portal
implementation on the host.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
-rw-r--r--Documentation/using-spectrum/creating-vms.adoc5
-rw-r--r--host/start-vmm/ch.rs7
-rw-r--r--host/start-vmm/lib.rs9
-rw-r--r--host/start-vmm/tests/vm_command-basic.rs2
-rw-r--r--img/app/Makefile5
5 files changed, 26 insertions, 2 deletions
diff --git a/Documentation/using-spectrum/creating-vms.adoc b/Documentation/using-spectrum/creating-vms.adoc
index 0bdf7a2..452e0ed 100644
--- a/Documentation/using-spectrum/creating-vms.adoc
+++ b/Documentation/using-spectrum/creating-vms.adoc
@@ -91,3 +91,8 @@ directory on the host, with the tag "virtiofs0".  The VM cannot write
 directly into that directory, but it's possible to create a
 subdirectory on the host and bind mount a directory from a writeable
 filesystem into it to provide the VM with access to shared storage.
+
+=== VSOCK
+
+Every VM has a virtio-vsock device for communication with host
+services.
diff --git a/host/start-vmm/ch.rs b/host/start-vmm/ch.rs
index 4ea1ec6..cf164c6 100644
--- a/host/start-vmm/ch.rs
+++ b/host/start-vmm/ch.rs
@@ -61,6 +61,12 @@ pub struct PayloadConfig {
 }
 
 #[derive(Serialize)]
+pub struct VsockConfig {
+    pub cid: u32,
+    pub socket: &'static str,
+}
+
+#[derive(Serialize)]
 pub struct VmConfig {
     pub console: ConsoleConfig,
     pub disks: Vec<DiskConfig>,
@@ -70,6 +76,7 @@ pub struct VmConfig {
     pub net: Vec<NetConfig>,
     pub payload: PayloadConfig,
     pub serial: ConsoleConfig,
+    pub vsock: VsockConfig,
 }
 
 fn command(vm_name: &str, s: impl AsRef<OsStr>) -> Command {
diff --git a/host/start-vmm/lib.rs b/host/start-vmm/lib.rs
index 1121e54..ee52e4d 100644
--- a/host/start-vmm/lib.rs
+++ b/host/start-vmm/lib.rs
@@ -18,7 +18,10 @@ use std::os::unix::process::parent_id;
 use std::path::Path;
 use std::process::{exit, Command};
 
-use ch::{ConsoleConfig, DiskConfig, FsConfig, GpuConfig, MemoryConfig, PayloadConfig, VmConfig};
+use ch::{
+    ConsoleConfig, DiskConfig, FsConfig, GpuConfig, MemoryConfig, PayloadConfig, VmConfig,
+    VsockConfig,
+};
 use fork::double_fork;
 use net::net_setup;
 use s6::notify_readiness;
@@ -152,6 +155,10 @@ pub fn vm_config(vm_name: &str, config_root: &Path) -> Result<VmConfig, String>
             mode: "File",
             file: Some(format!("/run/{vm_name}.log")),
         },
+        vsock: VsockConfig {
+            cid: 3,
+            socket: "env/vsock.sock",
+        },
     })
 }
 
diff --git a/host/start-vmm/tests/vm_command-basic.rs b/host/start-vmm/tests/vm_command-basic.rs
index 0564ed1..113e8ef 100644
--- a/host/start-vmm/tests/vm_command-basic.rs
+++ b/host/start-vmm/tests/vm_command-basic.rs
@@ -36,6 +36,8 @@ fn main() -> std::io::Result<()> {
     assert!(config.memory.shared);
     assert_eq!(config.serial.mode, "File");
     assert_eq!(config.serial.file.unwrap(), "/run/testvm.log");
+    assert_eq!(config.vsock.cid, 3);
+    assert_eq!(config.vsock.socket, "env/vsock.sock");
 
     Ok(())
 }
diff --git a/img/app/Makefile b/img/app/Makefile
index 31c9e82..d5be6a6 100644
--- a/img/app/Makefile
+++ b/img/app/Makefile
@@ -115,13 +115,14 @@ run-qemu: $(imgdir)/appvm/blk/root.img start-virtiofsd
 	    -device virtio-gpu-rutabaga-pci,cross-domain=on,hostmem=8G \
 	    -object memory-backend-memfd,id=mem,size=256M,share=on \
 	    -numa node,memdev=mem \
+	    -device vhost-vsock-pci,guest-cid=3 \
 	    -chardev vc,id=virtiocon0 \
 	    -device virtio-serial-pci \
 	    -device virtconsole,chardev=virtiocon0
 .PHONY: run-qemu
 
 run-cloud-hypervisor: $(imgdir)/appvm/blk/root.img start-vhost-user-gpu start-virtiofsd
-	rm -f build/vmm.sock
+	rm -f build/vmm.sock build/vsock.sock
 	@../../scripts/with-taps.elb ../../scripts/run-cloud-hypervisor.sh \
 	    --api-socket path=build/vmm.sock \
 	    --memory size=256M,shared=on \
@@ -129,6 +130,7 @@ run-cloud-hypervisor: $(imgdir)/appvm/blk/root.img start-vhost-user-gpu start-vi
 	           path=$(RUN_IMG),readonly=on \
 	    --fs tag=virtiofs0,socket=build/virtiofsd.sock \
 	    --gpu socket=build/vhost-user-gpu.sock \
+	    --vsock cid=3,socket=build/vsock.sock \
 	    --net tap=tap0 \
 	    --kernel $(KERNEL) \
 	    --cmdline "root=PARTLABEL=root" \
@@ -144,6 +146,7 @@ run-crosvm: $(imgdir)/appvm/blk/root.img start-vhost-user-gpu start-virtiofsd
 	    --net tap-name=tap0 \
 	    --vhost-user-fs build/virtiofsd.sock:virtiofs0 \
 	    --vhost-user-gpu build/vhost-user-gpu.sock \
+	    --vsock cid=3 \
 	    --serial type=file,hardware=serial,path=build/serial.log \
 	    --serial type=stdout,hardware=virtio-console,stdin=true \
 	    $(KERNEL)