Skip to content

Commit fbfde38

Browse files
committed
[otbn,dv] Enable RTL/ISS checker to tolerate mismatches
With this change one can tell the checker to tolerate a mismatch on the next RTL to ISS trace comparison. This is useful when FI related tests lead to escalations which fire one cycle delayed. Signed-off-by: Pascal Etterli <[email protected]>
1 parent dcaedae commit fbfde38

File tree

7 files changed

+67
-9
lines changed

7 files changed

+67
-9
lines changed

hw/ip/otbn/dv/model/otbn_model.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,11 @@ int OtbnModel::set_software_errs_fatal(unsigned char new_val) {
561561
return 0;
562562
}
563563

564+
int OtbnModel::tolerate_result_mismatch() {
565+
OtbnTraceChecker::get().TolerateResultMismatch();
566+
return 0;
567+
}
568+
564569
int OtbnModel::set_no_sec_wipe_chk() {
565570
OtbnTraceChecker::get().set_no_sec_wipe_chk();
566571
return 0;
@@ -1029,6 +1034,11 @@ int otbn_model_set_software_errs_fatal(OtbnModel *model,
10291034
return model->set_software_errs_fatal(new_val);
10301035
}
10311036

1037+
int otbn_model_tolerate_result_mismatch(OtbnModel *model) {
1038+
assert(model);
1039+
return model->tolerate_result_mismatch();
1040+
}
1041+
10321042
int otbn_set_no_sec_wipe_chk(OtbnModel *model) {
10331043
assert(model);
10341044
return model->set_no_sec_wipe_chk();

hw/ip/otbn/dv/model/otbn_model.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ class OtbnModel {
9090
// error. Returns 0 on success; -1 on failure.
9191
int invalidate_dmem();
9292

93+
// Tell the model to tolerate mismatches between RTL and ISS trace entries
94+
// for the next comparison. Required for tests covering FI countermeasures
95+
// with delayed escalation.
96+
int tolerate_result_mismatch();
97+
9398
// Set software_errs_fatal bit in ISS model.
9499
int set_software_errs_fatal(unsigned char new_val);
95100

@@ -167,6 +172,10 @@ class OtbnModel {
167172
std::string design_scope_;
168173

169174
bool stack_check_enabled_ = true;
175+
176+
// If true, tolerate a mismatch in results between ISS and RTL for the next
177+
// check.
178+
bool tolerate_result_mismatch_ = false;
170179
};
171180

172181
#endif // OPENTITAN_HW_IP_OTBN_DV_MODEL_OTBN_MODEL_H_

hw/ip/otbn/dv/model/otbn_model_dpi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ int otbn_model_invalidate_dmem(OtbnModel *model);
112112
// error.
113113
int otbn_model_set_software_errs_fatal(OtbnModel *model, unsigned char new_val);
114114

115+
// Tell the model to tolerate mismatches between RTL and ISS trace entries
116+
// for the next comparison. Required for tests covering FI countermeasures
117+
// with delayed escalation.
118+
int otbn_model_tolerate_result_mismatch(OtbnModel *model);
119+
115120
// Tell the model to not execute checks to see if secure wiping has written
116121
// random data to all registers before wiping them with zeroes.
117122
int otbn_set_no_sec_wipe_chk(OtbnModel *model);

hw/ip/otbn/dv/model/otbn_model_dpi.svh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ import "DPI-C" function int otbn_model_invalidate_dmem(chandle model);
5353

5454
import "DPI-C" function int otbn_model_set_software_errs_fatal(chandle model, bit new_val);
5555

56+
import "DPI-C" function int otbn_model_tolerate_result_mismatch(chandle model);
57+
5658
import "DPI-C" function int otbn_set_no_sec_wipe_chk(chandle model);
5759

5860
import "DPI-C" function int otbn_model_step_crc(chandle model,

hw/ip/otbn/dv/model/otbn_trace_checker.cc

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ OtbnTraceChecker::OtbnTraceChecker()
2020
iss_started_(false),
2121
iss_pending_(false),
2222
done_(true),
23+
tolerate_result_mismatch_(false),
2324
seen_err_(false),
2425
last_data_vld_(false) {
2526
OtbnTraceSource::get().AddListener(this);
@@ -245,6 +246,11 @@ const OtbnIssTraceEntry::IssData *OtbnTraceChecker::PopIssData() {
245246

246247
void OtbnTraceChecker::set_no_sec_wipe_chk() { no_sec_wipe_data_chk_ = true; }
247248

249+
void OtbnTraceChecker::TolerateResultMismatch() {
250+
tolerate_result_mismatch_ = true;
251+
std::cerr << "INFO: Next RTL/ISS trace entry mismatch will be tolerated.\n";
252+
}
253+
248254
bool OtbnTraceChecker::MatchPair() {
249255
if (!(rtl_pending_ && iss_pending_)) {
250256
return true;
@@ -256,17 +262,31 @@ bool OtbnTraceChecker::MatchPair() {
256262
std::string err_desc;
257263
if (!(rtl_entry_.compare_rtl_iss_entries(iss_entry_, no_sec_wipe_data_chk_,
258264
&err_desc))) {
259-
std::cerr << "ERROR: Mismatch between RTL and ISS trace entries: "
260-
<< err_desc << "\n RTL entry is:\n";
261-
rtl_entry_.print(" ", std::cerr);
262-
std::cerr << " ISS entry is:\n";
263-
iss_entry_.print(" ", std::cerr);
264-
seen_err_ = true;
265-
return false;
266-
if (rtl_entry_.trace_type() == OtbnTraceEntry::WipeComplete) {
267-
no_sec_wipe_data_chk_ = false;
265+
if (tolerate_result_mismatch_) {
266+
std::cerr << "INFO: Mismatch between RTL and ISS trace entries "
267+
<< "but tolerated: " << err_desc << "\n RTL entry is:\n";
268+
rtl_entry_.print(" ", std::cerr);
269+
std::cerr << " ISS entry is:\n";
270+
iss_entry_.print(" ", std::cerr);
271+
} else {
272+
std::cerr << "ERROR: Mismatch between RTL and ISS trace entries: "
273+
<< err_desc << "\n RTL entry is:\n";
274+
rtl_entry_.print(" ", std::cerr);
275+
std::cerr << " ISS entry is:\n";
276+
iss_entry_.print(" ", std::cerr);
277+
seen_err_ = true;
278+
return false;
279+
if (rtl_entry_.trace_type() == OtbnTraceEntry::WipeComplete) {
280+
no_sec_wipe_data_chk_ = false;
281+
}
268282
}
269283
}
284+
// We tolerate a mismatch only for one comparison.
285+
if (tolerate_result_mismatch_) {
286+
std::cerr << "INFO: No longer tolerating RTL/ISS mismatches.\n";
287+
}
288+
tolerate_result_mismatch_ = false;
289+
270290
// We've got a matching pair of entries. Move the ISS data out of the (now
271291
// defunct) iss_entry_ and into last_data_.
272292
if (rtl_entry_.trace_type() == OtbnTraceEntry::Exec) {

hw/ip/otbn/dv/model/otbn_trace_checker.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ class OtbnTraceChecker : public OtbnTraceListener {
8080
// secure wipe entry.
8181
void set_no_sec_wipe_chk();
8282

83+
// Tell the model to tolerate a mismatch in results between ISS and RTL for
84+
// the next check. This is required for FI tests where we expect the RTL to
85+
// misbehave.
86+
void TolerateResultMismatch();
87+
8388
private:
8489
// If rtl_pending_ and iss_pending_ are not both true, return true
8590
// immediately with no other change. Otherwise, compare the two pending trace
@@ -96,6 +101,7 @@ class OtbnTraceChecker : public OtbnTraceListener {
96101
OtbnIssTraceEntry iss_entry_;
97102

98103
bool done_;
104+
bool tolerate_result_mismatch_;
99105
bool seen_err_;
100106

101107
// The ISS entry for the last pair of trace entries that went through

hw/ip/otbn/dv/uvm/otbn_model_agent/otbn_model_if.sv

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ interface otbn_model_if
114114
release u_model.wakeup_iss;
115115
endtask: lock_immediately
116116

117+
function automatic void tolerate_result_mismatch();
118+
`uvm_info("otbn_model_if", "Enabling tolerate result mismatch for next check", UVM_HIGH);
119+
`DV_CHECK_FATAL(u_model.otbn_model_tolerate_result_mismatch(handle) == 0,
120+
"Failed to enable tolerating result mismatch", "otbn_model_if")
121+
endfunction
122+
117123
function automatic void set_software_errs_fatal(bit new_val);
118124
`uvm_info("otbn_model_if", "writing to software_errs_fatal", UVM_HIGH);
119125
`DV_CHECK_FATAL(u_model.otbn_model_set_software_errs_fatal(handle, new_val) == 0,

0 commit comments

Comments
 (0)