Memory¶
QEMU, gem5, hardware and OVP (Open Virtual Platforms). Fault models: single-bit flip, multi-bit, stuck-at. fault: memory.
A memory fault changes bits in the program's RAM: a variable, a buffer, a stack frame. In a real chip this is a particle strike or a weak cell that flips a stored bit, and the program only notices when it reads that byte again. An HFIM campaign runs the program many times, applies one fault per run at a drawn instant, and compares each run with a fault-free golden run of the same program.
The question a memory campaign answers is where the fault may land. You choose a window of addresses, and HFIM draws one address inside it for each injection. There are four ways to choose the window: one variable, one section, an address range, or the stack. A variable, a section and the stack are looked up in the program's ELF (Executable and Linkable Format) file, the linked binary, so they follow the program when you rebuild it. A range given as numbers does not.
The figure uses the template's Fibonacci benchmark, where result[64] (64 eight-byte numbers) is all of .bss. That is why the variable and the section give the same window there.
How HFIM applies the fault¶
For each injection, the campaign seed draws three things: the instant, an address inside the window, and the bit or bits to change. At the instant, HFIM stops the program, reads the memory at that address, changes the drawn bits with the fault model, writes the value back and lets the program continue. Nothing else changes, so the fault matters only if the program reads that byte before it overwrites it.
The drawn address is aligned to memory_access_size (default 1, so any byte). How much memory one fault touches depends on the backend:
| Backend | Width read and written | Bits that can flip |
|---|---|---|
| QEMU | memory_access_size bytes, through the debugger |
0 to 8 * memory_access_size - 1 |
| hardware | the whole memory_access_size word |
0 to 8 * memory_access_size - 1 |
| OVP | the whole memory_access_size word (1, 2, 4 or 8 bytes) |
0 to 8 * memory_access_size - 1 |
| gem5 | 8 bytes from the drawn address; original_value and faulty_value hold that 8-byte word |
0 to 7 with the default memory_access_size: 1, so only the drawn byte changes |
The word is little-endian, as on RISC-V: bit 0 is the low bit of the byte at the drawn address. With the default size, every fault is a change inside one byte on every backend. Keep memory_access_size the same across campaigns you compare, because it changes the draw.
One variable¶
fault: memory
target_symbol: result
HFIM looks the name up in the ELF symbol table and takes its address and size, so an array is covered whole and no debug information is needed. The run log names the range:
Resolved target_symbol 'result' to 0x800001e0 - 0x800003e0 (512 bytes)
This is the narrowest window: every fault lands in that variable. The symbol must be a data object with a fixed address. target_variable is the same key under another name.
| Symbol | Result |
|---|---|
file-scope variable, global or static |
accepted |
static variable inside a function |
accepted, under the name the compiler gives it |
| local variable | rejected at setup: it has no symbol, because it lives on the stack |
| function name | rejected at setup as a code symbol; to fault at a code address, use inject_at_symbol (When to inject) |
| symbol of size zero | rejected at setup; give memory_start and memory_end instead |
A static inside a function gets a compiler-made name: for a counter inside compute(), RISC-V GCC writes counter.0 and clang writes compute.counter. Read the real name from the built ELF with nm.
One section¶
fault: memory
section: .bss
The section name resolves from the ELF section headers to the whole section, from its start to its start plus its size. section: .bss is shorthand for memory_start: .bss with memory_end: .bss; setting section together with a different memory_start or memory_end is rejected. A section that does not exist stops the campaign with a list of the sections that do, and a section with address 0 (relocation data such as .rela.dyn) is refused because the program never runs from it.
Address range¶
fault: memory
memory_start: 0x80000200
memory_end: 0x80000300
The window is memory_start up to, but not including, memory_end. In the Fibonacci program this covers result[4] to result[35]. Either end also takes a section name. memory_end must be above memory_start. HFIM does not check a literal range against the ELF, so a range over bytes the program never reads gives only masked runs. When a campaign returns 100% masked, check the window first.
The stack¶
fault: memory
section: .stack
Most bare-metal ELFs carry no .stack section header. HFIM uses a real .stack header when there is one, and otherwise the first pair of linker symbols it finds:
| Lower symbol | Upper symbol |
|---|---|
__stack_bottom |
__stack_top |
_stack_bottom |
_stack_top |
__stack_start |
__stack_end |
_estack_bottom |
_estack |
.stack is the whole reservation, 16 KB in the template. A small program uses a few hundred bytes at the top of it, so most faults land in memory that is never read and come back masked. .stack-live narrows the window to the part in use:
fault: memory
section: .stack-live
The stack grows down from __stack_top, so the part in use runs from the stack pointer up to __stack_top. Which stack pointer depends on injection_mode:
injection_mode |
Window | Covers |
|---|---|---|
icount, timer |
sp_min to __stack_top, recorded by the golden run |
every frame the program pushes during the run |
breakpoint |
the stack pointer read at the stop, to __stack_top |
the frames live at that instant |
The golden run samples the stack pointer every 100 instructions, and sp_min is the lowest sample. The window can be slightly smaller than the deepest frame, never larger. In breakpoint mode the address is drawn over the whole reservation first and moved into the live window at the stop, so each injection still gets its own address from the seed.
Random DRAM byte¶
simulator_backend: gem5
fault: memory
memory_random_fallback: true
gem5 only. Instead of a window, the gem5 injector picks one byte anywhere in the simulated DRAM (dynamic random-access memory, the main memory) for each injection and applies the fault model to bits 0 to 7 of that byte. The rows carry an empty target_name, so you cannot tell from the results which variable was hit.
A campaign¶
The template's memory campaign injects 20 single-bit flips into .bss of the Fibonacci benchmark. The benchmark and what counts as correct (the result array) come from fibonacci.yaml, which it includes:
# campaigns/fibonacci/memory.yaml
include: fibonacci.yaml
campaign_name: fibonacci-memory
simulator_backend: qemu
seed: 7
num_injections: 20
num_workers: 1
target_types: [memory]
memory_start: .bss
memory_end: .bss
fault_model: single_bit_flip
injection_mode: icount
timeout: auto
output_dir: results
target_types: [memory] with memory_start and memory_end is the same as fault: memory with section: .bss. Run it from the template directory with hfim run campaigns/fibonacci/memory.yaml. At setup the log prints the resolved window on a line that starts with Target memory range:, with its size in bytes and the access size. Check that line before you read any results.
What you see in the results¶
Each injection is one row of injections.csv. A row from a QEMU memory campaign on the same benchmark, in icount mode:
injection_id,timestamp,instruction_count,target_type,target_name,original_value,faulty_value,bit_position,hit_instance,actual_pc,outcome,...
2,2026-09-16T12:46:43,942,memory,0x80000210,0x8,0x18,4,0,0x8000021e,sdc,...
target_name0x80000210is the drawn address: 48 bytes intoresult, the low byte ofresult[6].original_value0x8andfaulty_value0x18are the byte before and after.bit_position4is the bit that flipped:0x8 XOR (1 << 4) = 0x18.instruction_count942is the instant: the fault was applied after 942 retired instructions.outcomesdc(silent data corruption) means the program finished normally but its result differs from the golden run. Heresdc_detailsreadsresult[6]: expected 8, got 24.
In this program the outcome depends on timing. A flip in an element the loop has not written yet is overwritten when the loop reaches it, so the run is masked: the result matches the golden run. A flip in an element already written either feeds the following numbers or, for the last ones, stays in result until the end; both give sdc. result holds data, not addresses or code, so a flip in it does not redirect the program. The five outcomes and how HFIM decides between them: Fault classification.
Keys¶
| Key | Values | Default |
|---|---|---|
fault |
memory |
|
target_symbol |
a data symbol name; also accepted as target_variable |
|
section |
a section name, .stack or .stack-live; fills memory_start and memory_end |
|
memory_start, memory_end |
an address or a section name | required unless target_symbol or section is set |
memory_access_size |
1, 2, 4, 8: alignment of the drawn address in bytes; on QEMU, hardware and OVP also the width written |
1 |
memory_random_fallback |
true: one byte anywhere in DRAM (gem5 only) |
false |
memory_per_core |
true: one slice of the window per hart (hardware thread), see Multicore |
false |
When target_symbol is set, it decides the window and memory_start and memory_end are not used. A memory campaign takes no target_registers: one campaign has one target family, and a key of another family is rejected at load.
Limits¶
- A memory fault is applied once. The program can overwrite it right away, and then the run is
maskedeven though the bit did flip. A fault held in place is a property of the fault model, not of the target: see Stuck-at. - On gem5, keep
memory_access_size: 1. A gem5 faultlist replay rejects any memory row whose bit is above 7. .stack-liveinicountortimermode needs the stack envelope from the golden run. OVP always records it. For such a campaign, a QEMU golden run first runs the program once with a breakpoint after every instruction that lowers the stack pointer and keeps the lowest value, which is exact. That run is not timed: the golden run after it runs without probes, sotimeout: autois unaffected.hfim rundoes this by itself, and the golden it makes is kept apart from the golden of campaigns that do not need the envelope.hfim golden --sp-envelopeturns the probes on by hand. Every call that lowers the stack pointer is one probe stop. When GDB has Python, as the simulator images do, GDB handles each stop itself; otherwise hfim does, which is much slower. The probe run stops with an error after--sp-probe-budgetseconds (default 1800, 30 minutes) and names the ways out:breakpointmode, a smaller input, or a larger budget given tohfim golden <benchmark> --config <campaign> --sp-probe-budget <seconds>, whose Goldenhfim runthen reuses. A golden without the exact envelope is refused at setup. The gem5 and hardware golden runs do not, and such a campaign stops at setup with a message thatstack_sp_minandstack_sp_initialare missing..stack-liveinbreakpointmode stops the injection when the stack pointer at the stop lies outside the reservation, which happens when the breakpoint fires before the startup code has set up the stack.- An ELF with no
.stackheader and none of the symbol pairs above cannot use.stackor.stack-live; give the range withmemory_startandmemory_end. - On OVP,
memory_random_fallbackis refused at setup, and.stack-livewithnum_coresabove 1 needsbreakpointmode andstack_live_shared_reservation.
See also: QEMU backend · Single-bit flip · Registers · Configuration keys