Download presentation
Presentation is loading. Please wait.
Published byMolly Garrison Modified over 9 years ago
1
Lecture 26 Virtual Machine Monitors
3
Virtual Machines Goal: run an guest OS over an host OS Who has done this? Why might it be useful? Examples: Vmware, VirtualBox, Xen, KVM, Azure, Parallels Desktop, etc.
4
Motivation Functionality: want Linux programs on Mac OS X Consolidation: avoid light utilization Cloud computing: fast scalability Testing/Development: for example, xinu
5
Needs An OS expects to run on raw hardware. Need to give illusion to OS of private ownership of H/W. Didn’t we already virtualize H/W? How is this different?
6
Process Virtualization We have done two things: given illusion of private resources provided more friendly interface The interface (what processes see/use): virtual memory most instructions most registers syscalls, files, etc
7
Machine Virtualization We have done two things: given illusion of private resources provided more friendly interface The interface (what guest OS’s see/use): “physical” memory all instructions (even dangerous ones!) all registers “physical” devices, interrupts, disks, etc.
8
System Models Hardware Linux P1P3P2 VMM Linux P1P3P2 Hardware
9
VMM Linux P1P3P2 Hardware OS X P1P3P2 Windows P1P3P2
10
Hypervisor Linux P1P3P2 Hardware OS X P1P3P2 Windows P1P3P2
11
Architecture of Disco
12
Components to be Virtualized CPU Memory I/O
13
Approach 1 Write a simulator. For example: big array for “physical” memory run over OS instructions, call function for each Problems? Performance Solution? Limited Direct Execution!
14
Approach 2: Limited Direct Execution Hypervisor runs in kernel mode and can do anything. Processes and guest OS’s run in user mode when they don’t need to do anything privileged. Machine switch save the entire machine state (including registers, PC, and any privileged hardware state) restore the machine state of the to-be-run VM jump to the PC of the to-be-run VM
15
Process Privilege Process: how do processes correctly do privileged ops?
16
Executing a System Call
18
System Call Flow Without Virtualization
19
System Call Flow with Virtualization Must also have the VMM in the middle… Process Guest OS VMM system call: trap to OS process trapped: call os Trap handler (at reduced privilege) OS trap handler: decode trap, exec syscall return-from-trap OS tried return-from-trap: do real return-from-trap resume execution: (@PC after trap)
20
Where is the Guest OS Handler Without virtualization OS initialize trap table With virtualization When OS tries to initialize trap table, it traps into the VMM
21
Trap Table Initialization with Virtualization Must also have the VMM in the middle… VMM H/W Guest OS Initialize trap table Remember address Of various handlers Switch to guest Initialize trap table Store guest trap Table address User mode Kernel mode
22
System Call Flow with Virtualization There is overhead Disco takes advantage of supervisor mode on MIPS Process Guest OS VMM system call: trap to OS process trapped: call os Trap handler (at reduced privilege) OS trap handler: decode trap, exec syscall return-from-trap OS tried return-from-trap: do real return-from-trap resume execution: (@PC after trap)
23
Timer Interrupt Handlers VMM Trap Handler! tick() { if (…) { switch OS; } else { call OS tick; } Guest OS Trap Handler! tick() { maybe switch process; return-from-trap; }
24
Timer Interrupt Example VMM Linux P1P3P2 OS X P1P3P2 Windows P1P3P2
25
Another Example VMM Linux P1P3P2 OS X P1P3P2 Windows P1P3P2 P1 calls lidt! Linux kills P1. Privileged? Linux tries to return-from-trap to P2. Privileged?
26
Components to be Virtualized CPU Memory I/O
27
How to get more pages? Process: asks politely OS: just uses it! VMM needs to intercept such usage. How? (assume software-managed TLB)
29
Strategy: store VPN => MFN mapping in TLB. OS tries to insert VPN => PFN to TLB VMM intercepts it, looks up in its PT, inserts VPN => MFN Examples… Timeline…
30
Process Guest OS VMM Mem load TLB miss: trap Call OS TLB handler (reducing privilege) Extract VPN from VA. Do page table lookup. Get PFN, update TLB Unprivileged code trying to update TLB! Tried to install VPN-to-PFN. Insert VPN-to-MFN. Jump back to OS. Return from trap Return from trap. Resume execution: (@PC of instruction)
31
A VMM-level “Software TLB” TLB misses become more expensive on a virtualized system Extra steps to handle TLB miss TLB is shared TLB is flushed on machine switch A VMM-level “software TLB” Records every virtual-to-physical mapping that it sees the OS try to install Check whether it has the desired virtual-to-machine mapping
32
Information Gap OS’s were not built to run on top of a VMM. (less true than it used to be) H/W interface does not give VMM enough info about guest OS. In particular, is the OS using all its resources? How does the VMM know to give CPU to another OS? How does the VMM know to give pages to another OS? How does OS know page is already zeroed? Para-virtualization
33
Summary VM’s have overheads. New opportunities for sharing often outweigh the disadvantages, as utilization is improved.
34
TLB and Virtual Machine Monitor TLB Flows: We have an application accessing memory running on an OS with a software managed TLB. Assume, for simplicity, a simple linear page table kept in physical memory. Here are some different hardware and software things that can happen during memory access (next slide). At first, assume we are not running on a VMM, i.e., this is just an application running on top of the OS. (a) Write down the flow that occurs when a user application encounters a TLB hit: (b) Write down the flow that occurs when a user application encounters a TLB miss to a valid page that is present in memory: (c) Write down the flow that occurs when a user application encounters a TLB miss to a valid page that is not present in memory: Now assume that the OS is running on a virtual machine monitor. (d) Write down the flow that occurs when a user application encounters a TLB hit: (e) Write down the flow that occurs when a user application encounters a TLB miss to a valid page that is present in memory:
35
0. the hardware checks the TLB to see if the VPN-to-PFN (or VPN-to-MFN if on a VMM) translation is present 1. the hardware issues a load to a physical address (or machine address if on a VMM) 2. the OS code at the start of the TLB miss handler runs 3. the OS code at the end of the TLB miss handler runs, which returns from trap 4. the OS code that accesses the page table to lookup a translation runs 5. the OS code that updates the TLB with a new mapping runs 6. the OS code that updates the page table with a new VPN-to-PPN mapping runs 7. a disk request is initiated 8. a disk request completes 9. the VMM code at the start of the VMM TLB miss handler runs 10. the VMM code at the end of the VMM TLB miss handler runs, which returns from trap) 11. the VMM code that updates the TLB with a new mapping runs
36
Next Multiprocessor Scheduling Linux Scalability
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.