Skip to contentSkip to conversation

lib: sbi: pmu: Return SBI_EINVAL if cidx_mask is 0 in ctr_cfg_match

PATCH Superseded James Raphael Tiovalen 1 participant 2 messages May 12, 2025

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: sbi: pmu: Return SBI_EINVAL if cidx_mask is 0 in ctr_cfg_match

When configuring a matching counter, if the cidx_mask value being passed in is 0, return the SBI_ERR_INVALID_PARAM error code.

This also aligns OpenSBI's behavior with KVM's.

---
 lib/sbi/sbi_pmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sbi/sbi_pmu.c +1 -1
index 5983a78..62ce770 100644
@@ -840,7 +840,7 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask,
 	u32 event_code;
 
 	/* Do a basic sanity check of counter base & mask */
-	if ((cidx_base + sbi_fls(cidx_mask)) >= total_ctrs)
+	if (!cidx_mask || ((cidx_base + sbi_fls(cidx_mask)) >= total_ctrs))
 		return SBI_EINVAL;
 
 	event_type = pmu_event_validate(phs, event_idx, event_data);
Signature · 7 lines
2.43.0


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
author
#1 lore raw

After some more thought, I have decided to update the commit message of this patch to specify how OpenSBI's behavior changes with this patch. That way, we can keep track of how OpenSBI's behavior has changed in the Git history. I will do that in v2.

Quoted 25 lines · James Raphael Tiovalen

When configuring a matching counter, if the cidx_mask value being passed in is 0, return the SBI_ERR_INVALID_PARAM error code.

This also aligns OpenSBI's behavior with KVM's.

---
 lib/sbi/sbi_pmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sbi/sbi_pmu.c +1 -2
index 5983a78..62ce770 100644
@@ -840,7 +840,7 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask,
        u32 event_code;
 
        /* Do a basic sanity check of counter base & mask */
-       if ((cidx_base + sbi_fls(cidx_mask)) >= total_ctrs)
+       if (!cidx_mask || ((cidx_base + sbi_fls(cidx_mask)) >= total_ctrs))
                return SBI_EINVAL;
 
        event_type = pmu_event_validate(phs, event_idx, event_data);
--
Quoted 2 lines

2.43.0

Best regards,
James Raphael Tiovalen

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi