Based on slp's Using microVMs for Gaming on Fedora Asahi I tried to get things running on Ubuntu 23.04.

There is no PPA for this yet (afaik), so we'll have to build stuff manually here.

Preparations

  1. mesa (required for native-context support)
# clone Git repo and check out branch
$ git clone https://gitlab.freedesktop.org/slp/mesa.git mesa_slp
$ cd mesa_slp
$ git checkout asahi-native-context

# build
$ mkdir build
$ cd build
$ meson -D gallium-drivers="swrast,virgl,asahi" ..
$ ninja

# install to /usr/local
$ sudo ninja install
  1. virglrenderer (required for native-context support)
# clone Git repo and check out branch
$ git clone https://gitlab.freedesktop.org/slp/virglrenderer.git virglrenderer_slp
$ cd virglrenderer_slp
$ git checkout asahi-native-context

# build
$ meson -D drm-msm-experimental=True -D drm-asahi-experimental=True build
$ cd build
$ ninja

# install to /usr/local
$ sudo ninja install
  1. libkrunfw (dependency of libkrun)
# clone Git repo
$ git clone https://github.com/containers/libkrunfw.git

# install pyelftools
$ sudo apt install python3-pyelftools

# build
$ make

# install
$ sudo make install
  1. libkrun (dependency of krunvm)
# clone Git repo (slp's fork for now) and check out branch
$ git clone https://github.com/slp/libkrun.git libkrun_slp
$ cd libkrun_slp
$ git checkout virtio-gpu

We have make these changes to expose the gpu feature and link libkrunfw from /usr/local/lib64:

$ git diff
diff --git a/Makefile b/Makefile
index 7233ab0..81955ad 100644
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,9 @@ endif
 ifeq ($(NET),1)
     FEATURE_FLAGS += --features net
 endif
-
+ifeq ($(GPU),1)
+    FEATURE_FLAGS += --features gpu
+endif
 ifeq ($(ROSETTA),1)
     INIT_DEFS += -D__ROSETTA__
 endif
diff --git a/src/libkrun/build.rs b/src/libkrun/build.rs
index ce74b29..5dadd61 100644
--- a/src/libkrun/build.rs
+++ b/src/libkrun/build.rs
@@ -7,4 +7,6 @@ fn main() {
     println!("cargo:rustc-link-lib=krunfw");
     #[cfg(feature = "tee")]
     println!("cargo:rustc-link-lib=krunfw-sev");
+
+    println!("cargo:rustc-link-arg=-L/usr/local/lib64");
 }
# install dependencies
$ sudo apt install libepoxy-dev libvirglrenderer-dev patchelf

# build
make GPU=1

# install
$ sudo make install
  1. krunvm
# clone Git repo
$ git clone https://github.com/containers/krunvm.git
$ cd krunvm

# install asciidoctor
$ sudo apt install asciidoctor

We have to make these changes to link libkrunfw from /usr/local/lib64 and fix a Rust type error:

diff --git a/build.rs b/build.rs
index d7a571a..e1b86e2 100644
--- a/build.rs
+++ b/build.rs
@@ -28,6 +28,9 @@ fn main() {
 
     #[cfg(target_os = "macos")]
     println!("cargo:rustc-link-search=/opt/homebrew/lib");
+
+    println!("cargo:rustc-link-arg=-L/usr/local/lib64");
+    println!("cargo:rustc-link-lib=krunfw");
 }
 
 fn generate_man_page<P: AsRef<Path>>(outdir: P, command: &str) -> io::Result<()> {
diff --git a/src/start.rs b/src/start.rs
index 7dc5f02..aefef28 100644
--- a/src/start.rs
+++ b/src/start.rs
@@ -91,7 +91,7 @@ unsafe fn exec_vm(vmcfg: &VmConfig, rootfs: &str, cmd: Option<&str>, args: Vec<C
         let map = format!("{}:{}", host_port, guest_port);
         ports.push(CString::new(map).unwrap());
     }
-    let mut ps: Vec<*const i8> = Vec::new();
+    let mut ps: Vec<*const u8> = Vec::new();
     for port in ports.iter() {
         ps.push(port.as_ptr());
     }
@@ -113,10 +113,10 @@ unsafe fn exec_vm(vmcfg: &VmConfig, rootfs: &str, cmd: Option<&str>, args: Vec<C
 
     let hostname = CString::new(format!("HOSTNAME={}", vmcfg.name)).unwrap();
     let home = CString::new("HOME=/root").unwrap();
-    let env: [*const i8; 3] = [hostname.as_ptr(), home.as_ptr(), std::ptr::null()];
+    let env: [*const u8; 3] = [hostname.as_ptr(), home.as_ptr(), std::ptr::null()];
 
     if let Some(cmd) = cmd {
-        let mut argv: Vec<*const i8> = Vec::new();
+        let mut argv: Vec<*const u8> = Vec::new();
         for a in args.iter() {
             argv.push(a.as_ptr());
         }
# build
$ cargo build --release

# run
$ LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib/aarch64-linux-gnu target/release/krunvm

Testing

# install buildah
$ sudo apt install buildah

# create user namespace
$ buildah unshare

# create VM
# LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib/aarch64-linux-gnu target/release/krunvm create --cpus 6 --mem 6144 --name asahi-krun quay.io/slopezpa/asahi-krun
Trying to pull quay.io/slopezpa/asahi-krun:latest...
Getting image source signatures
Copying blob 3357a5ee36de done  
Copying config eb0f8b2ca1 done  
Writing manifest to image destination
microVM created with name: asahi-krun

# start VM
# LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib/aarch64-linux-gnu target/release/krunvm start asahi-krun
chown: cannot access '/dev/dri/*': No such file or directory
chown: cannot access '/dev/snd/*': No such file or directory
chmod: cannot access '/dev/dri/*': No such file or directory
failed to open virtgpu
error: could not initialize wayland channel: No such file or directory

Seems like we still need to tell krunvm to use our custom virglrenderer and mesa to make this work. Stay tuned!