66 lines
No EOL
8.2 KiB
Text
66 lines
No EOL
8.2 KiB
Text
<!DOCTYPE html>
|
|
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Minimising the virtual machine monitor</title><meta charset="UTF-8"/><link rel="stylesheet" href="/static/css/style.css"/><link rel="stylesheet" href="/static/css/highlight.css"/><script src="/static/js/highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script><link rel="alternate" href="/atom" title="Minimising the virtual machine monitor" type="application/atom+xml"/><meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"/></head><body><nav class="navbar navbar-default navbar-fixed-top"><div class="container"><div class="navbar-header"><a class="navbar-brand" href="/Posts">full stack engineer</a></div><div class="collapse navbar-collapse collapse"><ul class="nav navbar-nav navbar-right"><li><a href="/About"><span>About</span></a></li><li><a href="/Posts"><span>Posts</span></a></li></ul></div></div></nav><main><div class="flex-container"><div class="post"><h2>Minimising the virtual machine monitor</h2><span class="author">Written by hannes</span><br/><div class="tags">Classified under: <a href="/tags/future" class="tag">future</a><a href="/tags/mirageos" class="tag">mirageos</a><a href="/tags/security" class="tag">security</a></div><span class="date">Published: 2016-07-02 (last updated: 2021-11-19)</span><article><ul>
|
|
<li>Update (2016-10-19): all has been merged upstream now!
|
|
</li>
|
|
<li>Update (2016-10-30): <code>static_website_tls</code> works (TLS,HTTP,network via tap device)!
|
|
</li>
|
|
<li>Update (2017-02-23): no more extra remotes, Mirage3 is released!
|
|
</li>
|
|
</ul>
|
|
<h2 id="what">What?</h2>
|
|
<p>As described <a href="/Posts/OperatingSystem">earlier</a>, MirageOS is a library operating system developed in <a href="/Posts/OCaml">OCaml</a>. The code size is already pretty small, deployments are so far either as a UNIX binary or as a Xen virtual machine.</p>
|
|
<p>Xen is a hypervisor, providing concrete device drivers for the actual hardware of a physical machine, memory management, scheduling, etc. The initial release of Xen was done in 2003, since then the code size and code complexity of Xen is growing. It also has various different mechanisms for virtualisation, hardware assisted ones or purely software based ones, some where the guest operating system needs to cooperate others where it does not need to cooperate.</p>
|
|
<p>Since 2005, Intel CPUs (as well as AMD CPUs) provide hardware assistance for virtualisation (the VT-x extension), since 2008 extended page tables (EPT) are around which allow a guest to safely access the MMU. Those features gave rise to much smaller hypervisors, such as KVM (mainly Linux), <a href="http://bhyve.org">bhyve</a> (FreeBSD), <a href="http://xhyve.org">xhyve</a> (MacOSX), <a href="http://undeadly.org/cgi?action=article&sid=20150831183826">vmm</a> (OpenBSD), which do not need to emulate the MMU and other things in software. The boot sequence in those hypervisors uses kexec or multiboot, instead of doing all the 16 bit, 32 bit, 64 bit mode changes manually.</p>
|
|
<p>MirageOS initially targeted only Xen, in 2015 there was a port to use rumpkernel (a modularised NetBSD), and 2016 <a href="https://github.com/Solo5/solo5">solo5</a> emerged where you can run MirageOS on. Solo5 comes in two shapes, either as <code>ukvm</code> on top of KVM, or as a multiboot image using <code>virtio</code> interfaces (block and network, plus a serial console). Solo5 is only ~1000 lines of code (plus dlmalloc), and ISC-licensed.</p>
|
|
<p>A recent <a href="https://www.usenix.org/system/files/conference/hotcloud16/hotcloud16_williams.pdf">paper</a> describes the advantages of a tiny virtual machine monitor in detail, namely no more <a href="http://venom.crowdstrike.com/">venom</a> like security issues since there is no legacy hardware emulated. Also, each virtual machine monitor can be customised to the unikernel running on top of it: if the unikernel does not need a block device, the monitor shouldn't contain code for it. The idea is to have one customised monitor for each unikernel.</p>
|
|
<p>While lots of people seem to like KVM and Linux, I still prefer FreeBSD, their jails, and nowadays bhyve. I finally found some time, thanks to various cleanups to the solo5 code base, to finally look into porting solo5 to FreeBSD/bhyve. It runs and can output to console.</p>
|
|
<h2 id="how">How?</h2>
|
|
<p>These instructions are still slightly bumpy. If you've a FreeBSD with bhyve (I use FreeBSD-CURRENT), and OCaml and opam (>=1.2.2) installed, it is pretty straightforward to get solo5 running. First, I'd suggest to use a fresh opam switch in case you work on other OCaml projects: <code>opam switch -A 4.04.0 solo5</code> (followed by <code>eval `opam config env` </code> to setup some environment variables).</p>
|
|
<p>You need some software from the ports: <code>devel/pkgconf</code>, <code>devel/gmake</code>, <code>devel/binutils</code>, and <code>sysutils/grub2-bhyve</code>.</p>
|
|
<p>An <code>opam install mirage mirage-logs solo5-kernel-virtio mirage-bootvar-solo5 mirage-solo5</code> should provide you with a basic set of libraries.</p>
|
|
<p>Now you can get the <a href="https://github.com/mirage/mirage-skeleton">mirage-skeleton</a> repository, and inside of <code>device-usage/console</code>, run <code>mirage configure --no-opam --virtio</code> followed by <code>make</code>. There should be a resulting <code>mir-console.virtio</code>.</p>
|
|
<p>Once that is in place, start your VM:</p>
|
|
<pre><code class="language-bash">sudo grub-bhyve -M 128M console
|
|
> multiboot (host)/home/hannes/mirage-skeleton/console/mir-console.virtio
|
|
> boot
|
|
|
|
sudo bhyve -A -H -P -s 0:0,hostbridge -s 1:0,lpc -l com1,stdio -m 128M console
|
|
</code></pre>
|
|
<p>The following output will appear on your controlling terminal:</p>
|
|
<pre><code class="language-bash"> | ___|
|
|
__| _ \ | _ \ __ \
|
|
\__ \ ( | | ( | ) |
|
|
____/\___/ _|\___/____/
|
|
multiboot: Using memory: 0x100000 - 0x8000000
|
|
TSC frequency estimate is 2593803000 Hz
|
|
Solo5: new bindings
|
|
STUB: getenv() called
|
|
hello
|
|
world
|
|
hello
|
|
world
|
|
hello
|
|
world
|
|
hello
|
|
world
|
|
solo5_app_main() returned with 0
|
|
Kernel done.
|
|
Goodbye!
|
|
</code></pre>
|
|
<p>Network and TLS stack works as well (tested 30th October).</p>
|
|
<h2 id="open-issues">Open issues</h2>
|
|
<ul>
|
|
<li>I'm not happy to require <code>ld</code> from the ports (but the one in base does not produce sensible binaries with <code>-z max-page-size=0x1000</code> <a href="https://github.com/Solo5/solo5/pull/56">related</a>)
|
|
</li>
|
|
<li>Via <a href="https://twitter.com/bhyve_dev/status/748930600581492736">twitter</a>, bhyve devs suggested to port ukvm to ubhyve. This is a great idea, to no longer depend on virtio, and get more speed. Any takers?
|
|
</li>
|
|
<li>Debugging via gdb should be doable somehow, bhyve has <a href="https://wiki.freebsd.org/bhyve/DebuggingWithGdb">some support for gdb</a>, but it is unclear to me what I need to do to enter the debugger (busy looping in the VM and a gdb remote to the port opened by bhyve does not work).
|
|
</li>
|
|
</ul>
|
|
<h2 id="conclusion">Conclusion</h2>
|
|
<p>I managed to get solo5 to work with bhyve. I even use clang instead of gcc and don't need to link <code>libgcc.a</code>. :) It is great to see further development in hypervisors and virtual machine monitors. Especially thanks to <a href="https://lucina.net">Martin Lucina</a> for getting things sorted.</p>
|
|
<p>I'm interested in feedback, either via
|
|
<a href="https://twitter.com/h4nnes">twitter</a> or via eMail.</p>
|
|
<h2 id="other-updates-in-the-mirageos-ecosystem">Other updates in the MirageOS ecosystem</h2>
|
|
<p>There were some busy times, several pull requests are still waiting to get merged (e.g. some cosmetics in <a href="https://github.com/mirage/mirage/pull/544">mirage</a> as preconditions for treemaps and dependency diagrams), I <a href="https://github.com/mirage/mirage/pull/547">proposed</a> to use <code>sleep_ns : int64 -> unit io</code> instead of the <code>sleep : float -> unit io</code> (nobody wants floating point numbers); also an RFC for <a href="https://github.com/mirage/mirage/pull/551">random</a>, Matt Gray <a href="https://github.com/mirage/mirage/pull/548">proposed</a> to get rid of <code>CLOCK</code> (and have a <code>PCLOCK</code> and a <code>MCLOCK</code> instead). Soon there will be a major MirageOS release which breaks all the previous unikernels! :)</p>
|
|
</article></div></div></main></body></html> |