46
KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Embed Size (px)

Citation preview

Page 1: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

KVM/ARM: The Design and Implementation of the Linux ARM

Hypervisor

Fall 2014

Presented By: Probir Roy

Page 2: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Virtualization & Hypervisor

www.qyjohn.net

Page 3: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Virtualization & Hypervisor (cont.)

www.software.intel.com

Xen, VMWare ESX

Bare Metal / Native Hypervisor

VMWare Workstation

Hosted Hypervisor

Which type of Hypervisor is better?

Page 4: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

KVM/ARM: The Design and Implementation of the Linux ARM

Hypervisor

ARM

Linux Kernel Hypervisor (KVM)

QEMU

Guest OS

Apps

QEMU

Guest OS

Apps

QEMU

Guest OS

Apps

QEMU

Guest OS

Apps

Full Virtualization

Page 5: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Prior ARMV7

Cannot Emulate

Trap & EmulateNot Classically Virtualizable

Page 6: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

ARM V7 Virtualization Extension

Trap & Emulate

Page 7: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

CPU Virtualization

From Hyp Mode, hardware Configurable to trap sensitive instructions and interrupt to Hyp ModeHardware Configurable to trap sensitive instructions and interrupt directly to VM's Kernel mode

Trap

Trap

Why trapping at Kernel Mode is useful?

Page 8: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

CPU Virtualization

Hypervisor should be lightweight and simple to program

Reduced Number of Control Registers

Page tables entries is protected from user mode, as they should not be shared with user mode

Hyp mode has its own separate address space

Page 9: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Memory Virtualization

http://www.cs.columbia.edu/~cdall/pubs/KVMARM_talk.pdf

Hardware support to virtualize physical memory: Stage 2 Page Tables

Enabled/Disabled from Hyp Mode

Page 10: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Interrupt VirtualizationGeneric Interrupt Controller

http://infocenter.arm.com/

Configures GIC

Send ACK & EOI(End-of-interrupt)

Page 11: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Interrupt VirtualizationGeneric Interrupt Controller

http://infocenter.arm.com/

Cumbersome & Expensive

Trapping Interrupt in Hyp Mode

Hardware

Hypervisor

1) Interrupt

2) Trap

VM3) Emulate Virtual Interrupt

By signal

Page 12: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Interrupt VirtualizationGeneric Interrupt Controller (V2.0)

http://infocenter.arm.com/

Virtual GIC

Virtual CPU Interfaces

But No Virtual Distributor

Why Virtual Distributor is required?

Page 13: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Interrupt VirtualizationGeneric Interrupt Controller (V2.0)

http://infocenter.arm.com/

Virtual GIC

Trapping Interrupt in Kernel Mode

Virtual Hardware

Hypervisor

1) Interrupt

2) Trap

VM

Page 14: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Timer VirtualizationGeneric Timer support

http://infocenter.arm.com/

ARM introduces Virtual Timer and Counter

But requires Timer operations to be performed by Hyp

CPU 0

Counter

Timer 0

CPU 1Timer 1

CPU 2Timer 2

CPU 3Timer 3

Can be configured from Hyp Mode

Page 15: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Timer VirtualizationGeneric and Virtualized Timer support

CPU 0

Counter

Timer 0

Virtual CPU 0Virtual Timer 0

CPU 1Timer 1

Virtual CPU 1Virtual Timer 1

CPU 2Timer 2

Virtual CPU 2Virtual Timer 2

CPU 3Timer 3

Virtual CPU 3Virtual Timer 3

Virtual Counter

Virtual Counter

Virtual Counter

Virtual Counter

Accessible from Hyp mode

Accessible from VMs

Why Virtual Timer support is required?

Page 16: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Hypervisor Architecture

Linux Kernel KVM

Firstly, Linux is written to work in kernel mode and would not run unmodified in Hyp Mode

Secondly, Running entire kernel in Hyp Mode would adversely affect native performance

Hyp mode has its own separate address space. This requires explicitly map user space data while accessing user space memory

Some registers and table formats are different in Hyp mode than in kernel mode

Page 17: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Hypervisor ArchitectureSplit-Mode Virtualization

Linux Kernel KVM

http://www.cs.columbia.edu/~cdall/pubs/KVMARM_talk.pdf

Page 18: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Hypervisor ArchitectureSplit-Mode Virtualization

Handles High level

Functionality

Handles Low Level

