All of lore.kernel.org
 help / color / mirror / Atom feed
From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH V2] arm64: percpu: Make this_cpu accessors pre-empt safe
Date: Mon, 23 Mar 2015 10:17:58 +0000	[thread overview]
Message-ID: <20150323101758.GB11189@arm.com> (raw)
In-Reply-To: <1427035911-10585-1-git-send-email-steve.capper@linaro.org>

On Sun, Mar 22, 2015 at 02:51:51PM +0000, Steve Capper wrote:
> this_cpu operations were implemented for arm64 in:
>  5284e1b arm64: xchg: Implement cmpxchg_double
>  f97fc81 arm64: percpu: Implement this_cpu operations
> 
> Unfortunately, it is possible for pre-emption to take place between
> address generation and data access. This can lead to cases where data
> is being manipulated by this_cpu for a different CPU than it was
> called on. Which effectively breaks the spec.
> 
> This patch disables pre-emption for the this_cpu operations
> guaranteeing that address generation and data manipulation take place
> without a pre-emption in-between.
> 
> Fixes: 5284e1b4bc8a ("arm64: xchg: Implement cmpxchg_double")
> Fixes: f97fc810798c ("arm64: percpu: Implement this_cpu operations")
> Reported-by: Mark Rutland <mark.rutland@arm.com>
> Signed-off-by: Steve Capper <steve.capper@linaro.org>
> ---
> Changed in V2, moved over to preempt_enable() completely.
> Corrected the "Fixes" tag.
> 
> Mark, I've dropped your Reviewed-by as I've changed some logic, please
> let me know if I should re-add it.
> 
> Cheers,
> -- 
> Steve
> ---
>  arch/arm64/include/asm/cmpxchg.h | 32 +++++++++++++++++++++--------
>  arch/arm64/include/asm/percpu.h  | 44 ++++++++++++++++++++++++++++++----------
>  2 files changed, 57 insertions(+), 19 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/cmpxchg.h b/arch/arm64/include/asm/cmpxchg.h
> index cb95930..d8c25b7 100644
> --- a/arch/arm64/include/asm/cmpxchg.h
> +++ b/arch/arm64/include/asm/cmpxchg.h
> @@ -246,14 +246,30 @@ static inline unsigned long __cmpxchg_mb(volatile void *ptr, unsigned long old,
>  	__ret; \
>  })
>  
> -#define this_cpu_cmpxchg_1(ptr, o, n) cmpxchg_local(raw_cpu_ptr(&(ptr)), o, n)
> -#define this_cpu_cmpxchg_2(ptr, o, n) cmpxchg_local(raw_cpu_ptr(&(ptr)), o, n)
> -#define this_cpu_cmpxchg_4(ptr, o, n) cmpxchg_local(raw_cpu_ptr(&(ptr)), o, n)
> -#define this_cpu_cmpxchg_8(ptr, o, n) cmpxchg_local(raw_cpu_ptr(&(ptr)), o, n)
> -
> -#define this_cpu_cmpxchg_double_8(ptr1, ptr2, o1, o2, n1, n2) \
> -	cmpxchg_double_local(raw_cpu_ptr(&(ptr1)), raw_cpu_ptr(&(ptr2)), \
> -				o1, o2, n1, n2)
> +#define _protect_cmpxchg_local(pcp, o, n)			\
> +({								\
> +	typeof(*raw_cpu_ptr(&(pcp))) __ret;			\
> +	preempt_disable();					\
> +	__ret = cmpxchg_local(raw_cpu_ptr(&(pcp)), o, n);	\
> +	preempt_enable();					\
> +	__ret;							\
> +})
> +
> +#define this_cpu_cmpxchg_1(ptr, o, n) _protect_cmpxchg_local(ptr, o, n)
> +#define this_cpu_cmpxchg_2(ptr, o, n) _protect_cmpxchg_local(ptr, o, n)
> +#define this_cpu_cmpxchg_4(ptr, o, n) _protect_cmpxchg_local(ptr, o, n)
> +#define this_cpu_cmpxchg_8(ptr, o, n) _protect_cmpxchg_local(ptr, o, n)
> +
> +#define this_cpu_cmpxchg_double_8(ptr1, ptr2, o1, o2, n1, n2)		\
> +({									\
> +	int __ret;							\
> +	preempt_disable();						\
> +	__ret = cmpxchg_double_local(	raw_cpu_ptr(&(ptr1)),		\

Weird whitespace here, but the patch looks fine to me:

  Acked-by: Will Deacon <will.deacon@arm.com>

Thanks, Steve.

Will

      reply	other threads:[~2015-03-23 10:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-19 14:52 [PATCH] arm64: percpu: Make this_cpu accessors pre-empt safe Steve Capper
2015-03-19 15:44 ` Mark Rutland
2015-03-19 15:55   ` Steve Capper
2015-03-19 16:23     ` Mark Rutland
2015-03-19 16:00   ` Will Deacon
2015-03-19 16:11     ` Mark Rutland
2015-03-19 16:27       ` Will Deacon
2015-03-19 16:39         ` Mark Rutland
2015-03-20 18:02           ` Will Deacon
2015-03-22 14:51             ` [PATCH V2] " Steve Capper
2015-03-23 10:17               ` Will Deacon [this message]

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=20150323101758.GB11189@arm.com \
    --to=will.deacon@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.