linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix the x86 specializations of atomic_[set|clear]_mask
@ 2014-10-15 20:38 Patrick Palka
  2014-10-16  8:02 ` Peter Zijlstra
  0 siblings, 1 reply; 4+ messages in thread
From: Patrick Palka @ 2014-10-15 20:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Patrick Palka, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	Peter Zijlstra, Hans-Christian Egtvedt, Paul E. McKenney,
	Pranith Kumar

This patch fixes a number of issues with these specializations:

  1. The memory operand inside the asm specification is erroneously
  declared read-only instead of read-write.

  2. There is no reason to require the 1st operand of andl/orl to be
  inside a register; the 1st operand could also be an immediate operand.
  So change its specification from "r" to "ir".

  3. Since addr is supposed to be an atomic_t *, the memory operand
  should be addr->counter and not *addr.

  4. These specializations should be inline functions instead of macros.

  5. Finally, the "memory" clobbers are unnecessary, so they should be
  removed.  (This is in line with the other atomic functions such as
  atomic_add and atomic_sub, the likes of which do not have a "memory"
  clobber.)

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Hans-Christian Egtvedt <egtvedt@samfundet.no>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Pranith Kumar <bobby.prani@gmail.com>
Signed-off-by: Patrick Palka <patrick@parcs.ath.cx>
---
 arch/x86/include/asm/atomic.h | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
index 5e5cd12..83ae239 100644
--- a/arch/x86/include/asm/atomic.h
+++ b/arch/x86/include/asm/atomic.h
@@ -219,15 +219,19 @@ static inline short int atomic_inc_short(short int *v)
 	return *v;
 }
 
-/* These are x86-specific, used by some header files */
-#define atomic_clear_mask(mask, addr)				\
-	asm volatile(LOCK_PREFIX "andl %0,%1"			\
-		     : : "r" (~(mask)), "m" (*(addr)) : "memory")
+static inline void atomic_clear_mask(int mask, atomic_t *v)
+{
+	asm volatile(LOCK_PREFIX "andl %1, %0"
+		     : "+m" (v->counter)
+		     : "ir" (~mask));
+}
 
-#define atomic_set_mask(mask, addr)				\
-	asm volatile(LOCK_PREFIX "orl %0,%1"			\
-		     : : "r" ((unsigned)(mask)), "m" (*(addr))	\
-		     : "memory")
+static inline void atomic_set_mask(int mask, atomic_t *v)
+{
+	asm volatile(LOCK_PREFIX "orl %1, %0"
+		     : "+m" (v->counter)
+		     : "ir" (mask));
+}
 
 #ifdef CONFIG_X86_32
 # include <asm/atomic64_32.h>
-- 
2.1.2.443.g670a3c1


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

* Re: [PATCH] Fix the x86 specializations of atomic_[set|clear]_mask
  2014-10-15 20:38 [PATCH] Fix the x86 specializations of atomic_[set|clear]_mask Patrick Palka
@ 2014-10-16  8:02 ` Peter Zijlstra
       [not found]   ` <CA+C-WL-EKxA-oZ815vG9jau76BwQvAuL5WiuE-YvddgWPzt-Ew@mail.gmail.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2014-10-16  8:02 UTC (permalink / raw)
  To: Patrick Palka
  Cc: linux-kernel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	Hans-Christian Egtvedt, Paul E. McKenney, Pranith Kumar

On Wed, Oct 15, 2014 at 04:38:01PM -0400, Patrick Palka wrote:
> This patch fixes a number of issues with these specializations:
> 
>   1. The memory operand inside the asm specification is erroneously
>   declared read-only instead of read-write.
> 
>   2. There is no reason to require the 1st operand of andl/orl to be
>   inside a register; the 1st operand could also be an immediate operand.
>   So change its specification from "r" to "ir".
> 
>   3. Since addr is supposed to be an atomic_t *, the memory operand
>   should be addr->counter and not *addr.
> 
>   4. These specializations should be inline functions instead of macros.
> 
>   5. Finally, the "memory" clobbers are unnecessary, so they should be
>   removed.  (This is in line with the other atomic functions such as
>   atomic_add and atomic_sub, the likes of which do not have a "memory"
>   clobber.)

No real problem with this, but I'm going to kill off these functions
when I get a little time :)

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

* Re: [PATCH] Fix the x86 specializations of atomic_[set|clear]_mask
       [not found]   ` <CA+C-WL-EKxA-oZ815vG9jau76BwQvAuL5WiuE-YvddgWPzt-Ew@mail.gmail.com>
