Skip to content

Single-bit flip

QEMU, gem5, OVP (Open Virtual Platforms) and hardware. Targets: registers and memory on every backend, the gem5 cache targets, and control and status registers (CSRs) on OVP. fault_model: single_bit_flip.

A single-bit flip inverts one bit of the target: a 0 becomes a 1, or a 1 becomes a 0. In a real chip this is a single event upset (SEU): a particle strike deposits enough charge in one storage cell to change the bit it holds, and the cell keeps working normally afterwards. It is the fault model most soft-error studies start with, and the one every HFIM template campaign uses.

An HFIM campaign applies one such fault per run, at an instant drawn from the campaign seed, and compares each run with a fault-free golden run of the same program. The comparison gives each fault a verdict: no visible effect, wrong output, an error the program detected itself, a crash or a hang.

The byte at 0x80000210 holds 0x08. HFIM XORs it with 1 << 4, so bit 4 inverts from 0 to 1 and the byte holds 0x18; the other seven bits keep their values. The byte at 0x80000210 holds 0x08. HFIM XORs it with 1 << 4, so bit 4 inverts from 0 to 1 and the byte holds 0x18; the other seven bits keep their values.

How the bits change

Take the byte in the figure. It holds 0x08, binary 00001000. HFIM draws bit 4, builds the mask 1 << 4 (binary 00010000) and writes back the exclusive OR (XOR) of the two values: 0x08 XOR 0x10 = 0x18. Bit 4 was 0, so it becomes 1. Had it been 1, it would have become 0. Every other bit keeps its value.

fault_model Operation on bit b Models
single_bit_flip value XOR (1 << b) a single event upset

A flip always changes the value. That is the difference from a stuck-at fault, which forces a bit to 0 or 1 and leaves the value as it was when the bit already held that level.

The bit is drawn before the campaign starts. HFIM builds the whole fault list from the seed first: for each injection, the instant, the target, then the bit, uniformly from bit 0 to bit_width - 1. The same seed gives the same list, so the same bits, on every run and with any number of parallel workers. The width the bit is drawn from depends on the target:

Target Bits drawn by default
integer or floating-point register 0 to 63
memory 0 to 7: one byte, because memory_access_size defaults to 1
memory with memory_access_size: 2, 4 or 8 0 to 15, 31 or 63 across the access
gem5 cache data 0 to 7: one byte of the line

Setting bit_width (8, 16, 32 or 64) narrows the draw. Only the drawn bit changes: on a 64-bit register with bit_width: 32, the upper 32 bits keep their value.

Every backend computes the faulty value with the same XOR. QEMU and hardware campaigns read the target through the GNU Debugger (GDB), apply the flip in HFIM and write the result back. gem5 applies it inside the simulator, in the injector compiled into gem5. On OVP, HFIM computes the faulty value and its OVP driver writes it into the simulated processor.

A campaign

This is campaigns/fibonacci/memory.yaml from the nezha-c906-qemu template. The Fibonacci benchmark fills a 64-entry array result[], and this campaign flips one bit of one byte of it per run, 20 times.

include: fibonacci.yaml          # benchmark: fibonacci, observable result[]

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
hfim run campaigns/fibonacci/memory.yaml

The campaign log prints Fault model: single_bit_flip before the first injection. The same line appears in the campaign's results.txt. For a register campaign, keep fault_model: single_bit_flip and change only the target keys, as in the template's register.yaml.

What you see in the results

Each injection is one row of injections.csv in the campaign's results directory. This row comes from the memory campaign above:

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,...
  • bit_position 4 is the drawn bit.
  • original_value 0x8 and faulty_value 0x18 are the byte before and after the write. You can always check a single-bit flip row by hand: original_value XOR faulty_value equals 1 << bit_position, here 0x8 XOR 0x18 = 0x10.
  • target_name 0x80000210 is the byte's address, the low byte of result[6].
  • outcome sdc (silent data corruption) means the program finished normally but its output differs from the golden run. sdc_details reads result[6]: expected 8, got 24, the same flip seen as a number.

Register rows read the same way. This one is from a QEMU register campaign on the same benchmark (seed 1234): register x12 held 0x1028, bit 4 flipped, and it held 0x1038.

injection_id,timestamp,instruction_count,target_type,target_name,original_value,faulty_value,bit_position,hit_instance,outcome,execution_time,exit_code,timed_out,hang_cutoff,sdc_details,state_match
2,2026-09-07T12:10:05.204123,282,register,x12,0x1028,0x1038,4,0,masked,6.916,0,False,False,,True

That run is masked: result[] matched the golden run (state_match is True), so the flipped value never reached the output. A masked run is common: many bits hold nothing live, or are overwritten before anything reads them. A flip in live data gives sdc, a flip in a pointer or return address tends to give crash, and a flip in a loop counter can give timeout. How HFIM decides each outcome: Fault classification.

Limits

  • Applied once. HFIM writes the flipped value at one instant. If the program writes the target again before reading it, the fault is gone and the run is masked. That is the expected behavior of an upset, not a failed injection.
  • One bit, unless you ask for more. multi_bit_count above 1 keeps the XOR but flips several distinct bits, drawn independently, in one write. See Multi-bit faults.
  • Only these three names are accepted. fault_model takes single_bit_flip, stuck_at_0 or stuck_at_1. Another spelling is rejected at load, for example Invalid fault_model 'bit_flip'. Valid values: single_bit_flip, stuck_at_0, stuck_at_1.
  • fault_persistence: permanent changes the meaning. QEMU and hardware reject it. OVP rejects it for a flip unless you also set ovp_permanent_model: inverted_cell, where every value the program writes is stored with the bit inverted. On gem5, the injector re-applies the XOR after every committed instruction, so the bit inverts again at each instruction instead of staying inverted, and only for register targets. For a bit that stays at one level, use stuck-at with fault_persistence: permanent on gem5 or OVP.
  • A 32-bit hart on QEMU. With xlen: 32, an integer register of the hart (hardware thread) has 32 bits, but the fault list still draws from 0 to 63 unless you also set bit_width: 32. An injection that drew a bit above 31 fails instead of running. See Registers.
  • CSRs are not drawn. On OVP, a CSR campaign replays an explicit faultlist_csv, and each row names its register and bit.

See also: Fault models · Stuck-at · Memory · Configuration keys