E6998 - Virtual Machines Lecture 2 CPU Virtualization Scott Devine VMware, Inc.

Slides:



Advertisements
Similar presentations
Microprocessors General Features To be Examined For Each Chip Jan 24 th, 2002.
Advertisements

E Virtual Machines Lecture 3 Memory Virtualization
© 2012 VMware Inc. All rights reserved CPU and Memory Virtualization Prashanth Bungale, Sr. Member of Technical Staff, Mobile Virtualization January 23.
Computer Organization and Architecture
Computer Organization and Architecture
OS2-1 Chapter 2 Computer System Structures. OS2-2 Outlines Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection.
1 Hardware and Software Architecture Chapter 2 n The Intel Processor Architecture n History of PC Memory Usage (Real Mode)
X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT
PC hardware and x86 3/3/08 Frans Kaashoek MIT
Introduction to Virtual Machines
Budapesti Műszaki és Gazdaságtudományi Egyetem Méréstechnika és Információs Rendszerek Tanszék Virtualization Zoltan Micskei
© 2010 VMware Inc. All rights reserved Virtualization Based on materials from: Introduction to Virtual Machines by Carl Waldspurger Understanding Intel®
E Virtual Machines Lecture 4 Device Virtualization
General System Architecture and I/O.  I/O devices and the CPU can execute concurrently.  Each device controller is in charge of a particular device.
This document is for informational purposes only, and Tekelec reserves the right to change any aspect of the products, features or functionality described.
Keith Adams, Ole Agesen 1st October 2009 Presented by Chwa Hoon Sung, Kang Joon Young A Comparison of Software and Hardware Techniques for x86 Virtualization.
6.828: PC hardware and x86 Frans Kaashoek
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Architecture Support for OS CSCI 444/544 Operating Systems Fall 2008.
2.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 2: Computer-System Structures Computer System Operation I/O Structure.
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
Chapter 2: Computer-System Structures
DAIMIHenrik Bærbak Christensen1 Virtualization … from a reliability perspective.
1 Chapter 2: Computer-System Structures  Computer System Operation  I/O Structure  Storage Structure  Storage Hierarchy  Hardware Protection  General.
Fall 2012 Chapter 2: x86 Processor Architecture. Irvine, Kip R. Assembly Language for x86 Processors 6/e, Chapter Overview General Concepts IA-32.
The ISA Level The Instruction Set Architecture (ISA) is positioned between the microarchtecture level and the operating system level.  Historically, this.
Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection Network Structure.
1 CSE451 Architectural Supports for Operating Systems Autumn 2002 Gary Kimura Lecture #2 October 2, 2002.
Silberschatz, Galvin and Gagne  Applied Operating System Concepts Chapter 2: Computer-System Structures Computer System Architecture and Operation.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
Lecture 26 Virtual Machine Monitors. Virtual Machines Goal: run an guest OS over an host OS Who has done this? Why might it be useful? Examples: Vmware,
Lecture 12 Virtualization Overview 1 Dec. 1, 2015 Prof. Kyu Ho Park “Understanding Full Virtualization, Paravirtualization, and Hardware Assist”, White.
Protection of Processes Security and privacy of data is challenging currently. Protecting information – Not limited to hardware. – Depends on innovation.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
CSE 451: Operating Systems Winter 2015 Module 25 Virtual Machine Monitors Mark Zbikowski Allen Center 476 © 2013 Gribble, Lazowska,
© 2010 VMware Inc. All rights reserved Introduction to Virtual Machines Carl Waldspurger (SB SM ’89, PhD ’95), VMware R&D.
E Virtual Machines Lecture 1 What is Virtualization? Scott Devine VMware, Inc.
© 2010 VMware Inc. All rights reserved ARM Virtualization: CPU & MMU Issues Prashanth Bungale, Sr. Member of Technical Staff.
Running Commodity Operating Systems on Scalable Multiprocessors Edouard Bugnion, Scott Devine and Mendel Rosenblum Presentation by Mark Smith.
E Virtual Machines Lecture 5 Network Virtualization Scott Devine VMware, Inc.
CS 695 Topics in Virtualization and Cloud Computing, Autumn 2012 CS 695 Topics in Virtualization and Cloud Computing More Introduction + Processor Virtualization.
Scott Devine, VMware, Inc.
Virtualization.
Virtual Machine Monitors
Introduction to Operating Systems
Virtualization D. J. Foreman 2009.
Chapter 2: Computer-System Structures(Hardware)
Chapter 2: Computer-System Structures
Assembly language.
William Stallings Computer Organization and Architecture 8th Edition
x86 segmentation, page tables, and interrupts
Morgan Kaufmann Publishers Large and Fast: Exploiting Memory Hierarchy
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
OS Virtualization.
Computer-System Architecture
Module 2: Computer-System Structures
A Survey on Virtualization Technologies
Computer Architecture
Module 2: Computer-System Structures
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
CSE 451: Operating Systems Autumn Module 24 Virtual Machine Monitors
Lecture 13 Harvard architecture Coccone OS demonstrator
Chapter 2: Computer-System Structures
Chapter 2: Computer-System Structures
Module 2: Computer-System Structures
Module 2: Computer-System Structures
CSE 451: Operating Systems Autumn Module 24 Virtual Machine Monitors
Presentation transcript:

