[HN Gopher] Understanding QEMU Devices (2018)
       ___________________________________________________________________
        
       Understanding QEMU Devices (2018)
        
       Author : sipofwater
       Score  : 125 points
       Date   : 2024-06-06 09:33 UTC (13 hours ago)
        
 (HTM) web link (www.qemu.org)
 (TXT) w3m dump (www.qemu.org)
        
       | sipofwater wrote:
       | "USB disk as /dev/sda on a not-rooted smartphone using Termux,
       | QEMU, Alpine Linux":
       | https://news.ycombinator.com/item?id=40507319
        
       | SunlitCat wrote:
       | QEMU along with Bochs were my first tries getting into
       | virtualization / emulation way back (maybe around early 2000s? I
       | can't remember!).
       | 
       | Although the emulation / virtualization market already grew
       | larger with more and more options available today, QEMU was (and
       | still is) one of the most awesome projects out there.
        
         | rwmj wrote:
         | A lot of the options (especially the free ones) are either
         | using qemu or using ideas that were developed early (not
         | actually first) for qemu like virtio. There are just a lot more
         | layers on top these days, and not always for the better.
        
           | skrtskrt wrote:
           | Proxmox is great as a FOSS hypervisor, but their docs for
           | doing pretty much anything advanced are just "here's a qemu
           | command".
        
         | koala_man wrote:
         | Back in the day I ran Bochs in all its 4 Bogomips glory on a
         | university IP address and went to IRC channels where script
         | kiddies were "trading root".
         | 
         | I let them go first, and watched through an instrumented
         | terminal how they clumsily installed a rootkit, then inevitably
         | refused to give anything in return and laughed calling me a
         | noob.
         | 
         | Their laughter was short lived.
         | 
         | I had even spent quite a bit of effort kludging the kernel to
         | report much higher specs than Bochs could deliver, but all that
         | effort was wasted because no one knew how to check.
        
         | swozey wrote:
         | QEMU is used in basically every single hardware vendor today
         | and has been since I've been in virtualization/containerization
         | tech (2010+).
         | 
         | I've only seen Vmware (gsx/esx) at Windows shops for things
         | like big Exchange clusters, etc. Every CDN I've worked at used
         | qemu.
        
       | checker659 wrote:
       | What is the definitive new-comer friendly guide to QEMU? Not just
       | about using it but also understanding its internals (say to add
       | new instructions to a supported ISA etc)?
        
         | sipofwater wrote:
         | https://www.qemu.org/documentation/
        
           | checker659 wrote:
           | I am looking for some hand-holding with this. The
           | documentation seems more for reference (albeit a bit lack-
           | luster if I may say so).
        
         | cpach wrote:
         | What are your goals? Are you interested in emulation (i.e.
         | running a VM that uses another architecture than your physical
         | computer) or in virtualization? (i.e. running a VM that uses
         | the same architecture)
        
           | checker659 wrote:
           | Well both. I'm interested in implementing an ISA extension
           | (not sure if you know about CHERI). Also, there are reference
           | implementations for aarch64 and risc-v that I'd like to
           | understand.
        
           | hnthrowaway0328 wrote:
           | Just curious, what about simulation? I heard that simulation
           | is more serious than emulation and targets for say pipeline
           | level emulation, but maybe it's just a fancier word?
        
             | cpach wrote:
             | Beats me. What does simulation mean in this context?
        
               | hnthrowaway0328 wrote:
               | Ah nevermind then, probably just a synonym for emulation.
        
         | pm215 wrote:
         | Unfortuately there is none. QEMU is a large project and doesn't
         | have much formal design or API documentation. On the other hand
         | it's not big enough (compared for instance to the Linux kernel)
         | to have a wider community interested in trying to provide
         | internals documentation for newcomers.
         | 
         | Our general advice is "look at the existing code for the bit
         | you're interested in to see how it works". You can sometimes
         | find descriptions of the overall architecture online in third
         | party blog posts and the like, but if they're more than a few
         | years old then be wary that they might be out of date --
         | they're likely to be right in general principles and wrong in
         | details, because things change.
         | 
         | For adding new instructions to an existing ISA: the first
         | couple of sections of
         | https://www.qemu.org/docs/master/devel/index-tcg.html are
         | relevant here. Depending on the target it might or might not
         | use decodetree (decodetree is much easier to add a new insn to,
         | but some older targets still do by-hand switch-statement based
         | decoding.) Look at how an existing insn that is similar to what
         | you want to do works.
         | 
         | Implementing CHERI in particular is going to be pretty awful,
         | because the things it does (like 128-bit pointers) break
         | various assumptions QEMU makes. The University of Cambridge
         | forked QEMU to add CHERI support for MIPS and RISC-V and I
         | think also AArch64:
         | https://www.cl.cam.ac.uk/research/security/ctsrd/cheri/cheri...
         | -- but the changes are pretty invasive and also not likely to
         | be very fast. (The fork looks like it's based on 6.0, so three
         | years old now.)
         | 
         | (If anybody is interested in trying to write up some
         | documentation for QEMU's internals (either a general
         | overview/roadmap or something on a particular subsystem), I'd
         | be happy to code-review patches that add something to the
         | "Developer Information" subsection of our manual.)
        
           | cpach wrote:
           | Out of curiosity, how does one reach you? (Saw no
           | info/contact details in your profile.)
           | 
           | Also, where does QEMU people hang out online? AFAICT the IRC
           | channel is not very active. (Based on few and random visits,
           | so I could be wrong.)
        
             | pm215 wrote:
             | The primary nexus for QEMU developers is the qemu-devel
             | mailing list. (Very high traffic because it's also used for
             | patchmails.) The irc channel is a bit more variable and
             | tends in particular to be quiet outside UK/Europe working
             | hours, just because most QEMU devs happen to be Europe
             | based.
             | 
             | I discourage private emails sent direct to me on QEMU
             | topics (because they should generally be to public lists so
             | other community members can answer them or benefit from the
             | answer), but you can find me on the mailing lists and irc.
        
               | cpach wrote:
               | Ok, cool!
        
           | isjamesalive wrote:
           | > QEMU is a large project and doesn't have much formal design
           | or API documentation.
           | 
           | This is bonkers to me considering how it's used in industry.
        
             | pm215 wrote:
             | Wake me up when those industry users want to pay somebody
             | to improve the developer documentation :-)
        
               | mdaniel wrote:
               | Well, every time this line of thinking comes up, I don't
               | believe there is a gofundme, indiegogo, patreon, etc to
               | which I could donate. Because I for sure think that would
               | be a good investment for future generations, but you are
               | correct that I almost certainly couldn't convince my
               | employer to spend the money. I'd guess that's partially
               | because they don't _directly_ benefit from qemu, setting
               | aside the daily use of buildkit which for sure does. Come
               | to think of it, I 'd guess Docker(Mirantis?) is BY FAR
               | the most "you really, really should be a corporate
               | sponsor" of qemu
        
               | pm215 wrote:
               | Well, you _can_ donate to the project (there 's a paypal
               | link at the bottom of https://www.qemu.org/sponsors/
               | which donates to the Software Freedom Conservancy
               | earmarking it as being for QEMU), *but* doing that won't
               | cause somebody to be paid to work on the project (it can
               | cover random project expenses like CI usage, I think).
               | Mostly our sponsorship is either "in-kind" (access to
               | compute hosts, hosting downloads, cloud compute credits
               | etc) or else is sponsorship to help pay for the annual
               | KVM Forum conference.
               | 
               | In general there is no mechanism for "pay money to have
               | work happen" because pretty much all non-hobbyist QEMU
               | developers are doing it because they're paid by some
               | company (RedHat, Linaro, etc etc etc) to do that work as
               | their full time job. So they're not in the market for
               | random small side jobs.
        
         | candiddevmike wrote:
         | Start with libvirt, it provides a full GUI around QEMU
         | operations. Run ps to see the underlying QEMU commands it runs.
         | Inspect the XML files to understand how it builds machines.
        
           | cpach wrote:
           | A coworker came up with a similar idea: We started a VM using
           | Lima, then ran ps to see what args it passed to QEMU. It was
           | enlightening!
        
         | Neywiny wrote:
         | I implemented a bit of a STM32 and it was a _chore_ and a half.
         | I 've noticed 2 things with the code base: 1. It's C but they
         | really want C++. Qemu wrote their own class system, foreach
         | loops, containers, etc. And because of that, when I tried to
         | use actual cpp, compilation failed due to how many reserved
         | keywords were used in headers and other mess. 2. As noted in
         | other comments, copy paste and modify. It got me where I need
         | to go. But it was a slog. Eventually I had gdb debugging my
         | qemu build, and gdb debugging the program I was running. I
         | could even connect in from the STM32 IDE which was nice
        
         | skrtskrt wrote:
         | probably just start using Proxmox, as it's a pretty beginner-
         | friendly FOSS hypervisor with extensive docs and forums, and
         | it's largely a wrapper around qemu.
         | 
         | Their docs often include equivalent qemu commands for any UI
         | actions.
         | 
         | For anything the UI can't do yet, they only give the QEMU
         | command
        
       | zorked wrote:
       | qemu is a treasure and reading its source to learn how computers
       | work is very fun.
        
       | anonymousDan wrote:
       | This is such a fantastic description of what is going on
       | underneath the hood - it took me quite a while to understand how
       | qemu works, wish I had seen this before!
        
       | dlachausse wrote:
       | If you're on a Mac, UTM is an excellent wrapper around Qemu.
       | 
       | https://mac.getutm.app/
        
         | adeptima wrote:
         | you can choose Apple virtualisation in UTM instead of QEMU too.
         | Apple virtualization is optimized for M1+
        
           | cpach wrote:
           | QEMU has a Hypervisor[0] backend these days, called "hvf".
           | 
           | https://wiki.qemu.org/Features/HVF
           | 
           | [0] "Hypervisor" is a "sibling" to the Virtualization
           | framework. IMHO, the naming is incredibly confusing (:
        
           | zamadatix wrote:
           | That's a bit like saying "instead of ext4 you can use an SSD"
           | in that the things involved span multiple layers. When you
           | select the option to use Apple virtualization framework in
           | UTM you're still using QEMU, what you're changing is the
           | backend QEMU is using for the CPU virtualization.
        
             | ashconnor wrote:
             | Docs:
             | https://developer.apple.com/documentation/virtualization
        
       | adeptima wrote:
       | Warning for humans! If you are trying to run a virtual PC on QEMY
       | let's say on bare metal hosting from hetzner, you will very soon
       | discover - QEMU is a dead slow without actual graphic card or at
       | best you will get all kind of funky missing libs error messages
       | on Ubuntu and other OS in very surprise spots.
       | 
       | Had a very good experience simulating K8s cluster with QEMU aka
       | studing K8s hard way once I figure out how networking actually
       | works between virtual machines and domains can be assigned with
       | external proxy.
        
         | yjftsjthsd-h wrote:
         | Why would qemu care about having a graphics card? Do you mean
         | that whatever system you were running inside qemu expected a
         | GPU and was slow without it?
        
         | TeeMassive wrote:
         | > Had a very good experience simulating K8s cluster with QEMU
         | aka studing K8s hard way once I figure out how networking
         | actually works between virtual machines and domains can be
         | assigned with external proxy.
         | 
         | This is an awesome use of QEMU! I'm both interested in learning
         | K8s and what goes on under the hood at the kernel level because
         | I do cloud connected IoT stuff, so I'll definitely use that!
         | 
         | Is there any kind of "build the kernel from scratch" project
         | for that kind of stuff?
        
         | navaati wrote:
         | Hi, one probably really wants to use libvirt rather than qemu
         | directly. That way you can create your VMs remotely with a GUI
         | (virt-manager) using a ssh-based libvirt url, or a CLI (virsh)
         | and it will handle all the right parameters for qemu, the
         | required networking setup, etc. Check it out !
        
       | apitman wrote:
       | > Understanding QEMU...
       | 
       | Best of luck
        
         | ashconnor wrote:
         | Followed by libvirt, VirtIO, KVM, qcow2. If only there was one
         | book or course to pull it all together.
        
       ___________________________________________________________________
       (page generated 2024-06-06 23:01 UTC)