[PATCH 5/7] lib: sbi: dbtr: keep type and chain of a trigger in UPDATE
Heinrich Schuchardt
heinrich.schuchardt at canonical.com
Fri Nov 20 15:11:17 PST 2026
The specification requires an update of a debug trigger to fail if
trig_tdata1.type or trig_tdata1.chain differ from the installed trigger.
The update only asked if the hardware trigger can do the new type. A
trigger that supports several types, like the ones of QEMU that do
mcontrol and mcontrol6, was switched to another type. A changed chain
field was not noticed either.
Compare both with the tdata1 of the installed trigger and return
SBI_ERR_INVALID_PARAM. The specification names no error code for this
case, so use the one for an invalid trig_tdata1.
The chain field is defined by the trigger types mcontrol and mcontrol6 of
the RISC-V Debug Specification. Other types have no such field. For them
the same bits belong to other fields, for example to the count of icount,
and they are not compared.
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
---
lib/sbi/sbi_dbtr.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c
index d4be1be3..01b74f5f 100644
--- a/lib/sbi/sbi_dbtr.c
+++ b/lib/sbi/sbi_dbtr.c
@@ -693,6 +693,24 @@ int sbi_dbtr_read_trig(unsigned long smode,
return SBI_SUCCESS;
}
+/*
+ * Value of the chain field of tdata1, 0 if the trigger type has none. Only
+ * the types mcontrol and mcontrol6 define a chain field. The other types use
+ * the bits for something else, e.g. icount for its count, so they must not
+ * be compared as a chain.
+ */
+static unsigned long dbtr_tdata1_chain(unsigned long tdata1)
+{
+ switch (TDATA1_GET_TYPE(tdata1)) {
+ case RISCV_DBTR_TRIG_MCONTROL:
+ return !!(tdata1 & RV_DBTR_BIT_MASK(MC, CHAIN));
+ case RISCV_DBTR_TRIG_MCONTROL6:
+ return !!(tdata1 & RV_DBTR_BIT_MASK(MC6, CHAIN));
+ default:
+ return 0;
+ }
+}
+
/*
* Check the configuration of one trigger read from the shared memory.
*
@@ -730,6 +748,15 @@ static int dbtr_check_trigger_config(struct sbi_dbtr_hart_triggers_state *hs,
return SBI_ERR_NOT_SUPPORTED;
if (trig) {
+ /*
+ * An update keeps the type and the chain bit of the installed
+ * trigger, see the update function of the specification.
+ */
+ if (type != TDATA1_GET_TYPE(trig->tdata1) ||
+ dbtr_tdata1_chain(tdata1) !=
+ dbtr_tdata1_chain(trig->tdata1))
+ return SBI_ERR_INVALID_PARAM;
+
if (!__test_bit(type, &trig->type_mask) ||
!dbtr_trigger_hw_supported(trig->index, tdata1, tdata2,
tdata3))
--
2.53.0
More information about the opensbi
mailing list