E Virtual Machines Lecture 2 CPU Virtualization Scott Devine VMware, Inc.

Outline CPU Background Virtualization Techniques – System ISA Virtualization – Instruction Interpretation – Trap and Emulate – Binary Translation – Hybrid Models

Computer System Organization CPU MMU Memory Controller Local Bus Interface High-Speed I/O Bus NICControllerBridge Frame Buffer LAN Low-Speed I/O Bus USBCD-ROM

CPU Organization Instruction Set Architecture (ISA) Defines: – the state visible to the programmer registers and memory – the instruction that operate on the state ISA typically divided into 2 parts – User ISA Primarily for computation – System ISA Primarily for system resource management

User ISA - State User Virtual Memory Program Counter Condition Codes Reg 0 Reg 1 Reg n-1 FP 0 FP 1 FP n-1 Special-Purpose Registers General-Purpose Registers Floating Point Registers

User ISA – Instructions Add Sub And Compare … Load byte Load Word Store Multiple Push … Jump Jump equal Call Return … Add single Mult. double Sqrt double … IntegerMemoryControl FlowFloating Point FetchRegistersIssue Integer Memory FP Typical Instruction Pipeline Decode Instruction Groupings

System ISA Privilege Levels Control Registers Traps and Interrupts – Hardcoded Vectors – Dispatch Table System Clock MMU – Page Tables – TLB I/O Device Access System User Extension Kernel Level 0 Level 1 Level 2

Outline CPU Background Virtualization Techniques – System ISA Virtualization – Instruction Interpretation – Trap and Emulate – Binary Translation – Hybrid Models

Isomorphism Formally, virtualization involves the construction of an isomorphism from guest state to host state. Guest SiSi SjSj Host Si’Si’Sj’Sj’ e(S i ) e’(S i ’) V(S i )V(S j )

Virtualizing the System ISA Hardware needed by monitor – Ex: monitor must control real hardware interrupts Access to hardware would allow VM to compromise isolation boundaries – Ex: access to MMU would allow VM to write any page So… – All access to the virtual System ISA by the guest must be emulated by the monitor in software. – System state kept in memory. – System instructions are implemented as functions in the monitor.

Example: CPUState static struct { uint32 GPR[16]; uint32 LR; uint32 PC; int IE; int IRQ; } CPUState; void CPU_CLI(void) { CPUState.IE = 0; } void CPU_STI(void) { CPUState.IE = 1; } Goal for CPU virtualization techniques – Process normal instructions as fast as possible – Forward privileged instructions to emulation routines

Instruction Interpretation Emulate Fetch/Decode/Execute pipeline in software Postives – Easy to implement – Minimal complexity Negatives – Slow!

