From 0863531b534bb22df7d4663d9075484a27ed4f7c Mon Sep 17 00:00:00 2001 From: Thomas Stokes Date: Sun, 5 Jan 2025 16:47:33 +0800 Subject: [PATCH] support custom initramfs, build a non-debug kernel by default `make defconfig debug.config` will bring back the old options --- arch/wasm/configs/defconfig | 24 ------------------ tools/wasm/public/index.html | 36 ++++++++++++--------------- tools/wasm/public/initramfs.cpio | Bin 0 -> 11777 bytes tools/wasm/run.js | 11 ++++++--- tools/wasm/src/index.ts | 41 +++++++++++++++++++++---------- tools/wasm/src/virtio.ts | 2 -- 6 files changed, 52 insertions(+), 62 deletions(-) create mode 100644 tools/wasm/public/initramfs.cpio diff --git a/arch/wasm/configs/defconfig b/arch/wasm/configs/defconfig index 38749332532033..2f438ab0d72d54 100644 --- a/arch/wasm/configs/defconfig +++ b/arch/wasm/configs/defconfig @@ -52,30 +52,6 @@ CONFIG_EXT2_FS=y # CONFIG_INOTIFY_USER is not set # CONFIG_PROC_FS is not set # CONFIG_SYSFS is not set -CONFIG_SQUASHFS=y -CONFIG_PRINTK_TIME=y -CONFIG_PRINTK_CALLER=y # CONFIG_DEBUG_MISC is not set -CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y -CONFIG_FRAME_WARN=2048 -CONFIG_DEBUG_FS=y -CONFIG_UBSAN=y -CONFIG_PAGE_EXTENSION=y -CONFIG_DEBUG_OBJECTS=y -CONFIG_DEBUG_OBJECTS_FREE=y -CONFIG_DEBUG_OBJECTS_TIMERS=y -CONFIG_DEBUG_OBJECTS_WORK=y -CONFIG_DEBUG_OBJECTS_RCU_HEAD=y -CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER=y -CONFIG_DEBUG_STACK_USAGE=y -CONFIG_SCHED_STACK_END_CHECK=y -CONFIG_DEBUG_VM=y -CONFIG_DEBUG_VM_RB=y -CONFIG_DEBUG_VM_PGFLAGS=y -CONFIG_DEBUG_PER_CPU_MAPS=y -CONFIG_PANIC_ON_OOPS=y -CONFIG_SOFTLOCKUP_DETECTOR=y -CONFIG_DEBUG_IRQFLAGS=y -CONFIG_BUG_ON_DATA_CORRUPTION=y # CONFIG_RCU_TRACE is not set # CONFIG_RUNTIME_TESTING_MENU is not set diff --git a/tools/wasm/public/index.html b/tools/wasm/public/index.html index 87ac7670e370c4..0e98932b09bec5 100644 --- a/tools/wasm/public/index.html +++ b/tools/wasm/public/index.html @@ -70,25 +70,10 @@

- It's only early days for this port, and it doesn't make it all the way - through boot yet, but we're getting close, and all the fundamentals are - there. + We've got a patched version of the Linux kernel and Musl libc running, + complete with virtio devices, memory isolation, and multi-core support.

-

- (context switching was particularly painful to implement in such a - constrained environment, but I think the solution ended up being quite - elegant.) -

- -

All that's left to implement before we can boot BusyBox is:

- -

