W4118: virtual machines

Similar documents
Virtualization. Adam Belay

Virtualization. Dr. Yingwu Zhu

x86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT

Overview of System Virtualization: The most powerful platform for program analysis and system security. Zhiqiang Lin

IA32 Intel 32-bit Architecture

Virtualization. Pradipta De

CIS Operating Systems CPU Mode. Professor Qiang Zeng Spring 2018

CS 550 Operating Systems Spring Introduction to Virtual Machines

ECE 331 Hardware Organization and Design. UMass ECE Discussion 11 4/12/2018

Operating Systems Engineering Recitation #3 (part 2): Interrupt and Exception Handling on the x86. (heavily) based on MIT 6.

Background. IBM sold expensive mainframes to large organizations. Monitor sits between one or more OSes and HW

Microkernel Construction

[537] Virtual Machines. Tyler Harter

Microkernel Construction

Intel VMX technology

Linux and Xen. Andrea Sarro. andrea.sarro(at)quadrics.it. Linux Kernel Hacking Free Course IV Edition

Virtual Virtual Memory

Virtual Machines and Dynamic Translation: Implementing ISAs in Software

CS5460: Operating Systems. Lecture: Virtualization. Anton Burtsev March, 2013

ECE331: Hardware Organization and Design

Virtual Machines. Part 2: starting 19 years ago. Operating Systems In Depth IX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

W4118: interrupt and system call. Junfeng Yang

24-vm.txt Mon Nov 21 22:13: Notes on Virtual Machines , Fall 2011 Carnegie Mellon University Randal E. Bryant.

COS 318: Operating Systems. Virtual Machine Monitors

Mechanisms for entering the system

Advanced Computer Architecture

Lecture 3: O/S Organization. plan: O/S organization processes isolation

Virtualization and Virtual Machines. CS522 Principles of Computer Systems Dr. Edouard Bugnion

T Jarkko Turkulainen, F-Secure Corporation

Pre-virtualization internals

CSCE 410/611: Virtualization!

COMPUTER ARCHITECTURE. Virtualization and Memory Hierarchy

Module 1: Virtualization. Types of Interfaces

Introduction to Virtual Machines. Carl Waldspurger (SB SM 89 PhD 95) VMware R&D

Operating Systems 4/27/2015

Virtualization. Operating Systems, 2016, Meni Adler, Danny Hendler & Amnon Meisels

Tutorial 10 Protection Cont.

Fast access ===> use map to find object. HW == SW ===> map is in HW or SW or combo. Extend range ===> longer, hierarchical names

CSCE 410/611: Virtualization

1 Confining code with legacy OSes. 2 Virtual machines. 3 Implementing virtual machines. 4 Binary translation. 5 Hardware-assisted virtualization

Virtualization and memory hierarchy

CSE 120 Principles of Operating Systems

int $0x32 // call interrupt number 50

Operating Systems and Protection CS 217

Administrivia. Last project due Friday Final Exam. Final review session Friday (recorded) Extra office hours for me 1:30pm-4:30pm Friday

CS 550 Operating Systems Spring Interrupt

Advanced Operating Systems (CS 202) Virtualization

CSC 5930/9010 Cloud S & P: Virtualization

ICS143A: Principles of Operating Systems. Midterm recap, sample questions. Anton Burtsev February, 2017

Background. IBM sold expensive mainframes to large organiza<ons. Monitor sits between one or more OSes and HW

Background. IBM sold expensive mainframes to large organiza<ons. Monitor sits between one or more OSes and HW

6.828: Using Virtual Memory. Adam Belay

Confining code with legacy OSes. Administrivia. Escaping chroot. Using chroot. System call interposition. Limitations of syscall interposition

Chapter 5 C. Virtual machines

Virtualization. Virtualization

W4118: PC Hardware and x86. Junfeng Yang

Virtualization. ...or how adding another layer of abstraction is changing the world. CIS 399: Unix Skills University of Pennsylvania.

Virtual Machine Monitors (VMMs) are a hot topic in

Virtual Machines. To do. q VM over time q Implementation methods q Hardware features supporting VM q Next time: Midterm?

CS 350 Winter 2011 Current Topics: Virtual Machines + Solid State Drives

