Skip to content

Commit 2840dad

Browse files
Alexandre Ghitipalmer-dabbelt
authored andcommitted
drivers: perf: Fix smp_processor_id() use in preemptible code
As reported in [1], the use of smp_processor_id() in pmu_sbi_device_probe() must be protected by disabling the preemption, so simple use get_cpu()/put_cpu() instead. Reported-by: Nam Cao <namcao@linutronix.de> Closes: https://lore.kernel.org/linux-riscv/20240820074925.ReMKUPP3@linutronix.de/ [1] Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org> Tested-by: Nam Cao <namcao@linutronix.de> Fixes: a862521 ("drivers/perf: riscv: Implement SBI PMU snapshot function") Reported-by: Andrea Parri <parri.andrea@gmail.com> Tested-by: Andrea Parri <parri.andrea@gmail.com> Link: https://lore.kernel.org/r/20240826165210.124696-1-alexghiti@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 1ff95eb commit 2840dad

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/perf/riscv_pmu_sbi.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,11 +1373,15 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
13731373

13741374
/* SBI PMU Snapsphot is only available in SBI v2.0 */
13751375
if (sbi_v2_available) {
1376+
int cpu;
1377+
13761378
ret = pmu_sbi_snapshot_alloc(pmu);
13771379
if (ret)
13781380
goto out_unregister;
13791381

1380-
ret = pmu_sbi_snapshot_setup(pmu, smp_processor_id());
1382+
cpu = get_cpu();
1383+
1384+
ret = pmu_sbi_snapshot_setup(pmu, cpu);
13811385
if (ret) {
13821386
/* Snapshot is an optional feature. Continue if not available */
13831387
pmu_sbi_snapshot_free(pmu);
@@ -1391,6 +1395,7 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
13911395
*/
13921396
static_branch_enable(&sbi_pmu_snapshot_available);
13931397
}
1398+
put_cpu();
13941399
}
13951400

13961401
register_sysctl("kernel", sbi_pmu_sysctl_table);

0 commit comments

Comments
 (0)