XNU as a loadable kernel module inside Linux (macOS personality for arm64 Linux)
C
README: document bare-metal NVIDIA DGX Spark support
Heyang Zhou5b9600a48f2d
diff --git a/README.md b/README.mdindex 7a15eca..6cdcb29 100644--- a/README.md+++ b/README.md@@ -29,6 +29,17 @@ Straight from the hosted framebuffer, 1280×800.**Safari in the hosted macOS: Wikipedia's article on XNU, kernel.org and the Linux repository on GitHub, over thehosted system's network link through Linux, with the GPU bridge on (`GPU=auto`).*+++*Bare-metal NVIDIA DGX Spark (Ubuntu 24.04.5 LTS aarch64, Linux `7.0.0-1025-nvidia`): hosted macOS 27 running with+4 CPUs and 8 GiB of RAM (CPU rendering), shown over macOS Screen Sharing alongside an SSH session from the DGX Spark+host into the hosted Darwin userspace.*++++*Inside the hosted macOS on DGX Spark: About This Mac (`Chip: Unknown`, `7.80 GB` memory, `macOS Golden Gate 27.2`)+alongside `sysctl machdep.cpu` (`ARM processor`, `hw.cpufamily: 0`, `hw.ncpu: 4`) and `hw.optional.arm`.*+## How it works```@@ -51,44 +62,57 @@ hosted system's network link through Linux, with the GPU bridge on (`GPU=auto`).keyboard and pointer, an Ethernet link (a Linux network interface), a keystore and a GPU bridge.- **GPU**: Metal in the hosted macOS runs on `gpu/xnu-cpu-metal` (metal2vulkan over Vulkan). Vulkan reaches the Linuxhost's GPU through the DRM bridge (`kexts/XnuDrm` → host call → `gpu/xnu-drm/xnudrmd` → the Linux render node), using- Mesa's Venus driver; without a GPU it falls back to Mesa lavapipe on the CPU.+ Mesa's Venus driver; without a supported DRM bridge backend it falls back to Mesa lavapipe on the CPU.## Status-Working, on an Apple Silicon Mac running an arm64 Linux VM (krunkit) with 1 to 6 hosted CPUs:--- macOS 27.2.1 boots to the desktop with auto-login in 31–48 s (an Apple Virtualization macOS VM on the same Mac: 49 s).-- Apps open and quit, Spotlight and the file system work; a 30-minute stress run (40 rounds of Safari, Notes,- Calculator, TextEdit, System Settings, Spotlight and a disk walk) finishes with no panic and no crash report.-- Runs as a systemd service: started at boot, stopped cleanly with the VM, restarted after a hosted-kernel panic, each- run's log kept in `/var/log/xnulinux/`.-- The GPU bridge gives hosted apps the host GPU (`Virtio-GPU Venus (Apple M5 Max)`) and is enabled by default- (`GPU=auto`) when a Linux render node is present, falling back to CPU rendering (`GPU=off`) otherwise.+Working on two arm64 Linux setups:++- **Apple Silicon Mac in an arm64 Linux VM (`krunkit`, 1 to 6 hosted CPUs)**:+ - macOS 27.2.1 boots to the desktop with auto-login in 31–48 s (an Apple Virtualization macOS VM on the same Mac:+ 49 s).+ - Apps open and quit, Spotlight and the file system work; a 30-minute stress run (40 rounds of Safari, Notes,+ Calculator, TextEdit, System Settings, Spotlight and a disk walk) finishes with no panic and no crash report.+ - Runs as a systemd service: started at boot, stopped cleanly with the VM, restarted after a hosted-kernel panic, each+ run's log kept in `/var/log/xnulinux/`.+ - The GPU bridge gives hosted apps the host GPU (`Virtio-GPU Venus (Apple M5 Max)`) and is enabled by default+ (`GPU=auto`) when a virtio-gpu render node is present, falling back to CPU rendering (`GPU=off`) otherwise.+- **Bare-metal NVIDIA DGX Spark (Ubuntu 24.04.5 LTS aarch64, Linux `7.0.0-1025-nvidia`)**:+ - Boots to the full macOS desktop (Screen Sharing and SSH working) directly on bare-metal arm64 Linux with `CPUS=4`+ and 8 GiB of RAM reserved for XNU.+ - Currently renders on the CPU (Mesa lavapipe, `GPU=off`): `xnudrmd` only forwards `virtio-gpu` (Venus) ioctls today,+ so hardware GPU pass-through on the GB10 GPU requires a new DRM bridge backend.What is still a stopgap is listed in [`docs/production.md`](docs/production.md). Notably: the OS cryptex is merged intothe system volume, AMFI is patched and SIP relaxed, and memory access is slower than a native VM (4K pages vs 16K).## Requirements-- An arm64 Linux host with PAC (Apple Silicon M1 or later in a VM: krunkit for GPU access, or tart), 4K pages, 16 GB of- RAM (8 GB of it reserved for the hosted kernel).+- An arm64 Linux host with PAC (`FEAT_PAuth`), 4K pages, and at least 16 GB of RAM (8 GB reserved for the hosted+ kernel). Tested on:+ - **NVIDIA DGX Spark** (bare-metal Ubuntu 24.04.5 LTS aarch64, Linux `7.0.0-1025-nvidia`; CPU rendering for now).+ - **Apple Silicon Mac (M1 or later)** running an arm64 Linux VM (`krunkit` for GPU access via virtio-gpu Venus, or+ `tart`).- A Mac with Xcode to make the system disk and build the GPU parts.- A macOS 27 installation (an Apple Virtualization VM disk) of your own. **No Apple binaries are in this repository ordistributed by it**: the kexts Apple ships, the macOS system disk and its trust cache come from your own installation.## Building and running-1. `scripts/vm-xnu-build.sh` (in the Linux VM, once): sets up the macOS-DroidVM Linux toolchain and builds XNU+1. `scripts/vm-xnu-build.sh` (on the arm64 Linux host, once): sets up the macOS-DroidVM Linux toolchain and builds XNU(`xnu-12377.121.6`) natively on arm64.2. `scripts/vm-xnu-rebuild.sh`: applies `xnu-patches/`, builds the kernel and `kexts/`, and links the kernel collectionwith Apple's kexts from your macOS installation.3. `scripts/mk-macvm-disk.sh` (on the Mac): turns a macOS VM disk made by Apple's installer into the hosted system's diskand copies it into the Linux VM.-4. `scripts/xnulinux-boot.sh` (in the Linux VM): builds `fki.ko` and `xnu.ko` against the running kernel, brings up the- network (and the GPU bridge when there is a render node) and boots the hosted system. Its console is- `scripts/xnu-console.sh`, its screen `tools/hosted/fb2png.py`, input `tools/hosted/xnu-input.py`.-5. `scripts/install-service.sh` (in the Linux VM): runs it as `xnulinux.service`, configured in `/etc/xnulinux.conf`- (CPUs, memory, disk, GPU). On the Mac, `scripts/install-krun-agent.sh` keeps the VM itself running.+4. `scripts/xnulinux-boot.sh` (on the arm64 Linux host): builds `fki.ko` and `xnu.ko` against the running kernel, brings+ up the network (and the GPU bridge when there is a render node) and boots the hosted system. Its console is+ `scripts/xnu-console.sh`, its screen `tools/hosted/fb2png.py`, input `tools/hosted/xnu-input.py`. On a bare-metal+ host (such as a DGX Spark), set the carve-out (`mem=`, `carve_base=`, `carve_mb=`) to fit the machine's physical+ memory layout, and set `GPU=off` (`xnudrmd` supports only virtio-gpu for now).+5. `scripts/install-service.sh` (on the arm64 Linux host): runs it as `xnulinux.service`, configured in+ `/etc/xnulinux.conf` (CPUs, memory, disk, GPU). On the Mac, `scripts/install-krun-agent.sh` keeps the VM itself+ running.6. GPU (optional, on the Mac): `gpu/venus/build-darwin.sh` builds the hosted Vulkan driver, `gpu/xnu-cpu-metal/` theMetal plugin (see its README).diff --git a/docs/images/dgx-spark-about.jpg b/docs/images/dgx-spark-about.jpgnew file mode 100644index 0000000..3ed9787Binary files /dev/null and b/docs/images/dgx-spark-about.jpg differdiff --git a/docs/images/dgx-spark.jpg b/docs/images/dgx-spark.jpgnew file mode 100644index 0000000..417a7ecBinary files /dev/null and b/docs/images/dgx-spark.jpg differ