powerpc: Make rwlocks endian safe
authorAnton Blanchard <anton@samba.org>
Tue, 6 Aug 2013 16:01:51 +0000 (02:01 +1000)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Wed, 14 Aug 2013 05:33:40 +0000 (15:33 +1000)
Our ppc64 spinlocks and rwlocks use a trick where a lock token and
the paca index are placed in the lock with a single store. Since we
are using two u16s they need adjusting for little endian.

Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
arch/powerpc/include/asm/paca.h
arch/powerpc/include/asm/spinlock.h
arch/powerpc/kvm/book3s_hv_rm_mmu.c
arch/powerpc/kvm/book3s_hv_rmhandlers.S

index 17d40a2a00c443fba6b6e59356d65094f48d7693..a5954cebbc5594228c655906da83714eb6c772cd 100644 (file)
@@ -68,8 +68,13 @@ struct paca_struct {
         * instruction.  They must travel together and be properly
         * aligned.
         */
+#ifdef __BIG_ENDIAN__
        u16 lock_token;                 /* Constant 0x8000, used in locks */
        u16 paca_index;                 /* Logical processor number */
+#else
+       u16 paca_index;                 /* Logical processor number */
+       u16 lock_token;                 /* Constant 0x8000, used in locks */
+#endif
 
        u64 kernel_toc;                 /* Kernel TOC address */
        u64 kernelbase;                 /* Base address of kernel */
index 7c345b6518db6a26e3f8d26e7084ec38972f399a..5f54a744dcc5e26921ddafe1d267985f71dd8540 100644 (file)
 
 #ifdef CONFIG_PPC64
 /* use 0x800000yy when locked, where yy == CPU number */
+#ifdef __BIG_ENDIAN__
 #define LOCK_TOKEN     (*(u32 *)(&get_paca()->lock_token))
 #else
+#define LOCK_TOKEN     (*(u32 *)(&get_paca()->paca_index))
+#endif
+#else
 #define LOCK_TOKEN     1
 #endif
 
index fc25689a9f35076e61d83ca024a08e2bdf7564c1..c3785d4aeed766c8de371ca9334db8b386a42a23 100644 (file)
@@ -363,7 +363,11 @@ long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
                                 vcpu->arch.pgdir, true, &vcpu->arch.gpr[4]);
 }
 
+#ifdef __BIG_ENDIAN__
 #define LOCK_TOKEN     (*(u32 *)(&get_paca()->lock_token))
+#else
+#define LOCK_TOKEN     (*(u32 *)(&get_paca()->paca_index))
+#endif
 
 static inline int try_lock_tlbie(unsigned int *lock)
 {
index 20e7fcdc4c958fb15207e86be5a229c9fc731e7a..b93e3cd8bf2b746f20bc68b21bc79f626e9cc364 100644 (file)
@@ -393,7 +393,11 @@ toc_tlbie_lock:
        .tc     native_tlbie_lock[TC],native_tlbie_lock
        .previous
        ld      r3,toc_tlbie_lock@toc(2)
+#ifdef __BIG_ENDIAN__
        lwz     r8,PACA_LOCK_TOKEN(r13)
+#else
+       lwz     r8,PACAPACAINDEX(r13)
+#endif
 24:    lwarx   r0,0,r3
        cmpwi   r0,0
        bne     24b
@@ -968,7 +972,11 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
 32:    ld      r4,VCPU_KVM(r9)         /* pointer to struct kvm */
 
        /* Take the guest's tlbie_lock */
+#ifdef __BIG_ENDIAN__
        lwz     r8,PACA_LOCK_TOKEN(r13)
+#else
+       lwz     r8,PACAPACAINDEX(r13)
+#endif
        addi    r3,r4,KVM_TLBIE_LOCK
 24:    lwarx   r0,0,r3
        cmpwi   r0,0