BAR Register Emulation
The firmware can reproduce how the donor's memory BAR registers read and write, so a driver sees the values it expects. This page covers how that behavior is learned, what the firmware does when it cannot be learned, and the flags that control it.
How register behavior is learned
Register behavior is learned during Stage 1 collection, on the Linux host, as
root. The collector traces the donor's native driver with the kernel's
mmiotrace facility:
- It enables
mmiotrace, which records every CPU access to the donor's mapped BAR memory. - It re-probes the donor's native driver so the driver's own initialization traffic is captured.
- By default it also exercises the device through the driver (for example a network link up and down, a short block read), then undoes those changes, so runtime register programming is seen too.
The generator never writes to the device itself. The native driver does, exactly as it would on the target machine. Stage 2 then compiles the trace into a register model and generates a BAR module that reproduces each register's width, initial value, and which bits are writable.
Read-only by default
A served BAR with no learned register model is read-only: every read returns zero and every write is ignored across the whole aperture. This is the default because it claims nothing the capture did not show. The build logs a warning that register behavior will not match the donor.
Flags
| Flag | Effect |
|---|---|
--no-mmio-learning |
Skip driver tracing during collection. The served BAR falls back to read-only. |
--no-mmio-exercise |
Trace only the driver probe; do not exercise the device. |
--force-recapture |
Force a fresh MMIO capture instead of reusing a cached model. Rejected on offline builds. |
--writable-bar-fallback |
For a BAR with no learned model, serve generic writable RAM instead of the read-only default. |
--writable-bar-fallback
This replaces the read-only fallback with generic writable RAM that repeats every 4 KiB across the aperture. It is not donor behavior. Use it only for a driver that needs to read back a value it wrote to a scratch register, and expect the build to warn that the BAR does not match the donor.
When learning is unavailable
mmiotrace has preconditions. Learning is skipped, and the build serves the
read-only fallback, when:
- the kernel was built without
CONFIG_MMIOTRACE, or kernel lockdown is on; - no native (non-
vfio-pci) driver is bound to the donor; - another tracing session is already using the kernel tracer;
- the donor is in use in a way that makes rebinding its driver unsafe, such as
driving the display, having SR-IOV virtual functions enabled, or a
driver_overrideset.
A skipped capture is not a build failure. It means the served BAR registers are not modeled.
Limits
- Only plain storage behavior is reproduced: each register's width, initial value, and writable bits. Read side effects and other semantics are not modeled.
- Registers the capture cannot explain are not emulated.
- Read lanes with no mapped register return zero. That is an approximation, not a donor measurement.
- The firmware does not generate interrupts. See MSI-X and Requester Support.
- The served set is the primary register BAR and, when the MSI-X table lives in a different BAR, that BAR. Other BAR slots are disabled.