Chapter 5 B. Large and Fast: Exploiting Memory Hierarchy

CS140 Operating Systems Final December 12, 2007 OPEN BOOK, OPEN NOTES

MICROPROCESSOR MICROPROCESSOR ARCHITECTURE. Prof. P. C. Patil UOP S.E.COMP (SEM-II)

Portland State University ECE 587/687. Virtual Memory and Virtualization

143A: Principles of Operating Systems. Lecture 5: Address translation. Anton Burtsev October, 2018

Summer 2003 Lecture 27 07/28/03

CSE 237B Fall 2009 Virtualization, Security and RTOS. Rajesh Gupta Computer Science and Engineering University of California, San Diego.

Fast access ===> use map to find object. HW == SW ===> map is in HW or SW or combo. Extend range ===> longer, hierarchical names

OS Virtualization. Why Virtualize? Introduction. Virtualization Basics 12/10/2012. Motivation. Types of Virtualization.

Xen and the Art of Virtualization. Nikola Gvozdiev Georgian Mihaila

Software Virtualization Based Rootkits

Virtual Machines. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

1 Confining code with legacy OSes. 2 Virtual machines. 3 Implementing virtual machines. 4 Binary translation. 5 Hardware-assisted virtualization

PROTECTION CHAPTER 4 PROTECTION

Embedded Systems Programming

CS 152 Computer Architecture and Engineering. Lecture 22: Virtual Machines

CS 5600 Computer Systems. Lecture 11: Virtual Machine Monitors

Part I. X86 architecture overview. Secure Operating System Design and Implementation x86 architecture. x86 processor modes. X86 architecture overview

The Architecture of Virtual Machines Lecture for the Embedded Systems Course CSD, University of Crete (April 29, 2014)

iapx86 Protection Electronic Computers M

Testing System Virtual Machines

iapx Systems Electronic Computers M

What You Need to Know for Project Three. Dave Eckhardt Steve Muckle

Chapter 5 (Part II) Large and Fast: Exploiting Memory Hierarchy. Baback Izadi Division of Engineering Programs

CS 252 Graduate Computer Architecture. Lecture 15: Virtual Machines

references Virtualization services Topics Virtualization

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

238P: Operating Systems. Lecture 5: Address translation. Anton Burtsev January, 2018

CSCI 8530 Advanced Operating Systems. Part 19 Virtualization

Spring 2017 :: CSE 506. Introduction to. Virtual Machines. Nima Honarmand

Computer Architecture Lecture 13: Virtual Memory II

An overview of virtual machine architecture

Lecture 5: February 3

CS370 Operating Systems

Assembly Language. Lecture 2 - x86 Processor Architecture. Ahmed Sallam

CS 61 Section Notes 5

CS3210: Isolation Mechanisms

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

Function Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site)

x86 architecture et similia

Transcription:

W4118: virtual machines Instructor: Junfeng Yang References: Modern Operating Systems (3 rd edition), Operating Systems Concepts (8 th edition), previous W4118, and OS at MIT, Stanford, and UWisc

Virtual machines (VM) VM0 VM1 VM2 VM4 Software Real computer CPU Memory Devices 1

Why virtual machines? Manage big machines Multiplex CPUs/memory/devices at VM granularity E.g., Amazon EC2 Multiple OS on one machine E.g., use Windows on Linux OS Isolate faults/break-ins One VM is compromised/crashes, others OK Kernel development Like QEMU, but faster OS granularity checkpoint/record/replay 2

Usual VM goals Accurate Guest can t distinguish VM from real computer Isolated Guest can t escape VM Fast Some VM implementations require guest kernel modifications E.g., Xen 3

Virtual machine lineage 1960s: IBM used VMs to share mainframe VM/370, today s z/vm Still in use! 1990s: VMWare re-popularized VMs for x86 VMWare ESX servers VMWare work station 4

Virtual machine structures User programs Guest OS Virtual Machine Monitor (VMM) Real computer guest host User programs Guest OS Virtual Machine Monitor (VMM) Host OS Real computer 5

VMM responsibilities Time-share CPU among guests Space-share memory among guests Simulate disk, network, and other devices Often multiplex on host devices 6

