Skip to content

Commit ee95b88

Browse files
vvmitrofanovpalmer-dabbelt
authored andcommitted
perf: RISC-V: Limit the number of counters returned from SBI
Perf gets the number of supported counters from SBI. If it happens that the number of returned counters more than RISCV_MAX_COUNTERS the code trusts it. It does not lead to an immediate problem but can potentially lead to it. Prevent getting more than RISCV_MAX_COUNTERS from SBI. Signed-off-by: Viacheslav Mitrofanov <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Atish Patra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 4681dac commit ee95b88

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/perf/riscv_pmu_sbi.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,12 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
855855
goto out_free;
856856
}
857857

858+
/* It is possible to get from SBI more than max number of counters */
859+
if (num_counters > RISCV_MAX_COUNTERS) {
860+
num_counters = RISCV_MAX_COUNTERS;
861+
pr_info("SBI returned more than maximum number of counters. Limiting the number of counters to %d\n", num_counters);
862+
}
863+
858864
/* cache all the information about counters now */
859865
if (pmu_sbi_get_ctrinfo(num_counters, &cmask))
860866
goto out_free;

0 commit comments

Comments
 (0)