QEMU backend¶
Injects into architectural state: registers and memory. Default backend. 1 to 3 seconds per injection. Parallel workers on one machine and on the server worker fleet.
How a fault is injected¶
flowchart LR
subgraph host["Host"]
run["hfim run"]
gdb["GDB"]
end
subgraph qemu["QEMU process, one per injection"]
plugin["icount plugin"]
stub["gdbstub"]
guest["guest RISC-V<br/>x0-x31, f0-f31, RAM"]
end
run -- "GDB/MI commands" --> gdb
gdb -- "RSP over TCP" --> stub
guest -- "retired instructions" --> plugin
plugin -- "stop at instruction N" --> stub
stub -- "write flipped value" --> guest
GDB reaches only the state the RISC-V ISA exposes. QEMU does not model caches, so cache targets are rejected on this backend.
Setup¶
Two QEMU packages exist; a template pins the one its board needs, and hfim init installs it.
| Package | What it is | Used by |
|---|---|---|
hfim-sim-qemu |
upstream QEMU, from 9.2.4 with the SD-card fix the PolarFire HSS needs | hfim-template-polarfire-zephyr-qemu |
hfim-sim-qemu-xuantie |
the XuanTie fork (xuantie-qemu-9.0) with the C906 to C920 models, and XuanTie's bare-metal gcc, an x86-64 program; the image is linux/amd64 on every host and runs emulated on Apple Silicon |
hfim-template-nezha-c906-qemu |
hfim sim install qemu-xuantie # the newest release, a Docker image; or qemu
hfim doctor
A release that names a prebuilt image downloads it from the registry (downloading prebuilt image ... done) instead of building it, and hfim doctor names the image it came from. --from-source builds the image on this machine; so does an install whose download fails, after a line that says why. hfim-sim-qemu-xuantie publishes a linux/amd64 image, the image a build makes on every host, so an Apple Silicon Mac downloads it too and runs it emulated. Prebuilt images describes the check of the image's digest.
The command names the kind of package, so it takes the short name: qemu-xuantie is the package hfim-sim-qemu-xuantie, and the full name works too. qemu-xuantie@9.0.2 installs that release; without a version, the command installs the newest one.
A core decides that a package runs QEMU from its manifest's backends:, never from its name, and takes the QEMU binary, gdb, the plugin, the machine and the CPU from that manifest.
Without Docker
cd hfim-sim-qemu
HFIM_SIM_QEMU=/opt/hfim-sim-qemu ./install.sh
export HFIM_SIM_QEMU=/opt/hfim-sim-qemu
export HFIM_RUNTIME=native
Parameters¶
| Key | Values | Default |
|---|---|---|
simulator |
<package>@<version> of a QEMU package |
the template's pin in hfim.yaml |
fault |
register, memory |
required |
target_registers |
ABI or xN names |
required for register |
auto_registers |
true: only registers the code uses |
false |
target_symbol |
a variable name | |
memory_start, memory_end |
section name or address | |
injection_mode |
icount, breakpoint, timer, stepi |
icount |
inject_at_symbol |
symbol for breakpoint mode |
|
num_workers |
injections run at once | 1 |
All keys: Configuration keys.
# campaigns/fibonacci/register.yaml (as shipped in hfim-template-nezha-c906-qemu)
include: fibonacci.yaml # benchmark: fibonacci and its observable_outputs
campaign_name: fibonacci-register
simulator_backend: qemu
seed: 7
num_injections: 10
num_workers: 1
target_types: [register]
target_registers: [x10, x11, x12, x13, x14, x15]
fault_model: single_bit_flip
injection_mode: icount
timeout: auto
output_dir: results
Fault targets¶
| Target | Selected by | Bits that can flip |
|---|---|---|
| integer register | target_registers: [a0, a1] |
0 to 63 (RV64) |
| float register | target_registers: [fa0] |
0 to 63 |
| memory section | memory_start: .bss |
0 to 7 of one byte |
| address range | memory_start: 0x80000000 |
0 to 7 of one byte |
| variable | target_symbol: result |
0 to 7 of one byte |
Results¶
results/<campaign_id>/
├── injections.csv one row per injection
├── faultlist.json what each injection was asked to do
├── metadata.json the configuration as it ran
├── provenance.json tool version, simulator version, hashes
├── results.txt outcome distribution
└── injections/0001/
├── output.txt console output of the run
└── state.json observable values, when they differ
QEMU fills the register and memory columns of injections.csv. Cache, DRAM and power columns stay empty. Every column: Output files.
Limitations¶
- No cache, pipeline or memory-controller state.
- Multicore: injection into one hart works; runs are not bit-exact replays under SMP.
- A benchmark that waits on a serial feeder has an unstable instruction count. Use
injection_mode: breakpoint.