logo

drewdevault.com

[mirror] blog and personal website of Drew DeVault git clone https://hacktivis.me/git/mirror/drewdevault.com.git

2022-09-02-In-praise-of-qemu.md (4217B)


  1. ---
  2. title: In praise of qemu
  3. date: 2022-09-02
  4. ---
  5. [qemu][0] is another in a long line of great software started by [Fabrice
  6. Bellard][1]. It provides virtual machines for a wide variety of software
  7. architectures. Combined with KVM, it forms the foundation of nearly all cloud
  8. services, and it runs SourceHut in our self-hosted datacenters. Much like
  9. Bellard's ffmpeg revolutionized the multimedia software industry, qemu
  10. revolutionized virtualisation.
  11. [0]: https://www.qemu.org/
  12. [1]: https://bellard.org/
  13. [2]: https://www.kernel.org/doc/html/latest/admin-guide/binfmt-misc.html
  14. [3]: https://harelang.org/
  15. qemu comes with a large variety of studiously implemented virtual devices, from
  16. standard real-world hardware like e1000 network interfaces to accelerated
  17. virtual hardware like virtio drives. One can, with the right combination of
  18. command line arguments, produce a virtual machine of essentially any
  19. configuration, either for testing novel configurations or for running
  20. production-ready virtual machines. Network adapters, mouse & keyboard, IDE or
  21. SCSI or SATA drives, sound cards, graphics cards, serial ports — the
  22. works. Lower level, often arch-specific features, such as AHCI devices, SMP,
  23. NUMA, and so on, are also available and invaluable for testing any conceivable
  24. system configurations. And these configurations *work*, and work reliably.
  25. I have relied on this testing quite a bit when working on kernels, particularly
  26. on [my own Helios kernel][4]. With a little bit of command line magic, I can run
  27. a fully virtualised system with a serial driver connected to the parent
  28. terminal, with a hardware configuration appropriate to whatever I happen to be
  29. testing, in a manner such that running and testing my kernel is no different
  30. from running any other program. With -gdb I can set up gdb remote debugging and
  31. even debug my kernel as if it were a typical program. Anyone who remembers osdev
  32. in the Bochs days — or even earlier — understands the unprecedented
  33. luxury of such a development environment. Should I ever find myself working on a
  34. hardware configuration which is unsupported by qemu, my very first step will be
  35. patching qemu to support it. In my reckoning, qemu support is nearly as
  36. important for bringing up a new system as a C compiler is.
  37. [4]: https://drewdevault.com/2022/06/13/helios.html
  38. And qemu's implementation in C is simple, robust, and comprehensive. On the
  39. several occasions when I've had to read the code, it has been a pleasure.
  40. Furthermore, the comprehensive approach allows you to build out a virtualisation
  41. environment tuned precisely to your needs, whatever they may be, and it is
  42. accommodating of many needs. Sure, it's low level — running a qemu command
  43. line is certainly more intimidating than, say, VirtualBox — but the
  44. trade-off in power afforded to the user opens up innumerable use-cases that are
  45. simply not available on any other virtualisation platform.
  46. One of my favorite, lesser-known features of qemu is qemu-user, which allows you
  47. to register a [binfmt][2] handler to run executables compiled for an arbitrary
  48. architecture on Linux. Combined with a little chroot, this has made cross-arch
  49. development easier than it has ever been before, something I frequently rely on
  50. when working on [Hare][3]. If you do cross-architecture work and you haven't set
  51. up qemu-user yet, you're missing out.
  52. ```
  53. $ uname -a
  54. Linux taiga 5.15.63-0-lts #1-Alpine SMP Fri, 26 Aug 2022 07:02:59 +0000 x86_64 GNU/Linux
  55. $ doas chroot roots/alpine-riscv64/ /bin/sh
  56. # uname -a
  57. Linux taiga 5.15.63-0-lts #1-Alpine SMP Fri, 26 Aug 2022 07:02:59 +0000 riscv64 Linux
  58. ```
  59. <!-- Inline styles because lazy -->
  60. <small style="
  61. text-align: center;
  62. display: block;
  63. color: #555;
  64. ">This is amazing.</small>
  65. qemu also holds a special place in my heart as one of the first projects I
  66. contributed to over email 🙂 And they still use email today, and even [recommend
  67. SourceHut][5] to make the process easier for novices.
  68. [5]: https://qemu.readthedocs.io/en/v6.2.0/devel/submitting-a-patch.html#if-you-cannot-send-patch-emails
  69. So, to Fabrice, and the thousands of other contributors to qemu, I offer my
  70. thanks. qemu is one of my favorite pieces of software.