Two days after booting a computer straight into an LLM, developer Alexey Fateev went a level deeper. On November 27 he added Ring -1 Kernel Surgeon to his llm.asm repo. It's a 75 KB hypervisor that runs underneath an unmodified Linux kernel, with a 2-billion-parameter language model hidden inside it. When the kernel hits certain fatal errors, the model decides on the spot whether to rewrite the faulting machine code, hand the error back to Linux, or freeze the machine.

The demo is striking: Linux takes a crash that would normally bring it down, and keeps running. We read the code to work out what is really happening, and where the demo stops.

75,424 B
Size of the hypervisor
Project README
2B
Parameters in the hidden model (MiniCPM5-2B)
Project README
97.5%
Pass rate on 122 synthetic test crashes
Author's evaluation

I built a 74 KB bare-metal hypervisor that puts a 2B LLM BELOW Linux in Ring -1, catches a fatal Kernel panic mid-crash, patches the broken machine code live in RAM, and keeps Linux running without a reboot. Left window is standard Linux dying instantly from a Ring 0 Show more

Alexey Fateev
Alexey Fateev
@superalesha

I deleted Linux completely, baked Qwen3-0.6B into a 24 KB pure x86-64 assembly OS, and it runs up to 54% faster than native Linux llama.cpp. The entire Multiboot OS binary (asm-llm-os.elf) is 24,252 bytes, written from scratch without Linux, Windows, C, Rust, or libc. It boots

7.1K
Reply

What do "Ring 0" and "Ring -1" mean?

x86 processors have privilege levels called rings. Apps run in Ring 3, where they can't touch hardware directly. The operating system kernel runs in Ring 0, with full control of the machine. When the kernel itself makes a fatal mistake, such as reading through a null pointer, nothing sits above it to catch the error, so the kernel "panics" and the machine has to restart.

"Ring -1" is the informal name for a hypervisor: software that uses the CPU's virtualisation features to sit beneath the kernel and watch it. Cloud providers use hypervisors to run many virtual machines on one server. Fateev's hypervisor runs a single Linux system and watches it for crashes.

How does it catch a crash before Linux panics?

The architecture notes describe the setup.

Booting. GRUB loads the hypervisor, an unmodified Linux 5.15 kernel and a small file system. The hypervisor switches on AMD's virtualisation extension (SVM), builds the memory map Linux will see, and starts Linux as its guest.

Hiding itself. The hypervisor's own code, the 2 GiB model and a 64 MiB working area are all marked as missing in the memory map Linux receives. They are also left out of the hardware's translation tables for guest memory. Even a buggy kernel write can't reach them.

