public inbox for linux-riscv@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH -fixes v2] drivers: perf: Fix smp_processor_id() use in preemptible code
@ 2024-08-29  9:00 Alexandre Ghiti
  2024-08-30 16:39 ` Atish Patra
  2024-09-05 21:55 ` Nam Cao
  0 siblings, 2 replies; 3+ messages in thread
From: Alexandre Ghiti @ 2024-08-29  9:00 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, Andrea Parri, Nam Cao

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);
-- 
2.39.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

* Re: [PATCH -fixes v2] drivers: perf: Fix smp_processor_id() use in preemptible code
  2024-08-29  9:00 [PATCH -fixes v2] drivers: perf: Fix smp_processor_id() use in preemptible code Alexandre Ghiti
@ 2024-08-30 16:39 ` Atish Patra
  2024-09-05 21:55 ` Nam Cao
  1 sibling, 0 replies; 3+ messages in thread
From: Atish Patra @ 2024-08-30 16:39 UTC (permalink / raw)
  To: Alexandre Ghiti, Atish Patra, Anup Patel, Will Deacon,
	Mark Rutland, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	linux-riscv, linux-arm-kernel, linux-kernel
  Cc: Andrea Parri, Nam Cao

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>

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

* Re: [PATCH -fixes v2] drivers: perf: Fix smp_processor_id() use in preemptible code
  2024-08-29  9:00 [PATCH -fixes v2] drivers: perf: Fix smp_processor_id() use in preemptible code Alexandre Ghiti
  2024-08-30 16:39 ` Atish Patra
@ 2024-09-05 21:55 ` Nam Cao
  1 sibling, 0 replies; 3+ messages in thread
From: Nam Cao @ 2024-09-05 21:55 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, Andrea Parri

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

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

end of thread, other threads:[~2024-09-05 21:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-29  9:00 [PATCH -fixes v2] drivers: perf: Fix smp_processor_id() use in preemptible code Alexandre Ghiti
2024-08-30 16:39 ` Atish Patra
2024-09-05 21:55 ` Nam Cao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox