Virtualized Redox: from Virtio-FS to Cloud Hypervisor, and beyond

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

Virtualized Redox: from Virtio-FS to Cloud Hypervisor, and beyond

Virtualized Redox: from Virtio-FS to Cloud Hypervisor, and beyond By MJ Pooladkhay on Sunday, November 8, 2026 Hello, Reader! I’m MJ Pooladkhay, and for the past couple of months I have been building a Virtio-FS driver for Redox OS and, more recently, getting Redox to run on Cloud Hypervisor. The driver is merged into the base repository, where most Redox drivers and system components live. The kernel, bootloader and driver changes that let Redox boot to a shell on Cloud Hypervisor are merged too (details below). Both are fun pieces of work on their own, but they are really the first steps of a bigger effort with two directions: Redox as a guest: Redox runs as a cloud server, starting with Cloud Hypervisor, without the legacy PC hardware it used to depend on in QEMU. Most of this post is about this one. Redox as a host: Redox runs virtual machines itself. This one is still a proposal, and I’ll go over it at the end of this post. The guest work is generously funded by NGI Zero Commons and NLnet as part of the Virtualized Redox grant.

虚拟化 Redox:从 Virtio-FS 到 Cloud Hypervisor 及未来。作者:MJ Pooladkhay,2026 年 11 月 8 日,星期日。读者你好!我是 MJ Pooladkhay。在过去的几个月里,我一直在为 Redox OS 构建 Virtio-FS 驱动程序,最近还让 Redox 在 Cloud Hypervisor 上运行。该驱动程序已合并到基础存储库中,大多数 Redox 驱动程序和系统组件都位于此处。让 Redox 能够在 Cloud Hypervisor 上引导至 shell 的内核、引导加载程序和驱动程序更改也已合并(详情见下文)。这两项工作本身都很有趣,但它们实际上是一个更大努力的初步步骤,该努力包含两个方向:作为客户机的 Redox:Redox 作为云服务器运行,从 Cloud Hypervisor 开始,不再依赖它在 QEMU 中所依赖的传统 PC 硬件。本文大部分内容是关于这一点的。作为宿主机的 Redox:Redox 自身运行虚拟机。这目前仍是一个提案,我将在本文末尾讨论它。这项客户机工作由 NGI Zero Commons 和 NLnet 作为“虚拟化 Redox”资助项目的一部分慷慨资助。

Why run Redox as a guest? Most Internet-facing software today runs in virtual machines, either in the cloud or on edge servers close to its users. Web servers, databases, API backends and microservices spend all day handling input from strangers, and that is where a memory-safe microkernel-based operating system has the most to offer: A smaller, safer base. Redox is written in Rust, and its drivers, filesystems and network stack run as separate userspace processes instead of inside the kernel (microkernel architecture). A bug may hang or crash only that process, not the whole system, and the code running with highest system privileges stays small. Sandboxing built in. With capability-based security, each service can be limited to the files, sockets and devices it actually needs (more on that below). Hardware becomes the host’s problem. On bare metal, Redox needs a driver for every disk controller, network card and chipset it meets. Inside a VM, the host deals with the hardware, and Redox only needs a handful of VirtIO drivers. That makes a VM one of the quickest paths to running Redox in the real world, and real-world use is the best way to prove it as a secure platform. This is the direction the project set in its development priorities: Redox as a secure host for web services, first as a private or edge server, and eventually as a multi-tenant cloud server where each tenant is isolated from others.

为什么要将 Redox 作为客户机运行?当今大多数面向互联网的软件都运行在虚拟机中,无论是在云端还是在靠近用户的边缘服务器上。Web 服务器、数据库、API 后端和微服务整天都在处理来自陌生人的输入,而这正是基于内存安全微内核的操作系统最能发挥作用的地方:更小、更安全的基座。Redox 使用 Rust 编写,其驱动程序、文件系统和网络堆栈作为独立的用户空间进程运行,而不是在内核内部运行(微内核架构)。一个错误可能只会导致该进程挂起或崩溃,而不会影响整个系统,并且以最高系统权限运行的代码保持在很小的规模。内置沙箱。通过基于能力的安全性,每个服务都可以被限制在它实际需要的文件、套接字和设备上(下文将详细介绍)。硬件成为宿主机的问题。在裸机上,Redox 需要为它遇到的每个磁盘控制器、网卡和芯片组提供驱动程序。在虚拟机内部,宿主机处理硬件,而 Redox 只需要少量的 VirtIO 驱动程序。这使得虚拟机成为在现实世界中运行 Redox 的最快途径之一,而现实世界的使用是证明其作为安全平台价值的最佳方式。这是该项目在开发优先级中设定的方向:Redox 作为 Web 服务的安全宿主机,首先作为私有或边缘服务器,最终作为多租户云服务器,其中每个租户都与其他租户隔离。

How Virtualization Works The easiest way I know to think about a hypervisor is as an operating system whose processes are operating systems. A process runs directly on the CPU until it needs the kernel, for a system call, a page fault or a timer tick, and then the kernel takes over for a moment. A guest OS runs directly on the CPU in the same way, until it does something that only the hypervisor is allowed to handle. That moment a “VM exit” happens where the control is transferred to the hypervisor (similar to how a system call transfers control to the OS kernel). On Linux, KVM in the host kernel handles it, either by itself or by passing it to the virtual machine monitor (VMM), an ordinary process such as Cloud Hypervisor or QEMU. I went through the theory behind this, and why x86 needed new hardware (VT-x and AMD-V) to make it work, in an earlier post on my personal blog. From Redox’s side, a VM boots much like a laptop does. The virtual CPU starts in firmware, the firmware loads the bootloader from a disk, and the bootloader hands over to the kernel. It’s the same code that runs on real hardware, running natively, with the kernel in supervisor mode (ring 0 on x86) as usual. Most of what Redox does never leaves the guest. System calls, context switches and page faults are handled by the Redox kernel itself, and the hypervisor doesn’t even see them.

