Skip to content

Commit 8ec0c6f

Browse files
nasahlpavogelpi
authored andcommitted
[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 <[email protected]>
1 parent b6d8b9f commit 8ec0c6f

File tree

6 files changed

+67
-24
lines changed

6 files changed

+67
-24
lines changed

dv/uvm/core_ibex/ibex_dv.f

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
${PRJ_DIR}/dv/uvm/core_ibex/common/prim/prim_pkg.sv
2222
${LOWRISC_IP_DIR}/ip/prim/rtl/prim_assert.sv
2323
${LOWRISC_IP_DIR}/ip/prim/rtl/prim_util_pkg.sv
24+
${LOWRISC_IP_DIR}/ip/prim/rtl/prim_count.sv
2425
${LOWRISC_IP_DIR}/ip/prim/rtl/prim_secded_pkg.sv
2526
${LOWRISC_IP_DIR}/ip/prim/rtl/prim_secded_22_16_dec.sv
2627
${LOWRISC_IP_DIR}/ip/prim/rtl/prim_secded_22_16_enc.sv

dv/uvm/core_ibex/tb/core_ibex_tb_top.sv

+7
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,13 @@ module core_ibex_tb_top;
331331
run_test();
332332
end
333333

334+
// Manually set unused_assert_connected = 1 to disable the AssertConnected_A assertion for
335+
// prim_count in case lockstep (set by SecureIbex) is enabled. If not disabled, DV fails.
336+
if (SecureIbex) begin : gen_disable_count_check
337+
assign dut.u_ibex_top.gen_lockstep.u_ibex_lockstep.u_rst_shadow_cnt.
338+
unused_assert_connected = 1;
339+
end
340+
334341
// Disable the assertion for onhot check in case WrenCheck (set by SecureIbex) is enabled.
335342
if (SecureIbex) begin : gen_disable_onehot_check
336343
assign dut.u_ibex_top.gen_regfile_ff.register_file_i.gen_wren_check.u_prim_onehot_check.

ibex_top.core

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ filesets:
1313
- lowrisc:prim:and2
1414
- lowrisc:prim:buf
1515
- lowrisc:prim:clock_mux2
16+
- lowrisc:prim:count
1617
- lowrisc:prim:flop
1718
- lowrisc:prim:ram_1p_scr
1819
- lowrisc:prim:onehot_check

rtl/ibex_core.sv

+4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ module ibex_core import ibex_pkg::*; #(
4646
) (
4747
// Clock and Reset
4848
input logic clk_i,
49+
// Internally generated resets in ibex_lockstep cause IMPERFECTSCH warnings.
50+
// TODO: Remove when upgrading Verilator #2134.
51+
/* verilator lint_off IMPERFECTSCH */
4952
input logic rst_ni,
53+
/* verilator lint_on IMPERFECTSCH */
5054

5155
input logic [31:0] hart_id_i,
5256
input logic [31:0] boot_addr_i,

rtl/ibex_lockstep.sv

+52-23
Original file line numberDiff line numberDiff line change
@@ -120,44 +120,71 @@ module ibex_lockstep import ibex_pkg::*; #(
120120
// - The reset of the shadow core is synchronously released.
121121
// The comparison is started in the following clock cycle.
122122

123-
logic [LockstepOffsetW-1:0] rst_shadow_cnt_d, rst_shadow_cnt_q, rst_shadow_cnt_incr;
124-
// Internally generated resets cause IMPERFECTSCH warnings
125-
/* verilator lint_off IMPERFECTSCH */
126-
logic rst_shadow_set_d, rst_shadow_set_q;
127-
logic rst_shadow_n, enable_cmp_q;
128-
/* verilator lint_on IMPERFECTSCH */
123+
logic [LockstepOffsetW-1:0] rst_shadow_cnt;
124+
logic rst_shadow_cnt_err;
125+
ibex_mubi_t rst_shadow_set_d, rst_shadow_set_q;
126+
logic rst_shadow_n, rst_shadow_set_single_bit;
127+
ibex_mubi_t enable_cmp_d, enable_cmp_q;
128+
129+
// This counter primitive starts counting to LockstepOffset after a system
130+
// reset. The counter value saturates at LockstepOffset.
131+
prim_count #(
132+
.Width (LockstepOffsetW ),
133+
.ResetValue (LockstepOffsetW'(1'b0) )
134+
) u_rst_shadow_cnt (
135+
.clk_i (clk_i ),
136+
.rst_ni (rst_ni ),
137+
.clr_i (1'b0 ),
138+
.set_i (1'b0 ),
139+
.set_cnt_i ('0 ),
140+
.incr_en_i (1'b1 ),
141+
.decr_en_i (1'b0 ),
142+
.step_i (LockstepOffsetW'(1'b1) ),
143+
.cnt_o (rst_shadow_cnt ),
144+
.cnt_next_o ( ),
145+
.err_o (rst_shadow_cnt_err )
146+
);
129147

130-
assign rst_shadow_cnt_incr = rst_shadow_cnt_q + 1'b1;
148+
// When the LockstepOffset counter value is reached, activate the lockstep
149+
// comparison. We do not explicitly check whether rst_shadow_set_q forms a valid
150+
// multibit signal as this value is implicitly checked by the enable_cmp
151+
// comparison below.
152+
assign rst_shadow_set_d =
153+
(rst_shadow_cnt >= LockstepOffsetW'(LockstepOffset - 1)) ? IbexMuBiOn : IbexMuBiOff;
131154

132-
assign rst_shadow_set_d = (rst_shadow_cnt_q == LockstepOffsetW'(LockstepOffset - 1));
133-
assign rst_shadow_cnt_d = rst_shadow_set_d ? rst_shadow_cnt_q : rst_shadow_cnt_incr;
155+
// Enable lockstep comparison.
156+
assign enable_cmp_d = rst_shadow_set_q;
134157

135-
always_ff @(posedge clk_i or negedge rst_ni) begin
136-
if (!rst_ni) begin
137-
rst_shadow_cnt_q <= '0;
138-
enable_cmp_q <= '0;
139-
end else begin
140-
rst_shadow_cnt_q <= rst_shadow_cnt_d;
141-
enable_cmp_q <= rst_shadow_set_q;
142-
end
143-
end
158+
// This assignment is needed in order to avoid "Warning-IMPERFECTSCH" messages.
159+
// TODO: Remove when updating Verilator #2134.
160+
assign rst_shadow_set_single_bit = rst_shadow_set_q[0];
144161

145162
// The primitives below are used to place size-only constraints in order to prevent
146163
// synthesis optimizations and preserve anchor points for constraining backend tools.
147164
prim_flop #(
148-
.Width(1),
149-
.ResetValue(1'b0)
165+
.Width(IbexMuBiWidth),
166+
.ResetValue(IbexMuBiOff)
150167
) u_prim_rst_shadow_set_flop (
151168
.clk_i (clk_i),
152169
.rst_ni(rst_ni),
153170
.d_i (rst_shadow_set_d),
154171
.q_o (rst_shadow_set_q)
155172
);
156173

174+
prim_flop #(
175+
.Width(IbexMuBiWidth),
176+
.ResetValue(IbexMuBiOff)
177+
) u_prim_enable_cmp_flop (
178+
.clk_i (clk_i),
179+
.rst_ni(rst_ni),
180+
.d_i (enable_cmp_d),
181+
.q_o (enable_cmp_q)
182+
);
183+
157184
prim_clock_mux2 #(
158185
.NoFpgaBufG(1'b1)
159186
) u_prim_rst_shadow_n_mux2 (
160-
.clk0_i(rst_shadow_set_q),
187+
.clk0_i(rst_shadow_set_single_bit),
161188
.clk1_i(scan_rst_ni),
162189
.sel_i (test_en_i),
163190
.clk_o (rst_shadow_n)
@@ -458,8 +485,10 @@ module ibex_lockstep import ibex_pkg::*; #(
458485

459486
logic outputs_mismatch;
460487

461-
assign outputs_mismatch = enable_cmp_q & (shadow_outputs_q != core_outputs_q[0]);
462-
assign alert_major_internal_o = outputs_mismatch | shadow_alert_major_internal;
488+
assign outputs_mismatch =
489+
(enable_cmp_q != IbexMuBiOff) & (shadow_outputs_q != core_outputs_q[0]);
490+
assign alert_major_internal_o
491+
= outputs_mismatch | shadow_alert_major_internal | rst_shadow_cnt_err;
463492
assign alert_major_bus_o = shadow_alert_major_bus;
464493
assign alert_minor_o = shadow_alert_minor;
465494

rtl/ibex_pkg.sv

+2-1
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,8 @@ package ibex_pkg;
655655

656656
// Mult-bit signal used for security hardening. For non-secure implementation all bits other than
657657
// the bottom bit are ignored.
658-
typedef logic [3:0] ibex_mubi_t;
658+
parameter int IbexMuBiWidth = 4;
659+
typedef logic [IbexMuBiWidth-1:0] ibex_mubi_t;
659660

660661
// Note that if adjusting these parameters it is assumed the bottom bit is set for On and unset
661662
// for Off. This allows the use of IbexMuBiOn/IbexMuBiOff to work for both secure and non-secure

0 commit comments

Comments
 (0)