SVM Hypervisor in Rust, Part 1
Design Plan#
There are many ways people implement hypervisors. The most basic format are “Type 1” and “Type 2” hypervisors. The difference? One runs independently of an operating system and one doesnt. For example, KVM would be considered a Type 2 hypervisor because it runs as a Linux kernel module and VMWare ESXi would be a Type 1. Hyper-V would be considered a Type 1 too because technically it does run independently also. In this series, we will implement a Type 1 hypervisor and we will be hypervising our existing operating system.
Paravirtualization#
Both Type 1 and Type 2 hypervisors are not one to one and have to go through lengths to achieve good performance, we’re writing a very simple hypervisor, (it will just virtualize our existing operating system) But there’s a technique some hypervisors use called “paravirtualization” where the source code of the operating system is modified with something called “Hypercalls”, This are used for things like I/O, file systems, (such as the shared files on VMWare) and even actual hardware like an NVME drive. In our hypervisor we won’t really be implementing this because this series would be like 150 posts long.
On AMD, hypercalls look something like this
mov rax, 1
mov rcx, 195 ; random made up key
vmmcall
Which exits back to host, where you can inspect the registers and do whatever you want. In the real world, you’d probably want to supply a key like I did so it won’t be spammed with unrelated things.