Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1240857 > unrolled thread

[PATCH] x86: cmpxchg_double: Add missing memory clobber

Started byPranith Kumar <bobby.prani@gmail.com>
First post2015-10-06 21:00 +0200
Last post2015-10-07 15:10 +0200
Articles 5 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] x86: cmpxchg_double: Add missing memory clobber Pranith Kumar <bobby.prani@gmail.com> - 2015-10-06 21:00 +0200
    Re: [PATCH] x86: cmpxchg_double: Add missing memory clobber "H. Peter Anvin" <hpa@zytor.com> - 2015-10-06 22:20 +0200
      Re: [PATCH] x86: cmpxchg_double: Add missing memory clobber Pranith Kumar <bobby.prani@gmail.com> - 2015-10-06 22:30 +0200
        Re: [PATCH] x86: cmpxchg_double: Add missing memory clobber "H. Peter Anvin" <hpa@zytor.com> - 2015-10-06 23:40 +0200
          Re: [PATCH] x86: cmpxchg_double: Add missing memory clobber Peter Zijlstra <peterz@infradead.org> - 2015-10-07 15:10 +0200

#1240857 — [PATCH] x86: cmpxchg_double: Add missing memory clobber

FromPranith Kumar <bobby.prani@gmail.com>
Date2015-10-06 21:00 +0200
Subject[PATCH] x86: cmpxchg_double: Add missing memory clobber
Message-ID<qgFCW-6fq-9@gated-at.bofh.it>
We are reading from memory locations pointed to by p1 and p2 in the asm
block. Add a memory clobber flag to make gcc aware of this.

Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
---
 arch/x86/include/asm/cmpxchg.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
index 4a2e5bc..3e83949 100644
--- a/arch/x86/include/asm/cmpxchg.h
+++ b/arch/x86/include/asm/cmpxchg.h
@@ -214,7 +214,8 @@ extern void __add_wrong_size(void)
 		     : "=a" (__ret), "+d" (__old2),			\
 		       "+m" (*(p1)), "+m" (*(p2))			\
 		     : "i" (2 * sizeof(long)), "a" (__old1),		\
-		       "b" (__new1), "c" (__new2));			\
+		       "b" (__new1), "c" (__new2)			\
+		     : "memory");					\
 	__ret;								\
 })
 
-- 
2.5.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1240964

From"H. Peter Anvin" <hpa@zytor.com>
Date2015-10-06 22:20 +0200
Message-ID<qgGSn-8hZ-27@gated-at.bofh.it>
In reply to#1240857
On 10/06/2015 11:54 AM, Pranith Kumar wrote:
> We are reading from memory locations pointed to by p1 and p2 in the asm
> block. Add a memory clobber flag to make gcc aware of this.
> 
> Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
> ---
>  arch/x86/include/asm/cmpxchg.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
> index 4a2e5bc..3e83949 100644
> --- a/arch/x86/include/asm/cmpxchg.h
> +++ b/arch/x86/include/asm/cmpxchg.h
> @@ -214,7 +214,8 @@ extern void __add_wrong_size(void)
>  		     : "=a" (__ret), "+d" (__old2),			\
>  		       "+m" (*(p1)), "+m" (*(p2))			\
>  		     : "i" (2 * sizeof(long)), "a" (__old1),		\
> -		       "b" (__new1), "c" (__new2));			\
> +		       "b" (__new1), "c" (__new2)			\
> +		     : "memory");					\
>  	__ret;								\
>  })

NAK.  We already have the "+m" for exactly this reason; adding an
explicit memory clobber should only be used to prevent movement of
*other* memory operations around this one (i.e. a barrier).

	-hpa


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1240967

FromPranith Kumar <bobby.prani@gmail.com>
Date2015-10-06 22:30 +0200
Message-ID<qgH22-8u5-9@gated-at.bofh.it>
In reply to#1240964
On Tue, Oct 6, 2015 at 4:16 PM, H. Peter Anvin <hpa@zytor.com> wrote:
>
> NAK.  We already have the "+m" for exactly this reason; adding an
> explicit memory clobber should only be used to prevent movement of
> *other* memory operations around this one (i.e. a barrier).
>

OK. If that is so, can you please explain why we need it in the
__raw_cmpxchg() case? I think it is a good idea to make cmpxchg() and
cmpxchg_double() have similar barrier semantics.

Thanks!
-- 
Pranith
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1241011

From"H. Peter Anvin" <hpa@zytor.com>
Date2015-10-06 23:40 +0200
Message-ID<qgI7M-1zn-13@gated-at.bofh.it>
In reply to#1240967
On 10/06/2015 01:29 PM, Pranith Kumar wrote:
> On Tue, Oct 6, 2015 at 4:16 PM, H. Peter Anvin <hpa@zytor.com> wrote:
>>
>> NAK.  We already have the "+m" for exactly this reason; adding an
>> explicit memory clobber should only be used to prevent movement of
>> *other* memory operations around this one (i.e. a barrier).
>>
> 
> OK. If that is so, can you please explain why we need it in the
> __raw_cmpxchg() case? I think it is a good idea to make cmpxchg() and
> cmpxchg_double() have similar barrier semantics.
> 

OK, it is a bit of a mess.  We use the same macros for locked operations
(__cmpxchg and __sync_cmpxchg) and unlocked operations
(__cmpxchg_local).  For locked operations we generally want a compiler
barrier, although there are exceptions.  I'm wondering if it would be
better to add an explicit barrier(); to the locked versions.

However, I think one of the major uses for cmpxchg_double() is for page
table manipulation, and for that it isn't clear that a compiler barrier
is needed nor desired.

On the other hand, perhaps all of this is false optimization and we
should just add the memory clobber.  The real issue is the impact on the
_local variants.

	-hpa

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1241465

FromPeter Zijlstra <peterz@infradead.org>
Date2015-10-07 15:10 +0200
Message-ID<qgWDL-5In-1@gated-at.bofh.it>
In reply to#1241011
On Tue, Oct 06, 2015 at 02:39:02PM -0700, H. Peter Anvin wrote:

> However, I think one of the major uses for cmpxchg_double() is for page
> table manipulation, and for that it isn't clear that a compiler barrier
> is needed nor desired.

See mm/slub.c, that uses cmpxchg_double() (the LOCK prefixed one) and
one would expect that to also include a compiler barrier.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web