CPU Virtualization and System Virtualization

CPU Virtualization
Brian Kocoloski
CSE 522S – Advanced Operating Systems
Washington University in St. Louis
St. Louis, MO 63130
1
Virtualization
Virtualization
 refers to the act of
creating a virtual (rather than actual)
version of something
Examples of virtualization we’ve already
seen:
Virtual memory creates illusion of full access to
system memory
Context switching creates illusion of full access
to system CPU(s)
CSE 522S – Advanced Operating Systems
2
Virtualization
Virtual machine: 
emulation of a full computer
system
Rather than virtualize only specific resources to
support multi-processing, we can 
virtualize the
entire platform
 to support multi-operating
systems
Why would we want to?
Cloud computing
Server consolidation + software packaging
Virtual test environments
E.g., OS development for specific hardware platforms
Linux enthusiasts who still can not decide which
distribution is best
CSE 522S – Advanced Operating Systems
3
System Virtualization
Requires a 
hypervisor 
to share and
manage hardware, creating multiple
environments that are isolated from each
other
CSE 522S – Advanced Operating Systems
4
Hardware
OS
P1
P2
Hardware
Hypervisor
P1
P2
OS 1
OS 2
Types of Hypervisors
Type 1: hypervisor runs directly on
hardware (
no host operating system
)
Type 2: hypervisor runs within host
operating system
CSE 522S – Advanced Operating Systems
5
Hardware
Hypervisor
P1
P2
OS 1
OS 2
Hardware
Hypervisor
P1
P2
OS 1
OS 2
Host OS
Ways to Virtualize
The key challenge is to prevent the guest OS
from accessing shared hardware and possibly
corrupting other programs/Oses
As a result, guest behavior must be isolated
from other guests and host processes
Shared state:
CPU registers
Physical memory contents
I/O devices (next lecture)
CSE 522S – Advanced Operating Systems
6
Emulation vs Virtualization
Instruction emulation
Guest OS (and all processes it creates) run as a
user-mode process
An interpreter first checks that instructions are
legal and don’t manipulate shared state
Interpreter can even translate between different
instruction set architectures (ISA)
 (e.g., using
dynamic binary translation)
Hardware virtualization
Guest OS runs directly on the hardware with no
interpreter
CPU provides a 
separate privilege domain 
to
prevent guest from manipulating shared hardware
CSE 522S – Advanced Operating Systems
7
QEMU
qemu.org
Free and open source emulator
Can be configured to perform both 
instruction
emulation in software 
and leverage 
hardware
virtualization features
CSE 522S – Advanced Operating Systems
8
(QEMU) Emulation Example
Assume virtual machine executes:
P1: 
store 4 0xabcd
<ctx switch>
P2: 
store 5 0xabcd
What type of address is 0xabcd?
Virtual address – these should resolve to two different
physical memory locations
But QEMU runs all guest processes within a single user process
(e.g., single address space)
How to determine what the physical addresses are? QEMU
use a 
software MMU 
(memory management unit)
Performs the same functions as a page table – i.e., can convert to
physical address
Problems?
Every memory access requires a SW translation -- 
VERY
slow
CSE 522S – Advanced Operating Systems
9
Emulation Problems
Emulator is a software implementation of
hardware, meaning:
It must understand/interpret all instructions in the
ISA
It must model an MMU (including page tables) to
translate memory locations
It must understand the meaning of special CPU
control registers
Emulation requires the emulator to interpret
every
 instruction issued by the guest OS
Enter 
hardware virtualization
CSE 522S – Advanced Operating Systems
10
Hardware Virtualization
Modern hardware has support for drastically
improving the performance of virtualization
Basic idea: hardware introduces a new
privilege domain called 
supervisor mode
Supervisor mode indicates whether trusted
(host) or untrusted (guest) code is running
Supervisor mode allows the host to 
trap
specific instructions that might modify shared
state, thus retaining isolation
CSE 522S – Advanced Operating Systems
11
CPU Rings
CSE 522S – Advanced Operating Systems
12
https://en.wikipedia.org/wiki/Protection_ring
Rings and Supervisor Modes
Hardware
Hypervisor
P1
P2
Guest OS
Host OS
Ring 0,
Supervisor Mode
Ring 3, Supervisor Mode
Ring 0, Guest Mode
Ring 3, Guest Mode
CSE 522S – Advanced Operating Systems
13
Virtualization Hardware
 (e.g., x86)
VMX root 
(aka
 
host/supervisor mode)
VMX nonroot 
(aka 
guest mode)
Userspace
(e.g., x86 ring 3)
Kernel space
(e.g., x86 ring 0)
Host kernel code
Hypervisor code (e.g., KVM)
Regular userspace
 processes
Guest kernel code
Userspace processes
in the guest
CSE 522S – Advanced Operating Systems
14
Hardware Virtualization
Hardware virtualization allows guest code to run
directly on the hardware
P1: 
store 4 0xabcd 
(guest, userspace)
<ctx switch> (guest, kernel)
 
- will switch in page tables for P2
P2: 
store 5 0xabcd
 (guest, userspace)
Both of these processes run on the hardware
without emulation
The CPU’s page tables are used to map these
guest virtual addresses to distinct physical
memory locations (more on this on Weds)
CSE 522S – Advanced Operating Systems
15
Studio
Today’s studio gives you experience using
QEMU emulator and KVM hypervisor on
the Raspberry Pi
Support for KVM on ARM based CPUs is
very recent
We need to update the OS on the Raspberry Pi
Measure performance of virtualization vs
emulation
CSE 522S – Advanced Operating Systems
16
Slide Note
Embed
Share

Virtualization involves creating virtual versions of systems, such as virtual memory and virtual machines, to optimize resources and support multiple operating systems. Hypervisors are essential for managing hardware and creating isolated environments. Different types of hypervisors exist, with the key challenge being to prevent guest OS from accessing shared hardware. Emulation and hardware virtualization are two approaches to virtualization, each with its unique processes and benefits.

  • CPU Virtualization
  • System Virtualization
  • Hypervisors
  • Virtual Machines
  • Emulation

Uploaded on Oct 07, 2024 | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. CPU Virtualization Brian Kocoloski CSE 522S Advanced Operating Systems Washington University in St. Louis St. Louis, MO 63130 1

  2. Virtualization Virtualization refers to the act of creating a virtual (rather than actual) version of something Examples of virtualization we ve already seen: Virtual memory creates illusion of full access to system memory Context switching creates illusion of full access to system CPU(s) CSE 522S Advanced Operating Systems 2

  3. Virtualization Virtual machine: emulation of a full computer system Rather than virtualize only specific resources to support multi-processing, we can virtualize the entire platform to support multi-operating systems Why would we want to? Cloud computing Server consolidation + software packaging Virtual test environments E.g., OS development for specific hardware platforms Linux enthusiasts who still can not decide which distribution is best CSE 522S Advanced Operating Systems 3

  4. System Virtualization Requires a hypervisor to share and manage hardware, creating multiple environments that are isolated from each other P2 P1 OS 2 P1 P2 OS 1 OS Hypervisor Hardware Hardware CSE 522S Advanced Operating Systems 4

  5. Types of Hypervisors Type 1: hypervisor runs directly on hardware (no host operating system) Type 2: hypervisor runs within host operating system P2 P1 P2 P1 OS 2 OS 1 OS 2 OS 1 Hypervisor Hypervisor Host OS Hardware Hardware CSE 522S Advanced Operating Systems 5

  6. Ways to Virtualize The key challenge is to prevent the guest OS from accessing shared hardware and possibly corrupting other programs/Oses As a result, guest behavior must be isolated from other guests and host processes Shared state: CPU registers Physical memory contents I/O devices (next lecture) CSE 522S Advanced Operating Systems 6

  7. Emulation vs Virtualization Instruction emulation Guest OS (and all processes it creates) run as a user-mode process An interpreter first checks that instructions are legal and don t manipulate shared state Interpreter can even translate between different instruction set architectures (ISA) (e.g., using dynamic binary translation) Hardware virtualization Guest OS runs directly on the hardware with no interpreter CPU provides a separate privilege domain to prevent guest from manipulating shared hardware CSE 522S Advanced Operating Systems 7

  8. QEMU qemu.org Free and open source emulator Can be configured to perform both instruction emulation in software and leverage hardware virtualization features CSE 522S Advanced Operating Systems 8

  9. (QEMU) Emulation Example Assume virtual machine executes: P1: store 4 0xabcd <ctx switch> P2: store 5 0xabcd What type of address is 0xabcd? Virtual address these should resolve to two different physical memory locations But QEMU runs all guest processes within a single user process (e.g., single address space) How to determine what the physical addresses are? QEMU use a software MMU (memory management unit) Performs the same functions as a page table i.e., can convert to physical address Problems? Every memory access requires a SW translation -- VERY slow CSE 522S Advanced Operating Systems 9

  10. Emulation Problems Emulator is a software implementation of hardware, meaning: It must understand/interpret all instructions in the ISA It must model an MMU (including page tables) to translate memory locations It must understand the meaning of special CPU control registers Emulation requires the emulator to interpret every instruction issued by the guest OS Enter hardware virtualization CSE 522S Advanced Operating Systems 10

  11. Hardware Virtualization Modern hardware has support for drastically improving the performance of virtualization Basic idea: hardware introduces a new privilege domain called supervisor mode Supervisor mode indicates whether trusted (host) or untrusted (guest) code is running Supervisor mode allows the host to trap specific instructions that might modify shared state, thus retaining isolation CSE 522S Advanced Operating Systems 11

  12. CPU Rings https://en.wikipedia.org/wiki/Protection_ring CSE 522S Advanced Operating Systems 12

  13. Rings and Supervisor Modes Ring 3, Guest Mode P1 Ring 0, Guest Mode Guest OS Hypervisor P2 Ring 3, Supervisor Mode Ring 0, Supervisor Mode Host OS Hardware CSE 522S Advanced Operating Systems 13

  14. Virtualization Hardware (e.g., x86) Userspace processes in the guest Guest kernel code VMX nonroot (aka guest mode) Regular userspace processes VMX root (aka Host kernel code Hypervisor code (e.g., KVM) host/supervisor mode) Userspace (e.g., x86 ring 3) Kernel space (e.g., x86 ring 0) CSE 522S Advanced Operating Systems 14

  15. Hardware Virtualization Hardware virtualization allows guest code to run directly on the hardware P1: store 4 0xabcd (guest, userspace) <ctx switch> (guest, kernel) - will switch in page tables for P2 P2: store 5 0xabcd (guest, userspace) Both of these processes run on the hardware without emulation The CPU s page tables are used to map these guest virtual addresses to distinct physical memory locations (more on this on Weds) CSE 522S Advanced Operating Systems 15

  16. Studio Today s studio gives you experience using QEMU emulator and KVM hypervisor on the Raspberry Pi Support for KVM on ARM based CPUs is very recent We need to update the OS on the Raspberry Pi Measure performance of virtualization vs emulation CSE 522S Advanced Operating Systems 16

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#