Naïve approach: simulation Interpret each guest instruction Maintain each VM state purely in software Problem: too slow! 7

2 nd approach: trap-and-emulate Execute guest instructions on real CPU when possible E.g., addl %eax, %ebx Run guest OS in unprivileged mode Privileged instructions trap, and VMM emulates E.g., movl %eax, %cr3 VMM hides real machine state from guests E.g., virtual %cr3 set by guest, real %cr3 set by VMM, More: page table, privilege level, interrupt flag, 8

Trap-and-emulate: tricky on x86 Not all instructions that should be emulated cause traps Instructions have different effects depending on privilege mode Instructions reading privileged state don t trap Page table modifications don t trap Trap them all slow 9

Real x86 state to hide&protect CPL (low bits of CS) = 3, but guest expects 0 Physical memory: guest expects 0..PHYSTOP, VMM maps to one slice of physical memory Page table: don t map to physical addresses expected by guest OS Shadow page table %cr3: points to shadow page table 10

Real x86 state to hide&protect (cont.) GDT: guest OS descriptors have DPL = 3, but guest expects 0 GDTR: points to shadow GDT table IDT descriptors: traps go to VMM, not guest IDTR: points to shadow IDT table IF in EFLAGS: guest expects 0 after cli 11

Virtualize physical memory Guest wants Physical address starts at PA = 0 Use all physical memory VMM must Space-share all physical memory among guests Protect one guest s memory from another Idea: Claim DRAM smaller than real DRAM Ensuring paging is enabled Rewrite guest s PTEs to map to real PA Copy guest s PTEs to shadow page table and map copied PTEs to real PA 12

Example: VMM allocates a guest 0x1000000-0x2000000 13

Do all instructions that read/write sensitive state cause traps at CPL = 3? pushw %cs: reveals CPL = 3, not 0 sgdt: reveals real GDTR sidt: reveals real IDTR pushfl: reveals IF flag popfl: if CPL = 3, no trap iret: no privilge mode change so won t restore SS/ESP 14

3 rd approach: binary translation Simplified idea Replace non-trapping instructions that read/write sensitive state with trap instruction int3: triggers a break point exception. Shortest instruction (1 byte), doesn t change code size/layout Keep track of original instruction VMM emulate original instruction in trap Problems: how does the rewriter find all code? Or where the instruction boundaries are, Or whether bytes are code or data 15

Dynamic binary translation Idea: disassemble code only as executed, since jump instructions reveal where code is When VMM first loads guest kernel, translate from entry (fixed) up to first jump Replace bad instructions with equivalent instructions on virtual states Replace jmp X with movl X, %eax; jmp translator; In translator, look where the jump goes Repeat above steps Keep track of what we ve translated to avoid retranslate Store translated code in code cache (original translated mapping) 16

Binary translation example Entry: pushl %ebp popfl jnz x x: jmp y Entry : pushl %ebp vm->if = popfl movl x, %eax jnz translator x : movl y, %eax jmp translator 17

Handling page table modifications VMM must make shadow page table entries (PTEs) consistent with guest PTEs PTE loading: copy guest PTEs to shadow PTEs on context switch PTE tracing: when guest modifies guest PTEs, modify shadow PTEs as well 18

PTE loading Naïve approach: on guest %cr3 write, copy all gueste PTES Problem: slow context switch Another approach: start with minimum mappings (just the PTEs of VMM), and copy on demand Problem: too many page faults Approach used in VMware: reuse populated shadow PTEs 19

PTE tracing Approach I: mark the memory region holding guest PTES as readonly, and copy updates to shadow PTEs on hidden page faults Problem: too many page faults Approach II: binary translate code that writes to shadow PTEs to call out to VMM Faster than traps 20

4 th approach: hardware support Simplified implementation of VMM Hardware maintains per-guest virtual state CPL, EFLAGS, idtr, etc Hardware knows it is in guest mode Instructions directly modify virtual state Avoids many traps to VMM 21

Hardware support details Hardware basically adds a new privilege level VMM mode, CPL=0, CPL=3 Guest-mode, CPL=0 is not fully privileged No traps on system calls; hardware handles CPL transition Hardware supports two page tables: guest page table and VMM s page table Virtual address guest physical address Guest physical address host physical address 22