arXiv:2609.04043cs.LOSep 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2609.04043

Extending concurrent separation logic to the hardware level to verify the xv6 OS kernel on RISC-V with AI agents

M. Frans Kaashoek, Nickolai Zeldovich

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

MachCSL is a framework for verifying systems software, such as an OS kernel, on top of low-level semantics of a RISC-V computer, based on the Sail RISC-V semantics. The key idea behind MachCSL is to adapt concurrent separation logic, based on Iris, to reasoning about low-level hardware execution at the sub-instruction level: page-table translation, TLB, privilege levels, configuration registers, instruction fetch/decode/execute, traps and interrupts, DMA, shared memory, power failures, etc. Reasoning at this level of detail ensures that the system software correctly manages all of the hardware details.

Verifying software at this low level of abstraction is tedious, but LLM-based agents are capable of reasoning about such low-level details. As a case study, we verify the xv6 OS kernel (6,593 lines of C and assembly code), which provides a traditional Unix system call interface (processes, file system, file descriptors, and preemptive scheduling) and has substantial internal concurrency (multi-core support with fine-grained locking, shared memory, interrupts, DMA, etc.). In the verification process, we uncovered nine bugs in the xv6 implementation, as well as one bug in the Sail RISC-V semantics. The verification effort took us 77 days, including the time to develop the MachCSL framework.

1 Introduction

Virtually every application uses the operating system to allocate memory, read and write files, print output, and even to initialize the system so that the application can start running. As a result, applications depend on the correctness of the operating system kernel that they are running on. Operating system kernels, however, are hard to get right. Kernels have to program the underlying hardware to correctly implement user-mode isolation for processes, such as setting up page tables, physical memory protection, and other configuration registers. Kernels have to implement sophisticated abstractions, such as processes, file systems, file descriptors, etc. Kernels also have to implement drivers that interact with peripheral devices, such as disks. Finally, kernels have significant concurrency: execution on multiple CPUs; interrupts taken during user-space execution and even during kernel execution itself, either from devices or timer interrupts; DMA from devices; hardware executing page-table walks concurrently with the kernel's own accesses to the page table; and system crashes that can stop the kernel's execution at any point and start again with a fresh memory image after a reboot.

A promising approach for ensuring the absence of bugs in OS kernels is to use formal verification. Indeed, prior work has demonstrated that this can be made to work for microkernels, hypervisors, and security monitors [17, 26, 27, 30, 36, 48, 49, 56, 57, 59, 60, 62, 76, 79, 82, 92, 95].

The contribution of this work is a machine-checked proof of the xv6 kernel [22] directly on a low-level model of the RISC-V hardware [73], which includes the semantics of virtually all hardware mechanisms needed for an OS kernel, including page tables, interrupts, etc. One advance over prior work lies in the amount of concurrency that the xv6 kernel has, and that the proof therefore has to handle: xv6 runs on multiple CPUs; uses spinlocks and sleeplocks; uses flag variables in shared memory for some lock-free coordination; runs with interrupts enabled in the kernel; implements preemptive context-switching even for kernel code; handles concurrent DMA from devices; and includes a Unix file system and system call interface. xv6 implements the file system and system calls with fine-grained locking, which introduces further concurrency.

Another advance is that the proof covers the interactions between the xv6 kernel and the underlying hardware by using the existing off-the-shelf semantics for the RISC-V hardware, namely the Sail model from RISC-V International [73], combined with a model of the interconnect, shared memory, devices, and power failures that we developed. This model gives a precise description of how a RISC-V core executes, down to the sub-instruction level of instruction fetch, decode, execute, and retire, along with page-table walking in hardware, TLB caching, interrupt handling,

Figure

Figure 1: An overview of the proof approach for verifying the xv6 kernel.

configuration registers, execution in machine/supervisor/user privilege levels, power failures and reboots, etc. By basing the xv6 kernel proof on this model, the proof covers many low-level details, including all of the boot code, all of the assembly instructions required for context switching, interrupt handling, user-kernel transitions, page-table switching, TLB handling, device DMA, spinlocks, file system crash recovery, etc.

To eliminate the entire kernel build toolchain from our verification assumptions, we verify the xv6 kernel by proving a whole-system theorem about the single ELF binary produced by running make in the xv6 source tree, as well as the fs.img initial file system image produced by that same make command through running mkfs on the initial user-space binaries. This theorem states that, in any execution of our RISC-V hardware, with the memory contents at every boot being the bytes from the kernel ELF image, and with the initial contents of the disk at first boot being the fs.img bytes, the execution will maintain all kernel invariants. The kernel invariants are strong enough for this whole-system theorem to imply many powerful corollaries: kernel integrity, process isolation, crash safety, and hardware safety. Figure 1 shows an overview of this verification plan.

A key challenge in realizing this verification plan is the level of detail and concurrency that the proof must cover. To address this challenge, this paper introduces MachCSL, which adopts ideas from concurrent separation logic (CSL), and Iris [45, 46, 52] in particular, to reason about sub-instruction-level execution of RISC-V code. CSL enables the xv6 proof to introduce abstractions that allow its proofs to stay modular, reasoning about one function, one CPU, or one device at a time, while handling all of the concurrency present in xv6.

Another challenge is dealing with the tedious effort of verifying the xv6 kernel at the level of the bytes in the compiled kernel image. To address this challenge, we make extensive use of AI agents (Claude Code) to help us write the proofs and intermediate specs. One pleasant benefit of using agents for proofs is that we don't have to inspect them because they are machine-checked by Rocq [88], which will validate that the proofs imply the desired top-level theorem, such as our whole-system theorem.

Our whole-system theorem and verification project have some limitations. First, our proofs cover safety properties (e.g., the kernel does not crash), but do not yet cover liveness properties (e.g., every process will keep making progress), and do not cover non-interference properties (e.g., one process cannot leak data to another process or observe information from another process). Second, the whole-system theorem is subject to the assumption that our TCB is correct, which includes the Rocq proof-checker and our model of the RISC-V system (which includes the Sail RISC-V core model, as well as our model of the interconnect with shared memory and peripheral devices). Third, the whole-system theorem applies to our model of TSO shared memory. Finally, the verification relies on the whole-system theorem being meaningful: what we prove is the precise whole-system theorem statement, rather than the more vague "xv6 is correct or bug-free".

The overall proof of the whole-system theorem about the xv6 kernel comprises about 1.3 million lines of Rocq code; the xv6 kernel itself, which we verified, is 6,593 lines of C and assembly, which compile down to 8,607 RISC-V instructions. The proof effort took 77 days, starting from the bare idea and building the MachCSL framework from scratch, all the way to a closed theorem about the entire xv6 kernel. In the process, we discovered several bugs in xv6, including bugs that would crash the kernel, as well as a bug in the Sail RISC-V model (§8). Other than fixing these kernel bugs, and a few other minor changes (such as disabling unsafe code intended for use by students to debug their lab solutions that extend the xv6 kernel), the xv6 kernel that we verified is the upstream xv6 implementation that was not designed or implemented with verification in mind. The whole-system theorem implies that the xv6 kernel correctly isolates user process code, correctly recovers the file system after crashes, and never fails any of its internal consistency assertions.

The entire proof development is available at https://github.com/mit-pdos/xv6iris, and the precise version of the xv6 kernel covered by the whole-system theorem is available on the verified branch of https://github.com/mit-pdos/xv6-riscv.

References (86)