Skip to content

JiaweiHawk/yakvm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yet Another Kernel-based Virtual Machine

github CI

This is a simple kernel-based virtual machine for linux to understand AMD-V(AMD Virtualization) technology.

Usage

build the environment

Run the make env to generate the YAKVM environment image.

With this image, you can try kernel-based virtual machine in the image.

boot the qemu

Run the make run to boot up the qemu with yakvm.ko in /mnt/shares on guest.

debug the yakvm

Run the make debug to debug the YAKVM on the yakvm environment

test the yakvm

Run the make test to run the tests on the yakvm environment

Design

VMM interface

                  ┌────────┐   fd
                  │emulator├────────┬───┬───┬─────────┬──┬───┐
                  └────▲───┘        │   │   │         │  │   │
                       │            │   │   │         │  │   │
                     fd│            │   │   │         │  │   │
user space             │            │   │   │         │  │   │
───────────────────────┼────────────┼───┼───┼─────────┼──┼───┤
kernel space           │            │   │   │         │  │   │
                       │            │   │   │         │  │   │
                  ┌────▼─────┐  ┌───┼───▼───┼───┐     │  │   │
                  │/dev/yakvm│  │   │       │   │     │  │   │
                  └────▲─────┘  │ ┌─▼──┐ ┌──▼─┐ │     │  │   │
                       │        │ │vcpu│ │vcpu│ │     │  │   │
                       │        │ └────┘ └────┘ │ ┌───┼──▼───┼────┐
                       │        │virtual machine│ │   │      │    │
                       │        └──────▲────────┘ │ ┌─▼──┐ ┌─▼──┐ │
                       │               │          │ │vcpu│ │vcpu│ │
                       │               │          │ └────┘ └────┘ │
                 ┌─────▼──────┐        │          │virtual machine│
                 │yakvm driver│        │          └──────▲────────┘
                 └─────┬──────┘        │                 │
                       │               │                 │
                       └───────────────┴─────────────────┘

cpu virtualization

 ┌───────────────────┐             ┌───────────────────┐
 │                   │             │                   │
 │ ┌──────────────┐  │             │ ┌──────────────┐  │
 │ │  hsave area  │  │             │ │  hsave area  │  │
 │ └──────────────┘  │             │ └──────────────┘  │
 │                   │             │                   │
 │ ┌───────────────┐ │             │ ┌───────────────┐ │
 │ │Virtual Machine│ │vmrun   vmrun│ │Virtual Machine│ │
 │ │ Control Block ◄─┼─────┐  ┌────┼─► Control Block │ │
 │ │  struct vmcb  │ │     │  │    │ │  struct vmcb  │ │
 │ └───────────────┘ │     │  │    │ └───────────────┘ │
 │    virtual cpu    │     │  │    │    virtual cpu    │
 └─────────┬─────────┘     │  │    └─────────┬─────────┘
           │               │  │              │
           │               │  │              │
           │               │  │              │
           │               │  │              │
           │vmexit        ┌┴──┴┐       vmexit│
           └──────────────►host◄─────────────┘
                          └────┘

host must complete the following steps to execute the virtual machine:

memory virtualization

┌────────────────────────────────────────────────────────────────────────────┐
│                                                                            │
│  ┌─────────────────────────────────┐                                       │
│  │                                 │                                       │
│  │     ┌──────────────────────┐    │        ┌────────────────────────────┐ │
│  │     │guest physical address├────┼────▲──►│host physical address       │ │
│  │     └──────────────────────┘    │    │   └────────────────────────────┘ │
│  │                                 │    │                                  │
│  │ ┌─────────────────────────────┐ │    │                                  │
│  │ │Virtual Machine Control Block│ │  ┌─┴────────────────┐                 │
│  │ │        struct vmcb          ├─┼─►│nested page table │                 │
│  │ └─────────────────────────────┘ │  └──────────────────┘                 │
│  │            virtual cpu          │                                       │
│  └─────────────────────────────────┘                                       │
│                                                                            │
│                                      host                                  │
└────────────────────────────────────────────────────────────────────────────┘

host must complete the following steps to supported memory virtualization

device virtualization

Considering there are two ways to access devices under x86 architecture: Port I/O(PIO) and Memory Mapped I/O(MMIO), we should virtualizing there two methods.

PIO

PIO virtualization can be achieved by configuring the vmcb as yakvm_vcpu_init_vmcb() to intercept PIO as yakvm_cpu_handle_ioio().

MMIO

For MMIO, remove the _PAGE_PRESENT flag from the corresponding MMIO memory's Nested Paging Table entry as yakvm_vmm_npt_create() to intercept MMIO as yakvm_vcpu_handle_mmio().

Reference

About

Yet Another Kernel-based Virtual Machine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published