Example: Virtualizing the Interrupt Flag w/ Instruction Interpreter void CPU_Run(void) { while (1) { inst = Fetch(CPUState.PC); CPUState.PC += 4; switch (inst) { case ADD: CPUState.GPR[rd] = GPR[rn] + GPR[rm]; break; … case CLI: CPU_CLI(); break; case STI: CPU_STI(); break; } if (CPUState.IRQ && CPUState.IE) { CPUState.IE = 0; CPU_Vector(EXC_INT); } void CPU_CLI(void) { CPUState.IE = 0; } void CPU_STI(void) { CPUState.IE = 1; } void CPU_Vector(int exc) { CPUState.LR = CPUState.PC; CPUState.PC = disTab[exc]; }

Trap and Emulate Guest OS + Applications Virtual Machine Monitor Page Fault Undef Instr vIRQ MMU Emulation CPU Emulation I/O Emulation Unprivileged Privileged

“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 …

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

Binary Translator Translator Guest Code Translation Cache Callouts TC Index CPU Emulation Routines

Basic Blocks vPC mov ebx, eax cli and ebx, ~0xfff mov ebx, cr3 sti ret Guest Code Straight-line code Control flow Basic Block

Binary Translation vPC mov ebx, eax cli and ebx, ~0xfff mov ebx, cr3 sti ret mov ebx, eax call HANDLE_CLI and ebx, ~0xfff mov [CO_ARG], ebx call HANDLE_CR3 call HANDLE_STI jmp HANDLE_RET start Guest CodeTranslation Cache

Binary Translation vPC mov ebx, eax cli and ebx, ~0xfff mov ebx, cr3 sti ret mov ebx, eax mov [CPU_IE], 0 and ebx, ~0xfff mov [CO_ARG], ebx call HANDLE_CR3 mov [CPU_IE], 1 test [CPU_IRQ], 1 jne call HANDLE_INTS jmp HANDLE_RET start Guest CodeTranslation Cache

Basic Binary Translator void BT_Run(void) { CPUState.PC = _start; BT_Continue(); } void BT_Continue(void) { void *tcpc; tcpc = BTFindBB(CPUState.PC); if (!tcpc) { tcpc = BTTranslate(CPUState.PC); } RestoreRegsAndJump(tcpc); } void *BTTranslate(uint32 pc) { void *start = TCTop; uint32 TCPC = pc; while (1) { inst = Fetch(TCPC); TCPC += 4; if (IsPrivileged(inst)) { EmitCallout(); } else if (IsControlFlow(inst)) { EmitEndBB(); break; } else { /* ident translation */ EmitInst(inst); } return start; }

Basic Binary Translator – Part 2 void BT_CalloutSTI(BTSavedRegs regs) { CPUState.PC = BTFindPC(regs.tcpc); CPUState.GPR[] = regs.GPR[]; CPU_STI(); CPUState.PC += 4; if (CPUState.IRQ && CPUState.IE) { CPUVector(); BT_Continue(); /* NOT_REACHED */ } return; }

Controlling Control Flow vEPC test eax, 1 jeq add ebx, 18 mov ecx, [ebx] mov [ecx], eax test eax, 1 jeq call END_BB start Guest CodeTranslation Cache ret

Controlling Control Flow vEPC test eax, 1 jeq add ebx, 18 mov ecx, [ebx] mov [ecx], eax test eax, 1 jeq call END_BB Guest CodeTranslation Cache ret add ebx, 18 mov ecx, [ebx] mov [ecx], eax call HANDLE_RET eax == 0 find next

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 Guest CodeTranslation Cache ret add ebx, 18 mov ecx, [ebx] mov [ecx], eax call HANDLE_RET eax == 0

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 Guest CodeTranslation Cache ret add ebx, 18 mov ecx, [ebx] mov [ecx], eax call HANDLE_RET eax == 1 find next mov [ecx], eax call HANDLE_RET

Controlling Control Flow vEPC test eax, 1 jeq add ebx, 18 mov ecx, [ebx] mov [ecx], eax test eax, 1 jeq jmp Guest CodeTranslation Cache ret add ebx, 18 mov ecx, [ebx] mov [ecx], eax call HANDLE_RET eax == 1 mov [ecx], eax call HANDLE_RET

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

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

Hybrid Approach Binary Translation for the Kernel Direct Execution (Trap-and-emulate) for the User U.S. Patent 6,397,242 DirectExec OK? Direct Execution Jump to Guest PC Yes Execute In TC TC Validate Handle Priv. Instruction No Callout Trap

Homework 1 Binary Patching Binary Patching for profiling and code coverage – Process Virtualization – Patching code be compiled into program Follow execution by patching control flow instructions Patch instructions in-place – No need for translation or copying Instruction decoding need only determine – Length of instruction – Control flow points Callouts call through asm linkage – Saves EFLAGS – Saves registers – Calls C code