Functionality

http://www.cs.columbia.edu/~cdall/pubs/KVMARM_talk.pdf

Page 19: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Hypervisor ArchitectureSplit-Mode Virtualization

http://www.cs.columbia.edu/~cdall/pubs/KVMARM_talk.pdf

Page 20: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Hypervisor ArchitectureSplit-Mode Virtualization

Store GP regs, host config

Configure VGIC, Virtual Timer, Traps, stage2 pagetable regs Restore Guest GP regs, VM

config

Page 21: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Hypervisor ArchitectureSplit-Mode Virtualization

Lowvisor creates correct execution context by configuring hardware

Page 22: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Hypervisor ArchitectureSplit-Mode Virtualization

http://www.cs.columbia.edu/~cdall/pubs/KVMARM_talk.pdf

Page 23: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Hypervisor ArchitectureSplit-Mode Virtualization

Lowvisor: Handles Interrupts and Exceptions

Page 24: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Hypervisor ArchitectureSplit-Mode Virtualization

http://www.cs.columbia.edu/~cdall/pubs/KVMARM_talk.pdf

Page 25: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Hypervisor ArchitectureWhat are the Functionalities of LowVisor?

Trap handler: Handles Interrupt and Exception

Set Correct Execution context by configuring hardware

Perform Context Switch between Host and VM execution context

Page 26: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Hypervisor Architecture

Perform Context Switch between Host and VM execution context

Host Execution Context Virtual Execution Context

Page 27: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

CPU Virtualization

Perform Context Switch between Host and VM execution context

Page 28: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

CPU Virtualization

Perform Context Switch between Host and VM execution context

Page 29: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Memory Virtualization

Configuring page tables is a high level Functionality

http://www.cs.columbia.edu/~cdall/pubs/KVMARM_talk.pdf

Page 30: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Memory Virtualization

But LowVisor has hardware access as it runs in Hyp Mode

Page 31: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Memory Virtualization

Page Fault

get_user_pages()

http://www.cs.columbia.edu/~cdall/pubs/KVMARM_talk.pdf

Page 32: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Interrupt Virtualization

http://www.cs.columbia.edu/~cdall/pubs/KVMARM_talk.pdf

Page 33: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Interrupt Virtualization

http://www.cs.columbia.edu/~cdall/pubs/KVMARM_talk.pdf

Page 34: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Interrupt Virtualization

KVM/ARM implements virtual GIC Distributor in software

What happens when a virtual interrupt occurs?

Page 35: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Timer Virtualization

http://www.cs.columbia.edu/~cdall/pubs/KVMARM_talk.pdf

Page 36: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Timer Virtualization

http://www.cs.columbia.edu/~cdall/pubs/KVMARM_talk.pdf

Page 37: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Timer Virtualization

Virtual timers cannot directly raise virtual interrupts, but always raise hardware interrupts

Page 38: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Implementation & Experimental Setup

http://www.cs.columbia.edu/~cdall/pubs/KVMARM_talk.pdf

Page 39: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Implementation & Experimental Setup

http://www.cs.columbia.edu/~cdall/pubs/KVMARM_talk.pdf

Page 40: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Performance on Micro Benchmark

Two world switches

Cost of saving and restoring VGIC states hardware support

to save and restore state

Page 41: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Performance on Micro Benchmark

Switching the hardware mode

Manipulate two registers to trap hardware supported

save and restore state

Page 42: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Performance on Micro Benchmark

cost of an I/O operation

from the VM toa device

saving and restoring VGIC hardware supported

save and restore state

x86 KVMsaves and restores

additional state lazily

Page 43: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Performance on Micro Benchmark

cost of Inter-processor

Interrupt

Hardware supported VGIC

EOI/ACK must be handled in Root mode in x86

Page 44: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Recommendation to Hardware Designers

Share Kernel Mode Memory Model in Hyp Mode

- Current implementation is different and require extra effort for memory management

Make VGIC state access fast, or at least infrequent

- Cause overhead because of slow MMIO access. Summary registers describing virtual interrupt state could be an improvement

Completely avoid IPI traps

- As Virtual Distributors are implemented in software, this cause some overhead.

Page 45: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Summary

KVM/ARM was the first system to run unmodified guests on hardware

Facilitated by split-mode virtualization

Comparison with KVM

Page 46: KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor Fall 2014 Presented By: Probir Roy

Questions?