Module 11 · Lesson 101 of 107

Documentation, self-assessment and tradeoffs

Document a mini-VMM, sign off its module coverage with evidence, and defend its transport and queue choices using reproducible measurements.

  • Beginner to advanced
  • 9 min read
  • 50 min lab
What you will need

Ubuntu 24.04 in WSL2 or a VM with working /dev/kvm access, GCC, GNU Make, Bash, and the mini-VMM project with its guest artifacts

Your place in the module
By the end you can 4 objectives
  • Write a README, a virtio device summary, and an architecture diagram that agree with the implementation.
  • Map module checklist requirements to lesson IDs, implementation status, and verification evidence.
  • Reproduce the build and demo from a clean checkout.
  • Defend transport and queue choices using measured userspace exits and workload performance.
Video coming soonDocumentation, self-assessment and tradeoffs
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from The review checklist and code review
  • The used-ring slot wraps at queue size, while used.idx advances as a 16-bit counter.
  • The device publishes completion data before updating used.idx and notifying the guest.
  • KVM_EXIT_SHUTDOWN stops the vCPU run loop and starts teardown, while orderly guest poweroff requires its own evidence.
01

Document the system a reviewer can run

5 min read

The last lesson reviewed the code and tests. This lesson answers the documentation, the self-assessment against the must-cover list, and presenting the measured tradeoffs.

The KVM API defines KVM_EXIT_MMIO as a KVM_RUN exit reported to userspace for an MMIO access KVM could not satisfy. If a demo slide says “device I/O caused this many exits,” a reviewer needs to know where the counter sits, which device address range it covers, and whether the count includes boot. The same need for precision applies to claims about supported device features. Use the README, device summary, and diagram to give those claims a source that survives the demo.

Start README.md with the observable outcome. Name the guest workload and describe the result the reviewer should see, such as a verified request and completion for the selected device. Record the tested host architecture, Ubuntu release and kernel, guest architecture, kernel or image identity, and any build dependencies. State that the required KVM access is from the Ubuntu environment where the VMM runs. For WSL2 or a VM, the relevant check is whether the process can open /dev/kvm and initialize KVM in that environment. Record where to obtain the guest artifacts and how to verify their identity. Include the commands to build, boot, and run the demonstration, followed by the success condition, shutdown procedure, and paths to the saved evidence.

In the virtio device spec summary, name the device type and ID, the virtio specification revision used, and the transport variant the implementation exposes. Describe discovery as the guest actually sees it. For MMIO, give the configured register base and interrupt route and identify where the guest receives that description. Record which features the device offers, which the recorded guest run accepted, and what the device does when negotiation fails. These are different observations. The Linux kernel's Writing Virtio Drivers documentation provides the driver-side context for feature handling, queue setup, and completions.

Give each queue a row with its index, purpose, maximum size, ring format, and descriptor directions from the device's perspective. Describe what the backend reads or writes for a request, what completion it publishes, and when it signals an interrupt. Include the actual behavior for reset and for unsupported or malformed requests. If the implementation handles only some descriptor forms or operations, name those limits explicitly. Tie each guest-visible claim to the source that implements it or the test that shows it. Check the document against the offered feature bits and the accepted queue configuration before calling it complete.

Use the architecture diagram to place the Linux guest driver, guest RAM, host KVM, userspace VMM, and backend. Draw the request notification and completion signal separately from descriptor and payload access. In a userspace MMIO implementation, a queue notification can reach the VMM through a KVM exit, while the VMM reads descriptors through its mapping of guest RAM. Draw the interrupt route your build uses. If your build uses a different notification path, update the arrows and labels accordingly. Put source locations in the diagram caption or nearby prose so a reviewer can trace one request from the guest to the backend and back.

Virtio MMIO request and completion1. Guest driver → Guest RAMPublish descriptors2. Guest driver → Host KVMMMIO queue notify3. Host KVM → Userspace VMMReport MMIO exit4. Userspace VMM → Guest RAMRead request buffers5. Userspace VMM → BackendPerform backend operation6. Userspace VMM → Guest RAMPublish completion7. Userspace VMM → Host KVMSignal guest interrupt8. Host KVM → Guest driverDeliver interrupt1. Guest driver → Guest RAMPublish descriptors2. Guest driver → Host KVMMMIO queue notify3. Host KVM → Userspace VMMReport MMIO exit4. Userspace VMM → Guest RAMRead request buffers5. Userspace VMM → BackendPerform backend operation6. Userspace VMM → Guest RAMPublish completion7. Userspace VMM → Host KVMSignal guest interrupt8. Host KVM → Guest driverDeliver interrupt
A userspace virtio-mmio request path with an MMIO exit and interrupt completion
Going deeperBuild and boot from a clean checkout

Keep a Makefile and a boot script in the repository. The Makefile should declare the real source and guest artifact dependencies and provide a demo target that depends on the VMM build. The boot script should resolve project paths from its own location, check for required inputs, and launch the built VMM with the repository's actual arguments. A simple interface to provide is make for the build and make demo for the scripted boot and workload. Document these entry points after they exist in the checkout.

Pin any downloaded guest artifacts by version and checksum. Expose local artifact overrides explicitly so a reviewer can see which inputs were used. Have the script capture the guest console and the VMM's counters, bound the wait for completion, and return failure if the workload times out or the expected result is missing. A guest prompt can mark boot success. The demo target also needs an observable workload result, such as an explicit success marker emitted after the guest verifies the device response. Check failure propagation if the script sends output through tee.

Run the documented entry points from a fresh checkout at the revision under review. Supply only the dependencies and artifacts listed in the README. Save the exact invocation, revision, and result. Record a blocked run explicitly if that host cannot initialize KVM. Keep build reproducibility and run reproducibility distinct in the record, since either can fail independently.

02

Sign off against the module checklist

3 min read

Copy the module's must-cover list into a review table before assigning any status. Give each requirement its own row and add the lesson IDs it exercises, the implementation status, the verification result, and the evidence location. Keep the checklist wording so the reviewer can tell whether the evidence satisfies the requirement as written. Use the milestone and project definition lessons, M11-S12A through M11-S12A3, to identify the required project behavior and the agreed scope.

For example, a checklist entry for creating a VM, a vCPU, and registering guest memory maps to M11-S04A2. Point to the setup code and the run that reaches guest code. A row for the exit loop maps to M11-S04A3. Attach a run record that shows the relevant exit reason and source code that shows its handling. For userspace MMIO handling, use M11-S04B4 and M11-S05A2 as applicable. The useful evidence identifies the access and handler involved. A total exit count alone leaves that connection unresolved.

An MMIO device handshake maps to M11-S06A, with evidence for the guest's status and feature negotiation. Queue setup and completion can map to M11-S05B2 and M11-S06A2. Record which operation the guest issued, which queue accepted it, and which result the guest verified. If the checklist requires an interrupt, identify the evidence that the guest used the interrupt path. A completion observed by polling verifies a different behavior. These are example mappings. Use the lesson IDs and the evidence that apply to your own project. For wider module topics, such as ARM or Xen, record any required conceptual coverage with its own evidence and mark implementation scope according to the project definition.

Use implemented when real code performs the required behavior and stubbed when a placeholder responds without performing the required operation. For example, a handler that reports success while discarding a request has stubbed that operation. Record the implemented and stubbed operations individually when they share a handler. Use absent for an in-scope behavior with no implementation and out of scope when the agreed project definition excludes it. Keep the verification result in a separate column. Code can be implemented while verification is still pending or has failed, and an allowed stub can be verified to return the documented placeholder response.

Evidence for checklist sign-offReadrequirementLink lessonIDsRecord implementationstatusInspect verificationevidenceApplyacceptancecriterionRecordreviewdecisionReadrequirementLink lessonIDsRecord implementationstatusInspect verificationevidenceApplyacceptancecriterionRecordreviewdecision
A checklist requirement is traced to lesson IDs, implementation status, and verification evidence

Check each mandatory row against its acceptance criterion. An agreed stub can satisfy a criterion that explicitly calls for a stub. When a criterion requires working behavior, leave a placeholder or an unverified result open. Record the reviewed revision, reviewer, date, and overall decision, with a reference to every open mandatory row. When evidence conflicts, keep the row open and record the observation that must be repeated or investigated. This gives another reviewer enough information to reach the same sign-off decision.

03

Defend transport and queue choices with measurements

3 min read

Describe each decision in terms of a workload, an implementation cost, and the result you can show. Virtio-mmio is a reasonable choice for a fixed virtual machine layout when the guest can discover the configured device and the project already provides MMIO handling and interrupt delivery. The cost is maintaining that platform-specific description and matching the guest's transport support to it. Virtio over PCI fits a guest or virtual platform that expects PCI enumeration. It requires the PCI infrastructure needed to expose the device, including configuration space, BAR mappings, and an interrupt route. PCI can use memory-mapped registers too. A claim about how many exits either transport produces needs evidence from the actual notification and interrupt paths.

For one versus two virtqueues, name what each queue does. A single request queue can fit a device with one request stream and keeps queue state and testing simpler. A second queue can separate independent work or allow parallel processing when the guest driver, device contract, and backend support it. It adds queue setup, reset, and completion handling, and a shared backend may still serialize requests. Some device types assign distinct roles to their queues. For example, a virtio-net receive queue and transmit queue serve different functions. A one-queue alternative must preserve the requirements of the selected device and workload for the comparison to be valid. If only one design exists, defend its fit and label statements about the other design as expectations.

Count successful KVM_RUN returns by exit_reason over a defined measurement window. Handle interrupted or failed calls separately. If reporting device notification exits, identify the MMIO writes to the project's notification register, using the reported physical address and access direction. State whether all vCPUs are included. The counts describe exits reported to the userspace VMM. Hardware exits handled within KVM fall outside that measurement. The KVM API reference documents the return and exit data used for this distinction.

Start and stop the run at observable workload boundaries. Keep boot outside the window for a steady-state comparison. Record the host CPU, host and guest kernels, VMM revision, vCPU count, backend, request size and mix, concurrency, and the notification settings that can affect the result. Use a monotonic clock for elapsed time, for example CLOCK_MONOTONIC through clock_gettime. Capture elapsed seconds, completed requests, and verified bytes where applicable. Report raw exit counts and exits per completed request. Compute throughput as completed requests or bytes divided by elapsed seconds and state the unit. If you report latency, define the request start and completion events and use a recorded per-request timing method.

From workload to comparisonFixworkloadsettingsDefinemeasurementwindowCountcompletedworkCountuserspaceexitsCalculatereportedmetricsComparerepeatedrunsFixworkloadsettingsDefinemeasurementwindowCountcompletedworkCountuserspaceexitsCalculatereportedmetricsComparerepeatedruns
Equivalent workload runs yield exit counts, normalized counts, and throughput

Repeat each comparable configuration and retain the individual runs. Give the median and observed range for the metric you discuss. A reduction in exits per request can coexist with similar throughput if another stage limits the workload. If the configurations also differ in batching or backend concurrency, say which changes were made and limit the causal claim. When the queue or transport alternative is unavailable, enter not measured for that configuration and present the actual baseline figures with their scope. Use counts and timings from your saved logs. A blank comparison cell and an unexplained zero both leave the reviewer guessing.

On the demo slide, put the selected transport and queue layout next to the workload and measurement window. Read out the measured exit count, exits per completed request, and throughput with units. Show where the raw run records live. End by giving one condition that would make you revisit the choice, such as a guest that requires PCI discovery or an independent request stream the existing queue cannot serve adequately. The next lesson, “Knowledge questions across the module,” asks you to explain concepts across M11. Your sign-off gives you concrete project evidence to draw on when answering.

Key takeaways

  • A virtio device summary records the guest-visible contract and its implemented limits.
  • A checklist row needs a requirement, a status, and evidence tied to the reviewed revision.
  • A userspace KVM_RUN exit tally counts reported exits to the VMM.
  • A performance comparison needs equivalent work and a recorded measurement window.
Reflect
  1. Explain to a colleague, in two sentences: write a README, a virtio device summary, and an architecture diagram that agree with the implementation.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?
On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

References and further reading

Find your next step

↑ ↓ to move · Enter to open · Esc to close