Skip to content

San7o/rustemu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rustemu
-------

KVM virtual machine example.

Author:  Giovanni Santini
Mail:    giovanni.santini@proton.me
License: MIT


Overview
--------

Don't be scared by virtual machines! Virtualization really means
executing some CPU instructions in a virtualized / emulated
sandbox. Modern hardware can run virtual machines on the host CPU
instead of emulating one, we will talk about these types of virtual
machines. This is obviously faster, but you can only run virtual
machines which use the host's architecture (you cannot run riscv VMs
on a x86_64 machine, you would need an emulator in that case).

Most of the work for creating a virtual machine is done by the kernel
via the KVM module on linux, which is usually already installed by
major linux distributions. KVM itself greatly relies on hardware
support for virtualization such as Intel VT-x, hence you will need to
have a CPU with virtualization capabilities support and enabled.

You interact with KVM by opening `/dev/kvm` and issuing ioctl calls
with different operations. You will allocate some memory that will be
used by the virtual CPU, copy a program on that region, and create the
virtual cpu itself and set the values of its registers at the start.

Then you can start the CPU from an instruction in some memory
location. The CPU will sometimes stop and return control to us when
halting or reading/writing to ports. We need to handle this like the
hardware would, for example by providing an UART device on a standard
port of an IBM pc.

Hence our virtual machine will need to implement virtual devices for
our virtual CPU which is most of the work we have to do as developers.

In this implementation I used packages from the rust-vmm project, in
particular `kvm-ioctls` which provides rust wrappers over the ioctl
commands, and vm-memory which helps us access the VM physical memory.

About

KVM virtual machine example.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors