Dune: Safe User-‐Level Access to Privileged CPU Features

Dune: Safe User-‐Level Access to Privileged CPU Features

Dune: Safe User-level Access to Privileged CPU Features Adam Belay, Andrea Bi>au, Ali MashAzadeh, David Terei, David Mazières, and Christos Kozyrakis Stanford University A quick review of Virtualizaon HW • Last lecture talked about AMD SVM • This lecture: Intel VT-x (conceptually very similar) • Key idea: – Adds orthogonal Guest and Host CPU modes – arch state saved and restored in VMCS – HW performs transiAons between modes • VM Exit -> trap to hypervisor (enter host mode) • VM Enter -> run the guest OS (enter guest mode) 2 Normally IDT GDT PGTBL CPL CPU VMCS EPT With VT-X IDT GDT PGTBL CPL IDT GDT PGTBL CPL VM Entry CPU (Host Mode) CPU (Guest Mode) VM Exit Some Key VT-x InstrucAons • VMLAUNCH – called first Ame to enter guest mode • VMRESUME – called for subsequent entries to guest mode • VMPTRLD – sets the VMCS pointer (ordinary memory) • The VMCS is accessed with VMREAD and VMWRITE • Why is it not okay to modify VMCS memory directly? • VMCALL forces a VM exit 4 How has Virt. HW Changed? • Adams and Agesen’s study was > 6 years ago • VM exit and VM entry now much faster • More hardware support, less need to “trap- and-emulate” – IOMMU -> raw passthrough devices – Unrestricted guest mode -> faster boot • Nested paging HW is widely available • NET RESULT: Be>er performance, hypervisors commodiAzed (easy to implement) 5 Virtualizaon HW Support has become Ubiquitous • Not just AMD and Intel x86 • Available on ARM, Itanium, Power • Desktops, servers, notebooks, cell phones… 6 So what can we do with it? • Is it only useful for running virtual machines? • Idea behind Dune: Use virtualizaon HW to give user programs safe access to privilege CPU features 7 Outline • Review of Virtualizaon HW • Dune Mo.va.on • Design • Evaluaon 8 The power of privilege • Privileged CPU features are fundamental to kernels • But other, compelling uses: – Speed up garbage collecAon (Azul C4) • Page tables provide memory access informaon – Privilege separaon within a process (Palladium) • MMU hardware isolates compartments – Safe nave code in web browsers (Xax) • System call handler intercepts system calls 9 Should we change the kernel? App PTEs Kernel Patch PGTBL Root CPU • Problem: stability concerns, challenging to distribute, composability concerns 10 What about an Exokernel? App Garbage CollecAon Library OS Exokernel CPU • Problem: must replace enAre OS stack 11 What about a virtual machine? JVM Browser GC Kernel Linux Hypervisor CPU • Problem: virtual machines have strict parAAoning 12 Dune in a Nutshell Kernel POSIX App Host Mode Guest Mode CPU • Provide safe user-level access to privileged CPU features • SAll a normal process in all ways (POSIX API, etc) • Key idea: leverage exisAng virtualizaon hardware (VT-x) 13 Garbage collecAon in Dune PTEs Kernel App PTEs Host Mode Guest Mode Host Page CPU Guest Page Table Table • SoluAon: control the page table directly within a process 14 Outline • Review of Virtualizaon HW • Dune MoAvaon • Design • Evaluaon 15 Available CPU features • Privilege Modes – SYSRET, SYSEXIT, IRET • Virtual Memory – MOV CRn, INVLPG, INVPCID • Excepons – LIDT, LTR, IRET, STI, CLI • Segmentaon – LGDT, LLDT 16 Dune architecture Kernel Process Dune Module libDune Host Mode Guest Mode CPU • Host mode – Normally used for hypervisors – In Dune, we run the kernel here • Reason: need access to VT-x instrucAons Dune architecture Kernel Process Dune Module libDune Host Mode Guest Mode CPU • Guest mode – Normally used by the guest OS – In Dune, we run ordinary processes here • Reason: need access to privileged features Dune architecture Kernel Process Dune Module libDune Host Mode Guest Mode CPU • Dune Module (~2500 LOC) – Configures and manages virtualizaon hardware – Provides integraon with the rest of the kernel in order to support a process abstracAon – Uses Intel VT-x (could easily add AMD SVM) Dune architecture Kernel Process Dune Module libDune Host Mode Guest Mode CPU • libDune (~6,000 LOC) – A uAlity library to help applicaons manage privileged hardware features – Completely untrusted – ExcepAon handling, system call handling, page allocator, page table management, ELF loader Providing a process abstracAon • Memory management • System calls • POSIX Signals 21 Memory management in Dune • Configure the EPT to Dune Process provide process memory Guest-Virtual • User programs can then directly access the page User table Page Table Kernel Host-Virtual Guest-Physical Kernel Page EPT Table Host-Physical (RAM) 22 System calls in Dune VMCALL SYSCALL Syscall Kernel Process Syscall Handler Handler Host Mode Guest Mode CPU • SYSCALL will only trap back into the process • Use VMCALL (i.e. a hypercall) to perform normal kernel system calls 23 But SYSCALL is sAll useful Process Untrusted (ring 0) Code Syscall (ring 3) Handler • Isolate untrusted code by running it in a less privileged mode (i.e. ring 3 on x86) • Leverage the ‘supervisor’ bit in the page table to protect memory 24 Signals in Dune • Signals should only be delivered to ring 0 • What happens if process is in ring 3? • Possible soluAon: have the Dune module manually transiAon the process to ring 0 – Works but slow and somewhat complex • Our soluAon: deliver signals as injected interrupts – Hardware automacally switches to ring 0 – Can use CLI and STI to efficiently mask signals 25 Many implementaon challenges • Reducing VM exit and VM entry overhead • Pthread and fork were tricky to integrate with the Linux kernel • EPT does not support enough address space • Check the paper for details 26 Outline • Review of Virtualizaon HW • Dune MoAvaon • Design • Evaluaon 27 Evaluaon • How much overhead does Dune add? • What potenAal does Dune create for opAmizaon? • What is Dune’s performance in end-to-end use cases? 28 Overhead analysis • Two sources of overhead – VMX transiAons – EPT translaons (cycles) Getpid Page fault Page walk Linux 138 2,687 36 Dune 895 5,093 86 OpAmizaon analysis • Large opportuniAes for opAmizaon – Faster system call interposiAon and traps – More efficient user-level virtual memory manipulaon (cycles) ptrace trap Appel 1 Appel 2 (getpid) (TRAP, PROT1, (PROTN, TRAP, UNPROT) UNPROT) Linux 27,317 2,821 701,413 684,909 Dune 1,091 587 94,496 94,854 30 End-to-end case studies • We built and evaluated three systems • Applicaon sandbox (~1300 LOC) – Constrained the system calls performed by an untrusted binary • Garbage collecAon (less than 100 LOC change) – Improved dirty page detecAon through direct access to dirty bits • Privilege separaon (~750 LOC) – Supported several protecAon domains within a single process through use of mulAple page roots (with TLB tagging) 31 Sandbox: SPEC2000 performance 25 20 Sandbox Sandbox w/ LGPG 15 Linux w/ LGPG 10 5 0 −5 % Slowdown −10 −15 −20 −25 gzip vpr gcc mesa art mcf equakecraftyammpparsereon perlbmkgap vortexbzip2 twolf • Only notable end-to-end effect is EPT overhead • Can be eliminated through use of large pages 32 Sandbox: lighpd performance Lighpd performance (connecons per second) 30000 25000 20000 15000 10000 5000 0 Linux Dune Sandbox VMware Player • Slight reducAon in throughput (less than 2%) due to VMCALL overhead 33 Performance of other use cases • Up to 40% improvements in garbage collecAon performance (less than 100 LOC) • Privilege separaon system can context switch between subdomains 3x faster than Linux can switch between processes (750 LOC) 34 Conclusions • Applicaons can benefit from access to privileged CPU features • Virtualizaon hardware allows us to provide such access safely • Dune creates new opportuniAes to build and improve applicaons without kernel changes • Dune has modest performance overhead • Download Dune at h>p://dune.scs.stanford.edu 35 Future Work • ARM support, AMD support, 32-bit support, x32 support • Passthrough device support (w/ VT-d and SR- IOV) • Cool applicaons – C4 Garbage collector? – An awesome sandbox? 36 .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    36 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us