Control and status registers¶
OVP only. Fault models: single-bit flip, stuck-at. fault: csr.
A control and status register (CSR) holds the state a RISC-V hart (hardware thread) uses to run itself rather than the program's data. The trap vector, the return address of a trap, its cause, the interrupt enable bits and the floating-point rounding mode all live in CSRs. This target corrupts one of nine CSRs (six machine-mode trap and status CSRs and three floating-point CSRs) at an instant you name, on the OVP backend (Open Virtual Platforms, the Imperas instruction-set simulator). As in every HFIM campaign, each run applies one fault and HFIM compares the result with a fault-free golden run of the same program.
What makes a CSR different from an ordinary register is that the hart does not have to keep what you write. Many CSR fields are WARL (write any values, reads legal values) or read-only, so the processor model drops or rewrites some bits. HFIM therefore records what the hart actually kept, which is the fault that really happened.
The CSRs you can target¶
HFIM accepts these nine names, in any letter case. Any other name, including the counters, satp, the physical memory protection registers, the supervisor CSRs and the other user-level CSRs, is refused before the first run.
| CSR | What it holds |
|---|---|
mstatus |
machine status: interrupt enables, privilege fields, floating-point state |
mtvec |
address of the trap handler, and its mode |
mepc |
address of the instruction a trap interrupted |
mcause |
the cause of the last trap |
mtval |
extra information about the last trap, such as a faulting address |
mscratch |
a free word for the trap handler |
fcsr |
floating-point control and status: frm and fflags together |
frm |
floating-point rounding mode (a field of fcsr) |
fflags |
floating-point exception flags (a field of fcsr) |
A fault in a trap CSR such as mtvec or mepc usually changes nothing until the program takes a trap. A bare-metal benchmark that never traps can leave such a fault unread.
How HFIM applies the fault¶
CSR faults are replayed only. There is no seeded draw over CSRs, so you write a faultlist: a CSV (comma-separated values) file with one fault per row. Each row names the CSR, the bit and the instant.
injection_id,instruction_count,target_type,target_name,bit_position
1,500,csr,mscratch,5
2,500,csr,frm,0
3,900,csr,mtvec,2
target_type is csr and target_name is the CSR. instruction_count is the one-based instruction, counted from reset, that the fault lands before: the hart is stopped with instruction_count - 1 instructions retired. bit_position is a bit from 0 to 63 for every CSR, because a CSR on RV64 (64-bit RISC-V) is 64 bits wide. A narrow field such as frm accepts the row, and the readback shows which bits the hart kept. A row may also list several bits in a bit_positions column, separated by ;.
At the stop, the OVP driver reads the CSR and sends its value to HFIM. HFIM computes the requested value from the fault model: a single-bit flip XORs the bit, stuck_at_0 clears it and stuck_at_1 sets it. The driver writes the requested value to the CSR by name and reads it back.
HFIM then checks two things before the program continues. First, the driver must report that it wrote exactly the requested value. If it wrote anything else, HFIM aborts the run and records it as infrastructure_failure. Second, HFIM compares the readback, the value the hart kept, and names the effect of the fault:
| Effect | Readback | Meaning |
|---|---|---|
full |
equals the requested value | the hart kept every faulted bit |
none |
equals the original value, not the requested one | the hart dropped the change: the bit is read-only or WARL |
partial |
anything else | the hart kept some bits, or wrote a legal value of its own |
The run resumes in all three cases. A WARL field that rewrites the value is part of the fault, not an error.
A campaign¶
The campaign uses the Fibonacci benchmark. It names the OVP simulator package, the target, the fault model and the faultlist above, saved as campaigns/fibonacci/csr-faults.csv beside the campaign file. Like every path in a campaign, faultlist_csv is relative to the repository root, not to the campaign file.
include: fibonacci.yaml
campaign_name: fibonacci-csr
simulator: hfim-sim-ovp@0.6.9
simulator_backend: ovp
fault: csr
fault_model: single_bit_flip
faultlist_csv: campaigns/fibonacci/csr-faults.csv
num_injections: 3
seed: 7
hang_icount_factor: 3.0
timeout: auto
output_dir: results
faultlist_csv makes HFIM run every row of the file, in order, instead of drawing faults. Set num_injections to the number of rows so the campaign states how many runs it makes. hang_icount_factor is required on OVP: a run that executes more than this multiple of the golden run's instruction count stops with outcome timeout.
Run it like any other campaign:
hfim run campaigns/fibonacci/csr.yaml
The log shows Creating CSR fault injection campaign, then Starting 3 ovp replay injections (budget N instructions from reset), where N is the instruction budget the factor resolved to. Before the first injection HFIM checks every row, so a wrong CSR name or bit stops the campaign at once with the row number.
What you see in the results¶
Each run adds one row to injections.csv. For a CSR fault, target_type is csr and target_name is the CSR. original_value is the CSR value the driver read at the stop. faulty_value is the readback, the value the hart kept, not the value HFIM asked for.
faulty_value is what the hart kept
When faulty_value equals original_value, the CSR holds what it held before: the hart dropped the change, or a stuck-at asked for the value the bit already had. The program then ran on unchanged state, and the row shows the outcome of a run without a fault.
The full record of each fault is in ovp_evidence/injection_NNNN.json in the campaign's results folder. Under requested it has target: csr, the CSR name and the mask. Under observed it has the original value, the written value, the readback, requested_value and csr_effect (full, partial or none).
The outcome of each row comes from the same rules as any other target. The run is masked when its observables match the golden run, and sdc (silent data corruption) when the program finishes with a wrong answer. It is crash when the hart traps and reaches the reset trap vector with no handler installed, and timeout when the instruction budget runs out. Most of these CSRs steer traps and control flow rather than data. frm is the exception: it changes how floating-point results are rounded, so a program that computes in floating point can finish with a wrong answer. See Fault classification for the full decision order.
Keys¶
| Key | Values | Default |
|---|---|---|
fault |
csr |
required |
simulator_backend |
ovp |
qemu |
simulator |
hfim-sim-ovp@<version>, 0.5.1 or later for CSRs |
required on OVP |
faultlist_csv |
path to the faultlist | required for csr |
fault_model |
single_bit_flip, stuck_at_0, stuck_at_1 |
required |
hang_icount_factor |
number above 1.0 | required on OVP |
Limits¶
- OVP only. QEMU and gem5 have no CSR target. A campaign with
fault: csron another backend stops with:target_types: csr (a control and status register) is injected only by the OVP backend (simulator_backend: ovp); QEMU and gem5 have no CSR fault target. - Faultlist only. Without
faultlist_csv, HFIM refuses the campaign withtarget_types: csr is replayed from an explicit faultlist (faultlist_csv); there is no draw over CSRs. - Transient only.
fault_persistence: permanentis refused on a CSR. The fault is written once, and the program or the hart may overwrite it later. - One hart.
num_coresabove 1 is refused withtarget_types: csr with num_cores > 1 is not supported on OVP. - Package version. A simulator package older than 0.5.1 does not declare CSRs. Each row is then refused with a message that names the package and asks you to pin
hfim-sim-ovp@0.5.1or later. - Which bits stick depends on the model. HFIM does not predict which CSR bits are writable. The processor model decides, and the readback records the decision. A bit that the model does not implement gives
csr_effect: none. - Several bits come from the row. A CSR campaign draws nothing, so
multi_bit_counthas no effect. To change several bits in one fault, list them in the row'sbit_positionscolumn; the fault model applies to each listed bit.
See also: OVP backend · Registers · Stuck-at · Configuration keys