Skip to content
Rivoryxa Technologies

Proving the fix for an instruction count bug in debug mode

A closed bug report on a RISC-V core: an mret run in debug mode raised the retired instruction counter. We reproduced it and proved the maintainers' fix holds.

Open source RISC-V core, bug report 558Outcome: Bug reproduced, fix verified

1The issue

The minstret register counts the instructions a RISC-V core retires, meaning finishes. Issue 558 reported that an mret run in debug mode raised that count. An mret is the instruction that returns from a trap. The issue author also suggested where to fix it, in the decoder. The maintainers later changed the decoder to treat mret in debug mode as illegal, and the issue was closed.

The points on the issue

Before the fix: mret in debug modeCounted. A 10 cycle trace shows the mret retire with the count raised.
Each step of that traceEach reached on its own: debug mode at cycle 7, the mret retiring in debug mode at cycle 10.
After the fix: mret in debug modeNever counted. Proven for all time, and passes a 40 cycle bounded check.
The maintainers' fix, read after our proofsThe decoder flags mret in debug mode as illegal, so it never retires as an mret.

2What we did

  1. 1Wrote a rule: while the core is in debug mode, a retiring mret must not raise the instruction count.
  2. 2Ran it on the design from 27 May 2022, before the issue was filed. Formal checking found a 10 cycle trace: a debug request, then an mret fetched from the debug halt address that retires with the count raised.
  3. 3Proved the same rule on the current design for all time, and checked that an mret can no longer retire in debug mode at all.
  4. 4Only then read the maintainers' fix. It blocks the exact path the trace isolates, at the place the issue author proposed.

3Result

The bug is reproduced on the old design and proven absent from the current one. The mechanism our trace isolates matches the maintainers' fix.

The fix is verified against the checks in the report only, not the wider test suite, and only for the configuration the report names.

Have a bug like this one?

Describe the problem in a few lines. An engineer replies, and we agree the scope together.

Discuss a verification problem