diff mbox series

[-fixes,v2] drivers: perf: Fix smp_processor_id() use in preemptible code

Message ID 20240829090034.15777-1-alexghiti@rivosinc.com (mailing list archive)
State Superseded, archived
Headers show
Series [-fixes,v2] drivers: perf: Fix smp_processor_id() use in preemptible code | expand

Checks

Context Check Description
conchuod/vmtest-fixes-PR success PR summary
conchuod/patch-1-test-1 success .github/scripts/patches/tests/build_rv32_defconfig.sh
conchuod/patch-1-test-2 success .github/scripts/patches/tests/build_rv64_clang_allmodconfig.sh
conchuod/patch-1-test-3 success .github/scripts/patches/tests/build_rv64_gcc_allmodconfig.sh
conchuod/patch-1-test-4 success .github/scripts/patches/tests/build_rv64_nommu_k210_defconfig.sh
conchuod/patch-1-test-5 success .github/scripts/patches/tests/build_rv64_nommu_virt_defconfig.sh
conchuod/patch-1-test-6 warning .github/scripts/patches/tests/checkpatch.sh
conchuod/patch-1-test-7 success .github/scripts/patches/tests/dtb_warn_rv64.sh
conchuod/patch-1-test-8 success .github/scripts/patches/tests/header_inline.sh
conchuod/patch-1-test-9 success .github/scripts/patches/tests/kdoc.sh
conchuod/patch-1-test-10 success .github/scripts/patches/tests/module_param.sh
conchuod/patch-1-test-11 success .github/scripts/patches/tests/verify_fixes.sh
conchuod/patch-1-test-12 success .github/scripts/patches/tests/verify_signedoff.sh

Commit Message

Alexandre Ghiti Aug. 29, 2024, 9 a.m. UTC
As reported in [1], the use of smp_processor_id() in
pmu_sbi_device_probe() must be protected by disabling the preemption, so
simply use get_cpu()/put_cpu() instead.

Reported-by: Andrea Parri <parri.andrea@gmail.com>
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>
---

Changes in v2:
- Do not disable the preemption in static_key_enable() (Will)

 drivers/perf/riscv_pmu_sbi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Atish Kumar Patra Aug. 30, 2024, 4:39 p.m. UTC | #1
On 8/29/24 2:00 AM, Alexandre Ghiti wrote:
> As reported in [1], the use of smp_processor_id() in
> pmu_sbi_device_probe() must be protected by disabling the preemption, so
> simply use get_cpu()/put_cpu() instead.
> 
> Reported-by: Andrea Parri <parri.andrea@gmail.com>
> 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>
> ---
> 
> Changes in v2:
> - Do not disable the preemption in static_key_enable() (Will)
> 
>   drivers/perf/riscv_pmu_sbi.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
> index 31a17a56eb3b..febd8e74a72f 100644
> --- a/drivers/perf/riscv_pmu_sbi.c
> +++ b/drivers/perf/riscv_pmu_sbi.c
> @@ -1373,11 +1373,16 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
>   
>   	/* SBI PMU Snapsphot is only available in SBI v2.0 */
>   	if (sbi_v2_available) {
> +		int cpu;
> +
>   		ret = pmu_sbi_snapshot_alloc(pmu);
>   		if (ret)
>   			goto out_unregister;
>   
> -		ret = pmu_sbi_snapshot_setup(pmu, smp_processor_id());
> +		cpu = get_cpu();
> +		ret = pmu_sbi_snapshot_setup(pmu, cpu);
> +		put_cpu();
> +
>   		if (ret) {
>   			/* Snapshot is an optional feature. Continue if not available */
>   			pmu_sbi_snapshot_free(pmu);

Reviewed-by: Atish Patra <atishp@rivosinc.com>
Nam Cao Sept. 5, 2024, 9:55 p.m. UTC | #2
On Thu, Aug 29, 2024 at 11:00:34AM +0200, Alexandre Ghiti wrote:
> As reported in [1], the use of smp_processor_id() in
> pmu_sbi_device_probe() must be protected by disabling the preemption, so
> simply use get_cpu()/put_cpu() instead.
> 
> Reported-by: Andrea Parri <parri.andrea@gmail.com>
> 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>

Tested-by: Nam Cao <namcao@linutronix.de>

Best regards,
Nam
diff mbox series

Patch

diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
index 31a17a56eb3b..febd8e74a72f 100644
--- a/drivers/perf/riscv_pmu_sbi.c
+++ b/drivers/perf/riscv_pmu_sbi.c
@@ -1373,11 +1373,16 @@  static int pmu_sbi_device_probe(struct platform_device *pdev)
 
 	/* SBI PMU Snapsphot is only available in SBI v2.0 */
 	if (sbi_v2_available) {
+		int cpu;
+
 		ret = pmu_sbi_snapshot_alloc(pmu);
 		if (ret)
 			goto out_unregister;
 
-		ret = pmu_sbi_snapshot_setup(pmu, smp_processor_id());
+		cpu = get_cpu();
+		ret = pmu_sbi_snapshot_setup(pmu, cpu);
+		put_cpu();
+
 		if (ret) {
 			/* Snapshot is an optional feature. Continue if not available */
 			pmu_sbi_snapshot_free(pmu);