* [PATCH v3 1/1] perf: RISC-V: Limit the number of counters returned from SBI
@ 2023-05-05 7:20 Viacheslav Mitrofanov
2023-06-25 23:17 ` Palmer Dabbelt
2023-06-25 23:20 ` patchwork-bot+linux-riscv
0 siblings, 2 replies; 3+ messages in thread
From: Viacheslav Mitrofanov @ 2023-05-05 7:20 UTC (permalink / raw)
Cc: linux, Viacheslav Mitrofanov, Andrew Jones, Atish Patra,
Atish Patra, Anup Patel, Will Deacon, Mark Rutland,
Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-riscv,
linux-arm-kernel, linux-kernel
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 <v.v.mitrofanov@yadro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
---
Chnages in v3:
- Detail the output
Changes in v2:
- Add new line
- Substitute pr_warn for pr_info
drivers/perf/riscv_pmu_sbi.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
index 70cb50fd41c2..7bf494930e92 100644
--- a/drivers/perf/riscv_pmu_sbi.c
+++ b/drivers/perf/riscv_pmu_sbi.c
@@ -868,6 +868,12 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
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 */
if (pmu_sbi_get_ctrinfo(num_counters, &cmask))
goto out_free;
--
2.37.2
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v3 1/1] perf: RISC-V: Limit the number of counters returned from SBI
2023-05-05 7:20 [PATCH v3 1/1] perf: RISC-V: Limit the number of counters returned from SBI Viacheslav Mitrofanov
@ 2023-06-25 23:17 ` Palmer Dabbelt
2023-06-25 23:20 ` patchwork-bot+linux-riscv
1 sibling, 0 replies; 3+ messages in thread
From: Palmer Dabbelt @ 2023-06-25 23:17 UTC (permalink / raw)
To: Viacheslav Mitrofanov
Cc: linux, Andrew Jones, Atish Patra, Atish Patra, Anup Patel,
Will Deacon, Mark Rutland, Paul Walmsley, Palmer Dabbelt,
Albert Ou, linux-riscv, linux-arm-kernel, linux-kernel
On Fri, 05 May 2023 07:20:57 +0000, Viacheslav Mitrofanov wrote:
> 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.
>
>
Applied, thanks!
[1/1] perf: RISC-V: Limit the number of counters returned from SBI
https://git.kernel.org/palmer/c/ee95b88d71b9
Best regards,
--
Palmer Dabbelt <palmer@rivosinc.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v3 1/1] perf: RISC-V: Limit the number of counters returned from SBI
2023-05-05 7:20 [PATCH v3 1/1] perf: RISC-V: Limit the number of counters returned from SBI Viacheslav Mitrofanov
2023-06-25 23:17 ` Palmer Dabbelt
@ 2023-06-25 23:20 ` patchwork-bot+linux-riscv
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+linux-riscv @ 2023-06-25 23:20 UTC (permalink / raw)
To: Viacheslav Mitrofanov
Cc: linux-riscv, linux, ajones, atishp, atishp, anup, will,
mark.rutland, paul.walmsley, palmer, aou, linux-arm-kernel,
linux-kernel
Hello:
This patch was applied to riscv/linux.git (for-next)
by Palmer Dabbelt <palmer@rivosinc.com>:
On Fri, 5 May 2023 07:20:57 +0000 you wrote:
> 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 <v.v.mitrofanov@yadro.com>
> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
> Reviewed-by: Atish Patra <atishp@rivosinc.com>
>
> [...]
Here is the summary with links:
- [v3,1/1] perf: RISC-V: Limit the number of counters returned from SBI
https://git.kernel.org/riscv/c/ee95b88d71b9
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-25 23:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-05 7:20 [PATCH v3 1/1] perf: RISC-V: Limit the number of counters returned from SBI Viacheslav Mitrofanov
2023-06-25 23:17 ` Palmer Dabbelt
2023-06-25 23:20 ` patchwork-bot+linux-riscv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®