]> Git Repo - linux.git/commitdiff
perf: RISC-V: fix access beyond allocated array
authorSergey Matyukevich <[email protected]>
Tue, 30 Aug 2022 15:53:04 +0000 (18:53 +0300)
committerPalmer Dabbelt <[email protected]>
Thu, 8 Sep 2022 20:50:25 +0000 (13:50 -0700)
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: e9991434596f ("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]>
drivers/perf/riscv_pmu_sbi.c

index 6f6681bbfd36de515b52bfc58ed6e04a1d34518f..8de4ca2fef210119b04da6bd28a13460cab681ca 100644 (file)
@@ -473,7 +473,7 @@ static int pmu_sbi_get_ctrinfo(int nctr)
        if (!pmu_ctr_list)
                return -ENOMEM;
 
-       for (i = 0; i <= nctr; i++) {
+       for (i = 0; i < nctr; i++) {
                ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_GET_INFO, i, 0, 0, 0, 0, 0);
                if (ret.error)
                        /* The logical counter ids are not expected to be contiguous */
This page took 0.064861 seconds and 4 git commands to generate.