Commit 2b2fe605 authored by Mathieu Desnoyers's avatar Mathieu Desnoyers Committed by Shuah Khan

selftests/rseq: Use rseq_unqual_scalar_typeof in macros

Use rseq_unqual_scalar_typeof() rather than typeof() in macros to remove
the volatile qualifier (if there is one in the input argument), thus
generating better assembly code in those scenarios.

Also add extra brackets around the "p" parameter in RSEQ_READ_ONCE(),
RSEQ_WRITE_ONCE(), and rseq_unqual_scalar_typeof() across architectures
to preserve expectations of operator priority. Here is an example that
shows how operator priority may be an issue with missing parentheses:

    #define m(p) \
    do { \
            __typeof__(*p) v = 0; \
    } while (0)

    void fct(unsigned long long *p1)
    {
            m(p1 + 1);      /* works */
            m(1 + p1);      /* broken */
    }
Signed-off-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 0fbbf07c
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
#define rseq_smp_load_acquire(p) \ #define rseq_smp_load_acquire(p) \
__extension__ ({ \ __extension__ ({ \
__typeof(*p) ____p1 = RSEQ_READ_ONCE(*p); \ rseq_unqual_scalar_typeof(*(p)) ____p1 = RSEQ_READ_ONCE(*(p)); \
rseq_smp_mb(); \ rseq_smp_mb(); \
____p1; \ ____p1; \
}) })
...@@ -76,7 +76,7 @@ __extension__ ({ \ ...@@ -76,7 +76,7 @@ __extension__ ({ \
#define rseq_smp_store_release(p, v) \ #define rseq_smp_store_release(p, v) \
do { \ do { \
rseq_smp_mb(); \ rseq_smp_mb(); \
RSEQ_WRITE_ONCE(*p, v); \ RSEQ_WRITE_ONCE(*(p), v); \
} while (0) } while (0)
#define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, start_ip, \ #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, start_ip, \
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
#define rseq_smp_load_acquire(p) \ #define rseq_smp_load_acquire(p) \
__extension__ ({ \ __extension__ ({ \
__typeof(*p) ____p1 = RSEQ_READ_ONCE(*p); \ rseq_unqual_scalar_typeof(*(p)) ____p1 = RSEQ_READ_ONCE(*(p)); \
rseq_smp_mb(); \ rseq_smp_mb(); \
____p1; \ ____p1; \
}) })
...@@ -55,7 +55,7 @@ __extension__ ({ \ ...@@ -55,7 +55,7 @@ __extension__ ({ \
#define rseq_smp_store_release(p, v) \ #define rseq_smp_store_release(p, v) \
do { \ do { \
rseq_smp_mb(); \ rseq_smp_mb(); \
RSEQ_WRITE_ONCE(*p, v); \ RSEQ_WRITE_ONCE(*(p), v); \
} while (0) } while (0)
#if _MIPS_SZLONG == 64 #if _MIPS_SZLONG == 64
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#define rseq_smp_load_acquire(p) \ #define rseq_smp_load_acquire(p) \
__extension__ ({ \ __extension__ ({ \
__typeof(*p) ____p1 = RSEQ_READ_ONCE(*p); \ rseq_unqual_scalar_typeof(*(p)) ____p1 = RSEQ_READ_ONCE(*(p)); \
rseq_smp_lwsync(); \ rseq_smp_lwsync(); \
____p1; \ ____p1; \
}) })
...@@ -33,7 +33,7 @@ __extension__ ({ \ ...@@ -33,7 +33,7 @@ __extension__ ({ \
#define rseq_smp_store_release(p, v) \ #define rseq_smp_store_release(p, v) \
do { \ do { \
rseq_smp_lwsync(); \ rseq_smp_lwsync(); \
RSEQ_WRITE_ONCE(*p, v); \ RSEQ_WRITE_ONCE(*(p), v); \
} while (0) } while (0)
/* /*
......
...@@ -36,8 +36,8 @@ ...@@ -36,8 +36,8 @@
#define rseq_smp_load_acquire(p) \ #define rseq_smp_load_acquire(p) \
__extension__ ({ \ __extension__ ({ \
__typeof(*(p)) ____p1 = RSEQ_READ_ONCE(*(p)); \ rseq_unqual_scalar_typeof(*(p)) ____p1 = RSEQ_READ_ONCE(*(p)); \
RISCV_FENCE(r, rw) \ RISCV_FENCE(r, rw); \
____p1; \ ____p1; \
}) })
...@@ -46,7 +46,7 @@ __extension__ ({ \ ...@@ -46,7 +46,7 @@ __extension__ ({ \
#define rseq_smp_store_release(p, v) \ #define rseq_smp_store_release(p, v) \
do { \ do { \
RISCV_FENCE(rw, w); \ RISCV_FENCE(rw, w); \
RSEQ_WRITE_ONCE(*(p), v); \ RSEQ_WRITE_ONCE(*(p), v); \
} while (0) } while (0)
#define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, start_ip, \ #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, start_ip, \
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#define rseq_smp_load_acquire(p) \ #define rseq_smp_load_acquire(p) \
__extension__ ({ \ __extension__ ({ \
__typeof(*p) ____p1 = RSEQ_READ_ONCE(*p); \ rseq_unqual_scalar_typeof(*(p)) ____p1 = RSEQ_READ_ONCE(*(p)); \
rseq_barrier(); \ rseq_barrier(); \
____p1; \ ____p1; \
}) })
...@@ -25,7 +25,7 @@ __extension__ ({ \ ...@@ -25,7 +25,7 @@ __extension__ ({ \
#define rseq_smp_store_release(p, v) \ #define rseq_smp_store_release(p, v) \
do { \ do { \
rseq_barrier(); \ rseq_barrier(); \
RSEQ_WRITE_ONCE(*p, v); \ RSEQ_WRITE_ONCE(*(p), v); \
} while (0) } while (0)
#ifdef __s390x__ #ifdef __s390x__
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
#define rseq_smp_load_acquire(p) \ #define rseq_smp_load_acquire(p) \
__extension__ ({ \ __extension__ ({ \
__typeof(*p) ____p1 = RSEQ_READ_ONCE(*p); \ rseq_unqual_scalar_typeof(*(p)) ____p1 = RSEQ_READ_ONCE(*(p)); \
rseq_barrier(); \ rseq_barrier(); \
____p1; \ ____p1; \
}) })
...@@ -52,7 +52,7 @@ __extension__ ({ \ ...@@ -52,7 +52,7 @@ __extension__ ({ \
#define rseq_smp_store_release(p, v) \ #define rseq_smp_store_release(p, v) \
do { \ do { \
rseq_barrier(); \ rseq_barrier(); \
RSEQ_WRITE_ONCE(*p, v); \ RSEQ_WRITE_ONCE(*(p), v); \
} while (0) } while (0)
#define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \ #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment