[PATCH 07/18] dbtr: Check for invalid and unsupported triggers in update

Nicholas Piggin
2026-03-13T05:20:47Z

Update triggers does not check supported or valid, so it permits tdata1.m
and tdata1.dmode bits being set.

Fix update to test that triggers are valid and supported.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
lib/sbi/sbi_dbtr.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c
index d2845fec..3925170f 100644
--- a/lib/sbi/sbi_dbtr.c
+++ b/lib/sbi/sbi_dbtr.c
@@ -749,7 +749,7 @@ int sbi_dbtr_update_trig(unsigned long smode,

/* Check requested triggers configuration */
for_each_trig_entry(shmem_base, trig_count, typeof(*entry), entry) {
- unsigned long trig_idx, tdata1;
+ unsigned long trig_idx, tdata1, type;

trig_idx = entry->id.idx;
if (trig_idx >= hs->total_trigs) {
@@ -769,7 +769,23 @@ int sbi_dbtr_update_trig(unsigned long smode,

recv = (struct sbi_dbtr_data_msg *)(&entry->data);
tdata1 = lle_to_cpu(recv->tdata1);
- if (TDATA1_GET_TYPE(tdata1) != TDATA1_GET_TYPE(trig->tdata1)) {
+ type = TDATA1_GET_TYPE(tdata1);
+
+ if (!dbtr_trigger_supported(type, tdata1)) {
+ *out = _idx;
+ sbi_hart_protection_unmap_range((unsigned long)shmem_base,
+ trig_count * sizeof(*entry));
+ return SBI_ERR_NOT_SUPPORTED;
+ }
+
+ if (!dbtr_trigger_valid(type, tdata1)) {
+ *out = _idx;
+ sbi_hart_protection_unmap_range((unsigned long)shmem_base,
+ trig_count * sizeof(*entry));
+ return SBI_ERR_INVALID_PARAM;
+ }
+
+ if (type != TDATA1_GET_TYPE(trig->tdata1)) {
*out = _idx;
sbi_hart_protection_unmap_range((unsigned long)shmem_base,
trig_count * sizeof(*entry));