Trapping errors. The hypervisor asks the CPU to hand it certain exceptions: page faults, invalid instructions and, per the README, divide-by-zero. It sends ordinary ones straight back to Linux. A page fault from an app is normal (it's how memory is loaded on demand), so only faults inside the kernel that touch the first 4 KB of memory, the classic null-pointer crash, go to the "surgeon."

Staying invisible. Linux is told the CPU has no virtualisation support, so it doesn't notice it is running as a guest.

What does the model actually do?

Flow diagram: Linux crashes, the CPU traps to the Ring -1 hypervisor, MiniCPM5-2B proposes a decision, a safety check runs, and the result is a patch, a hand-back to Linux, or a frozen machine

When a kernel crash reaches the surgeon (hv/surgeon.c), the hypervisor reads Linux's page tables to find the faulting instruction in memory. It copies out the instruction bytes and the CPU registers. It then builds a short text report: the exception, the bytes and their disassembly, the registers, a "contract" describing what the code was supposed to do, and flags such as whether a lock was held.

That report goes to MiniCPM5-2B, compressed to 4 bits and run by a freestanding engine (hv/llm_engine.c) spread across up to 24 CPU cores. The system prompt is one line: "Ring -1 Kernel Surgeon. Output 3 lines only: DIAGNOSIS, ACTION, PATCH." Generation is capped at 64 tokens. While the model works, the hypervisor draws its output directly onto the screen.

The action must be one of three:

  • PATCH_BYTES: overwrite the faulting instruction with new bytes of exactly the same length, then resume Linux.
  • PASS_TO_LINUX: let Linux handle the error the normal way, for cases it is designed to recover from.
  • HALT_FOR_DUMP: freeze the machine, used when a lock is held, interrupts are being handled, or the crash would leave the system in a bad state.

What stops the model writing something dangerous?

The model's patch is not trusted. validate_patch_bytes() rejects it unless all of these hold:

  • it's exactly the same length as the instruction it replaces, and no longer than 15 bytes;
  • it contains no jumps, calls, returns, software interrupts, halts or interrupt on/off instructions;
  • every byte decodes as a complete x86 instruction.

If any check fails, or the model's answer can't be parsed, the surgeon freezes the machine instead of guessing. The approved patch is written straight into the kernel's code in physical memory, bypassing the kernel's own write protection. So the change is permanent for that running system, not just a one-off skip.

How was a 2B model taught to do this?

The README describes a three-step pipeline:

  1. Synthetic data. A generator produced 600 crash scenarios across five types: patchable null-pointer, divide-by-zero and invalid-instruction crashes, plus cases that should go back to Linux and cases that should freeze. Answers were written by a DeepSeek model through its API, a technique known as distillation. The scenarios were split 356/122/122 for training, validation and testing, with "zero family overlap" between the sets.
  2. Fine-tuning. MiniCPM5-2B was fine-tuned on those answers with LoRA.
  3. Reinforcement learning. It was then trained with GRPO, a reinforcement learning method. Each answer was scored by a three-level checker: a format and instruction-safety check using the Capstone disassembler, a policy check, then actually running the patched code in a throwaway Linux 5.15 virtual machine.

Bar chart: on 122 held-out synthetic crash scenarios, the base model passed 16.4 percent and let 8.2 percent of dangerous crashes continue; after fine-tuning it passed 95.9 percent, after GRPO 97.5 percent, both with zero dangerous continues

On the 122 test scenarios, the base model passed 16.4% and let 10 dangerous crashes carry on. After fine-tuning it passed 95.9%, and after GRPO 97.5%, with no dangerous continues in either case. The three failures were all null-pointer cases.

Does it work end to end?

The README reports a full run in which the hypervisor, Linux and the model all run inside QEMU on an AMD EPYC, using nested virtualisation (a virtual machine running a hypervisor of its own). A test kernel module triggers each crash type on demand:

  • Null-pointer write: an 11-byte store to address 0 is replaced with 11 NOPs, instructions that do nothing. Linux prints "SURVIVED NULL-DEREF!"
  • Divide by zero: the 2-byte div ecx becomes xor eax, eax, which sets the result to 0.
  • Invalid instruction: a 2-byte ud2 trap becomes two NOPs.
  • Harmless probe: a deliberately failing read from user memory is passed back to Linux, which handles it as designed.
  • Crash while holding a lock: the machine is frozen.

Across the run, uptime and the boot ID stayed the same, meaning Linux never restarted.

"When patched, Linux never panics and continues running with its original uptime and processes intact."
Ring -1 Kernel Surgeon README, 27 Nov 2026

What are the catches?

It skips the bug, it doesn't fix it. Replacing a crashing store with NOPs means the store never happens. Replacing a division with "result = 0" means the code carries on with a made-up answer. Linux survives, but the function no longer does what its author intended. On a real system that can quietly corrupt data, which is arguably worse than a clean crash. In the demo these choices are safe only because the test cases were designed so that skipping the instruction is harmless.

The crashes describe themselves first. Before each crash, the test module sends the hypervisor a hint through a special vmmcall instruction. The hint includes the "contract" text, for example "skipping store preserves out=0x100 and returns 0", plus the lock and context flags. When no hint arrives, the hypervisor fills in a built-in default contract for each crash type. A real kernel bug wouldn't announce what is safe to skip. So the end-to-end demo tests whether the model follows good information, not whether it can work that information out.

The evaluation is synthetic. The 97.5% comes from 122 scenarios produced by the author's own generator, labelled by another model, and scored by his own checker. Nobody has tested it on real kernel bugs.

Only virtual machines, only AMD. It needs an AMD CPU with SVM and nested page tables. Every published run is nested inside QEMU/KVM.

Not pure assembly. Unlike the earlier parts of llm.asm, the hypervisor is mostly freestanding C. By our count, about 465 of its roughly 4,500 lines of code and headers are assembly.

It is still an unusual piece of systems engineering. A model has been trained, then constrained by hard checks, to make a narrow decision at the lowest software level of a machine, and the whole stack fits in 75 KB plus the weights.

For the first part of this project, the 24 KB OS that boots straight into Qwen3, see our earlier explainer.

Background explainers

FAQ

What is Ring -1 Kernel Surgeon?

Part 04 of Alexey Fateev's open-source llm.asm project, released November 27, 2026 under the MIT license. It's a 75 KB AMD hypervisor that runs Linux as a guest and uses a built-in MiniCPM5-2B model to respond to certain kernel crashes without a reboot.

Does it really fix kernel bugs?

No. It stops a crash by rewriting the faulting instruction, typically into NOPs or an instruction that sets a result to zero. Linux keeps running, but the original bug is still there and the affected code now behaves differently.

Which crashes can it handle?

Kernel-mode null-pointer page faults, divide-by-zero errors and invalid-instruction traps. Faults from apps, and kernel page faults outside the first 4 KB of memory, go straight back to Linux.

Can I run it on my own PC?

Only for experiments. It needs an AMD CPU with SVM and nested page tables, and the published setup runs inside QEMU/KVM with nested virtualisation. The README lists the build tools, a Linux 5.15 kernel and the Python packages used for training.

How accurate is the model?

On the author's 122 held-out synthetic scenarios, it passed 97.5% after GRPO training, with no dangerous crashes allowed to continue. That hasn't been tested on real-world kernel bugs.

Reader poll

Would you let an LLM live-patch a crashing kernel?

Vote to see results.

  • #llm-asm
  • #hypervisor
  • #linux-kernel
  • #minicpm
  • #bare-metal