Skip to content

aannjjiiccaa/hypervisor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hypervisor

This project was developed as part of the coursework for the university subject AOR2 (Computer Architecture and Organization 2).

It implements a simple mini-hypervisor using the KVM API with three levels of functionality:

  • Version A: Basic hypervisor features
  • Version B: Support for multiple virtual machines (VMs)
  • Version C: File I/O support for guest VMs

Contents of each version

  • mini_hypervisor – the hypervisor executable
  • guest*.img – guest machine code files

Version A – Basic Hypervisor Features

The hypervisor supports:

  • Fixed physical memory sizes for the VM: 2 MB, 4 MB or 8 MB
    Command line option: -m, --memory <size_MB>
  • VMs run in 64-bit long mode
  • Page size: 4 KB or 2 MB
    Command line option: -p, --page <page_size>
  • Single virtual CPU per VM
  • Serial I/O through port 0xE9 (1 byte per operation)
  • Only VMs that terminate with the hlt instruction are supported
  • Launching a guest VM:
    -g, --guest <file.img>

Example command: ./mini_hypervisor --memory 4 --page 2 --guest guest.img


Version B – Multiple VM Support

This version adds support for running multiple VMs:

  • Number of VMs is specified via the -g option with a list of guest files
  • Each VM runs in its own POSIX thread

Example command: ./mini_hypervisor --memory 4 --page 2 --guest guest1.img guest2.img


Version C – File I/O Support

This version adds file operations for guest VMs:

  • Supports opening, closing, reading and writing files via I/O port 0x0278
  • Opening a non-existing file for writing creates that file
  • File paths are specified via command line: -f, --file ...
  • Copy-on-write: Shared files between VMs are copied locally when a VM writes to prevent conflicts
  • Hypervisor ensures that each guest accesses only its own files or allowed shared files

Example command: ./mini_hypervisor -m 4 -p 2 -g guest1.img guest2.img -f ./flowers.png


Notes

  • The hypervisor runs as a 64-bit process
  • Guest programs must terminate using the hlt instruction.
  • Each VM is isolated in its own thread with separate virtual memory and I/O
  • File handling is managed to prevent conflicts between VMs

Build & Run

Requirements

  • Linux environment
  • gcc
  • make
  • POSIX threads support

Building the Hypervisor

The hypervisor is built using a provided Makefile. Navigate to the wanted version directory.

  • To compile the hypervisor, run: make
  • To clean the build artifacts, run: make clean

Building Guest Programs

To build a guest program, navigate to the wanted directory and run: make.

This will:

  • Compile guest.c into guest.o
  • Link the object file using guest.ld
  • Generate the final guest image guest.img

To clean guest build files: make clean.

Running the Hypervisor

After building the hypervisor and guest images, run wanted commands and ensure correct file paths to the guest images.

About

Mini hypervisor with KVM

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors