Skip to content

XNU as a loadable kernel module inside Linux (macOS personality for arm64 Linux)

C

Hosted on a machine that is not a Mac: timebase, stop and halt, device names

秋 奈月63a4bf42ca73
diff --git a/kexts/XnuCpuMetal/XnuCpuMetal.cpp b/kexts/XnuCpuMetal/XnuCpuMetal.cpp
index 2b5ac4a..989fc2f 100644
--- a/kexts/XnuCpuMetal/XnuCpuMetal.cpp
+++ b/kexts/XnuCpuMetal/XnuCpuMetal.cpp
@@ -2,8 +2,8 @@
// XnuCpuMetal: the hosted macOS's Metal device, as a kext of the kernel collection (written for xnulinux, clean room).
// Metal.framework finds GPUs by watching IOServiceMatching("IOAccelerator") and loads the plugin bundle named by the service's
// MetalPluginName from /Library/GPUBundles, taking MetalPluginClassName (an IOGPUMetalDevice subclass) as the device class.
-// XnuCpuMetalDevice runs its work in the calling process (Metal -> metal2vulkan -> Mesa lavapipe on the CPU), so the service
-// is only a registry entry: no user client, no hardware. It matches IOResources, so no device tree node is needed.
+// XnuCpuMetalDevice runs its work in the calling process (Metal -> metal2vulkan -> Mesa), so the service is only a registry
+// entry. It sits on the device tree's sgx node: System Information describes the GPU from that node's first child.
#include <IOKit/IOService.h>
#include <IOKit/IOLib.h>
#include <mach/kmod.h>
@@ -28,7 +28,19 @@ bool XnuCpuMetalAccelerator::start(IOService *provider)
setProperty("MetalPluginClassName", "XnuCpuMetalDevice");
// No "Removable" / "SafeEjectRequested": Metal (-[MTLIOAccelService initWithAcceleratorPort:deviceClass:]) skips
// a service on which either is present at all, whatever the value.
- setProperty("model", "XnuCpuMetal (lavapipe)");
+ {
+ // the host GPU's name (the node's "model") and its PCI vendor
+ char name[64] = "XnuCpuMetal (lavapipe)";
+ OSData *m = OSDynamicCast(OSData, provider->getProperty("model"));
+ if (m && m->getLength() > 1 && m->getLength() <= sizeof(name)) {
+ memcpy(name, m->getBytesNoCopy(), m->getLength());
+ name[sizeof(name) - 1] = 0;
+ }
+ setProperty("model", name);
+ uint32_t vendor = !strncmp(name, "NVIDIA", 6) ? 0x10de : !strncmp(name, "AMD", 3) ? 0x1002 :
+ !strncmp(name, "Intel", 5) ? 0x8086 : !strncmp(name, "Apple", 5) ? 0x106b : 0;
+ if (vendor) setProperty("vendor-id", &vendor, sizeof(vendor));
+ }
// The GPU bridge's user client (kexts/XnuDrm) hangs off this service: the sandbox's system-graphics rules let
// processes that draw open user clients of an IOAccelerator ((iokit-connection "IOAccelerator")), whatever their class.
setProperty("IOUserClientClass", "AGXDeviceUserClient");
diff --git a/kexts/XnuCpuMetal/XnuCpuMetal.json b/kexts/XnuCpuMetal/XnuCpuMetal.json
index 23f9908..80e1fa7 100644
--- a/kexts/XnuCpuMetal/XnuCpuMetal.json
+++ b/kexts/XnuCpuMetal/XnuCpuMetal.json
@@ -15,8 +15,8 @@
"XnuCpuMetal": {
"CFBundleIdentifier": "org.xnulinux.driver.XnuCpuMetal",
"IOClass": "XnuCpuMetalAccelerator",
- "IOProviderClass": "IOResources",
- "IOResourceMatch": "IOKit",
+ "IOProviderClass": "IOPlatformDevice",
+ "IONameMatch": "xnulinux,gpu",
"IOMatchCategory": "IOAccelerator",
"MetalPluginName": "XnuCpuMetal",
"MetalPluginClassName": "XnuCpuMetalDevice"
diff --git a/scripts/xnulinux-boot.sh b/scripts/xnulinux-boot.sh
index fe93eaf..01b33cf 100755
--- a/scripts/xnulinux-boot.sh
+++ b/scripts/xnulinux-boot.sh
@@ -18,7 +18,7 @@
set -euo pipefail
cd "$(dirname "$0")/.."
if [ "${1:-}" = stop ]; then # end the running hosted system (its disk synced first) and remove xnu.ko
- if ! lsmod | grep -q '^xnu '; then
+ if [ ! -d /sys/module/xnu ]; then
sudo systemctl stop xnudrmd 2>/dev/null || true
echo "no hosted system is running"; exit 0
fi
@@ -26,7 +26,7 @@ if [ "${1:-}" = stop ]; then # end the running hosted system (its disk synced fi
echo 1 | sudo tee /sys/module/xnu/parameters/stop_run >/dev/null
# every XNU CPU sees the stop at its next host call; one in a long one (disk I/O while the VM shuts down) takes a while
for _ in $(seq 1 600); do pgrep -f "insmod xnu-ko/xnu.ko" >/dev/null || break; sleep 0.2; done
- if lsmod | grep -q '^xnu '; then sudo rmmod xnu; fi
+ if [ -d /sys/module/xnu ]; then sudo rmmod xnu; fi
sudo systemctl stop xnudrmd 2>/dev/null || true
echo "hosted system stopped"
exit
@@ -39,7 +39,7 @@ CONSOLE_IN=${CONSOLE_IN:-/var/tmp/console-in}; INPUT_IN=${INPUT_IN:-/var/tmp/xnu
KEYSTORE=${KEYSTORE:-/var/tmp/xnu-keystore.bin}; TRUSTCACHE=${TRUSTCACHE:-xnu/trustcache-mac.bin}; IMAGE=${IMAGE:-xnu/kc.bin}
BOOTARGS=${BOOTARGS:-amfi_get_out_of_my_way=1 lp-sip0=2050}
: "${ROOT_UUID:?no ROOT_UUID (/var/tmp/mac.conf from mk-macvm-disk.sh)}" "${BOOT_UUID:?no BOOT_UUID}"
-lsmod | grep -q '^xnu ' && { echo "xnu.ko is loaded: a hosted system is running (sudo rmmod xnu first)" >&2; exit 1; }
+[ -d /sys/module/xnu ] && { echo "xnu.ko is loaded: a hosted system is running (sudo rmmod xnu first)" >&2; exit 1; }
K=/lib/modules/$(uname -r)/build
build() { # a module; its compiler errors on failure
@@ -94,7 +94,7 @@ if [ "$GPU" != off ] && [ -e /dev/dri/renderD128 ]; then
DRM_READY=0
DRM_INV=$(systemctl show -p InvocationID --value xnudrmd 2>/dev/null || true)
for _ in $(seq 1 100); do
- if [ -n "$DRM_INV" ] && sudo journalctl _SYSTEMD_INVOCATION_ID="$DRM_INV" -q --no-pager 2>/dev/null | grep -q "xnudrmd: serving"; then
+ if [ -n "$DRM_INV" ] && sudo journalctl _SYSTEMD_INVOCATION_ID="$DRM_INV" -q --no-pager 2>/dev/null | grep "xnudrmd: serving" >/dev/null; then
DRM_READY=1; break
fi
DRM_STATE=$(systemctl show -p ActiveState --value xnudrmd 2>/dev/null || true)
@@ -103,11 +103,19 @@ if [ "$GPU" != off ] && [ -e /dev/dri/renderD128 ]; then
done
if [ "$DRM_READY" = 1 ]; then
echo "gpu: xnudrmd ready on /dev/dri/renderD128 (journalctl -u xnudrmd)"
+ # GPU name for System Information (override: GPU_MODEL=)
+ GPU_MODEL=${GPU_MODEL:-$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | head -1 || true)}
else
echo "gpu: xnudrmd did not become ready within 10 s (journalctl -u xnudrmd); continuing with GPU=off" >&2
sudo systemctl stop xnudrmd 2>/dev/null || true
fi
fi
+# Chip name for System Information (override: SOC_NAME=)
+XCPU0=$(cat /sys/module/fki/parameters/cpu_list 2>/dev/null | tr -d '\n' | cut -d, -f1); XCPU0=${XCPU0:-0}
+SOC_NAME=${SOC_NAME:-$(lscpu -e=CPU,MODELNAME 2>/dev/null | awk -v c="$XCPU0" '$1 == c { $1 = ""; sub(/^ +/, ""); print }' || true)}
+NAMES=()
+[ -n "${SOC_NAME:-}" ] && NAMES+=("soc_name=\"$SOC_NAME\"")
+[ -n "${GPU_MODEL:-}" ] && NAMES+=("gpu_model=\"$GPU_MODEL\"")
# mode=3: the kernel collection; the run lasts until the hosted system halts.
# insmod returns when the run ends: it runs detached, its output in /var/tmp/xnu-insmod.log.
for try in 1 2 3 4 5 6 7 8 9; do
@@ -115,15 +123,15 @@ for try in 1 2 3 4 5 6 7 8 9; do
sudo dmesg -C
sudo setsid nohup insmod xnu-ko/xnu.ko mode=3 cpus="$CPUS" ram_mb="$RAM_MB" image="$IMAGE" \
trustcache="$TRUSTCACHE" disk="$DISK" root_uuid="$ROOT_UUID" boot_uuid="$BOOT_UUID" preboot_uuid="$BOOT_UUID" \
- console_in="$CONSOLE_IN" input_in="$INPUT_IN" fb_dump="$FB_DUMP" keystore="$KEYSTORE" bootargs="\"$BOOTARGS\"" ${XNU_ARGS:-} \
+ console_in="$CONSOLE_IN" input_in="$INPUT_IN" fb_dump="$FB_DUMP" keystore="$KEYSTORE" bootargs="\"$BOOTARGS\"" "${NAMES[@]}" ${XNU_ARGS:-} \
> /var/tmp/xnu-insmod.log 2>&1 < /dev/null &
sleep 5
- if sudo dmesg | grep -aqE "fki: carve-out .* (overlaps|is not all RAM)"; then # a configuration error: no retry
+ if sudo dmesg | grep -aE "fki: carve-out .* (overlaps|is not all RAM)" >/dev/null; then # a configuration error: no retry
sudo dmesg | grep -aE "fki: carve-out .* (overlaps|is not all RAM)" >&2
sudo systemctl stop xnudrmd 2>/dev/null || true
exit 1
fi
- sudo dmesg | grep -aq "contiguous allocation failed" || break
+ sudo dmesg | grep -a "contiguous allocation failed" >/dev/null || break
if [ $try = 9 ]; then
echo "no contiguous memory for XNU (CMA: $(grep CmaFree /proc/meminfo))" >&2
sudo systemctl stop xnudrmd 2>/dev/null || true
@@ -141,7 +149,7 @@ collect() { # the run's kernel log, kept; the status says how it ended
local LOGDIR=/var/log/xnulinux LOG
# insmod has returned but xnu.ko stays loaded after a run that ended by itself (a panic, a halt): unload it, or the
# next start (systemd's restart after a panic) finds it and refuses
- if lsmod | grep -q '^xnu '; then sudo rmmod xnu || echo "xnu.ko did not unload" >&2; fi
+ if [ -d /sys/module/xnu ]; then sudo rmmod xnu || echo "xnu.ko did not unload" >&2; fi
sudo systemctl stop xnudrmd 2>/dev/null || true
sudo mkdir -p "$LOGDIR"
LOG=$LOGDIR/run-$(date -d @"$START" +%Y%m%d-%H%M%S).log
@@ -149,6 +157,7 @@ collect() { # the run's kernel log, kept; the status says how it ended
sudo tee "$LOG" >/dev/null
ls -1t "$LOGDIR"/run-*.log | tail -n +21 | xargs -r sudo rm -f # the last 20 runs
if grep -aq "XNU panic" "$LOG"; then echo "the hosted system panicked: $LOG" >&2; return 2; fi
+ if grep -aq "the hosted system halted\|the hosted system restarts" "$LOG"; then echo "the hosted system halted: $LOG"; return 0; fi
if [ "${1:-}" = stopped ] || grep -aq "run stopped by the host" "$LOG"; then echo "the hosted system stopped: $LOG"; return 0; fi
echo "the run ended: $LOG" >&2; return 3
}
diff --git a/xnu-ko/xnu_main.c b/xnu-ko/xnu_main.c
index 0c62269..38366f8 100644
--- a/xnu-ko/xnu_main.c
+++ b/xnu-ko/xnu_main.c
@@ -52,6 +52,7 @@ static signed char linux_cpu_of_slot[LINUX64_CPU_SLOTS];
static unsigned long long cpu_mpidr[XNU_MAX_CPUS];
static void *cpu_thread[XNU_MAX_CPUS];
static volatile int cpu_running[XNU_MAX_CPUS];
+static void stop_commit(void);
static u64_t a_cpu_entry; /* XNU's linux64_cpu_entry */
static inline unsigned this_slot(void) { unsigned long m; __asm__ volatile("mrs %0, mpidr_el1" : "=r"(m)); return LINUX64_CPU_SLOT(m); }
/* Writing 1 ends the run at XNU's next call into the host; insmod returns and the module can be removed */
@@ -196,6 +197,11 @@ struct boot_args_v2 { /* pexpert/arm64/boot.h layout */
*/
static char *model = "VirtualMac2,1"; /* Apple's own virtual Mac's model identifier */
module_param(model, charp, 0444);
+/* Names for System Information: the chip (/product product-soc-name) and the GPU (the sgx node's "model"). */
+static char *soc_name;
+module_param(soc_name, charp, 0444);
+static char *gpu_model;
+module_param(gpu_model, charp, 0444);
/* the compressor's limit is in VM pages: 6 GB either way */
static const char *cmdline = "debug=0x8 -v -noprogress serial=0 startup_debug=1";
@@ -414,6 +420,7 @@ static int cpu_fn(void *arg)
in_xnu = 0;
if (!r) logkv("xnu: linux64_cpu_entry returned (unexpected) on CPU", (u64_t)c);
stop_run = 1; /* one CPU's run ending (a fatal fault, a stop) ends all of them */
+ stop_commit();
cpu_running[c] = 0;
while (!fki_thread_should_stop()) /* kthread_stop() from the module's exit wants the thread alive */
fki_msleep(10);
@@ -437,6 +444,53 @@ static inline void acct_add(unsigned long call, u64_t ticks)
acct_calls_slot[s][b]++;
}
+/*
+ * Stopping the run: the CPUs leave XNU together. A CPU still inside XNU could otherwise wait for good, interrupts masked,
+ * for one that had already left. Each parks briefly at its host calls; the run is abandoned once all are parked at once.
+ * stop_state: the number of parked CPUs, and STOP_COMMIT once the run is abandoned.
+ */
+#define STOP_COMMIT 0x10000u
+static volatile unsigned stop_state;
+static inline int stop_cas(unsigned old, unsigned new)
+{
+ unsigned cur, fail;
+ __asm__ volatile(
+ "1: ldaxr %w[cur], [%[p]]\n"
+ " cmp %w[cur], %w[old]\n"
+ " b.ne 2f\n"
+ " stlxr %w[fail], %w[new], [%[p]]\n"
+ " cbnz %w[fail], 1b\n"
+ "2:"
+ : [cur] "=&r"(cur), [fail] "=&r"(fail)
+ : [p] "r"(&stop_state), [old] "r"(old), [new] "r"(new)
+ : "cc", "memory");
+ return cur == old;
+}
+static void stop_commit(void)
+{
+ unsigned s;
+ do s = stop_state; while (!(s & STOP_COMMIT) && !stop_cas(s, s | STOP_COMMIT));
+}
+static int stop_park(void) /* 1: the run is abandoned, do not return to XNU */
+{
+ unsigned s, in_xnu_cpus = 1;
+ u64_t end;
+
+ for (int c = 1; c < cpus; c++)
+ in_xnu_cpus += cpu_running[c] != 0;
+ do {
+ s = stop_state;
+ if (s & STOP_COMMIT) return 1;
+ } while (!stop_cas(s, s + 1));
+ end = fki_counter() + fki_counter_frequency() / 500; /* 2 ms */
+ for (;;) {
+ s = stop_state;
+ if (s & STOP_COMMIT) return 1;
+ if ((s & (STOP_COMMIT - 1)) >= in_xnu_cpus) { stop_cas(s, s | STOP_COMMIT); continue; }
+ if (fki_counter() > end && stop_cas(s, s - 1)) return 0;
+ }
+}
+
/* XNU calls into the host: enum linux64_call (linux64_abi.h); a non-zero return ends the run */
static long xnu_hook_body(unsigned long call, unsigned long a1, unsigned long a2);
/* each CPU's host calls so far, the last one's number, and whether it is inside one: the monitor's silent-CPU check */
@@ -459,7 +513,7 @@ long xnu_hook(unsigned long call, unsigned long a1, unsigned long a2)
}
}
in_xnu = 0;
- if (*(volatile int *)&stop_run) { /* the host asked the run to end (scripts/xnulinux-boot.sh stop): XNU is abandoned here */
+ if (*(volatile int *)&stop_run && stop_park()) { /* the host asked the run to end: XNU is abandoned here */
logs("xnu: run stopped by the host (stop_run)");
return 1;
}
@@ -468,6 +522,12 @@ long xnu_hook(unsigned long call, unsigned long a1, unsigned long a2)
long r = xnu_hook_body(call, a1, a2);
in_call_slot[in_s] = 0;
acct_add(call, fki_counter() - t0);
+ if (r)
+ stop_commit(); /* this CPU ends the run by itself (a panic, a failed assert) */
+ else if (*(volatile int *)&stop_run && stop_park()) { /* back from a long call when the stop was asked */
+ logs("xnu: run stopped by the host (stop_run)");
+ r = 1;
+ }
if (!r) in_xnu = 1;
return r;
}
@@ -638,6 +698,11 @@ static long xnu_hook_body(unsigned long call, unsigned long a1, unsigned long a2
logkv("xnu: XNU enters user space (EL0); user pc", a1);
return 0;
}
+ if (call == LINUX64_CALL_HALT) { /* shutdown or reboot inside the hosted system */
+ logs(a1 ? "xnu: the hosted system restarts: the run ends (the host starts it again if it is set up to)" :
+ "xnu: the hosted system halted: the run ends");
+ return 1;
+ }
if (call == LINUX64_CALL_PANIC) {
char m[500]; const char *f = (const char *)a1; unsigned i = 0;
while (f && f[i] && i < sizeof(m) - 1) { m[i] = f[i]; i++; }
@@ -723,7 +788,7 @@ static struct boot_args_v2 *build_boot(unsigned char *base_va, u64_t phys, u64_t
logkv("xnu: XNU CPUs", (u64_t)cpus);
adt_init(&a, base_va + off_dt, 0x40000);
- adt_node(&a, 3, 6); /* / */
+ adt_node(&a, 3, 7); /* / */
adt_prop_str(&a, "name", "device-tree");
{ /* the platform's own name, then the model: user space's product type (MobileGestalt) comes from this list */
static char compat[96];
@@ -821,7 +886,7 @@ static struct boot_args_v2 *build_boot(unsigned char *base_va, u64_t phys, u64_t
}
adt_node(&a, 1, 0); /* /defaults: XNU looks these up without checking */
adt_prop_str(&a, "name", "defaults");
- adt_node(&a, 4, 0); /* /product */
+ adt_node(&a, 4 + (soc_name && soc_name[0] ? 1 : 0), 0); /* /product */
adt_prop_str(&a, "name", "product");
/*
* MobileGestalt's product type in sandboxed processes: their profiles let them read only these two /product
@@ -830,6 +895,15 @@ static struct boot_args_v2 *build_boot(unsigned char *base_va, u64_t phys, u64_t
adt_prop_str(&a, "sub-product-type", model);
adt_prop_str(&a, "unique-model", model);
adt_prop_str(&a, "product-name", "xnulinux");
+ if (soc_name && soc_name[0])
+ adt_prop_str(&a, "product-soc-name", soc_name);
+ /* /sgx: System Information describes the GPU from the first child of the service of this name (kexts/XnuCpuMetal) */
+ adt_node(&a, 3 + (gpu_model && gpu_model[0] ? 1 : 0), 0);
+ adt_prop_str(&a, "name", "sgx");
+ adt_prop_str(&a, "device_type", "sgx");
+ adt_prop_str(&a, "compatible", "xnulinux,gpu");
+ if (gpu_model && gpu_model[0])
+ adt_prop_str(&a, "model", gpu_model);
adt_node(&a, 1, 0); /* /options: NVRAM's node (AppleImage4 keeps its nonce seeds there) */
adt_prop_str(&a, "name", "options");
adt_node(&a, 3, FB_SIZE ? 1 : 0); /* /arm-io: XNU needs a nonzero SoC base */
@@ -893,6 +967,18 @@ static struct boot_args_v2 *build_boot(unsigned char *base_va, u64_t phys, u64_t
const char *rd = " rd=md0";
x_memcpy(ba->CommandLine + x_strlen(ba->CommandLine), rd, x_strlen(rd) + 1);
}
+ {
+ /*
+ * Apple's user space assumes a 24 MHz timebase (libswift_Concurrency: ticks = ns * 3 / 125) and XNU's machine
+ * timeouts are in those ticks: on another counter rate the kernel scales the counter (droidvm-timebase-hz).
+ * The debugger's cross-call gets 1 s, not 10 ms: a CPU may be inside a host call when asked to stop.
+ */
+ const char *a = fki_counter_frequency() != 24000000 ?
+ " ml-timeout-debug-ack-scale=100 droidvm-timebase-hz=24000000" : " ml-timeout-debug-ack-scale=100";
+
+ if (x_strlen(ba->CommandLine) + x_strlen(a) < sizeof(ba->CommandLine))
+ x_memcpy(ba->CommandLine + x_strlen(ba->CommandLine), a, x_strlen(a) + 1);
+ }
if (bootargs && x_strlen(ba->CommandLine) + 1 + x_strlen(bootargs) < sizeof(ba->CommandLine)) {
char *e = ba->CommandLine + x_strlen(ba->CommandLine);
*e++ = ' ';
@@ -1136,6 +1222,7 @@ static int enter_arm_init(struct boot_args_v2 *ba)
long r = xnu_world_call(a_init, (unsigned long)ba);
in_xnu = 0;
stop_run = 1; /* the other CPUs end at their next call into the host (kicked out of idle) */
+ stop_commit();
for (int c = 1; c < cpus; c++) {
for (int t = 0; cpu_running[c] && t < 500; t++) { fki_kick_cpu(c); fki_msleep(10); }
if (cpu_running[c]) logkv("xnu: CPU did not leave XNU in 5 s:", (u64_t)c);
diff --git a/xnu-patches/0006-linux64-host-ram-cache-attributes.patch b/xnu-patches/0006-linux64-host-ram-cache-attributes.patch
new file mode 100644
index 0000000..a728528
--- /dev/null
+++ b/xnu-patches/0006-linux64-host-ram-cache-attributes.patch
@@ -0,0 +1,24 @@
+From: xnulinux
+Subject: [PATCH] linux64: memory outside our own is the host's RAM, mapped as normal memory
+
+Hosted, a physical page pmap does not manage is the host's RAM (a Linux buffer mapped into a task by kexts/XnuDrm),
+not a device: mapped as device memory, unaligned accesses to it fault.
+---
+diff --git a/osfmk/arm/pmap/pmap.c b/osfmk/arm/pmap/pmap.c
+--- a/osfmk/arm/pmap/pmap.c
++++ b/osfmk/arm/pmap/pmap.c
+@@ -10676,9 +10676,13 @@
+
+ assert(vm_last_phys > vm_first_phys); // Check that pmap has been bootstrapped
+
+ if (!pa_valid(paddr)) {
++ extern unsigned long linux64_hook;
+ pmap_io_range_t *io_rgn = pmap_find_io_attr(paddr);
+- return (io_rgn == NULL) ? VM_WIMG_IO : io_rgn->wimg;
++ if (io_rgn != NULL) {
++ return io_rgn->wimg;
++ }
++ return linux64_hook ? VM_WIMG_DEFAULT : VM_WIMG_IO; /* LINUX64: the host's RAM */
+ }
+
+ result = VM_WIMG_DEFAULT;
diff --git a/xnu-patches/0007-linux64-halt-ends-the-run.patch b/xnu-patches/0007-linux64-halt-ends-the-run.patch
new file mode 100644
index 0000000..b71ba2e
--- /dev/null
+++ b/xnu-patches/0007-linux64-halt-ends-the-run.patch
@@ -0,0 +1,24 @@
+From: xnulinux
+Subject: [PATCH] linux64: a halt or restart ends the run in the host
+
+Hosted, there is no machine to halt or reset: halt_all_cpus found no platform handler and span with interrupts masked,
+holding its Linux CPU for good (and the others where they were). The host is told instead (LINUX64_CALL_HALT) and ends
+the run on every CPU.
+---
+diff --git a/osfmk/arm64/machine_routines.c b/osfmk/arm64/machine_routines.c
+--- a/osfmk/arm64/machine_routines.c
++++ b/osfmk/arm64/machine_routines.c
+@@ -941,6 +941,13 @@
+ __attribute__((noreturn))
+ void
+ halt_all_cpus(boolean_t reboot)
+ {
++ {
++ /* LINUX64 (xnulinux): no machine to halt or reset; the host ends the run (the call does not return). */
++ if (linux64_hook) {
++ printf(reboot ? "MACH Reboot\n" : "CPU halted\n");
++ linux64_call2(LINUX64_CALL_HALT, reboot ? 1 : 0, 0);
++ }
++ }
+ if (reboot) {
+ printf("MACH Reboot\n");
diff --git a/xnu-patches/include/linux64_abi.h b/xnu-patches/include/linux64_abi.h
index 72dbdd2..e38056a 100644
--- a/xnu-patches/include/linux64_abi.h
+++ b/xnu-patches/include/linux64_abi.h
@@ -41,6 +41,7 @@ enum linux64_call {
LINUX64_CALL_HOSTCALL = 830, /* a1 = struct linux64_hostcall_req: a message to a Linux service and its reply */
LINUX64_CALL_CPU_START = 840, /* a1 = a CPU's MPIDR, a2 = its cpu_data_t: the host enters linux64_cpu_entry(a2) there */
LINUX64_CALL_IPI = 841, /* a1 = the target CPU's MPIDR: its linux64_ipi_pending slot is set; make it look */
+ LINUX64_CALL_HALT = 992, /* the hosted system halts (a1 = 0) or restarts (a1 = 1): the run ends */
LINUX64_CALL_CONSOLE_READ = 993, /* a1 = struct linux64_buf_req: console input bytes */
LINUX64_CALL_RAMDISK_RW = 994, /* a1 = struct linux64_rw_req on the host-file md disk */
LINUX64_CALL_RAMDISK_SIZE = 995, /* a1 = u64 *: the host-file md disk's size, 0 when there is none */