]> git.baikalelectronics.ru Git - kernel.git/commit
perf: RISC-V: fix access beyond allocated array
authorSergey Matyukevich <sergey.matyukevich@syntacore.com>
Tue, 30 Aug 2022 15:53:04 +0000 (18:53 +0300)
committerPalmer Dabbelt <palmer@rivosinc.com>
Thu, 8 Sep 2022 20:50:25 +0000 (13:50 -0700)
commit5613fab2e2d3b5c9a3c122f88668dde9eb3aeb4e
treeff6fc31691dd292508a305c2e44636bd14e39288
parent47a64aa927252efe8852f32c159b5d88a50bb779
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: dff7f050cfad ("RISC-V: Add perf platform driver based on SBI PMU extension")
Signed-off-by: Sergey Matyukevich <sergey.matyukevich@syntacore.com>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20220830155306.301714-2-geomatsi@gmail.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
drivers/perf/riscv_pmu_sbi.c