Commit graph

585 commits

Author SHA1 Message Date
Greg Chadwick
27dd6b2e06 [rtl] Update use of prim_count following port changes
The latest version of `prim_count` from OpenTitan introduces a
`commit_i` input. To retain the behaviour of the previous `prim_count`
this should be set to a constant 1.

The `cnt_next_o` output has been renamed to `cnt_after_commit_o`.
2024-03-01 10:18:25 +00:00
Adrian Lees
5a8a1a9993 [tracer] Fix reporting of load/store data
Modify tracer to use the appropriate read/write masks when logging
load/store traffic from the Load Store Unit.

Signed-off-by: Adrian Lees <a.lees@lowrisc.org>
2024-02-17 20:43:01 +00:00
Pascal Nasahl
8ec0c6f18e [rtl] Harden lockstep enable against FI
Currently, the dual-core lockstep FI mitigation is enabled/disabled
using a single bit.
For transient bit-flips, this is not problematic, as one bit-flip
into this signal and one bit into the Ibex is required to threaten
the security of the system.

However, a permanent stuck-at-0 fault could disable the lockstep
completely by targeting this signal. Then, only a single, additional
fault (transient or permanent) is required.

This PR enhances the FI resilience of the Ibex lockstep by encoding
this single bit into a ibex_mubi_t signal, i.e., a 4-bit multi-bit
signal.

Signed-off-by: Pascal Nasahl <nasahlpa@lowrisc.org>
2024-01-23 09:14:45 +00:00
Michael Schaffner
56413ecf10 [icache] Disable S&P diffusion layer in memory scrambling
Signed-off-by: Michael Schaffner <msf@opentitan.org>
2024-01-19 03:24:48 +00:00
Pascal Nasahl
35bbdb7be3 [rtl] Fix FI vulnerability in RF
As described in #20715, a single fault-induced bit-flip inside the
register file could change which of the register file value is
provided to Ibex.

This PR fixes this issue by (i) encoding raddr_a/b to one-hot
encoded signals, (ii) checking these signals for faults, and
(iii) using an one-hot encoded MUX to select which register file
value is forwarded to rdata_a/b.

Area increases by ~1% (Yosys + Nangate45 synthesis).

I conducted a formal fault injection verification at the Yosys
netlist to ensure that the issue really is fixed.

Signed-off-by: Pascal Nasahl <nasahlpa@lowrisc.org>
2024-01-04 15:26:32 +00:00
Rupert Swarbrick
d097c918f5 [rtl] Avoid name collision in ibex_pmp.sv
Recent versions of Verilator complain about the code that was there
because the csr_pmp_cfg argument clashes with a name in ibex_core.sv.

What's more, they mean different things! In ibex_core.sv, it was the
PMP configuration for the entire core. In the functions, it's the PMP
configuration for a single region. This patch adds a "region_" prefix
to the names, which fixes both the Verilator warning and my confusion!
2023-12-05 15:18:40 +00:00
Rupert Swarbrick
fe84d64d79 [verilator] Slight refactor in ibex_tracer to avoid BLKSEQ warning
The existing code wanted to open file_handle as a trace file if
necessary and then use it on that clock cycle. So it (sensibly) used a
blocking assignment.

Verilator now warns about blocking assignments to globals in
"sequential logic processes" (the always_ff that is driving
everything). This is sort of easy to fix: just use an "always" block!

This commit looks slightly more involved because I've changed things
to pass the file handle to printbuffer_dumpline as an argument. It
makes the state update (where we open the file handle) a little easier
to follow.
2023-11-22 09:46:03 +00:00
Michael Schaffner
bac72d96ec [ibex_pmp/lint] Declare functions before using them
Signed-off-by: Michael Schaffner <msf@opentitan.org>
2023-10-19 07:58:30 +00:00
Greg Chadwick
1084ac118e [dv] Add asserts to check alerts for memory integrity failures 2023-05-15 13:51:06 +00:00
Greg Chadwick
1120e8ddbf [dv] Improve interrupt signalling to cosim
Previously any changes in interrupt state or debug requests were
strictly associated with retired instructions. This causes cosim
mismatches where a lower priority interrupt occurs in time before a
higher priority interrupt or debug request but between instruction
fetches/retirements so both the low and high priority interrupts are
signalled with the instruction retirement.

