Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: robin.murphy@arm.com (Robin Murphy)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] arm64: smp: Prevent raw_smp_processor_id() recursion
Date: Thu, 1 Dec 2016 17:16:50 +0000	[thread overview]
Message-ID: <2bd54897-df2e-a20e-d748-07966642b850@arm.com> (raw)
In-Reply-To: <bb132e9abf4d256e40ad311b106b05d724b290fb.1480607460.git.robin.murphy@arm.com>

On 01/12/16 15:55, Robin Murphy wrote:
> Under CONFIG_DEBUG_PREEMPT=y, this_cpu_ptr() ends up calling back into
> raw_smp_processor_id(), resulting in some hilariously catastrophic
> infinite recursion. In the normal case, we have:
> 
>   #define this_cpu_ptr(ptr) raw_cpu_ptr(ptr)
> 
> and everything is dandy. However for CONFIG_DEBUG_PREEMPT, this_cpu_ptr()
> is defined in terms of my_cpu_offset, wherein the fun begins:
> 
>   #define my_cpu_offset per_cpu_offset(smp_processor_id())
>   ...
>   #define smp_processor_id() debug_smp_processor_id()
>   ...
>   notrace unsigned int debug_smp_processor_id(void)
>   {
>   	return check_preemption_disabled("smp_processor_id", "");
>   ...
>   notrace static unsigned int check_preemption_disabled(const char *what1,
>   							const char *what2)
>   {
>   	int this_cpu = raw_smp_processor_id();
> 
> and bang. Use raw_cpu_ptr() directly to avoid that.
> 
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Acked-by: Will Deacon <will.deacon@arm.com>
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>

I wasn't sure whether commit IDs on for-next/core are stable, but if
they are, this could also have:

Fixes: 57c82954e77f ("arm64: make cpu number a percpu variable")

Robin.

> ---
> 
> Since I just reproduced this locally to verify Will's suggestion, it
> seemed I might as well just write it up as a patch :)
> 
>  arch/arm64/include/asm/smp.h | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/include/asm/smp.h b/arch/arm64/include/asm/smp.h
> index a62db952ffcb..d050d720a1b4 100644
> --- a/arch/arm64/include/asm/smp.h
> +++ b/arch/arm64/include/asm/smp.h
> @@ -41,8 +41,10 @@ DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
>   * We don't use this_cpu_read(cpu_number) as that has implicit writes to
>   * preempt_count, and associated (compiler) barriers, that we'd like to avoid
>   * the expense of. If we're preemptible, the value can be stale at use anyway.
> + * And we can't use this_cpu_ptr() either, as that winds up recursing back
> + * here under CONFIG_DEBUG_PREEMPT=y.
>   */
> -#define raw_smp_processor_id() (*this_cpu_ptr(&cpu_number))
> +#define raw_smp_processor_id() (*raw_cpu_ptr(&cpu_number))
>  
>  struct seq_file;
>  
> 

  reply	other threads:[~2016-12-01 17:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20161201155519epcas2p28dc6c3f466f1455bed3b13cbb20e25e6@epcas2p2.samsung.com>
2016-12-01 15:55 ` [PATCH] arm64: smp: Prevent raw_smp_processor_id() recursion Robin Murphy
2016-12-01 17:16   ` Robin Murphy [this message]
2016-12-01 17:27     ` Catalin Marinas
2016-12-02  6:31   ` Marek Szyprowski

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=2bd54897-df2e-a20e-d748-07966642b850@arm.com \
    --to=robin.murphy@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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