aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/compat
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-08-04 15:18:57 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-08-04 16:40:06 +0200
commitfccd1b07daa2faaaa3b25fdb377c973f9f50213b (patch)
tree9988283b17cec9925db1c9df4ec10a36e31563f8 /src/compat
parentsend: switch handshake stamp to an atomic (diff)
downloadwireguard-monolithic-historical-fccd1b07daa2faaaa3b25fdb377c973f9f50213b.tar.xz
wireguard-monolithic-historical-fccd1b07daa2faaaa3b25fdb377c973f9f50213b.zip
compat: better atomic acquire/release backport
Diffstat (limited to '')
-rw-r--r--src/compat/compat.h26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/compat/compat.h b/src/compat/compat.h
index 86df5f3..c6e1e50 100644
--- a/src/compat/compat.h
+++ b/src/compat/compat.h
@@ -52,8 +52,12 @@
#define READ_ONCE ACCESS_ONCE
#endif
#ifndef WRITE_ONCE
+#ifdef ACCESS_ONCE_RW
+#define WRITE_ONCE(p, v) (ACCESS_ONCE_RW(p) = (v))
+#else
#define WRITE_ONCE(p, v) (ACCESS_ONCE(p) = (v))
#endif
+#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)
#include "udp_tunnel/udp_tunnel_partial_compat.h"
@@ -614,24 +618,14 @@ static inline void *skb_put_data(struct sk_buff *skb, const void *data, unsigned
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0)
-#ifndef smp_store_release
-#define smp_store_release(p, v) \
-do { \
- smp_mb(); \
- ACCESS_ONCE(*p) = (v); \
-} while (0)
-#endif
-#ifndef smp_load_acquire
-#define smp_load_acquire(p) \
-({ \
- typeof(*p) ___p1 = ACCESS_ONCE(*p); \
- smp_mb(); \
- ___p1; \
-})
+#include <linux/atomic.h>
+#ifndef atomic_read_acquire
+#define atomic_read_acquire(v) ({ int ___p1 = atomic_read(v); smp_rmb(); ___p1; })
#endif
+#ifndef atomic_set_release
+#define atomic_set_release(v, i) ({ smp_wmb(); atomic_set(v, i); })
#endif
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0)
+#elif LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0)
#include <linux/atomic.h>
#ifndef atomic_read_acquire
#define atomic_read_acquire(v) smp_load_acquire(&(v)->counter)