HaLVM

The Haskell Lightweight Virtual Machine

A Galois Project

by

Adam Wick, Trevor Elliott

Hypervisor

  • Virtualization
  • Manage and share machine resources intelligently across multiple, potentially different hosts.
  • Implementations
    • bhyve, Hypervisor.Framework, KVM, Xen
    • HaLVM 2.x specifically targets Xen only
    • Xen heavily used by AWS

Components

  • halvm-ghc/rts/xen (entry-exit.c, timers, clocks, interrupts, memory management)
    • Manages interaction between Haskell application and Xen layer
  • bootloader, openlibm, minlibc, ldkernel, Makefile
  • shell scripts (halvm-ghc, halvm-ghc-pkg, halvm-cabal)
  • No unix (network, directory)
  • HaLVMCore, XenDevice

Getting HaLVM

Updated for GHC 8.0.2

λ nix-shell -p haskell.compiler.ghcHaLVM240
λ nix-shell -p haskell.compiler.integer-simple.ghcHaLVM240

Available from cache.nixos.org

Hello World

λ nixos ~ → cat > Main.hs <<EOF
heredoc> module Main where
heredoc>
heredoc> import Hypervisor.Console
heredoc> import Control.Concurrent
heredoc> import Control.Monad
heredoc>
heredoc> main :: IO ()
heredoc> main = do
heredoc>   () <$ initXenConsole
heredoc>   forever $ do
heredoc>     threadDelay (1000 * 1000)
heredoc>     putStrLn "Hello world!"
heredoc> EOF

Building

[nix-shell:~]$ halvm-ghc Main.hs -o main

Xen config

[nix-shell:~]$ cat > main.config <<EOF
> name = "main"
> kernel = "main"
> memory = 16
> EOF

Running

[nix-shell:~]$ sudo xl create main.config -c

Result

[nix-shell:~]$ sudo xl create main.config -c
Parsing config from main.config
Hello world!
Hello world!
Hello world!
C-[

Status

[nix-shell:~/halvm-beginning]$ sudo xl list
Name       ID   Mem VCPUs   State   Time(s)
main       28    64   1    -b----    0.1

Cleaning up

[nix-shell:~]$ sudo xl destroy main

ldkernel

Where it all comes together

ghc -pgml ldkernel

HaNS

HaLVM web server example

Result

building path(s) /nix/store/<long-nix-hash>-hello-halvm
Parsing config from /nix/store/<long-nix-hash>-xenConfig
Assigned IP: (10,0,1,188)
C-[
$ curl 10.0.1.188
<!doctype html>
<html>
  <head></head>
  <body>HaLVM says Hello! You are request 0</body>
</html>%

Future work

  • HaLVM3 Roadmap
    • Backpack (ML Modules for Haskell), musl, Solo5
    • Swap out different hypervisor targets with ease

Thanks!

HaLVM Lightning Talk

@dmjio