Introduction to Virtual Machines

35
Introduction to Virtual Machines Scott Devine Principal Engineer, Co- Founder VMware, Inc.

description

Introduction to Virtual Machines. Scott Devine Principal Engineer, Co-Founder VMware, Inc. Outline. What is virtualization? How-to virtualize CPU Memory I/O. What is Virtualization. Linux. Linux (devel). XP. Vista. MacOS. Virtual Machine Monitor. Hardware. Isomorphism. - PowerPoint PPT Presentation

Transcript of Introduction to Virtual Machines

Page 1: Introduction to Virtual Machines

Introduction to Virtual Machines

Scott DevinePrincipal Engineer, Co-Founder

VMware, Inc.

Page 2: Introduction to Virtual Machines

Outline

• What is virtualization?• How-to virtualize– CPU – Memory– I/O

Page 3: Introduction to Virtual Machines

What is Virtualization

Hardware

Virtual Machine Monitor

Linux Linux (devel) XP Vista MacOS

Page 4: Introduction to Virtual Machines

Isomorphism

Formally, virtualization involves the construction of an isomorphism from guest state to host state.

GuestSi Sj

HostSi’ Sj’

e(Si)

e’(Si’)

V(Si) V(Sj)

Page 5: Introduction to Virtual Machines

Virtualization Properties

• Isolation• Encapsulation• Interposition

Page 6: Introduction to Virtual Machines

Types of Virtualization

• Process Virtualization– Language construction– Cross-ISA emulation• Apple’s 68000-PowerPC-Intel Transition

• Device Virtualization– RAID

• System Virtualization– VMware– Xen– Microsoft’s Hyper-V

Page 7: Introduction to Virtual Machines

System Virtualization Applications

• Server Consolidation• Data Center Management– VMotion

• High Availability– Automatic Restart

• Disaster Recovery• Fault Tolerance• Test and Development• Application Flexibility

Page 8: Introduction to Virtual Machines

CPU Virtualization

• Trap and Emulate• Binary Translation

Page 9: Introduction to Virtual Machines

Privileged State

State of the processor is privileged if• access to that state breaks the virtual

machine’s isolation boundaries• if it is needed by the monitor to implement

virtualization

Page 10: Introduction to Virtual Machines

Trap and Emulate

Guest OS + Applications

Virtual Machine Monitor

PageFault

UndefInstr

vIRQ

MMUEmulation

CPUEmulation

I/OEmulation

Unp

rivile

ged

Priv

ilege

d

Page 11: Introduction to Virtual Machines

“Strictly Virtualizable”

A processor or mode of a processor is strictly virtualizable if, when executed in a lesser privileged mode:

• all instructions that access privileged state trap

• all instructions either trap or execute identically

• …

Page 12: Introduction to Virtual Machines

Issues with Trap and Emulate

• Not all architectures support it• Trap costs may be high• Monitor uses a privilege level– Need to virtualize the protection levels

Page 13: Introduction to Virtual Machines

Binary Translation

vEPC mov ebx, eax

cli

and ebx, ~0xfff

mov ebx, cr3

sti

ret

mov ebx, eax

mov [VIF], 0

and ebx, ~0xfff

mov [CO_ARG], ebx

call HANDLE_CR3

mov [VIF], 1

test [INT_PEND], 1

jne

call HANDLE_INTS

jmp HANDLE_RET

start

Guest Code Translation Cache

Page 14: Introduction to Virtual Machines

Controlling Control Flow

vEPC test eax, 1

jeq

add ebx, 18

mov ecx, [ebx]

mov [ecx], eax

test eax, 1

jeq

call END_BB

vEPC

call END_BB

vEPC

start

Guest Code Translation Cache

ret

Page 15: Introduction to Virtual Machines

Controlling Control Flow

vEPC

test eax, 1

jeq

add ebx, 18

mov ecx, [ebx]

mov [ecx], eax

test eax, 1

jeq

call END_BB

vEPC

call END_BB

vEPC

Guest Code Translation Cache

ret

add ebx, 18

mov ecx, [ebx]

mov [ecx], eax

call HANDLE_RETeax == 0

findnext

Page 16: Introduction to Virtual Machines

Controlling Control Flow

vEPC

test eax, 1

jeq

add ebx, 18

mov ecx, [ebx]

mov [ecx], eax

test eax, 1

jeq

jmp

call END_BB

vEPC

Guest Code Translation Cache

ret

add ebx, 18

mov ecx, [ebx]

mov [ecx], eax

call HANDLE_RETeax == 0

Page 17: Introduction to Virtual Machines

Controlling Control Flow

vEPC

test eax, 1

jeq

add ebx, 18

mov ecx, [ebx]

