From d8d47c69e0282dd8d27da2b849238e6912485fef Mon Sep 17 00:00:00 2001 From: Daniel Martinez Date: Mon, 21 Oct 2024 15:38:51 +0200 Subject: [PATCH 1/4] New package: libkrunfw-4.4.2 --- common/shlibs | 1 + srcpkgs/libkrunfw/template | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 srcpkgs/libkrunfw/template diff --git a/common/shlibs b/common/shlibs index 338c0eb0b3709e..93428776dd0e8b 100644 --- a/common/shlibs +++ b/common/shlibs @@ -4537,3 +4537,4 @@ libsfdo-desktop-file.so.0 libsfdo-0.1.3_1 libsfdo-icon.so.0 libsfdo-0.1.3_1 libKMahjongg6.so.6 libkmahjongg-24.08.2_1 libflashrom.so.1 flashrom-1.4.0_1 +libkrunfw.so.4 libkrunfw-4.4.2_1 diff --git a/srcpkgs/libkrunfw/template b/srcpkgs/libkrunfw/template new file mode 100644 index 00000000000000..9bff54c881e4b2 --- /dev/null +++ b/srcpkgs/libkrunfw/template @@ -0,0 +1,41 @@ +# Template file for 'libkrunfw' +pkgname=libkrunfw +version=4.4.2 +revision=1 +_kernel_version=6.6.52 +archs="x86_64* aarch64*" +build_style=gnu-makefile +hostmakedepends="python3-pyelftools tar xz bc cpio flex perl elfutils-devel" +short_desc="Dynamic library bundling the guest payload consumed by libkrun" +maintainer="Daniel Martinez " +license="GPL-2.0-only AND LGPL-2.1-only" +homepage="https://github.com/containers/libkrunfw" +distfiles="https://github.com/containers/libkrunfw/archive/refs/tags/v${version}.tar.gz +${KERNEL_SITE}/kernel/v${_kernel_version%%.*}.x/linux-${_kernel_version}.tar.xz" +checksum="26a348bcb0a43a56ee98d67178a78fa6c9b6378a64532b2ad0bc9fe1f4cc3297 + 1591ab348399d4aa53121158525056a69c8cf0fe0e90935b0095e9a58e37b4b8" + +skip_extraction="linux-${_kernel_version}.tar.xz" + + +do_build() { + local _arch _cross + + case "$XBPS_TARGET_MACHINE" in + x86_64*) _arch=x86_64;; + aarch64*) _arch=arm64 ;; + esac + + if [ "$CROSS_BUILD" ]; then + _cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-" + fi + + export LDFLAGS= + + make ARCH=$_arch ${_cross} ${makejobs} +} + +post_extract() { + mkdir tarballs + vsrccopy linux-${_kernel_version}.tar.xz tarballs +} From bbe37a133a5a158080465351e5a3f300562a9393 Mon Sep 17 00:00:00 2001 From: Daniel Martinez Date: Mon, 21 Oct 2024 23:48:49 +0200 Subject: [PATCH 2/4] New package: libkrun-1.9.5 --- common/shlibs | 1 + srcpkgs/libkrun-devel | 1 + srcpkgs/libkrun-init | 1 + srcpkgs/libkrun/patches/makefile.patch | 22 +++ srcpkgs/libkrun/patches/musl-statx.patch | 183 +++++++++++++++++++++++ srcpkgs/libkrun/template | 34 +++++ 6 files changed, 242 insertions(+) create mode 120000 srcpkgs/libkrun-devel create mode 120000 srcpkgs/libkrun-init create mode 100644 srcpkgs/libkrun/patches/makefile.patch create mode 100644 srcpkgs/libkrun/patches/musl-statx.patch create mode 100644 srcpkgs/libkrun/template diff --git a/common/shlibs b/common/shlibs index 93428776dd0e8b..169d33a8841cf1 100644 --- a/common/shlibs +++ b/common/shlibs @@ -4538,3 +4538,4 @@ libsfdo-icon.so.0 libsfdo-0.1.3_1 libKMahjongg6.so.6 libkmahjongg-24.08.2_1 libflashrom.so.1 flashrom-1.4.0_1 libkrunfw.so.4 libkrunfw-4.4.2_1 +libkrun.so.1 libkrun-1.9.5_1 diff --git a/srcpkgs/libkrun-devel b/srcpkgs/libkrun-devel new file mode 120000 index 00000000000000..e33274fc2461c8 --- /dev/null +++ b/srcpkgs/libkrun-devel @@ -0,0 +1 @@ +libkrun \ No newline at end of file diff --git a/srcpkgs/libkrun-init b/srcpkgs/libkrun-init new file mode 120000 index 00000000000000..e33274fc2461c8 --- /dev/null +++ b/srcpkgs/libkrun-init @@ -0,0 +1 @@ +libkrun \ No newline at end of file diff --git a/srcpkgs/libkrun/patches/makefile.patch b/srcpkgs/libkrun/patches/makefile.patch new file mode 100644 index 00000000000000..3909cd0e534a2c --- /dev/null +++ b/srcpkgs/libkrun/patches/makefile.patch @@ -0,0 +1,22 @@ +diff --git a/Makefile b/Makefile +index c4c532f..572c898 100644 +--- a/Makefile ++++ b/Makefile +@@ -83,7 +83,7 @@ debug: $(LIBRARY_DEBUG_$(OS)) libkrun.pc + ifeq ($(BUILD_INIT),1) + INIT_BINARY = init/init + $(INIT_BINARY): $(INIT_SRC) +- gcc -O2 -static -Wall $(INIT_DEFS) -o $@ $(INIT_SRC) $(INIT_DEFS) ++ $(CC) -O2 -static -Wall $(INIT_DEFS) -o $@ $(INIT_SRC) $(INIT_DEFS) + endif + + $(LIBRARY_RELEASE_$(OS)): $(INIT_BINARY) +@@ -92,7 +92,7 @@ ifeq ($(SEV),1) + mv target/release/libkrun.so target/release/$(KRUN_BASE_$(OS)) + endif + ifeq ($(OS),Linux) +- patchelf --set-soname $(KRUN_SONAME_$(OS)) --output $(LIBRARY_RELEASE_$(OS)) target/release/$(KRUN_BASE_$(OS)) ++ patchelf --set-soname $(KRUN_SONAME_$(OS)) --output $(LIBRARY_RELEASE_$(OS)) target/$(XBPS_CROSS_RUST_TARGET)/release/$(KRUN_BASE_$(OS)) + else + ifeq ($(EFI),1) + ifeq ($(OS),Darwin) diff --git a/srcpkgs/libkrun/patches/musl-statx.patch b/srcpkgs/libkrun/patches/musl-statx.patch new file mode 100644 index 00000000000000..da0c6d9c084b28 --- /dev/null +++ b/srcpkgs/libkrun/patches/musl-statx.patch @@ -0,0 +1,183 @@ +commit 1acd6a975adf824f821a99211b4fda3fdf6dbbfb +Author: Daniel Martinez +Date: Mon Oct 21 15:58:19 2024 +0200 + + Revert "virtio/fs/linux: announce submounts" + + This reverts commit 240ea9647017c05fc257ab8b6a875a1239872f98. + +diff --git a/src/devices/src/virtio/fs/linux/passthrough.rs b/src/devices/src/virtio/fs/linux/passthrough.rs +index 38ec1e7..d774b28 100644 +--- a/src/devices/src/virtio/fs/linux/passthrough.rs ++++ b/src/devices/src/virtio/fs/linux/passthrough.rs +@@ -39,15 +39,12 @@ type Handle = u64; + struct InodeAltKey { + ino: libc::ino64_t, + dev: libc::dev_t, +- mnt_id: u64, + } + + struct InodeData { + inode: Inode, + // Most of these aren't actually files but ¯\_(ツ)_/¯. + file: File, +- dev: u64, +- mnt_id: u64, + refcount: AtomicU64, + } + +@@ -156,56 +153,6 @@ fn stat(f: &File) -> io::Result { + } + } + +-fn statx(f: &File) -> io::Result<(libc::stat64, u64)> { +- let mut stx = MaybeUninit::::zeroed(); +- +- // Safe because this is a constant value and a valid C string. +- let pathname = unsafe { CStr::from_bytes_with_nul_unchecked(EMPTY_CSTR) }; +- +- // Safe because the kernel will only write data in `st` and we check the return +- // value. +- let res = unsafe { +- libc::statx( +- f.as_raw_fd(), +- pathname.as_ptr(), +- libc::AT_EMPTY_PATH | libc::AT_SYMLINK_NOFOLLOW, +- libc::STATX_BASIC_STATS | libc::STATX_MNT_ID, +- stx.as_mut_ptr(), +- ) +- }; +- if res >= 0 { +- // Safe because the kernel guarantees that the struct is now fully initialized. +- let stx = unsafe { stx.assume_init() }; +- +- // Unfortunately, we cannot use an initializer to create the stat64 object, +- // because it may contain padding and reserved fields (depending on the +- // architecture), and it does not implement the Default trait. +- // So we take a zeroed struct and set what we can. (Zero in all fields is +- // wrong, but safe.) +- let mut st = unsafe { MaybeUninit::::zeroed().assume_init() }; +- +- st.st_dev = libc::makedev(stx.stx_dev_major, stx.stx_dev_minor); +- st.st_ino = stx.stx_ino; +- st.st_mode = stx.stx_mode as _; +- st.st_nlink = stx.stx_nlink as _; +- st.st_uid = stx.stx_uid; +- st.st_gid = stx.stx_gid; +- st.st_rdev = libc::makedev(stx.stx_rdev_major, stx.stx_rdev_minor); +- st.st_size = stx.stx_size as _; +- st.st_blksize = stx.stx_blksize as _; +- st.st_blocks = stx.stx_blocks as _; +- st.st_atime = stx.stx_atime.tv_sec; +- st.st_atime_nsec = stx.stx_atime.tv_nsec as _; +- st.st_mtime = stx.stx_mtime.tv_sec; +- st.st_mtime_nsec = stx.stx_mtime.tv_nsec as _; +- st.st_ctime = stx.stx_ctime.tv_sec; +- st.st_ctime_nsec = stx.stx_ctime.tv_nsec as _; +- Ok((st, stx.stx_mnt_id)) +- } else { +- Err(io::Error::last_os_error()) +- } +-} +- + /// The caching policy that the file system should report to the FUSE client. By default the FUSE + /// protocol uses close-to-open consistency. This means that any cached contents of the file are + /// invalidated the next time that file is opened. +@@ -340,7 +287,6 @@ pub struct PassthroughFs { + // Whether writeback caching is enabled for this directory. This will only be true when + // `cfg.writeback` is true and `init` was called with `FsOptions::WRITEBACK_CACHE`. + writeback: AtomicBool, +- announce_submounts: AtomicBool, + + cfg: Config, + } +@@ -390,7 +336,6 @@ impl PassthroughFs { + proc_self_fd, + + writeback: AtomicBool::new(false), +- announce_submounts: AtomicBool::new(false), + cfg, + }) + } +@@ -492,21 +437,11 @@ impl PassthroughFs { + // Safe because we just opened this fd. + let f = unsafe { File::from_raw_fd(fd) }; + +- let (st, mnt_id) = statx(&f)?; +- +- let mut attr_flags: u32 = 0; +- +- if st.st_mode & libc::S_IFMT == libc::S_IFDIR +- && self.announce_submounts.load(Ordering::Relaxed) +- && (st.st_dev != p.dev || mnt_id != p.mnt_id) +- { +- attr_flags |= fuse::ATTR_SUBMOUNT; +- } ++ let st = stat(&f)?; + + let altkey = InodeAltKey { + ino: st.st_ino, + dev: st.st_dev, +- mnt_id, + }; + let data = self.inodes.read().unwrap().get_alt(&altkey).cloned(); + +@@ -524,13 +459,10 @@ impl PassthroughFs { + InodeAltKey { + ino: st.st_ino, + dev: st.st_dev, +- mnt_id, + }, + Arc::new(InodeData { + inode, + file: f, +- dev: st.st_dev, +- mnt_id, + refcount: AtomicU64::new(1), + }), + ); +@@ -544,7 +476,7 @@ impl PassthroughFs { + inode, + generation: 0, + attr: st, +- attr_flags, ++ attr_flags: 0, + attr_timeout: self.cfg.attr_timeout, + entry_timeout: self.cfg.entry_timeout, + }) +@@ -798,7 +730,7 @@ impl FileSystem for PassthroughFs { + // Safe because we just opened this fd above. + let f = unsafe { File::from_raw_fd(fd) }; + +- let (st, mnt_id) = statx(&f)?; ++ let st = stat(&f)?; + + // Safe because this doesn't modify any memory and there is no need to check the return + // value because this system call always succeeds. We need to clear the umask here because +@@ -813,13 +745,10 @@ impl FileSystem for PassthroughFs { + InodeAltKey { + ino: st.st_ino, + dev: st.st_dev, +- mnt_id, + }, + Arc::new(InodeData { + inode: fuse::ROOT_ID, + file: f, +- dev: st.st_dev, +- mnt_id, + refcount: AtomicU64::new(2), + }), + ); +@@ -829,12 +758,6 @@ impl FileSystem for PassthroughFs { + opts |= FsOptions::WRITEBACK_CACHE; + self.writeback.store(true, Ordering::Relaxed); + } +- +- if capable.contains(FsOptions::SUBMOUNTS) { +- opts |= FsOptions::SUBMOUNTS; +- self.announce_submounts.store(true, Ordering::Relaxed); +- } +- + Ok(opts) + } + diff --git a/srcpkgs/libkrun/template b/srcpkgs/libkrun/template new file mode 100644 index 00000000000000..4227ee1a4daab2 --- /dev/null +++ b/srcpkgs/libkrun/template @@ -0,0 +1,34 @@ +# Template file for 'libkrun' +pkgname=libkrun +version=1.9.5 +revision=1 +build_style=gnu-makefile +build_helper=rust +make_build_args="BLK=1 GPU=1 NET=1 SND=1 BUILD_INIT=1" +hostmakedepends="patchelf cargo pkg-config llvm18-devel" +makedepends="libkrunfw cargo libepoxy-devel libdrm-devel virglrenderer-devel pipewire-devel" +short_desc="Library providing Virtualization-based process isolation capabilities" +maintainer="Daniel Martinez " +license="Apache-2.0" +homepage="https://github.com/containers/libkrun" +distfiles="https://github.com/containers/libkrun/archive/refs/tags/v${version}.tar.gz" +checksum=17533ce6a2c76565816b3d80d69779a5972075998c34795ad98c589206549a12 + +export XBPS_CROSS_RUST_TARGET + +libkrun-devel_package() { + depends="${sourcepkg}>=${version}_${revision}" + short_desc+=" - development files" + pkg_install() { + vmove usr/include + vmove usr/lib/pkgconfig + vmove "usr/lib/*.so" + } +} + +libkrun-init_package() { + short_desc+=" - init binary" + pkg_install() { + vbin init/init libkrun-init + } +} From 59dd82308ab8a09b78441a3eba2a7c48ad680a29 Mon Sep 17 00:00:00 2001 From: Daniel Martinez Date: Thu, 31 Oct 2024 11:50:20 -0400 Subject: [PATCH 3/4] New package: hidpipe-0.1.1 --- srcpkgs/hidpipe/template | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 srcpkgs/hidpipe/template diff --git a/srcpkgs/hidpipe/template b/srcpkgs/hidpipe/template new file mode 100644 index 00000000000000..52431abf907416 --- /dev/null +++ b/srcpkgs/hidpipe/template @@ -0,0 +1,24 @@ +# Template file for 'hidpipe' +pkgname=hidpipe +version=0.1.1 +revision=1 +build_style=cargo +hostmakedepends="pkg-config" +makedepends="eudev-libudev-devel" +short_desc="Pass input devices through to virtual machines" +maintainer="Daniel Martinez " +license="MIT" +homepage="https://github.com/AsahiLinux/hidpipe" +distfiles="https://github.com/AsahiLinux/hidpipe/archive/refs/tags/v${version}.tar.gz" +checksum=0e64b25066c97d07f5b84bb7ab2f7257cae0205a2cd56c65bed2abcfc1e22362 + +if [ ! "$XBPS_TARGET_WORDSIZE" == 64 ]; then + broken="mismatched types expected 'i64', found 'i32'" +fi + +post_install() { + vlicense LICENSE + + vinstall etc/systemd/user/hidpipe.socket 644 etc/systemd/user + vinstall etc/systemd/user/hidpipe.service 644 etc/systemd/user +} From 4547225e0b5c92ea149818cc9b42ac316af9c142 Mon Sep 17 00:00:00 2001 From: Daniel Martinez Date: Tue, 22 Oct 2024 00:34:46 +0200 Subject: [PATCH 4/4] New package: muvm-0.1.3 --- srcpkgs/muvm/patches/eudev.patch | 13 +++++++++++++ srcpkgs/muvm/template | 26 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 srcpkgs/muvm/patches/eudev.patch create mode 100644 srcpkgs/muvm/template diff --git a/srcpkgs/muvm/patches/eudev.patch b/srcpkgs/muvm/patches/eudev.patch new file mode 100644 index 00000000000000..f0900e566b4dc2 --- /dev/null +++ b/srcpkgs/muvm/patches/eudev.patch @@ -0,0 +1,13 @@ +diff --git a/crates/muvm/src/guest/bin/muvm-guest.rs b/crates/muvm/src/guest/bin/muvm-guest.rs +index 311b2ca..809bf12 100644 +--- a/crates/muvm/src/guest/bin/muvm-guest.rs ++++ b/crates/muvm/src/guest/bin/muvm-guest.rs +@@ -38,7 +38,7 @@ fn main() -> Result<()> { + if let Err(err) = mount_filesystems() { + return Err(err).context("Failed to mount filesystems, bailing out"); + } +- Command::new("/usr/lib/systemd/systemd-udevd").spawn()?; ++ Command::new("/usr/bin/udevd").spawn()?; + + setup_fex()?; + diff --git a/srcpkgs/muvm/template b/srcpkgs/muvm/template new file mode 100644 index 00000000000000..4046ce39448aa3 --- /dev/null +++ b/srcpkgs/muvm/template @@ -0,0 +1,26 @@ +# Template file for 'muvm' +pkgname=muvm +version=0.1.3 +revision=1 +build_style=cargo +hostmakedepends="llvm18-devel" +makedepends="libkrun-devel" +depends="passt hidpipe" +short_desc="Run programs from your system in a microVM" +maintainer="Daniel Martinez " +license="MIT AND Apache-2.0" +homepage="https://github.com/AsahiLinux/muvm" +distfiles="https://github.com/AsahiLinux/muvm/archive/refs/tags/muvm-${version}.tar.gz" +checksum=bf721e1fdf3c7b3f7a1c83aaa78d1913d4c17b6a740dca3ca1a726698423e477 + +do_install() { + local _target + _target="target/${XBPS_CROSS_RUST_TARGET:=$XBPS_RUST_TARGET}/release" + vbin ${_target}/muvm + vbin ${_target}/muvm-guest + vbin ${_target}/muvm-server +} + +post_install() { + vlicense crates/muvm/LICENSE +}