Re: [cpuops cmpxchg V1 2/4] x86: this_cpu_cmpxchg and this_cpu_xchgoperations

From: Christoph Lameter
Date: Wed Dec 08 2010 - 17:20:20 EST


Argh. I included __this_cpu_cmpxchg_8 done with cmpxchg8b for 32 bit. That
has some issues....


Subject: Fixup __this_cpu_cmpxchg_8

__this_cpu_cmpxchg_8 can cause compilation failure since it is expanded
for any this_cpu_cmpxchg independent of the size or type of argument.
However. __this_cpu_cmpxchg_8 only generates code for the 8 byte
case. Use a union to get around the compilation failures.

Signed-off-by: Christoph Lameter <cl@xxxxxxxxx>

---
arch/x86/include/asm/percpu.h | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)

Index: linux-2.6/arch/x86/include/asm/percpu.h
===================================================================
--- linux-2.6.orig/arch/x86/include/asm/percpu.h 2010-12-08 14:48:02.000000000 -0600
+++ linux-2.6/arch/x86/include/asm/percpu.h 2010-12-08 16:01:24.000000000 -0600
@@ -391,15 +391,23 @@ do { \

#ifndef CONFIG_X86_64
#ifdef CONFIG_X86_CMPXCHG64
-/* We can support a 8 byte cmpxchg with a special instruction on 32 bit */
+/*
+ * We can support a 8 byte cmpxchg with a special instruction on 32 bit.
+ *
+ * Note that some of the strangeness here with the __new variable is due to
+ * the need to expand and compile this function for arbitary types even
+ * though the code will not be included in the .o file if used for a smaller
+ * type.
+ */
#define __this_cpu_cmpxchg_8(pcp, oval, nval) \
({ \
- typeof(var) __ret; \
- typeof(var) __old = (oval); \
- typeof(var) __new = (nval); \
+ typeof(pcp) __ret; \
+ typeof(pcp) __old = (oval); \
+ union x { typeof(pcp) n;u64 m; } __new; \
+ __new.n = (nval); \
asm("cmpxchg8b %2, "__percpu_arg(1) \
- : "=A" (__ret), "+m" (&pcp) \
- : "b" (((u32)new), "c" ((u32)(new >> 32)), "0" (__old) \
+ : "=A" (__ret), "+m" (pcp) \
+ : "b" ((u32)__new.m), "c" ((u32)(__new.m >> 32)), "0" (__old) \
: "memory"); \
__ret; \
})

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