[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Make sure the grant table stuff uses locked cmpxchg instructions even when compiled



ChangeSet 1.1696, 2005/06/09 11:54:32+01:00, sos22@xxxxxxxxxxxxxxxxxxxx

        Make sure the grant table stuff uses locked cmpxchg instructions even 
when compiled
        !CONFIG_SMP.
        
        Signed-off-by: Steven Smith <sos22@xxxxxxxxx>



 arch/xen/kernel/gnttab.c                |    5 ++--
 include/asm-xen/asm-i386/synch_bitops.h |   40 ++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 2 deletions(-)


diff -Nru a/linux-2.6.11-xen-sparse/arch/xen/kernel/gnttab.c 
b/linux-2.6.11-xen-sparse/arch/xen/kernel/gnttab.c
--- a/linux-2.6.11-xen-sparse/arch/xen/kernel/gnttab.c  2005-06-09 10:02:52 
-04:00
+++ b/linux-2.6.11-xen-sparse/arch/xen/kernel/gnttab.c  2005-06-09 10:02:52 
-04:00
@@ -19,6 +19,7 @@
 #include <asm-xen/xen_proc.h>
 #include <asm-xen/linux-public/privcmd.h>
 #include <asm-xen/gnttab.h>
+#include <asm/synch_bitops.h>
 
 #if 1
 #define ASSERT(_p) \
@@ -125,7 +126,7 @@
         if ( (flags = nflags) & (GTF_reading|GTF_writing) )
             printk(KERN_ALERT "WARNING: g.e. still in use!\n");
     }
-    while ( (nflags = cmpxchg(&shared[ref].flags, flags, 0)) != flags );
+    while ( (nflags = synch_cmpxchg(&shared[ref].flags, flags, 0)) != flags );
 
     put_free_entry(ref);
 }
@@ -172,7 +173,7 @@
      * Otherwise invalidate the grant entry against future use.
      */
     if ( likely(flags != GTF_accept_transfer) ||
-         (cmpxchg(&shared[ref].flags, flags, 0) != GTF_accept_transfer) )
+         (synch_cmpxchg(&shared[ref].flags, flags, 0) != GTF_accept_transfer) )
         while ( unlikely((frame = shared[ref].frame) == 0) )
             cpu_relax();
 
diff -Nru a/linux-2.6.11-xen-sparse/include/asm-xen/asm-i386/synch_bitops.h 
b/linux-2.6.11-xen-sparse/include/asm-xen/asm-i386/synch_bitops.h
--- a/linux-2.6.11-xen-sparse/include/asm-xen/asm-i386/synch_bitops.h   
2005-06-09 10:02:52 -04:00
+++ b/linux-2.6.11-xen-sparse/include/asm-xen/asm-i386/synch_bitops.h   
2005-06-09 10:02:52 -04:00
@@ -60,6 +60,46 @@
     return oldbit;
 }
 
+struct __synch_xchg_dummy { unsigned long a[100]; };
+#define __synch_xg(x) ((struct __synch_xchg_dummy *)(x))
+
+#define synch_cmpxchg(ptr, old, new) \
+((__typeof__(*(ptr)))__synch_cmpxchg((ptr),\
+                                     (unsigned long)(old), \
+                                     (unsigned long)(new), \
+                                     sizeof(*(ptr))))
+
+static inline unsigned long __synch_cmpxchg(volatile void *ptr,
+                                           unsigned long old,
+                                           unsigned long new, int size)
+{
+       unsigned long prev;
+       switch (size) {
+       case 1:
+               __asm__ __volatile__("lock; cmpxchgb %b1,%2"
+                                    : "=a"(prev)
+                                    : "q"(new), "m"(*__synch_xg(ptr)),
+                                      "0"(old)
+                                    : "memory");
+               return prev;
+       case 2:
+               __asm__ __volatile__("lock; cmpxchgw %w1,%2"
+                                    : "=a"(prev)
+                                    : "q"(new), "m"(*__synch_xg(ptr)),
+                                      "0"(old)
+                                    : "memory");
+               return prev;
+       case 4:
+               __asm__ __volatile__("lock; cmpxchgl %1,%2"
+                                    : "=a"(prev)
+                                    : "q"(new), "m"(*__synch_xg(ptr)),
+                                      "0"(old)
+                                    : "memory");
+               return prev;
+       }
+       return old;
+}
+
 static __inline__ int synch_const_test_bit(int nr, const volatile void * addr)
 {
     return ((1UL << (nr & 31)) & 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.