lib: sbi: reject PMU skip-match counter class mismatches

SKIP_MATCH selects the first counter in the caller-provided set, but the
current path checks only that the index exists and is active.  A supervisor
can select an active hardware counter for a firmware event.  CLEAR_VALUE or
AUTO_START then indexes firmware-counter state with
ctr_idx - num_hw_ctrs, which underflows.  The inverse mismatch sends a
firmware-counter index to hardware-counter operations.

Reject the selected counter when its hardware/firmware class cannot monitor
the requested event.  Return SBI_ENOTSUPP, matching the PMU specification's
case where the selected counter cannot monitor that event.

Fixes: 13d40f21d5 ("lib: sbi: Add PMU support")
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
Tested-by: Sebastian Alba Vives <sebasjosue84@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260827115718.50124-1-pengpeng@iscas.ac.cn
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Pengpeng Hou authored and Anup Patel committed 2026-10-25 11:20:03 +05:30
1 parent 131bda9447
commit 9f37e25f80
1 file changed
+6
+6
View File
@@ -939,6 +939,12 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask,
if (cidx_first >= total_ctrs)
return SBI_EINVAL;
if ((event_type == SBI_PMU_EVENT_TYPE_FW &&
cidx_first < num_hw_ctrs) ||
(event_type != SBI_PMU_EVENT_TYPE_FW &&
cidx_first >= num_hw_ctrs))
return SBI_ENOTSUPP;
if (phs->active_events[cidx_first] == SBI_PMU_EVENT_IDX_INVALID)
return SBI_EINVAL;
ctr_idx = cidx_first;