This introduces a way for the RVFI to signal an interrupt has occurred
that isn't associated with an instruction retirement to allow the cosim
to see the seperation in time between different interrupts and debug
requests and hence model behaviour correctly.
2023-04-27 12:04:22 +00:00
Greg Chadwick
5e3474c9da Remove TODOs
- rvfi_trap now correctly handled for writeback
 - issue created to track coverpoint for pmpcfg reserved bits writes.
 - flush pipe on debug CSR writes is reasonable
2023-04-25 14:23:34 +00:00
Saad Khalid
6e4352af10 Fixed capture info for spike cosim in case of multiple interrupts
Signed-off-by: Saad Khalid <saad.khalid@lowrisc.org>
2023-04-13 17:30:33 +00:00
Greg Chadwick
e58a9ff792 [rtl] Add missing `include to ibex_if_stage
The include is needed for a FCOV related macro. Lack of this include can
cause issues in some simulators.
2023-04-11 14:22:05 +00:00
Flavien Solt
43aeda171d Avoid explicit module names references to signals
This allows changing the module names without breaking the sim flow.
2023-03-10 14:47:17 +00:00
Greg Chadwick
381fc845ba [rtl] Fix MISA X bit for balanced bitmanip config
All RV32B configs include non-ratified sub-extensions so the 'X' bit
MISA must be set for all of them.
2023-03-02 10:15:34 +00:00
Andreas Kurth
911a6735b9 [rtl/dv] Add assertions for icache scramble keys
This commit adds two assertions in `ibex_top` to ensure that the
scramble key is correctly applied to the icache scrambled memory
primitives.  Those assertions previously existed in the module that
instantiated Ibex in OpenTitan, but the reference into the generate
loops was problematic for some EDA tools; see lowRISC/opentitan#17155.

Additionally, the assertions previously used the input scramble key
(`scramble_key_i`) even though they tolerated a delay after which the
input scramble key was not necessarily valid anymore (i.e.,
`scramble_key_valid_i` could go low and `scramble_key_i` could take any
value).  This mistake has been corrected by sampling the input scramble
key for the assertions when it is valid and using the sampled value in
the comparison of the assertions.  This problem surfaced in the DV
environment of Ibex (but not in OpenTitan), where multiple tests
(including `riscv_rand_instr_test`, `riscv_mem_error_test`, and
`riscv_multiple_interrupt_test`) failed; these tests now pass.

Signed-off-by: Andreas Kurth <adk@lowrisc.org>
2023-01-31 17:59:50 +01:00
Pirmin Vogel
590d196e62 [rtl] Improve FI hardening around data_rvalid_i
Previously, it was possible to glitch data_rvalid_i at the interconnect
level and if the data integrity bits happened to be valid, Ibex would
write the current data_rdata_i into the register file even if it wasn't
doing a load. Since the glitch is inserted at the interconnect level,
both the main and the shadow core are affected equally.

This commit changes the WB stage to only forward the LSU write enable,
which is generated from data_rvalid_i, when Ibex is actually waiting for
an interconnect response for a load instruction. This substantially
narrows down the window for attacks at the interconnect level.

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
2023-01-16 18:53:17 +01:00
Guillermo Maturana
ec32fb1a64 [rtl] Change code to be more xprop-friendly
Xprop is a simulation feature that improves the SV semantics when
conditions contain 'X values. Change RTL or DV code to enable more xprop
instrumentation.

This addresses lowRISC/opentitan#16791 and some of
lowRISC/opentitan#16723.

Signed-off-by: Guillermo Maturana <maturana@google.com>
2022-12-22 10:09:06 +01:00
Greg Chadwick
726eb97a88 [rtl] Flush pipe on MSECCFG CSR write
Without this an instruction executed immediately after the MSECCFG write
doesn't have the new MSECCFG setup applied to its execute permission.
2022-11-17 15:16:33 +00:00
Greg Chadwick
c48ca23c40 [dv] Various fcov fixes and tweaks 2022-11-16 12:52:33 +00:00
Greg Chadwick
581f5d45da [lint] Minor lint fixes 2022-11-15 16:11:20 -08:00
Greg Chadwick
d8b00f0b17 [fpv] Only include double fault prediction logic where RVFI exists 2022-11-15 19:21:56 +00:00
Greg Chadwick
b736680ddb [dv] Add assertions checking double_fault_seen_o 2022-11-14 16:49:23 +00:00
Greg Chadwick
ddf56b3603 [dv] Add debug_mode to rvfi_ext
This indicates if debug mode was active when the instruction was
executed in ID/EX.
2022-11-14 16:49:23 +00:00
Greg Chadwick
abe1ab03e6 [dv] Don't set rvfi_trap when executing ebreak into debug
This aids the implementation of the double fault detector checker (as an
ebreak into debug doesn't sync the seen_sync_exec flag).
2022-11-14 16:49:23 +00:00
Greg Chadwick
b399c7c8c4 [fpv] Fix linting issues in oustanding access tracking logic
This refactors the code to avoid a -1 index access that caused no issues
in functional verification but caused lint errors and is problematic for
formal tools.

Fixes #1799
2022-11-14 11:07:49 +00:00
Greg Chadwick
c9dc225135 [fpv] Add asserts to check crash dump connectivity 2022-11-14 09:13:59 +00:00
Greg Chadwick
c07414e8f6 [rtl] Fix zbs bitmanip instruction tracer output
They only have 5 bit immediates so use the shift form for I format
decode.
2022-11-14 09:11:08 +00:00
Andreas Kurth
550c9b2903 [dv] Add coverpoints for dummy instructions in each stage
Signed-off-by: Andreas Kurth <adk@lowrisc.org>
2022-11-07 18:42:41 +00:00
Canberk Topal
1ba7a3af38 [dv] V2S Coverage Implementation
This commit adds coverpoints and crosses for security countermeasures
implemented in the design.

Signed-off-by: Canberk Topal <ctopal@lowrisc.org>
2022-11-07 18:42:41 +00:00
Greg Chadwick
346eacb46c [cosim] Add write suppress support
When Ibex does a load that receives data with bad integrity it
suppresses the write to the destination register. The implements
matching functionality for cosim.
2022-11-07 16:24:48 +00:00
Canberk Topal
715292ce55 [cosim] Cosim integration of internal NMI
This commit is mainly an extension to cosim environment to drive the newly
introduced state variable `nmi_int` in Spike.

This commit
 - Extends RVFI interface by a single bit (ext_nmi_int)
 - Configures cosim to set nmi_int inside Spike

Signed-off-by: Canberk Topal <ctopal@lowrisc.org>
2022-11-07 16:24:48 +00:00
Greg Chadwick
ad584baa9a [rtl] Fix dummy instructions
Previously there was a single dummy_instr_id_o signal from ibex_core
which the register file used to determine if it could write to the zero
register (which reads as zero always for real instructions). However a
write occurs in the writeback stage so this signal was not asserted
correctly.

This adds a dummy_instr_wb_o signal to control the write to zero
register. dummy_instr_id_o remains as it's still employed for register
reads for dummy instructions.
2022-10-31 17:42:12 +00:00
Greg Chadwick
eca86aef03 [rtl] Fix id_exception_o signal
Previously it was asserted when an instruction in ID would cause an
exception but an earlier instruction in WB also causes an exception
which takes priority.

This didn't cause a functional bug as the `id_exception_o` signal was
used in a single place ORed with `wb_exception_o`. However it was
confusing behaviour and could cause killed instructions to appear on the
RVFI causing false cosim mismatches.
2022-10-31 14:29:59 +00:00
Greg Chadwick
57e691507d [cov] Fix debug_wfi_cross
It was triggered only on the debug wakeup actually occurring, so in
particular would never capture debug activity around entering sleep. Now
it just considers if there's something that would trigger debug wakeup.
2022-10-28 11:59:58 +01:00
Greg Chadwick
bb92ea6df4 [cov] Remove pointless cross
This cross wasn't much use as many of the transitions it was crossing
with instruction types only occur when the pipeline is empty (so there's
no instruction type to check).

The remaining interesting cases are already covered by other crosses
(e.g. `debug_if_entry_instr_cross` and `pipe_flush_instr_cross`).

Also adds an assertion to check the pipe is empty when we transition to
IRQ_TAKEN (we need this condition to hold to ensure we don't need extra
coverage for instruction types on this transition).
2022-10-28 11:59:58 +01:00
Greg Chadwick
2f9fd69ec4 [rtl] Remove unused transition in ibex_controller FSM
When in the FLUSH state we cannot have `csr_pipe_flush` set as it
depends upon `instr_executing` being set (within `ibex_id_stage`) and
that is only set in the DECODE stage.
2022-10-28 11:59:58 +01:00
Greg Chadwick
1851e86113 [rtl] Fix ebreak debug cause
We should only indicate an ebreak debug cause if an ebreak leads to a
debug entry (otherwise when single stepping over an ebreak that traps to
an exception we incorrectly enter debug mode with an ebreak cause).
2022-10-26 12:13:19 +01:00
Pirmin Vogel
28935490c2 [rtl] Protect core_busy_o with a multi-bit encoding
This commit protects the core_busy_o signal using a multi-bit encoding
to reduce the chances of an adversary for glitching this signal to low,
thereby putting the core to sleep and e.g. not handling an alert.

Without this commit, the glitch would only be detected once both the
main core and the shadow core wake up again and the comparison of the
core_busy_o signals continues.

This resolves lowRISC/Ibex#1827.

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
2022-10-25 12:52:01 +02:00
Greg Chadwick
a0fe5ea3b7 [dv] Fix RVFI stage valid logic
Previously if a dummy instruction entered the pipeline whilst it
wouldn't make RVFI stage 0 valid, it would make RVFI stage 1 valid.

Now stage 1 can only become valid if stage 0 was valid.
2022-10-22 20:30:49 +01:00
Andreas Kurth
ce536ae476 [rtl] Assert that dummy instructions only write R0
Signed-off-by: Andreas Kurth <adk@lowrisc.org>
2022-10-19 10:50:01 +01:00
Greg Chadwick
27907d1d4a [rtl] Immediately stop execution when fetch disabled
Previously `fetch_enable_i` only controlled the request going into the
instruction fetch stage.  Due to buffering in the prefetch queue and
icache when this request is dropped it's possible for multiple
instructions to still be available for the ID/EX stage to consume. So
when `fetch_enable_i` was set to off you would get a 'soft stop'. Some
finite number of instructions may still execute and Ibex would come to
an eventual halt.

Now `fetch_enable_i` also gates the instruction moving between the fetch
stage and the ID/EX stage. This gives a 'hard stop' where once fetch is
disabled Ibex comes to an immediate halt.
2022-10-16 17:17:15 +01:00
Harry Callahan
75a93dbed0 Fixup signal used when checking for ebreak cause 2022-10-14 18:44:02 +01:00
Canberk Topal
f2c1d6dc9d [rtl] Change how we record debug causes
This commit changes when we cath the debug causes. Since debug_cause_o
only gets latched when `csr_save_cause_o` is high, it would work if
we change the cause with a mux that is connected to the input signals.

Resolves #1772

Signed-off-by: Canberk Topal <ctopal@lowrisc.org>
2022-10-14 18:44:02 +01:00
Greg Chadwick
298c8789da [rtl/dv] Bring back data integrity check on write responses
Previously Ibex signalled a major alert on an integrity error (where
incoming read data doesn't match its integrity bits) for both read and
write responses. This was removed as the data part of a response to a
write is ignored.

This brings it back in a more measured way. This provides a little extra
fault injection hardening as an attacker glitching the memory bus will
generate an alert on both read and write responses.
2022-10-14 18:22:58 +01:00
Greg Chadwick
48733e23ec [rtl] Ignore MIE bit in U mode 2022-10-13 17:30:05 +01:00
Greg Chadwick
48789dd095 [rtl] Don't take interrupts when single stepping
Fixes #1814
2022-10-13 17:30:05 +01:00
Marno van der Maas
7ab2571bea [if,pmp] Check second bit instead of third for instruction alignment
Signed-off-by: Marno van der Maas <mvdmaas+git@lowrisc.org>
2022-10-06 10:23:01 +01:00
Harry Callahan
836bd67531 Update SCONTEXT address, add MSCONTEXT csr to match riscv_debug 1.0
Observing the spec change:
RISC-V Debug Support Version 1.0.0-STABLE
1.2.1.4 New Features from 0.13 to 1.0
> 8. Move scontext, renaming original to mscontext, and create hcontext. #535

MSCONTEXT is a backwards-compatible alias to SCONTEXT
In Ibex, SCONTEXT is a read-only zero register. Hence MSCONTEXT has the same behaviour.
2022-10-05 16:59:12 +01:00
Greg Chadwick
7b1be3354d [rtl] Don't cache instructions in debug mode
RISC-V debug modules may utilise dynamically changing code. Don't cache
any instructions in debug mode to correctly support this.

Fixes #1472
2022-09-27 10:12:09 +01:00