Today
-
Why virtualize?
$ cat announce.txt
-
ASST3.2 is due Friday @ 5PM.
-
Schedule change today: virtualization is awesome!
-
Please suggest topics for later in the class…
Read "Xen and the Art of Virtualization" (PDF) for Wednesday.
What Is Virtualization?
Until today we’ve been talking about operating systems running on physical machines: a collection of
-
real hardware resources,
-
that the operating system has exclusive access to
-
through hardware interfaces (instruction set architectures, device I/O ports, etc.
What Is Virtualization?
Operating systems can also run inside virtual machines (VMs) implemented by virtual machine monitors (VMMs).
-
We refer to an operating system running inside a virtual machine as a guest OS.
-
They do not provide the guest OS with exclusive access to the underlying physical machine.
-
Equivalently, they do not provide the guest OS with privileged (or fully-privileged) access to the physical machine.
What Is Virtualization?
-
a piece of software running on an operating system (the host OS)
-
that can allow another operating system (the guest OS) to be run as an application
-
alongside other applications.
-
When we said that the operating system was really just another program we weren’t kidding!
This is not
The only matrix
Why Virtualize?
(Clearly there is a big how question here, but let’s start with why!)
-
We’ve been talking about operating systems all semester…
-
…and I hope by this point I’ve convinced you that they are pretty great.
But just for the sake of argument… what might be some problems with the operating system environments we’ve discussed thus far?
Problems with Operating Systems: Hardware Coupling
-
Hard to run multiple operating systems on the same machine. (Geeky.)
-
Difficult to transfer software setups to another machine, unless it has identical or nearly identical hardware.
-
Messy to adjust hardware resources to system needs. Requires sticking your hand in the box and mucking around.
-
Requires static, up-front provision of machine resources.
Problems with Operating Systems: Application Isolation
-
Operating systems "leak" a lot of information between processes through the file system and other channels.
-
Multiple applications may require specific (and conflicting) software packages to run.
-
Certain applications may have very specific operating systems configuration and tuning requirements.
-
In some cases, software vendors will not provide support if you are running their precious application alongside anything else.
Why We Virtualize
-
We can package and distribute an entire software development environment which can be used and discarded.
-
We can dynamically divide up one large machine into multiple smaller machines, each running a different operating system and applications.
-
We can easily replicate an entire machine image in order to duplicate or move it.
To Be a VMM
In 1974 (!) Popek and Goldberg provide three essential requirements for a piece of software to be considered a virtual machine monitor (VMM), or to implement a virtual machine:
-
Fidelity: software on the VMM executes identically to how it would on real hardware (modulo timing effects).
-
Performance: to achieve good performance most instructions executed by the guest OS should be run directly on the underlying physical hardware.
-
Safety: the VMM should manage all hardware resources.
Two Approaches to Virtualization
-
Full virtualization. Should be able to run an unmodified guest OS. We will discuss this today.
-
Paravirtualization. Includes small changes to the guest operating system to improve interaction with the virtual machine monitor. We will read this paper for Monday.
Full Virtualization
Our goal: run an unmodified operating system and applications in a VM itself running on a host OS and potentially next to other VMs.
-
VMware is the best-known provider of full virtualization software solutions.
-
How do we handle traps by applications running in the guest OS?
-
Guest OS will try to execute privileged instructions!
De-Privileging the Guest OS
-
Privileged instructions work as expected, but guest has access to the entire machine! (Violates safety.)
-
Need to figure out how to deal with privileged instructions…
Trapping Privileged Instructions
Ideally, when privileged instructions are run by the guest OS at user privilege level:
-
The CPU traps the instruction due to a privilege violation.
-
The trap is handled by the VMM.
-
Assuming the guest OS is doing something legitimate, the VMM adjusts the VM state and continues the guest OS.
-
We refer to an instruction set having this property as classically virtualizable.
-
We refer to the approach described above as trap and emulate.
Trap and Emulate
-
If the trap is caused by an application, pass the trap to the guest OS.
-
If the trap is caused by the guest OS, handle the trap by adjusting the state of the virtual machine.
Getting Trappy
VMware and VirtualBox VMMs run as standard system processes but require operating system support.
-
All traps and exceptions originating inside the VM must be handled by the VMM.
-
Most of the time guest applications and the guest OS simply use the physical processor normally.
-
syscall
: host OS vectors trap to VMM. -
VMM inspects trap, identifies it as a system call, and passes control and arguments to the guest OS trap handling code.
-
rfe
: when the guest OS is done, it will also trap back to the VMM by executing a privileged instruction. -
VMM will pass arguments back to the process that originated the system call.
Getting (Really) Trappy
-
Trap to the host OS.
-
Hand trap to the VMM.
-
VMM inspects trap, sees that it was generated by the application, passes control to the guest OS.
-
Guest OS begins handling the TLB fault, tries to load an entry into the TLB.
-
Trap to the host OS.
-
Hand trap to the VMM.
-
VMM inspects trap, sees that it was generated by the guest OS, adjusts the state of the virtual machine appropriately.
Hardware Virtualization
Note that what is being virtualized is the hardware interface.
Let’s compare to virtual memory:
-
Load and store.
Translate every unprivileged memory access.
-
Cache translations in the TLB.
What about full hardware virtualization:
-
All instructions executed on the processor that modify the state of the machine.
-
Intercept or rewrite unsafe instructions that could "pierce" the VM.
-
Allow safe instructions to run directly on the physical hardware (or "bare metal").
Sadly
The x86 architecture is not (or was not) classically virtualizable.
-
Some instructions did not trap correctly.
-
Others had different side effects when run in kernel or user mode. Ugh.
-
During guest OS execution scan code pages for non-virtualizable instructions and rewrite them to safe instruction sequences.
-
Cache translations to improve performance.
A Short, Non-Exhaustive List of Cool Details I Have Glossed Over
-
x86 privilege rings.
-
Primary and shadow page tables.
-
Memory traces.
-
x86 extensions to better support virtualization.
-
Lot’s of good resources out there to learn more.
Next Time
-
Paravirtualization.