If this sounds interesting, you can check out the source at github.com/tombl/linux @@ -105,6 +90,8 @@ + + @@ -145,11 +132,14 @@ term.write("Error: not cross origin isolated\n"); } - const { cmdline = "no_hash_pointers console=hvc0", memory = 128 } = Object.fromEntries( - new URLSearchParams(location.search) - ); + const { + cmdline = "", + memory = 128, + initcpio: initcpioPath = "initramfs.cpio", + } = Object.fromEntries(new URLSearchParams(location.search)); document.querySelector("input[name=cmdline]").value = cmdline; document.querySelector("input[name=memory]").value = memory; + document.querySelector("input[name=initcpio]").value = initcpioPath; const stdin = new ReadableStream({ start(controller) { @@ -170,6 +160,11 @@ }, }); + const initcpio = await fetch(initcpioPath).then((res) => res.ok && res.arrayBuffer()); + if (!initcpio) { + term.write(`Failed to fetch initramfs.\n`); + } + const machine = new Machine({ cmdline: cmdline.replace(/\+/g, " "), memoryMib: memory, @@ -178,6 +173,7 @@ new EntropyDevice(), new BlockDevice(new Uint8Array(8 * 1024 * 1024)), ], + initcpio, }); machine.bootConsole.pipeTo(stdout2); diff --git a/tools/wasm/public/initramfs.cpio b/tools/wasm/public/initramfs.cpio new file mode 100644 index 0000000000000000000000000000000000000000..fc37a77f5b0f984ae108f94afbe715bd84bc3f63 GIT binary patch literal 11777 zcmV+cF8=I-^{&tckk}q#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+gLikLg)aJ_Ap(BVr)xkqR5N)^cNB?V-D;(=^1%8q;7A z?!qrM?i4f-%1t&?1qhfZqcX%&yt3oodv|hA%(o}b&D7>F7_PQ`kKS8&x{%1l>-oH1 jxXqtLUXDGg4?j5mXti1u|Nry<%;*0A%xSoF0A>IH`)EM+ literal 0 HcmV?d00001 diff --git a/tools/wasm/run.js b/tools/wasm/run.js index 487bf9de8c610d..e591c208fd5009 100755 --- a/tools/wasm/run.js +++ b/tools/wasm/run.js @@ -12,19 +12,23 @@ const args = parseArgs(Deno.args, { string: ["cmdline"], boolean: ["help"], default: { - cmdline: "no_hash_pointers console=hvc0", + cmdline: "", memory: 128, cpus: navigator.hardwareConcurrency, + initcpio: import.meta.url + .replace("run.js", "public/initramfs.cpio") + .replace("file://", ""), }, - alias: { cmdline: "c", memory: "m", cpus: "j", help: "h" }, + alias: { cmdline: "c", memory: "m", initcpio: "i", cpus: "j", help: "h" }, }); if (args.help) { console.log(`usage: run.ts [options] options: - -c, --cmdline Command line arguments to pass to the kernel (default: "no_hash_pointers") + -c, --cmdline Command line arguments to pass to the kernel -m, --memory Amount of memory to allocate in MiB (default: 128) + -i, --initcpio Path to the initramfs to boot -j, --cpus Number of CPUs to use (default: number of CPUs on the machine) -h, --help Show this help message `); @@ -43,6 +47,7 @@ const machine = new Machine({ new EntropyDevice(), new BlockDevice(new Uint8Array(8 * 1024 * 1024)), ], + initcpio: await Deno.readFile(args.initcpio), }); machine.bootConsole.pipeTo(Deno.stderr.writable, { preventClose: true }); diff --git a/tools/wasm/src/index.ts b/tools/wasm/src/index.ts index fdf1be1c3fab41..fe54e94cc67c03 100644 --- a/tools/wasm/src/index.ts +++ b/tools/wasm/src/index.ts @@ -2,7 +2,6 @@ import initramfs from "./build/initramfs_data.cpio"; import sections from "./build/sections.json" with { type: "json" }; import vmlinuxUrl from "./build/vmlinux.wasm"; import { type DeviceTreeNode, generate_devicetree } from "./devicetree.ts"; -import init2 from "./init2.cpio"; import { assert, EventEmitter, get_script_path, unreachable } from "./util.ts"; import { virtio_imports, VirtioDevice } from "./virtio.ts"; import { type Imports, type Instance, kernel_imports } from "./wasm.ts"; @@ -17,7 +16,7 @@ const vmlinux_promise = "compileStreaming" in WebAssembly ? WebAssembly.compileStreaming(vmlinux_response) : vmlinux_response.then((r) => r.arrayBuffer()).then(WebAssembly.compile); -const INIT2_ADDR = 0x200000; +const INITCPIO_ADDR = 0x200000; export class Machine extends EventEmitter<{ halt: void; @@ -29,6 +28,7 @@ export class Machine extends EventEmitter<{ #workers: Worker[] = []; #memory: WebAssembly.Memory; #devices: VirtioDevice[]; + #initcpio?: ArrayBufferView; memory: Uint8Array; devicetree: DeviceTreeNode; @@ -42,11 +42,13 @@ export class Machine extends EventEmitter<{ memoryMib?: number; cpus?: number; devices: VirtioDevice[]; + initcpio?: ArrayBufferView; }) { super(); this.#boot_console = new TransformStream(); this.#boot_console_writer = this.#boot_console.writable.getWriter(); this.#devices = options.devices; + this.#initcpio = options.initcpio; const PAGE_SIZE = 0x10000; const BYTES_PER_MIB = 0x100000; @@ -65,11 +67,9 @@ export class Machine extends EventEmitter<{ "#size-cells": 1, chosen: { "rng-seed": crypto.getRandomValues(new Uint8Array(64)), - bootargs: options.cmdline ?? "no_hash_pointers", + bootargs: `console=hvc0 ${options.cmdline ?? ""}`, ncpus: options.cpus ?? navigator.hardwareConcurrency, sections, - "linux,initrd-start": INIT2_ADDR, - "linux,initrd-end": INIT2_ADDR + init2.byteLength, }, aliases: {}, memory: { @@ -83,7 +83,20 @@ export class Machine extends EventEmitter<{ }, }; - this.memory.set(init2, INIT2_ADDR); + if (this.#initcpio) { + const chosen = this.devicetree.chosen as DeviceTreeNode; + chosen["linux,initrd-start"] = INITCPIO_ADDR; + chosen["linux,initrd-end"] = INITCPIO_ADDR + this.#initcpio.byteLength; + + this.memory.set( + new Uint8Array( + this.#initcpio.buffer, + this.#initcpio.byteOffset, + this.#initcpio.byteLength, + ), + INITCPIO_ADDR, + ); + } for (const [i, dev] of this.#devices.entries()) { this.devicetree[`virtio${i}`] = { @@ -97,10 +110,16 @@ export class Machine extends EventEmitter<{ } async boot() { + const memory_reservations: { address: number; size: number }[] = []; + if (this.#initcpio) { + memory_reservations.push({ + address: INITCPIO_ADDR, + size: this.#initcpio.byteLength, + }); + } + const devicetree = generate_devicetree(this.devicetree, { - memory_reservations: [ - { address: INIT2_ADDR, size: init2.byteLength }, - ], + memory_reservations, }); const vmlinux = await vmlinux_promise; @@ -182,10 +201,6 @@ export class Machine extends EventEmitter<{ const instance = (await WebAssembly.instantiate(vmlinux, imports)) as Instance; - // @ts-expect-error - globalThis.instance = instance; - // @ts-expect-error - globalThis.memory = this.#memory; instance.exports.boot(); } } diff --git a/tools/wasm/src/virtio.ts b/tools/wasm/src/virtio.ts index 21eb53087b3e67..01e26ce27da460 100644 --- a/tools/wasm/src/virtio.ts +++ b/tools/wasm/src/virtio.ts @@ -188,12 +188,10 @@ export abstract class VirtioDevice { vqs: Virtqueue[] = []; enable(vq: number, queue: Virtqueue) { this.vqs[vq] = queue; - console.log("enable", this.constructor.name, vq, queue.size); } disable(vq: number) { const queue = this.vqs[vq]; assert(queue); - console.log("disable", this.constructor.name, vq); } abstract notify(vq: number): void;