基础

Virtio

Reference

CPU虚拟化

Untitled

struct kvm_sregs sregs;
if (ioctl(v->vcpu_fd, KVM_GET_SREGS, &sregs) < 0)
    return throw_err("Failed to get registers");

#define X(R) sregs.R.base = 0, sregs.R.limit = ~0, sregs.R.g = 1
    X(cs), X(ds), X(fs), X(gs), X(es), X(ss);
#undef X

sregs.cs.db = 1;
sregs.ss.db = 1;
sregs.cr0 |= 1; /* enable protected mode */

if (ioctl(v->vcpu_fd, KVM_SET_SREGS, &sregs) < 0)
    return throw_err("Failed to set special registers");
  
struct kvm_regs regs;
if (ioctl(v->vcpu_fd, KVM_GET_REGS, &regs) < 0)
    return throw_err("Failed to get registers");

regs.rflags = 2;
regs.rip = 0x100000, regs.rsi = 0x10000;
if (ioctl(v->vcpu_fd, KVM_SET_REGS, &regs) < 0)
    return throw_err("Failed to set registers");

When using bzImage, the protected-mode kernel was relocated to 0x100000 (“high memory”), and the kernel real-mode block (boot sector, setup, and stack/heap) was made relocatable to any address between 0x10000 and end of low memory.

内存虚拟化

https://royhunter.github.io/2014/06/18/KVM-EPT/

VPID是一种用于优化TLB(Translation Lookaside Buffer)资源管理的技术,它可以为每个虚拟处理器分配一个标识符,用于区分不同虚拟处理器的地址空间。VPID的作用是,当虚拟机切换时,可以避免清空TLB中属于其他虚拟处理器的条目,从而减少TLB失效和页表访问的开销,VPID是Intel在Nehalem架构的CPU中引入的一种硬件虚拟化扩展,与EPT(Extended Page Tables)一起提升了内存虚拟化的性能。VPID也可以提高虚拟机的实时迁移(Live Migration)的效率,减少迁移的延迟(Latency)。

影子页表

Untitled

EPT

Untitled

Untitled