mov [ecx], eax

test eax, 1

jeq

jmp

call END_BB

vEPC

Guest Code Translation Cache

ret

add ebx, 18

mov ecx, [ebx]

mov [ecx], eax

call HANDLE_RETeax == 1

findnext

mov [ecx], eax

call HANDLE_RET

Page 18: Introduction to Virtual Machines

Controlling Control Flow

vEPC

test eax, 1

jeq

add ebx, 18

mov ecx, [ebx]

mov [ecx], eax

test eax, 1

jeq

jmp

jmp

Guest Code Translation Cache

ret

add ebx, 18

mov ecx, [ebx]

mov [ecx], eax

call HANDLE_RETeax == 1 mov [ecx], eax

call HANDLE_RET

Page 19: Introduction to Virtual Machines

Issues with Binary Translation

• Translation cache index data structure• PC Synchronization on interrupts• Self-modifying code– Notified on writes to translated guest code

Page 20: Introduction to Virtual Machines

Other Uses for Binary Translation

• Cross ISA translators– Digital FX!32

• Optimizing translators– H.P. Dynamo

• High level language byte code translators– Java– .NET/CLI

Page 21: Introduction to Virtual Machines

New Hardware Support for CPU Virtualization

• New guest mode• Guest control block– Specifies guest state

• New operations– VM enter– VM exit

Page 22: Introduction to Virtual Machines

Memory Virtualization

• Shadow Page Tables• Nested Page Tables

Page 23: Introduction to Virtual Machines

Traditional Address Spaces

Virtual Address Space

0 4GB

Physical Address Space

0 4GB

Page 24: Introduction to Virtual Machines

Traditional Address Translation

Virtual Address Physical Address

ProcessPage Table

1 2

2

3

4 5

TLB

Operating System’s Page Fault Handler

Page 25: Introduction to Virtual Machines

Virtualized Address Spaces

Virtual Address Space

0 4GB

Physical Address Space

0

Machine Address Space

0

Guest Page Table

VMM PhysMap

4GB

4GB

Page 26: Introduction to Virtual Machines

Virtualized Address Spacesw/ Shadow Page Tables

Virtual Address Space

0 4GB

Physical Address Space

0

Machine Address Space

0

Guest Page Table

VMM PhysMap

4GB

4GB

Shad

owPa

ge T

able

Page 27: Introduction to Virtual Machines

Virtualized Address Translationw/ Shadow Page Tables

Virtual Address Machine Address

ShadowPage Table

GuestPage Table PMap

1 2

2

3

45

3

6

TLB

A

Page 28: Introduction to Virtual Machines

Issues with Shadow Page Tables

• Guest page table consistency– Rely on Guest’s need to invalidate TLB

• Performance considerations– Aggressive shadow page table caching necessary– Need to trace writes to cached page tables

Page 29: Introduction to Virtual Machines

Virtualized Address Spacesw/ Nested Page Tables

Virtual Address Space

0 4GB

Physical Address Space

0

Machine Address Space

0

Guest Page Table

VMM PhysMap

4GB

4GB

Page 30: Introduction to Virtual Machines

Virtualized Address Translationw/ Nested Page Tables

Virtual Address Machine Address

GuestPage Table

PhysMapBy VMM

1

2

TLB

3

2

3

Page 31: Introduction to Virtual Machines

Issues with Nested Page Tables

• Positives– Simplifies monitor design– No need for page protection calculus

• Negatives– Guest page table is in physical address space– Need to walk PhysMap multiple times

• Need physical to machine mapping to walk guest page table• Need physical to machine mapping for original virtual address

• Other Memory Virtualization Hardware Assists– Monitor Mode has its own address space

• No need to hide the monitor

Page 32: Introduction to Virtual Machines

VM1

Interposition with Memory VirtualizationPage Sharing

Virtual

Physical

Machine

Read-OnlyCopy-on-wrte

VM2

Virtual

Physical

Page 33: Introduction to Virtual Machines

I/O Virtualization

Hardware

Guest

H.W. Device Driver H.W. Device Driver

Virtual Device Driver

Virtual Device Model

Abstract Device ModelDevice Interposition

Compression Bandwidth Control Record / ReplayOvershadowPage Sharing Copy-on-Write DisksEncryption Intrusion Detection Attestation

Device Back-endsRemote Access Cross-device Emulation Disconnected Operation

MultiplexingDevice Sharing Scheduling Resource Management

Virtual Device Driver

Virtual Device Model

Virtual Device Driver

Virtual Device Model

Page 34: Introduction to Virtual Machines

Issues with I/O Virtualization

• Need physical memory address translation– need to copy– need translation– need IO MMU

• Need way to dispatch incoming requests