02 - Virtual Machine Monitor
Virtual Machine Monitor
Overview
All computer problems can be solved with another layer of redirection.

VMM Definition
VMM transform the single machine interface into the illusion of many. Each interfaces is a replica of original computer system, complete with all of the processor instructions.
VMM 能操纵 processors
VMM implemented by adding software to an execution for all Platform HW
Platform HW: Mem, Processors, I/O devices
Why use VMM
许多商用 PC 都为大型机,闲置的时候有很多空闲算力,可以以 VMM 的形式抽象多个虚拟 PC,作为 Server 向其他用户提供计算服务。这样能提高物理机的利用率。
VMM Essential Features
Equivalence: VMMs are identical virtual platform, excepts some system resources differences, e.g. memory size.
VMM 几乎和物理机一样,但是物理机分配给 VMM 的资源可以有差异
Isolation: resource control, VMM is a complete control of system resources
VMMs couldn’t disturbe others
Efficiency: speed >> emulator/simulators(模拟器)
Emulator(仿真器): QEMU, VMM 不需要多一步解释,肯定是要比 QEMU 快滴
How VMM Work
With or Without VMM?
- Without VMM, user mode communicate with kernel mode by syscall.

- 当前 OS 架构: 由 VMM 分割了 user-mode syscall, virtual HW/ `SW interface, physical HW/SW interface.
Run OS as user-level program

运作方式:依靠 CPU 来捕获 (trap) sensitive instructions,并将其移交给 VMM
- VMM emulates guest OS’s instructions effects on HW.
- VMM provides virtual HW/SW interface to guest OSs by trapping and emulating sensitive instructions.
Processes 由 CPU 控制,OS 仅提供服务
Two classes of instructions:
- priviledged instructions: those that trap when CPU is in user-mode
- sensitive instructions: which modify HW configuration or resources, 和一些需要依赖 HW configuration 的 behaviors
Memory with/without virtualization
- Without virtualization

VPN: Virtual Page Number
VA: Virtual Address
TLB: Translation Lookaside Buffer - 页表缓存
2. With Virtualization

VMM will check TLB miss handler and then the sensitive instructions reduced to priviledge instructions.
