Advanced virtualization techniques for FAUmachine Hans-Jrg Hxer - - PowerPoint PPT Presentation

advanced virtualization techniques for faumachine
SMART_READER_LITE
LIVE PREVIEW

Advanced virtualization techniques for FAUmachine Hans-Jrg Hxer - - PowerPoint PPT Presentation

Introduction Just In Time Compiler Host Kernel Support Advanced virtualization techniques for FAUmachine Hans-Jrg Hxer Volkmar Sieh Martin Waitz Department of Computer Science 3: Computer Architecture Friedrich-Alexander-University


slide-1
SLIDE 1

Introduction Just In Time Compiler Host Kernel Support

Advanced virtualization techniques for FAUmachine

Hans-Jörg Höxer Volkmar Sieh Martin Waitz

Department of Computer Science 3: Computer Architecture Friedrich-Alexander-University Erlangen-Nuremberg

September 2004

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-2
SLIDE 2

Introduction Just In Time Compiler Host Kernel Support

Outline

1

Introduction

2

Just In Time Compiler

3

Host Kernel Support

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-3
SLIDE 3

Introduction Just In Time Compiler Host Kernel Support

Outline

1

Introduction

2

Just In Time Compiler

3

Host Kernel Support

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-4
SLIDE 4

Introduction Just In Time Compiler Host Kernel Support

Many Different Virtualization Projects

Commercial: VMware, Virtual PC, Simics, ... Open Source: bochs, plex86, QEMU, PearPC, FAUmachine, ... partial virtualization: UML, VServer, ...

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-5
SLIDE 5

Introduction Just In Time Compiler Host Kernel Support

History of FAUmachine

Motivation: Fault injection UMLinux started as a user mode Linux (different to UML) Moved to a hardware simulator with minimal changes in the guest system Now called FAUmachine

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-6
SLIDE 6

Introduction Just In Time Compiler Host Kernel Support

Goals of FAUmachine

Complete simulation of a PC Simulator runs in user mode No need to patch host kernel Efficient

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-7
SLIDE 7

Introduction Just In Time Compiler Host Kernel Support

CPU: Direct Execution

No performance penalty Privileged instructions and privilege level changes need special care Examples: Hardware support in S390, vm86

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-8
SLIDE 8

Introduction Just In Time Compiler Host Kernel Support

Memory: Mapped Files

Files to represent the physical memory Process’ address space to represent virtual memory mmap(2) to simulate MMU Only 3GB are available in Linux

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-9
SLIDE 9

Introduction Just In Time Compiler Host Kernel Support

Peripherals: Simulated

Hardware is represented by software Input/output is mapped to function calls Simulated hardware can interact with the host system:

hard disk content is stored in a file video signal is displayed in a window sound is sent to real sound card

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-10
SLIDE 10

Introduction Just In Time Compiler Host Kernel Support

Differences Between User And Kernel Mode

Different memory mappings

Only the kernel can access all the physical memory

Some instructions are only available in kernel mode

All hardware access Processor configuration

Some instructions behave differently on i386

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-11
SLIDE 11

Introduction Just In Time Compiler Host Kernel Support

Virtualization of User Mode Code

Code consists of unprivileged instructions Simulator has to handle user/kernel mode transitions Traps either provoke a signal or a real host system call

Can be detected by ptrace(2) or a special kernel extension

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-12
SLIDE 12

Introduction Just In Time Compiler Host Kernel Support

Virtualization of Kernel Mode Code

Code contains many privileged instructions Those cannot be executed in user mode A JIT compiler is used to generate code that can be executed directly

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-13
SLIDE 13

Introduction Just In Time Compiler Host Kernel Support

Outline

1

Introduction

2

Just In Time Compiler

3

Host Kernel Support

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-14
SLIDE 14

Introduction Just In Time Compiler Host Kernel Support

Kernel Mode Code

Direct execution of kernel code not possible in user mode C implementation of every instruction Simulator works on a shadow copy of the CPU state inb imm8 ⇒ regs->al = host_bus_inb(instp->imm8);

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-15
SLIDE 15

Introduction Just In Time Compiler Host Kernel Support

Switching Between Simulation And Direct Execution

Direct execution is not possible all the time Simulation is slow Solution: Only use simulation when it is necessary Switch back to direct execution as soon as possible Problems: Real CPU state and the shadow copy have to stay in sync How/when to activate the simulator?

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-16
SLIDE 16

Introduction Just In Time Compiler Host Kernel Support

pushf/popf

CF SF ZF 0 AF PF TF IF DF OF IOPL NT RF VM AC VIF VIP ID

