Lecture: lvisor walkthrough
Today’s plan
- review kernel programming
- hypervisor overview
- review exercise 1
Kernel workflow
- draw workflow: bootloader → kernel → (user ↔ kernel)*
tests/lv6/head.S
: bootstrapping
tests/lv6/main.c
: kernel & user setup
kernel/trap.c
& kernel/idt.c
kernel/entry.S
- syscall fast path
- exception/interrupt
- how registers are saved
tests/lv6/syscall.c
: system calls
hypervisor workflow
- workflow
- Intel SDM 23.4, Figure 23-1: Interaction of a Virtual-Machine Monitor and Guests
- vmxon → (VM-entry ↔ VM-exit)* → vmxoff
- see
vmm/kvm.c
(more on EPT later)
- VMCS: virtual-machine control structure
- key data structure to control virtual machines
- guest state
- host state
- control fields: VM-exectuion, VM-exit, VM-entry
- VM-exit information
- state machine: SDM 24.1, Figure 24-1: States of VMCS X
vmptrld
, vmlaunch
, vmresume
, vmclear
vmread
, vmwrite
- VMCB on AMD
vmm/vmx.c
vmx_cpu_has_kvm_support
: check if hardware supports vmx
vmx_disabled_by_bios
: check if vmx is disabled by BIOS
vmx_vcpu_enable
: enter root mode via vmxon
vmx_vcpu_setup
: initialize vmcs
vmx_vcpu_run
: VM-entry and VM-exit
- what registers are saved by the cpu (in VMCS)
- what registers are saved by software (in
struct kvm_vcpu
)
vmx_handle_exit
: read exit rason & dispatch to VM-exit handlers
vmx_skip_emulated_instruction
: skip current instruction in guest
- guest bootstrapping
firmware/*
- draw physical memory map: guest kernel, vmm
- one approach is to emulate a real machine
- a simpler/faster way: communicate with the host (see
guest_params
)
- summary
- power-on → bootstrapping → OS/hypervisor
- → vmxon → guest power-on → guest bootstrapping → (guest OS ↔ hypervisor)*