mykvm is a small vm tool written using the KVM API. The goal of this project is to be able to boot a custom modular kernel designed at the LSE, called stos.


stos is a monolithic kernel written in a modular way, used at EPITA in order to teach basic kernel programming.

Some of the assignments are:

  • Memory protection
    • GDT
    • Protected mode
  • Events
    • IDT
    • IRQs
    • 8259A PIC
    • i8254 PIT
  • Virtual memory
    • 32-bit x86 paging
    • Page mapping
    • IO mapping


KVM is the Linux Hypervisor that exposes an API for virtualization. It’s usually split in two parts:

  • KVM, the kernel module
  • QEMU, device emulation, vm setup

In mykvm, KVM is used for the vm, vcpu and memory management, through ioctls.

It allows us to setup a booting environment for stos.


The work done for this project is divided in multiple modules:

VM setup

This consists in initializing the following parts of KVM:

  • /dev/kvm
  • the virtual machine
  • the virtual cpu

And some extras:

  • the IRQ chip
  • the PIT
Protected mode

Going into protected mode takes care of:

  • Setting up all the memory segments to flat.

  • Enabling the %CR0.PE flag.


Setting up the %CR3 address, pointing to a temporary page directory handling the kernel mapping.

We would normally set up the %CR0.PG flag, but KVM is unable to boot with that flag set. We will have to go through a trampoline setting the flag and calling the kernel entry point.

Boot interface

Loading the kernel (stos) ELF into the memory, then taking care of stos’ boot protocol.

That consists in setting up the following parts:

  • A boot allocator.

  • The boot segments, representing the memory parts that are reserved/available.

  • The boot modules, which are the kernel modules that should be loaded in memory for stos to dynamically load them in the init phase.

  • The command line and the initramfs.

This should allow stos to boot properly using KVM.