available both in user and kernel mode but with different semantics

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-17
SLIDE 17

Introduction Just In Time Compiler Host Kernel Support

pushf/popf

CF SF ZF 0 AF PF DF OF ID VIP VIF AC VM RF NT IOPL IF TF

available both in user and kernel mode but with different semantics some bits only available to kernel

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-18
SLIDE 18

Introduction Just In Time Compiler Host Kernel Support

Detecting Instructions That Need To Be Simulated

No hardware support to detect problematic instructions on i386 Every instruction has to be checked before it is executed But: every instruction has to be checked only once The result can be stored in a cache

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-19
SLIDE 19

Introduction Just In Time Compiler Host Kernel Support

Cache

Executable code in the cache Problematic instructions are replaced with special simulator calls Cache is filled instruction by instruction by a JIT compiler A special “compile-next-instruction” call is appended to the cached code

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-20
SLIDE 20

Introduction Just In Time Compiler Host Kernel Support

Code Transformation

normal code normal code normal code normal code save CPU state simulate instruction restore CPU state call sim problematic instr.

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-21
SLIDE 21

Introduction Just In Time Compiler Host Kernel Support

Cache Lines

normal code normal code normal code call sim problematic instr. normal code

cache lines

  • riginal code

Cache is split into several cache lines Direct mapping between original and cached code inside of each cache line Hash tables to map real address to cache line

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-22
SLIDE 22

Introduction Just In Time Compiler Host Kernel Support

More Code Modifications

Execution in a separate cache influences Instruction Pointer (%eip) → call and ret have to be simulated, too Layout of code is changed → Jump targets may have to be represented using more bits

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-23
SLIDE 23

Introduction Just In Time Compiler Host Kernel Support

Outline

1

Introduction

2

Just In Time Compiler

3

Host Kernel Support

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-24
SLIDE 24

Introduction Just In Time Compiler Host Kernel Support

Handling of a System Call

System calls in the guest user mode code will be executed directly, too The simulator has to intercept these system calls and redirect them to the guest kernel

syscall syscall simulator user kernel simulator user kernel kernel user kernel user guest system guest system host system host system

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-25
SLIDE 25

Introduction Just In Time Compiler Host Kernel Support

Redirection of a System Call

A signal is delivered instead of executing the system call The signal handler of the simulator fakes the system call in the guest system The simulator code residing in the CPU process still has to be able to execute system calls to the host kernel System calls coming from the simulator address space must not be redirected

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-26
SLIDE 26

Introduction Just In Time Compiler Host Kernel Support

ptrace(2)

A special process (“tracer”) uses PTRACE_SYSCALL to trace system calls executed by the CPU process It gets notified on system call entry and exit If the system call is coming from a guest process:

System call entry: redirect system call number to getpid(2) System call exit: restore system call number, send signal to CPU process

Total: four context switches, several system calls

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-27
SLIDE 27

Introduction Just In Time Compiler Host Kernel Support

Kernel Support For Redirection

Conversion of a system call to a signal is trivial in kernel space Only system calls from a guest process inside a FAUmachine CPU process have to be converted New system call to register FAUmachine CPU processes The address range of the simulator is given as parameter

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-28
SLIDE 28

Introduction Just In Time Compiler Host Kernel Support

Address Space

Real machine has a 4GB address space User space processes only have a 3GB address space 4G patch has two problems:

extra TLB flush on every system call → slowdown for all processes. needs a fixed 16MB area for switching

We are working on a conditional 4GB patch with a dynamic switching zone ⇒ Should allow us to efficiently run unmodified kernels in the future

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-29
SLIDE 29

Introduction Just In Time Compiler Host Kernel Support

Performance

141 1439 514 1547 635

ptrace native with JIT without JIT kernel support Benchmark: Kernel compilation JIT compiler has a performance impact Host kernel support can increase performance

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-30
SLIDE 30

Introduction Just In Time Compiler Host Kernel Support

Conclusion

Direct execution to increase speed JIT to convert kernel to user mode code Host kernel support can increase performance More information is available on faumachine.org.

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-31
SLIDE 31

Introduction Just In Time Compiler Host Kernel Support

Thank you! Questions?

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-32
SLIDE 32

Introduction Just In Time Compiler Host Kernel Support

Thank you! Have a nice time at LinuxKongress!

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine

slide-33
SLIDE 33

Cache Line Usage

100 200 300 400 500 600 700 800 900 20 40 60 80 100 120 cache line length

Hans-Jörg Höxer, Volkmar Sieh, Martin Waitz Advanced virtualization techniques for FAUmachine