Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic x112virtgpu support #72

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion crates/muvm/src/guest/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down Expand Up @@ -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")?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should either move this check to muvm-guest.rs or have this method return has_dax so we can avoid doing the same check again in setup_x11_forwarding.

.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(())
}
22 changes: 21 additions & 1 deletion crates/muvm/src/guest/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P>(run_path: P) -> Result<()>
where
P: AsRef<Path>,
Expand All @@ -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.
Expand Down
Loading