Message ID | 20230428110256.711352-2-v.v.mitrofanov@yadro.com (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
Series | Limit the number of counter returned from SBI. | expand |
Context | Check | Description |
---|---|---|
conchuod/cover_letter | success | Series has a cover letter |
conchuod/tree_selection | success | Guessed tree name to be for-next at HEAD 3ec1aafb0ff9 |
conchuod/fixes_present | success | Fixes tag not required for -next series |
conchuod/maintainers_pattern | success | MAINTAINERS pattern errors before the patch: 1 and now 1 |
conchuod/verify_signedoff | success | Signed-off-by tag matches author and committer |
conchuod/kdoc | success | Errors and warnings before: 0 this patch: 0 |
conchuod/build_rv64_clang_allmodconfig | success | Errors and warnings before: 18 this patch: 18 |
conchuod/module_param | success | Was 0 now: 0 |
conchuod/build_rv64_gcc_allmodconfig | success | Errors and warnings before: 18 this patch: 18 |
conchuod/build_rv32_defconfig | success | Build OK |
conchuod/dtb_warn_rv64 | success | Errors and warnings before: 3 this patch: 3 |
conchuod/header_inline | success | No static functions without inline keyword in header files |
conchuod/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 11 lines checked |
conchuod/source_inline | success | Was 0 now: 0 |
conchuod/build_rv64_nommu_k210_defconfig | success | Build OK |
conchuod/verify_fixes | success | No Fixes tag |
conchuod/build_rv64_nommu_virt_defconfig | success | Build OK |
On Fri, Apr 28, 2023 at 11:02:56AM +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. I recall suggesting we do this during the KVM PMU review, but I guess we forgot. > > Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com> > --- > drivers/perf/riscv_pmu_sbi.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c > index 70cb50fd41c2..0183bf911bfb 100644 > --- a/drivers/perf/riscv_pmu_sbi.c > +++ b/drivers/perf/riscv_pmu_sbi.c > @@ -867,6 +867,11 @@ static int pmu_sbi_device_probe(struct platform_device *pdev) > pr_err("SBI PMU extension doesn't provide any counters\n"); > goto out_free; > } Need blank line here > + /* It is possible to get from SBI more than max number of counters */ > + if (num_counters > RISCV_MAX_COUNTERS) { > + pr_warn("SBI returned more than maximum number of counters\n"); ^ the This should be a pr_info. > + num_counters = RISCV_MAX_COUNTERS; > + } Otherwise, Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Thanks, drew
diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 70cb50fd41c2..0183bf911bfb 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -867,6 +867,11 @@ static int pmu_sbi_device_probe(struct platform_device *pdev) pr_err("SBI PMU extension doesn't provide any counters\n"); goto out_free; } + /* It is possible to get from SBI more than max number of counters */ + if (num_counters > RISCV_MAX_COUNTERS) { + pr_warn("SBI returned more than maximum number of counters\n"); + num_counters = RISCV_MAX_COUNTERS; + } /* cache all the information about counters now */ if (pmu_sbi_get_ctrinfo(num_counters, &cmask))
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> --- drivers/perf/riscv_pmu_sbi.c | 5 +++++ 1 file changed, 5 insertions(+)