From 4dafc32f63127b56709c4de60f543ebb5e852375 Mon Sep 17 00:00:00 2001 From: Asahi Lina Date: Sat, 6 Jul 2024 15:15:40 +0900 Subject: [PATCH 1/2] Share /dev/shm if DAX is enabled With DAX, we have coherent mmap with the host. Sharing /dev/shm means that POSIX shared memory will work across the VM boundary. Signed-off-by: Asahi Lina --- crates/muvm/src/guest/mount.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/muvm/src/guest/mount.rs b/crates/muvm/src/guest/mount.rs index 74c8760..f5da8b8 100644 --- a/crates/muvm/src/guest/mount.rs +++ b/crates/muvm/src/guest/mount.rs @@ -7,7 +7,8 @@ use std::path::Path; use anyhow::{Context, Result}; use rustix::fs::{mkdir, symlink, Mode, CWD}; use rustix::mount::{ - mount2, mount_bind, move_mount, open_tree, MountFlags, MoveMountFlags, OpenTreeFlags, + mount2, mount_bind, move_mount, open_tree, unmount, MountFlags, MoveMountFlags, OpenTreeFlags, + UnmountFlags, }; fn make_tmpfs(dir: &str) -> Result<()> { @@ -144,5 +145,21 @@ pub fn mount_filesystems() -> Result<()> { make_tmpfs("/tmp/.X11-unix")?; } + // Check for DAX active on the root filesystem (first line of /proc/mounts should be the root FS) + let has_dax = std::fs::read_to_string("/proc/mounts")? + .lines() + .next() + .map(|a| a.contains("dax=always")) + .unwrap_or(false); + + // If we have DAX, set up shared /dev/shm + if has_dax { + // Unmount the /dev/shm that was set up for us by libkrun + unmount("/dev/shm", UnmountFlags::empty()).context("Failed to unmount /dev/shm")?; + // Bind-mount /dev/shm to the target + mount_bind(host_path.join("dev/shm"), "/dev/shm") + .context("Failed to bind-mount /dev/shm from the host")?; + } + Ok(()) } From 5a65576b83f8b2cd9665b943f045ca716036c3f5 Mon Sep 17 00:00:00 2001 From: Asahi Lina Date: Wed, 2 Oct 2024 23:32:21 +0900 Subject: [PATCH 2/2] x11: Use x112virtgpu for the secondary X11 forward if it is installed This lets us easily test this alternative to sommelier+XWayland without committing to making it the default. --- crates/muvm/src/guest/x11.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/muvm/src/guest/x11.rs b/crates/muvm/src/guest/x11.rs index a38ea71..739d9b5 100644 --- a/crates/muvm/src/guest/x11.rs +++ b/crates/muvm/src/guest/x11.rs @@ -2,12 +2,15 @@ use std::env; use std::fs::File; use std::io::{Read, Write}; use std::path::Path; +use std::process::Command; use anyhow::{anyhow, Context, Result}; use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; use super::socket::setup_socket_proxy; +use crate::utils::env::find_in_path; + pub fn setup_x11_forwarding

(run_path: P) -> Result<()> where P: AsRef, @@ -23,7 +26,24 @@ where } let host_display = &host_display[1..]; - setup_socket_proxy(Path::new("/tmp/.X11-unix/X1"), 6000)?; + // Check for DAX since x112virtgpu needs this + let has_dax = std::fs::read_to_string("/proc/mounts")? + .lines() + .next() + .map(|a| a.contains("dax=always")) + .unwrap_or(false); + + let x112virtgpu_path = + find_in_path("x112virtgpu").context("Failed to check existence of `x112virtgpu`")?; + + if has_dax && x112virtgpu_path.is_some() { + let mut cmd = Command::new(x112virtgpu_path.unwrap()); + cmd.args(["--listen-display", ":1"]); + + cmd.spawn().context("Failed to spawn `x112virtgpu`")?; + } else { + setup_socket_proxy(Path::new("/tmp/.X11-unix/X1"), 6000)?; + } // Set HOST_DISPLAY to :1, which is the display number within the guest // at which the actual host display is accessible.