Contents of /trunk/kernel26-xen/patches-2.6.25-r1/1030-2.6.25-xen-x86_64-Add-sync_cmpxchg.patch
Parent Directory | Revision Log
Revision 606 -
(show annotations)
(download)
Thu May 22 23:13:13 2008 UTC (16 years ago) by niro
File size: 2634 byte(s)
Thu May 22 23:13:13 2008 UTC (16 years ago) by niro
File size: 2634 byte(s)
-ver bump to 2.6.25-magellan-r1: - linux-2.6.25.4 - fbcondecor-0.9.4 - squashfs-3.3 - unionfs-2.3.3 - tuxonice-3.0-rc7 - linux-phc-0.3.0 - acpi-dstd-0.9a - reiser4 - xen-3.2.0 . ipw3945-1.2.2
1 | From 82328d0ef4a109e66264e70692fec273b201ee41 Mon Sep 17 00:00:00 2001 |
2 | From: Eduardo Habkost <ehabkost@Rawhide-64.localdomain> |
3 | Date: Tue, 27 Nov 2007 18:08:41 -0200 |
4 | Subject: [PATCH] x86_64: Add sync_cmpxchg() |
5 | |
6 | Add a sync_cmpxchg() for x86_64, including a sync_cmpxchg64() |
7 | implementation. |
8 | |
9 | Needed for Xen's grant table implementation. |
10 | |
11 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> |
12 | Signed-off-by: Mark McLoughlin <markmc@redhat.com> |
13 | --- |
14 | include/asm-x86/cmpxchg_64.h | 47 ++++++++++++++++++++++++++++++++++++++++++ |
15 | 1 files changed, 47 insertions(+), 0 deletions(-) |
16 | |
17 | diff --git a/include/asm-x86/cmpxchg_64.h b/include/asm-x86/cmpxchg_64.h |
18 | index 56f5b41..1556f64 100644 |
19 | --- a/include/asm-x86/cmpxchg_64.h |
20 | +++ b/include/asm-x86/cmpxchg_64.h |
21 | @@ -91,6 +91,45 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, |
22 | return old; |
23 | } |
24 | |
25 | +/* |
26 | + * Always use locked operations when touching memory shared with a |
27 | + * hypervisor, since the system may be SMP even if the guest kernel |
28 | + * isn't. |
29 | + */ |
30 | +static inline unsigned long __sync_cmpxchg(volatile void *ptr, |
31 | + unsigned long old, |
32 | + unsigned long new, int size) |
33 | +{ |
34 | + unsigned long prev; |
35 | + switch (size) { |
36 | + case 1: |
37 | + __asm__ __volatile__("lock; cmpxchgb %b1,%2" |
38 | + : "=a"(prev) |
39 | + : "q"(new), "m"(*__xg(ptr)), "0"(old) |
40 | + : "memory"); |
41 | + return prev; |
42 | + case 2: |
43 | + __asm__ __volatile__("lock; cmpxchgw %w1,%2" |
44 | + : "=a"(prev) |
45 | + : "r"(new), "m"(*__xg(ptr)), "0"(old) |
46 | + : "memory"); |
47 | + return prev; |
48 | + case 4: |
49 | + __asm__ __volatile__("lock; cmpxchgl %k1,%2" |
50 | + : "=a"(prev) |
51 | + : "r"(new), "m"(*__xg(ptr)), "0"(old) |
52 | + : "memory"); |
53 | + return prev; |
54 | + case 8: |
55 | + __asm__ __volatile__("lock; cmpxchgq %1,%2" |
56 | + : "=a"(prev) |
57 | + : "r"(new), "m"(*__xg(ptr)), "0"(old) |
58 | + : "memory"); |
59 | + return prev; |
60 | + } |
61 | + return old; |
62 | +} |
63 | + |
64 | static inline unsigned long __cmpxchg_local(volatile void *ptr, |
65 | unsigned long old, unsigned long new, int size) |
66 | { |
67 | @@ -132,6 +171,14 @@ static inline unsigned long __cmpxchg_local(volatile void *ptr, |
68 | BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ |
69 | cmpxchg((ptr), (o), (n)); \ |
70 | }) |
71 | +#define sync_cmpxchg(ptr, o, n) \ |
72 | + ((__typeof__(*(ptr)))__sync_cmpxchg((ptr), (unsigned long)(o), \ |
73 | + (unsigned long)(n), sizeof(*(ptr)))) |
74 | +#define sync_cmpxchg64(ptr, o, n) \ |
75 | + ({ \ |
76 | + BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ |
77 | + sync_cmpxchg((ptr), (o), (n)); \ |
78 | + }) |
79 | #define cmpxchg_local(ptr, o, n) \ |
80 | ((__typeof__(*(ptr)))__cmpxchg_local((ptr), (unsigned long)(o), \ |
81 | (unsigned long)(n), sizeof(*(ptr)))) |
82 | -- |
83 | 1.5.4.1 |
84 |