public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Will Deacon <will@kernel.org>
To: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: Atish Patra <atishp@atishpatra.org>,
	Anup Patel <anup@brainfault.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	linux-riscv@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Nam Cao <namcao@linutronix.de>
Subject: Re: [PATCH -fixes] drivers: perf: Fix smp_processor_id() use in preemptible code
Date: Tue, 27 Aug 2024 13:53:35 +0100	[thread overview]
Message-ID: <20240827125335.GD4772@willie-the-truck> (raw)
In-Reply-To: <20240826165210.124696-1-alexghiti@rivosinc.com>

On Mon, Aug 26, 2024 at 06:52:10PM +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
> 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>
> ---
>  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..25b1b699b3e2 100644
> --- a/drivers/perf/riscv_pmu_sbi.c
> +++ b/drivers/perf/riscv_pmu_sbi.c
> @@ -1373,11 +1373,15 @@ 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);
>  		if (ret) {
>  			/* Snapshot is an optional feature. Continue if not available */
>  			pmu_sbi_snapshot_free(pmu);
> @@ -1391,6 +1395,7 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
>  			 */
>  			static_branch_enable(&sbi_pmu_snapshot_available);
>  		}
> +		put_cpu();

Are you sure it's safe to enable the static key with preemption disabled?
I thought that could block on a mutex.

Will


  parent reply	other threads:[~2024-08-27 12:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-26 16:52 [PATCH -fixes] drivers: perf: Fix smp_processor_id() use in preemptible code Alexandre Ghiti
2024-08-26 16:58 ` Anup Patel
2024-08-26 17:31 ` Nam Cao
2024-08-26 17:37   ` Alexandre Ghiti
2024-08-26 19:35 ` Andrea Parri
2024-08-27  6:06   ` Alexandre Ghiti
2024-08-27 12:53 ` Will Deacon [this message]
2024-08-28 12:36   ` Alexandre Ghiti
2024-08-28 17:13     ` Atish Patra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240827125335.GD4772@willie-the-truck \
    --to=will@kernel.org \
    --cc=alexghiti@rivosinc.com \
    --cc=anup@brainfault.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=atishp@atishpatra.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=namcao@linutronix.de \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox