Skip to content

Commit 20e0fba

Browse files
sm-scpalmer-dabbelt
authored andcommitted
perf: RISC-V: fix access beyond allocated array
SBI firmware should report total number of firmware and hardware counters including unused ones or special ones. In this case the kernel doesn't need to make any assumptions about gaps in reported counters, e.g. excluded timer counter. That was fixed in OpenSBI v1.1 by commit 3f66465fb6bf ("lib: pmu: allow to use the highest available counter"). This kernel patch has no effect if SBI firmware behaves correctly. However it eliminates access beyond the allocated pmu_ctr_list if the kernel is used with OpenSBI older than v1.1. Fixes: e999143 ("RISC-V: Add perf platform driver based on SBI PMU extension") Signed-off-by: Sergey Matyukevich <[email protected]> Reviewed-by: Atish Patra <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent d958edb commit 20e0fba

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/perf/riscv_pmu_sbi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ static int pmu_sbi_get_ctrinfo(int nctr)
473473
if (!pmu_ctr_list)
474474
return -ENOMEM;
475475

476-
for (i = 0; i <= nctr; i++) {
476+
for (i = 0; i < nctr; i++) {
477477
ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_GET_INFO, i, 0, 0, 0, 0, 0);
478478
if (ret.error)
479479
/* The logical counter ids are not expected to be contiguous */

0 commit comments

Comments
 (0)