linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -fixes] drivers: perf: Fix wrong put_cpu() placement
@ 2024-11-12 11:34 Alexandre Ghiti
  2024-11-12 19:06 ` Atish Kumar Patra
  2024-11-12 22:53 ` patchwork-bot+linux-riscv
  0 siblings, 2 replies; 3+ messages in thread
From: Alexandre Ghiti @ 2024-11-12 11:34 UTC (permalink / raw)
  To: Atish Patra, Anup Patel, Will Deacon, Mark Rutland, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, linux-riscv, linux-arm-kernel,
	linux-kernel
  Cc: Alexandre Ghiti, Atish Patra

Unfortunately, the wrong patch version was merged which places the
put_cpu() after enabling a static key, which is not safe as pointed by
Will [1], so move put_cpu() before to avoid this.

Fixes: 2840dadf0dde ("drivers: perf: Fix smp_processor_id() use in preemptible code")
Reported-by: Atish Patra <atishp@rivosinc.com>
Link: https://lore.kernel.org/all/20240827125335.GD4772@willie-the-truck/ [1]
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
---
 drivers/perf/riscv_pmu_sbi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
index 391ca1422cae..1aa303f76cc7 100644
--- a/drivers/perf/riscv_pmu_sbi.c
+++ b/drivers/perf/riscv_pmu_sbi.c
@@ -1393,8 +1393,9 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
 			goto out_unregister;
 
 		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);
@@ -1408,7 +1409,6 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
 			 */
 			static_branch_enable(&sbi_pmu_snapshot_available);
 		}
-		put_cpu();
 	}
 
 	register_sysctl("kernel", sbi_pmu_sysctl_table);
-- 
2.39.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH -fixes] drivers: perf: Fix wrong put_cpu() placement
  2024-11-12 11:34 [PATCH -fixes] drivers: perf: Fix wrong put_cpu() placement Alexandre Ghiti
@ 2024-11-12 19:06 ` Atish Kumar Patra
  2024-11-12 22:53 ` patchwork-bot+linux-riscv
  1 sibling, 0 replies; 3+ messages in thread
From: Atish Kumar Patra @ 2024-11-12 19:06 UTC (permalink / raw)
  To: Alexandre Ghiti
  Cc: Atish Patra, Anup Patel, Will Deacon, Mark Rutland, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, linux-riscv, linux-arm-kernel,
	linux-kernel

On Tue, Nov 12, 2024 at 3:34 AM Alexandre Ghiti <alexghiti@rivosinc.com> wrote:
>
> Unfortunately, the wrong patch version was merged which places the
> put_cpu() after enabling a static key, which is not safe as pointed by
> Will [1], so move put_cpu() before to avoid this.
>
> Fixes: 2840dadf0dde ("drivers: perf: Fix smp_processor_id() use in preemptible code")
> Reported-by: Atish Patra <atishp@rivosinc.com>
> Link: https://lore.kernel.org/all/20240827125335.GD4772@willie-the-truck/ [1]
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> ---
>  drivers/perf/riscv_pmu_sbi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
> index 391ca1422cae..1aa303f76cc7 100644
> --- a/drivers/perf/riscv_pmu_sbi.c
> +++ b/drivers/perf/riscv_pmu_sbi.c
> @@ -1393,8 +1393,9 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
>                         goto out_unregister;
>
>                 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);
> @@ -1408,7 +1409,6 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
>                          */
>                         static_branch_enable(&sbi_pmu_snapshot_available);
>                 }
> -               put_cpu();
>         }
>
>         register_sysctl("kernel", sbi_pmu_sysctl_table);
> --
> 2.39.2
>

Reviewed-by: Atish Patra <atishp@rivosinc.com>
Tested-by: Atish Patra <atishp@rivosinc.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH -fixes] drivers: perf: Fix wrong put_cpu() placement
  2024-11-12 11:34 [PATCH -fixes] drivers: perf: Fix wrong put_cpu() placement Alexandre Ghiti
  2024-11-12 19:06 ` Atish Kumar Patra
@ 2024-11-12 22:53 ` patchwork-bot+linux-riscv
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+linux-riscv @ 2024-11-12 22:53 UTC (permalink / raw)
  To: Alexandre Ghiti
  Cc: linux-riscv, atishp, anup, will, mark.rutland, paul.walmsley,
	palmer, aou, linux-arm-kernel, linux-kernel, atishp

Hello:

This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:

On Tue, 12 Nov 2024 12:34:22 +0100 you wrote:
> Unfortunately, the wrong patch version was merged which places the
> put_cpu() after enabling a static key, which is not safe as pointed by
> Will [1], so move put_cpu() before to avoid this.
> 
> Fixes: 2840dadf0dde ("drivers: perf: Fix smp_processor_id() use in preemptible code")
> Reported-by: Atish Patra <atishp@rivosinc.com>
> Link: https://lore.kernel.org/all/20240827125335.GD4772@willie-the-truck/ [1]
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> 
> [...]

Here is the summary with links:
  - [-fixes] drivers: perf: Fix wrong put_cpu() placement
    https://git.kernel.org/riscv/c/57f7c7dc78cd

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:[~2024-11-12 22:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-12 11:34 [PATCH -fixes] drivers: perf: Fix wrong put_cpu() placement Alexandre Ghiti
2024-11-12 19:06 ` Atish Kumar Patra
2024-11-12 22:53 ` 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;
as well as URLs for NNTP newsgroup(s).