@ 2014-10-16 20:24     ` Peter Zijlstra
  2014-10-17  0:19       ` Patrick Palka
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2014-10-16 20:24 UTC (permalink / raw)
  To: Patrick Palka
  Cc: Paul E. McKenney, x86, Thomas Gleixner, Ingo Molnar,
	Pranith Kumar, H. Peter Anvin, Hans-Christian Egtvedt,
	linux-kernel

On Thu, Oct 16, 2014 at 12:49:43PM -0400, Patrick Palka wrote:
> On Oct 16, 2014 4:02 AM, "Peter Zijlstra" <peterz@infradead.org> wrote:
> >
> > On Wed, Oct 15, 2014 at 04:38:01PM -0400, Patrick Palka wrote:
> > > This patch fixes a number of issues with these specializations:
> > >
> > >   1. The memory operand inside the asm specification is erroneously
> > >   declared read-only instead of read-write.
> > >
> > >   2. There is no reason to require the 1st operand of andl/orl to be
> > >   inside a register; the 1st operand could also be an immediate operand.
> > >   So change its specification from "r" to "ir".
> > >
> > >   3. Since addr is supposed to be an atomic_t *, the memory operand
> > >   should be addr->counter and not *addr.
> > >
> > >   4. These specializations should be inline functions instead of macros.
> > >
> > >   5. Finally, the "memory" clobbers are unnecessary, so they should be
> > >   removed.  (This is in line with the other atomic functions such as
> > >   atomic_add and atomic_sub, the likes of which do not have a "memory"
> > >   clobber.)
> >
> > No real problem with this, but I'm going to kill off these functions
> > when I get a little time :)
> 
> Hmm why's that?

because they're odd (inconsistent with the rest of the atomic
interfaces) and not implemented by all archs.

See: https://lkml.org/lkml/2014/2/6/196

3.18 will include up to 4/5 of that series and when I get a spare moment
I need cleanup/post the next arch sweep that will get us that 5/5 thing.



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

* Re: [PATCH] Fix the x86 specializations of atomic_[set|clear]_mask
  2014-10-16 20:24     ` Peter Zijlstra
@ 2014-10-17  0:19       ` Patrick Palka
  0 siblings, 0 replies; 4+ messages in thread
From: Patrick Palka @ 2014-10-17  0:19 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Paul E. McKenney, x86, Thomas Gleixner, Ingo Molnar,
	Pranith Kumar, H. Peter Anvin, Hans-Christian Egtvedt,
	Linux Kernel Mailing List

On Thu, Oct 16, 2014 at 4:24 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> On Thu, Oct 16, 2014 at 12:49:43PM -0400, Patrick Palka wrote:
>> On Oct 16, 2014 4:02 AM, "Peter Zijlstra" <peterz@infradead.org> wrote:
>> >
>> > On Wed, Oct 15, 2014 at 04:38:01PM -0400, Patrick Palka wrote:
>> > > This patch fixes a number of issues with these specializations:
>> > >
>> > >   1. The memory operand inside the asm specification is erroneously
>> > >   declared read-only instead of read-write.
>> > >
>> > >   2. There is no reason to require the 1st operand of andl/orl to be
>> > >   inside a register; the 1st operand could also be an immediate operand.
>> > >   So change its specification from "r" to "ir".
>> > >
>> > >   3. Since addr is supposed to be an atomic_t *, the memory operand
>> > >   should be addr->counter and not *addr.
>> > >
>> > >   4. These specializations should be inline functions instead of macros.
>> > >
>> > >   5. Finally, the "memory" clobbers are unnecessary, so they should be
>> > >   removed.  (This is in line with the other atomic functions such as
>> > >   atomic_add and atomic_sub, the likes of which do not have a "memory"
>> > >   clobber.)
>> >
>> > No real problem with this, but I'm going to kill off these functions
>> > when I get a little time :)
>>
>> Hmm why's that?
>
> because they're odd (inconsistent with the rest of the atomic
> interfaces) and not implemented by all archs.
>
> See: https://lkml.org/lkml/2014/2/6/196
>
> 3.18 will include up to 4/5 of that series and when I get a spare moment
> I need cleanup/post the next arch sweep that will get us that 5/5 thing.
>
>

Cool! Perhaps atomic_inc_short() should be killed off too. It
currently has no callers and, despite what its name suggests, it is
not even atomic..

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

end of thread, other threads:[~2014-10-17  0:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-15 20:38 [PATCH] Fix the x86 specializations of atomic_[set|clear]_mask Patrick Palka
2014-10-16  8:02 ` Peter Zijlstra
     [not found]   ` <CA+C-WL-EKxA-oZ815vG9jau76BwQvAuL5WiuE-YvddgWPzt-Ew@mail.gmail.com>
2014-10-16 20:24     ` Peter Zijlstra
2014-10-17  0:19       ` Patrick Palka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).