r/freebsd
•
u/Opposite_Benefit_675
•
2d ago
•
1
1
AI Bhyve finally got nested virtualization.
Here we go again.
After a full month of work,night and day,I've implemented the nested virtualization for (qemu) + bhyve :
https://github.com/Marietto2008/freebsd-src/tree/vmm-nested-16
It works with every permutation of FreeBSD,Linux and Windows,as you can see from the pictures below :
Permutation 1 :
L0=FreeBSD 16.0-CURRENT
L1=Windows 11
L2=FreeBSD 15.2 (on top of Hyper-V and WSL2)

Permutation 2 :
L0=FreeBSD 16.0-CURRENT
L1=KUbuntu-Noble-Wayland-KDE
L2=FreeBSD-15.1-RELEASE

Permutation 3 :
L0=FreeBSD 16.0-CURRENT
L1=FreeBSD-15.1-RELEASE
L2=Linux omarchy

This has been the most complicated, delicate, treacherous project that I've worked on so far. But what matters is that I had fun and I've learnt a lot.
Here is a small kit for replicating the project on your PC :
https://github.com/Marietto2008/bhyve-nested-strumenti/tree/main/kit
If you try it, please attach the manifest and the smoke-test output.
For the record, my host is consumer hardware: an i9-9900K on a Gigabyte Z390 AORUS PRO, BIOS F12g (2020), running FreeBSD 16-CURRENT. The CPU has VMCS shadowing but no APICv and no posted interrupts, and that shapes the results below.
**On AI use, since that is what the policy discussion is about.**
Code, the test scripts and the performance report were produced with Claude 5.5 with the help of Astra 6. Design reviews during development were also done by AI models, not by people. KVM (GPL) was studied for its behaviour, never copied. Commits carry a "Co-Authored-By: Claude" line. Nothing here has had independent human review yet, and I'd welcome it.
From here on I'll post one item at a time, when there is something new, instead of long reports. Raw data and scripts are in kit/full-report/.
8
u/CodeDriveRepeat 2d ago •
First, it helps to know your audience. This looks like interesting experimental work, but I’d be cautious about recommending it to FreeBSD users in its current state. It replaces the stock hypervisor module and requires root, so people need a clear basis for trusting the code and understanding its effects.
Before I’d consider running it, I’d want exact source revisions pinned, provenance and licensing clearly documented, clean-machine build and reproduction steps, and security testing of the modified hypervisor and guest isolation. The reported testing is on one machine, and the project lists stability issues, so I’d describe it as experimental for now.
Keep developing it, but make sure you understand and can review the code and the tools involved, including AI-generated contributions. Licensing deserves particular care: identify the licenses for each component and patch, retain required notices, and document how changes relate to upstream projects.
These steps would help others evaluate and reproduce the work. Right now, the results are promising, but they’re still at the “works on my machine” stage.
2
u/Opposite_Benefit_675 1d ago
**The bug.** With a KASAN kernel in the L1, the L1 panicked as soon as its L2 issued INVEPT:
```
panic: Unaligned free of 0xfffff80228959000 from zone ... (malloc-4096)
uma_dbg_free <- free <- vept_free_level <- vept_root_wipe <- vmx_vept_invept <- nested_invept
```
The shadow EPT tables were allocated with `malloc_aligned()`. The child tables were then found again through the direct-map alias of their physical address, and freed with that alias. Without KASAN, UMA on amd64 normally hands out direct-map pages, so the two pointers matched by accident; with KASAN they don't. The fix (commit `ec105b041f72`) allocates the tables as physical pages used through the direct map, the way pmap does with its page tables.
**How it was tested**
The test stack, on one machine (an i9-9900K):
- the host (L0) runs this project's `vmm`;
- the L1 is FreeBSD 16-CURRENT built from the branch, with the sanitizer kernel and a `vmm-restore.ko` built the same way;
- inside the L1 runs the kit's smoke test: its L2, a FreeBSD 15.1 guest, loads vmm (VMXON) and boots an L3 kernel up to the root-mount prompt.
So every VMX instruction of the L2 goes through the L1's nested code, under the sanitizer.
| L1 kernel | result | sanitizer reports |
|---|---|---|
| GENERIC (baseline) | all passed | — |
| KASAN, before the fix | panic above | 1 (the bug) |
| KASAN, with the fix | all passed | 0 |
| KMSAN, with the fix | all passed | 0 |
With four levels everything is slow: the L3 needed about 10-11 minutes to reach the prompt. So the runs used longer time limits than the stock smoke test; that was the only change to the script.
The testing also turned up a bug in the kit itself. The smoke test's console reader turned echo off only after bhyve had started. A freshly opened nmdm starts with echo on, so for a moment the guest got its own output back as keystrokes. My own L1 launcher had the same pattern, and there it was enough for the loader menu to pick "Boot Single user". The reader now turns echo off before the VM starts, both on the host and inside the L1; the fixed `kit/smoke-test.sh` passes on the host.
**Where to find them**
- **Kernels:** https://github.com/Marietto2008/bhyve-nested-strumenti/releases/tag/nested-sanitizers-v2
- `kernel.nested-kasan.tar.xz` (66 MB) and `kernel.nested-kmsan.tar.xz` (118 MB): each kernel with all its modules, including `vmm-restore.ko`. These are the exact binaries that passed: the modules' sha256 match the ones loaded in the test.
- `SHA256SUMS`: check with `sha256sum -c SHA256SUMS`.
- Release `nested-sanitizers-v1` is superseded: its module still has the bug. Don't use it.
- **Source:** `Marietto2008/freebsd-src`, branch `vmm-nested-16`, commit `ec105b041f72`.
- `sys/amd64/conf/NESTED-KASAN` and `NESTED-KMSAN`: `GENERIC` plus `options KASAN` / `options KMSAN`.
- `tools/nested/build-sanitizer.sh`: rebuilds both, so you don't have to trust my binaries.
**How to use them**
Not on your host. Use a FreeBSD 16-CURRENT VM that has nested VMX (bhyve with `-o x86.nested_virt=true` and `-w`):
A sanitizer report shows up as a panic, with a stack, on the console.
**What this is and isn't**
It is one functional test on one machine: it covers the code paths that this test exercises, not the whole module. There is still no fuzzing and no independent human review; `SECURITY.md` in the repository lists what is open. If you run the kernels and get a report, please open an issue with:
- the full console text;
- the output of `kit/host-manifest.sh`;
- the commit hash.
2
u/taosecurity seasoned user 2d ago
Can you say more about how you used Claude and Astra? Did Claude code and Astra reviewed?
2
u/jjccs 2d ago
thank you sir for you efforts ! really interesting to see what you can do with help of AI to bring interesting features to FreeBSD. Even though we know the kernel team wont accept AI generated codes.
11
u/CodeDriveRepeat 2d ago •
Sweet! Great job. Keep up the good work. I’ll check it out. And add a star.
2
u/grahamperrin Claude user 2d ago
scan of /Marietto2008/freebsd-src on github.com
I changed the flair (tag) of your post:
1
u/fazelesswhite Hayzam – author of Sylve 1d ago
I think this is the fourth implementation of nested virtualization I've seen in the last six months or so. All of them have been written with the help of Claude/LLMs (which I have absolutely no issue with), but with the exception of one (https://reviews.freebsd.org/D61708), the others haven't really been presented in a coherent, reviewable form.
Just my two cents as a -src committer: if you want a feature, regardless of how big or small, to eventually land, it helps enormously to engage with the community first. IRC, the FreeBSD Discord, and other channels are excellent places to discuss ideas, get feedback, and find out whether someone is already working on the same thing.
Imagine how much more productive it would've been to point those LLMs at reviewing and improving D61708 instead of starting yet another independent implementation around the same subject.
1
u/Such_One_406 2d ago edited 2d ago
What sanitizer methods did you give Claude to use?
2
u/CodeDriveRepeat 4h ago
I think I should create an Agents.md for people who haven’t been programming since they were 8 like me and may not have an understanding of security necessities.
If anyone wants this let me know, I’ll create it and share it then your agent should do better.
1
u/nrgmilk 2d ago
Thank you a lot!
0
u/grahamperrin Claude user 2d ago
https://beige.party/@fuzzy/117694964510634915 – u/Opposite_Benefit_675 if anything there needs adjustment, please let me know.