虚拟化是如何工作的?我认为理解虚拟机管理程序(Hypervisor)最简单的方法是将其视为一种操作系统,其进程就是其他操作系统。一个进程直接在 CPU 上运行,直到它需要内核进行系统调用、页面错误或计时器中断,此时内核会接管片刻。客户机操作系统以同样的方式直接在 CPU 上运行,直到它执行了只有虚拟机管理程序才被允许处理的操作。那一刻会发生“VM 退出”(VM exit),控制权被转移给虚拟机管理程序(类似于系统调用将控制权转移给操作系统内核)。在 Linux 上,宿主机内核中的 KVM 会处理它,要么由其自身处理,要么将其传递给虚拟机监视器(VMM),即像 Cloud Hypervisor 或 QEMU 这样的普通进程。我在个人博客的早期文章中详细介绍了其背后的理论,以及为什么 x86 需要新的硬件(VT-x 和 AMD-V)来实现这一点。从 Redox 的角度来看,虚拟机的引导方式与笔记本电脑非常相似。虚拟 CPU 从固件开始启动,固件从磁盘加载引导加载程序,引导加载程序再将控制权交给内核。它与在真实硬件上运行的代码相同,以原生方式运行,内核像往常一样处于监督模式(x86 上的 ring 0)。Redox 执行的大部分操作都不会离开客户机。系统调用、上下文切换和页面错误都由 Redox 内核自身处理,虚拟机管理程序甚至看不到它们。

Memory takes a few more steps than on bare metal, because there are now two kernels that each think they own it. Redox’s page tables turn a guest virtual address (GVA) into a guest physical address (GPA), the address Redox believes is in RAM. But guest RAM is really just a big chunk of memory the VMM allocated in its own address space, and the VMM tells KVM which part of it backs which range of guest RAM (a memslot). So every GPA is also a host virtual address (HVA) in the Cloud Hypervisor process, and the host kernel’s page tables turn that into a host physical address (HPA), the actual spot in RAM: GVA —[Redox’s page tables]—> GPA —[KVM memslots]—> HVA —[host page tables]—> HPA Going through all of that on every memory access would be painfully slow, so KVM collapses the GPA to HPA part into a single step. It builds nested page tables that map guest physical addresses straight to host physical ones, and fills them in lazily as the guest touches memory. The CPU then walks Redox’s page tables and the nested ones together in hardware, and caches the result in the TLB. Redox manages its own page tables freely, and only touching guest memory that isn’t mapped yet causes an exit. The HVA step has a nice side effect: since guest RAM is an ordinary mapping in the VMM, it can be shared with other host processes. That’s how virtiofsd reads Virtio-FS requests straight out of the guest’s memory, and why sharing a directory requires the guest’s memory to be shared.

内存处理比在裸机上多出几个步骤,因为现在有两个内核,它们都认为自己拥有内存。Redox 的页表将客户机虚拟地址(GVA)转换为客户机物理地址(GPA),即 Redox 认为在 RAM 中的地址。但客户机 RAM 实际上只是 VMM 在其自身地址空间中分配的一大块内存,VMM 会告诉 KVM 哪一部分支持客户机 RAM 的哪个范围(memslot)。因此,每个 GPA 也是 Cloud Hypervisor 进程中的宿主机虚拟地址(HVA),而宿主机内核的页表将其转换为宿主机物理地址(HPA),即 RAM 中的实际位置:GVA —[Redox 页表]—> GPA —[KVM memslots]—> HVA —[宿主机页表]—> HPA。如果每次内存访问都经历所有这些步骤,速度会慢得令人痛苦,因此 KVM 将 GPA 到 HPA 的部分合并为一个步骤。它构建嵌套页表,将客户机物理地址直接映射到宿主机物理地址,并在客户机访问内存时延迟填充它们。然后,CPU 在硬件中同时遍历 Redox 的页表和嵌套页表,并将结果缓存在 TLB 中。Redox 可以自由管理自己的页表,只有在访问尚未映射的客户机内存时才会导致退出。HVA 步骤有一个很好的副作用:由于客户机 RAM 是 VMM 中的普通映射,因此它可以与其他宿主机进程共享。这就是 virtiofsd 如何直接从客户机内存中读取 Virtio-FS 请求,以及为什么共享目录需要共享客户机内存的原因。

Devices are where the hypervisor earns its keep, because every device the guest sees is made up. Some are emulations of real hardware, such as an 8259 interrupt controller, a programmable interval timer (PIT), a serial port or each CPU’s local APIC, and every register access to them is a VM exit that the hypervisor turns into behavior. Others are VirtIO devices, which don’t pretend to be hardware at all and talk to the host through queues in shared memory. Interrupts are made up too. The host keeps the real ones, and the guest only gets the ones the hypervisor injects on behalf of its virtual devices and timers. If the hypervisor doesn’t emulate a device, nobod

设备是虚拟机管理程序发挥作用的地方,因为客户机看到的每个设备都是虚构的。有些是对真实硬件的模拟,例如 8259 中断控制器、可编程间隔定时器(PIT)、串行端口或每个 CPU 的本地 APIC,对它们的每次寄存器访问都是一次 VM 退出,虚拟机管理程序将其转化为相应的行为。其他则是 VirtIO 设备,它们根本不假装是硬件,而是通过共享内存中的队列与宿主机通信。中断也是虚构的。宿主机保留真实的中断,而客户机只接收虚拟机管理程序代表其虚拟设备和定时器注入的中断。如果虚拟机管理程序不模拟某个设备,那么没有人