Instruction access fault reports mtval = pc+2 when the first half of an unaligned instruction fails its bus access and the second half fails PMP
Maintainer antworten meist innerhalb von 2 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 55/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Bereich
- backend-api-design
Rechercherichtung
Start with the if_instr_err_plus2 assignment in rtl/ibex_if_stage.sv (lines 435–436) and trace how first-half bus and PMP errors affect the reported fault address. Reproduce with the attached bench and compare the f1_errplus2 and control runs. Done when the PMP case reports mtval = pc while the second-half-only fault behavior remains correct.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Observed Behavior
A 32-bit instruction at a halfword address pc (pc[1] = 1) spans two fetch words. If the fetch of the first word gets a bus error (instr_err_i) and the second half (pc + 2) is in a PMP region without execute permission, Ibex takes an instruction access fault with mepc = pc but mtval = pc + 2, as if the first half had been fetched without fault.
| run | mcause | mepc | mtval |
|---|---|---|---|
f1_errplus2 (first half: bus error; second half: bus error + PMP no-X) |
1 | 0xd6cbfffe |
0xd6cc0000 |
f1_errplus2_ctl (same, no PMP region; both halves: bus error only) |
1 | 0xd6cbfffe |
0xd6cbfffe |
if_instr_err_plus2 is set by a PMP error on the second half and cleared only by a PMP error on the first half (& ~pmp_err_if_i), not by a bus error on the first half: rtl/ibex_if_stage.sv:435-436. When the second half has only a bus error, the prefetch buffer reports it only if the first half had no error, so that case is correct (control run above). mcause and mepc are correct in both runs; only mtval is wrong.
Attached: simulation logs of both runs (evidence/*.log) and a formal counterexample on the same RTL (evidence/formal_ibex_top_u_bp_u_spec_BP5_CAUSE.vcd, 14 cycles from a NOP start state).
Expected Behavior
mtval = pc = 0xd6cbfffe, as in the control run and as Ibex already reports when the first half fails PMP. RISC-V Privileged Specification, "Machine Trap Value Register (mtval)":
If mtval is written with a nonzero value when an instruction access-fault or page-fault exception occurs on a system with variable-length instructions, then mtval will contain the virtual address of the portion of the instruction that caused the fault, while mepc will point to the beginning of the instruction.
The pc + 2 reporting was added for the case where only the second half faults (#709, #713). A possible fix is to clear if_instr_err_plus2 on any first-half fault, not only a PMP one:
assign if_instr_err_plus2 = ((if_instr_addr[1] & ~instr_is_compressed & pmp_err_if_plus2_i) |
fetch_err_plus2) & ~(pmp_err_if_i | fetch_err);
Steps to reproduce the issue
The attached bench tb_ibex_bp.sv instantiates ibex_top with PMPEnable = 1, PMPNumRegions = 4, PMPGranularity = 0, plus the experimental-branch-predictor settings of ibex_configs.yaml (RV32M = RV32MSingleCycle, RV32ZC = RV32ZcaZcbZcmp, BranchTargetALU = 1, WritebackStage = 1, BranchPredictor = 1). Only PMPEnable = 1 and an instruction-bus error are needed; the branch predictor plays no part. The bench answers every fetch from 0xD0000000-0xDFFFFFFF with an error and returns 0xffffffff as data (OBI leaves error-response data undefined).
f1_errplus2.Slocks PMP region 2 as NAPOT 4 KiB at0xd6cc0000with R/W and no X, then jumps to0xd6cbfffe.f1_errplus2_ctl.Sis the same without the PMP region.
git clone https://github.com/lowRISC/ibex && cd ibex && git checkout 626034d7- Run the attached script, which builds the bench with Verilator (defines
+define+AB_PMP +define+SYNTHESIS), assembles both programs and runs them:sh run.sh <ibex checkout> # per program: riscv32-unknown-elf-gcc -march=rv32imc_zicsr_zifencei_zca_zcb_zcmp -mabi=ilp32 -nostdlib -nostartfiles -T link.ld crt.S f1_errplus2.S # simv +hex=f1_errplus2.hex +ierrdata=ffffffff - Each run prints three
SIGlines: mcause, mepc, mtval. Output:== f1_errplus2 SIG 00000001 SIG d6cbfffe SIG d6cc0000 == f1_errplus2_ctl SIG 00000001 SIG d6cbfffe SIG d6cbfffe
No changes to the Ibex source code.
My Environment
EDA tool and version:
Verilator 5.044 (simulation); riscv32-unknown-elf-gcc 16.1.0.
Operating system:
Red Hat Enterprise Linux 8.10
Version of the Ibex source code:
626034d7557ab85a6d989b13011b44296bad26fa (master, 2026-11-06), unmodified.
All of the relevant materials pertaining to the bug:
- Vorherrschende Sprache
- SystemVerilog
- Sterne
- 2.2k
- Forks
- 836
- Ø Merge
- 5 T. 8 Std.
- Gemergte PRs (30 T.)
- 22
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus lowRISC/ibex
-
[Bug Report] rvfi_intr is not set on the first instruction of an exception handlerEvtl. vergeben @h-filali hat das vor 6 Tagen übernommen. OffenType:Bug
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 68/100
lowRISC/ibex#2556 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Type:Bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
lowRISC/ibex#2528 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
mip documentation errorOffenType:Bug
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
Maintainer antworten meist innerhalb von 2 Tagen
-
[doc] Document basic commands for running/checking IbexEvtl. vergeben @shrutikbalwan hat das vor 46 Tagen übernommen. OffenComponent:Doc Good First Issue Type:Task
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
lowRISC/ibex#741 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 42/100
Maintainer antworten meist innerhalb von 2 Tagen
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
ROCm/rocm-libraries#15665 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
shadps4-emu/shadPS4#5705 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug multiple issues priority: high
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
storytold/gridcraft#3928 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Qiskit/qiskit-aer#2533 ·
Maintainer antworten meist innerhalb von 1 Tag