Add RISC-V baremetal fault injection: variable tracing, section/stack targeting, FP registers - #2
Open
HeavenlyDevv wants to merge 1 commit into
Conversation
… targeting, FP registers Extends the existing RISC-V baremetal support so full fault-injection campaigns can run on RV64GC targets. Six additions, each verified end-to-end: - intercept.c: add RISC-V NOP encodings (0x00000013 addi x0,x0,0; 0x85020001 compressed c.nop) to the serviceHandler marker guard, so variable tracing produces trace files on RISC-V (the guard previously only matched ARM NOPs). - classification.py (gui + support/tools) and commonStructsAndEnumerators.h: add the 32 RISC-V floating-point registers (ft/fs/fa) to the whitelist so register campaigns can target FP registers. The register buffer is sized via MAX_REGISTERS with a copy-loop clamp to stay within bounds. - FI.sh + intercept.c + faultInjector.c: section-based and .stack memory targeting. An SP write-watchpoint records the stack range into goldinformation; FI.sh extracts per-section ELF ranges (readelf) and reads the stack range for a .stack campaign. - faultInjector.c: add a 'Var Inconsistency' report column (compareTracedVariable) that classifies SDC by comparing the traced variable gold vs fault dumps. - gui/options.py + gui/faultlist.py: --minfaulttime option that raises the fault insertion-time floor to skip the initialization phase. - FI.sh: --override mstatus_FS=1 to enable the FPU on RISCV*GC/F/D variants. Verified: all sources compile cleanly (-Werror) and pass python syntax checks against a fresh clone of the extensions branch. ARM code paths are untouched.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RISC-V baremetal fault injection: variable tracing, section/stack targeting, FP registers
Summary
serviceHandlerguardplatformOP/intercept/intercept.cgui/classification.py+commonStructsAndEnumerators.hft/fs/fa).stackmemory targetingFI.sh+intercept.c+faultInjector.c.data/.bss/.rodata/.stackinstead of a fixed rangefaultInjector.c--minfaulttimegui/options.py+gui/faultlist.pyFI.sh--override mstatus_FS=1enables the FPU onRISCV*GC/F/Dvariants (needed for FP-register campaigns)1 — RISC-V NOP encodings
Problem.
serviceHandleronly acts if the intercepted instruction is a known NOP; the whitelist only had ARM encodings. On RISC-V the guard never matched → the handler returned early → no trace files were produced (trace_gold_variable/trace_fault_variable).Before / after (RISCV64GC campaign, 30 faults,
TRACE_VARIABLE=result):trace_gold_variabletrace_fault_variable2 — RISC-V FP registers
Problem. The RISC-V register whitelist (in
gui/classification.py, which feeds the fault-list generatorfaultList2.py → gui/faultlist.py) only had the integer registers. Targeting an FP register failed during generation.self.listOfpossibleRegisters = [ "ra","sp","gp","tp", "t0",...,"t6", "pc", + # floating-point ABI + "ft0",...,"ft7", "fs0","fs1", "fa0",...,"fa7", "fs2",...,"fs11", "ft8",...,"ft11", ](The C header
possibleRegistersRVgets the same extension, so the FP regs can be read when comparing at runtime.)Before / after (register campaign with
REG_LIST=fa5,fs0,fa0):ValueError: 'fa5' is not in list→ fault list not generated3 — Section-based +
.stackmemory targetingProblem. Memory injection used a fixed range (
TARGET_MEM_BASE/SIZE). This adds extraction of the real range per ELF section (readelf), plus a special.stackcase whose range is obtained from SP tracking during the golden run.3-file chain for
.stack:intercept.c— an SP watchpoint writesDumps/stack_range.txt(Stack SP Min/Initial)faultInjector.c— appends that file intogoldinformationFI.sh— the.stackpath reads those keys to bound the campaignBefore / after (
.stackwith the SP watchpoint on/off):.stackcampaignStack SP Min/InitialStack SP Initial=…,Stack SP Min=…,Stack Size=3664For
.data/.bss/.rodatathe range comes fromEntryAddress + Sizeof the section (verified: correct range covering the section).4 — "Var Inconsistency" column
compareTracedVariable()compares the traced-variable dump (gold vs fault) and adds a 14th column to the report file with the verdict (Yes/No), to classify SDC by observing the output variable.5 —
--minfaulttimeBounds the minimum injection time to skip the initialization phase (implemented in
gui/faultlist.py:206-208).Before / after (gold = 3,128,172 instructions,
minfaulttime= 50%):minfaulttime=0)minfaulttime=1,564,086)6 — RISC-V FPU enable
Adds
--override mstatus_FS=1forRISCV*GC/F/Dvariants so the floating-point unit is enabled — required for the FP-register campaigns in component 2. ARM variants are unaffected.Notes for the reviewer