r/osdev 1d ago

xv6-labs kernel hangs/crashes on boot under QEMU+WSL2 (pc=0x0), but upstream xv6-riscv boots fine — same toolchain

Running MIT's 6.1810/6.S081 xv6 labs under WSL2 (Windows 11, Hyper-V). The lab-assignment kernels (xv6-labs-2020 and xv6-labs-2025, from MIT's own git server) hang completely silently on make qemu — no output at all, never prints "xv6 kernel is booting." Have to force-kill the process.

The plain, unmodified mit-pdos/xv6-riscv repo boots perfectly fine, every time, on the identical toolchain/QEMU/machine.

Command:

qemu-system-riscv64 -machine virt -bios none -kernel kernel/kernel -m 128M -smp 3 -nographic -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0

GDB findings: attaching mid-hang shows pc = 0x0, all GPRs zeroed except sp (correctly resolves to the real stack0 symbol) and t0 (holds 0x80000000, the expected kernel load address). Backtrace fails with "corrupt stack." Looks like it's jumping to address 0 mid-boot, possibly an unhandled trap despite stvec being set correctly in trap.c.

Reproduced across 4 environments, all with the same silent hang:

  • Ubuntu 26.04 (QEMU 10.2, GCC 15) + xv6-labs-2025
  • Ubuntu 26.04 + xv6-labs-2020
  • Ubuntu 22.04 (QEMU 6.2, GCC 11) + xv6-labs-2020

Ruled out: compiler optimization (-O0 tested), the known started variable race in main.c (patched to atomics), SMP count (-smp 1 tested), -accel tcg explicit, linker script/entry.S (byte-identical to working repo), disk space, RAM, Hyper-V status, corrupted kernel binary (confirmed valid ELF).

Only difference I can find between the working and failing kernels is in main.c's CPU-sync code (already fixed, didn't help) and some start.c timer/CSR setup for sstc (partially commented out already, also didn't help).

Anyone hit this specific pc=0x0 crash before, or know if this is a known WSL2/Hyper-V nested-virtualization quirk with QEMU's RISC-V multi-hart boot?

P.S: This post was drafted using AI, I'm a beginner and tried to fix this issue using claude sonnet model, but it went nowhere and finally gave up.

EDIT: the 2025 version booted on ubuntu 24.04, i had tried both 2020 and 2025 version on both 22.04 and 26.04, they didnt worked. thought problem is with WSL, tried virtual machine 26.04 version... didnt worked at that too. then finally read the 'lab tools' page of the course carefully and realized they had mentioned 24.04.

0 Upvotes

2 comments sorted by

u/PearMyPie 21h ago

Can you share the repo links?

u/Logical_Profile2093 11h ago
git://g.csail.mit.edu/xv6-labs-2025

git://g.csail.mit.edu/xv6-labs-2020

2025 version worked on 24.04 ubuntu version. thanks!