Commit ee95b88d authored by Viacheslav Mitrofanov's avatar Viacheslav Mitrofanov Committed by Palmer Dabbelt

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: default avatarViacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: default avatarAndrew Jones <ajones@ventanamicro.com>
Reviewed-by: default avatarAtish Patra <atishp@rivosinc.com>
Link: https://lore.kernel.org/r/20230505072058.1049732-1-v.v.mitrofanov@yadro.comSigned-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
parent 4681daca
...@@ -855,6 +855,12 @@ static int pmu_sbi_device_probe(struct platform_device *pdev) ...@@ -855,6 +855,12 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
goto out_free; goto out_free;
} }
/* It is possible to get from SBI more than max number of counters */
if (num_counters > RISCV_MAX_COUNTERS) {
num_counters = RISCV_MAX_COUNTERS;
pr_info("SBI returned more than maximum number of counters. Limiting the number of counters to %d\n", num_counters);
}
/* cache all the information about counters now */ /* cache all the information about counters now */
if (pmu_sbi_get_ctrinfo(num_counters, &cmask)) if (pmu_sbi_get_ctrinfo(num_counters, &cmask))
goto out_free; goto out_free;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment