Transcript Lecture 18

CSE 451: Operating Systems
Winter 2011
Module 18
Virtual Machines
Mark Zbikowski and Gary Kimura
What is “Virtualization”?
• Beyond the buzz-word du jour:
– Abstraction of computing resources
– Hide the physical characteristics of a resource
– Allow multiple “instances” of the resource
• Why?
– Sharing the resource among multiple clients
• Disks (I/O system)
• Cpu (scheduler and context switches)
• Memory (processes and virtual memory)
– Fault isolation
• Application
• Operating System
• Hardware(!)
4/8/2016
2
Classes of Virtualization
• Resource
– aggregation, spanning, or concatenation combines individual
components into larger resources or resource pools (RAID)
– VPN or NAT
– Multiprocessor/multicore
– Encapsulation: hide complexity by the creation with
simplified interface.
4/8/2016
3
Classes of Virtualization
• Platform
– 1960’s term: virtual machines used hardware and software
– Host running sofware using hardware assistance to execute
a guest
– Guest can be application or entire OS
– Guest runs as if it were installed on bare metal
– Typically many guests run on a single host
4/8/2016
4
Platform Virtualization – What?
• Emulation/simulation
– Software/hardware decodes each instruction and emulates
the guest hardware
– Emulate completely different CPU (VirtualPC on PowerPC
Mac)
– Typically slow (but some clever tricks can be used)
• Native/Full Virtualization
– Host emulates only enough hardware to allow guest to run
unmodified
• OS-Level Virtualization
– “personalities”
– Underlying OS emulates programming environment: Win32,
POSIX, OS/2
4/8/2016
5
Platform Virtualization – How?
• Emulation/Simulation
– Naively, very slow: decode and execute instruction
– Why not play compiler?
•
•
•
•
“dynamic recompilation”
Decode sequence of guest instructions (basic block)
Generate native host instructions
Hash table of guest address -> codelet block
– Memory management emulation difficult
• Simulate page directory/table and TLB
• Java VM and VirtualPC
4/8/2016
6
Platform Virtualization – Difficulties
• Requirements
– Fidelity: guest executes identically to execution on native
hardware, barring timing effects
– Performance: an overwhelming majority of guest instructions
are executed by the hardware without intervention by host
– Safety: host manages all hardware resources
• X86 is not classically virtualizable
– Run guest in unprivileged mode (“deprivileging”)
– Trap to host on illegal instructions, emulate effects in guest
– Illegal instructions:
• CR (chip control registers)
• I/O port
• Memory-mapped devices
4/8/2016
7
More x86 woes
• Primary and shadow structures
– Host maintains shadows of guest’s primary structures
– On-CPU state:
• Page directory pointer
• Processor status register (interrupt state, flags, debug state)
• Trivial to maintain
– Off-CPU state:
• Page tables
• Encodes mappings and permissions
• Modified by guest AND guest H/W
4/8/2016
8
Improving host performance
• Allow slightly modified guests
– Augment the “hardware” to add host-calls
– VMWare Tools/VirtualPC Machine Additions
• Device drivers that export the I/O at a high level for emulation
• Dynamic recompliation
• Hardware extensions
–
–
–
–
4/8/2016
Intel VMRUN VMEXIT instructions
Hardware maintains shadow state
Traps to host when needed
Too limited to be of value
9
Platform Virtualization
• Emulating an “environment”
–
–
–
–
“Win32 API” implemented on Windows 95
Native API to DOS/Win-based kernel
Windows NT built to allow emulation
DLLs in application address space emulate Windows 95 API
but run on an entirely different operating system
– Vast majority of Windows 95 applications ran on Windows
NT 4 without modification
• Java
– Byte-code defines a virtual machine
– Emulator written in portable C, can be compiled and run on
almost all hardware architectures
– Pcode can be run anywhere
– Dynamic recompilation (aka incremental compilation)
4/8/2016
10