From 3eca3b81248aa58cf84ba656d6ec268755519e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Thu, 25 Jun 2020 09:00:08 +0000 Subject: [PATCH] inline_asm: add missing "memory" constraints --- userland/arch/aarch64/inline_asm/futex_ldxr_stxr.c | 12 ++++++++++-- userland/arch/aarch64/inline_asm/wfe_ldxr_str.cpp | 14 ++++++++++++-- userland/arch/aarch64/inline_asm/wfe_ldxr_stxr.cpp | 13 +++++++++++-- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/userland/arch/aarch64/inline_asm/futex_ldxr_stxr.c b/userland/arch/aarch64/inline_asm/futex_ldxr_stxr.c index 3fb4d66..9fa9e14 100644 --- a/userland/arch/aarch64/inline_asm/futex_ldxr_stxr.c +++ b/userland/arch/aarch64/inline_asm/futex_ldxr_stxr.c @@ -31,7 +31,11 @@ void __attribute__ ((noinline)) busy_loop( void* thread_main(void *arg) { (void)arg; - __asm__ __volatile__ ("ldxr x0, [%0]" : : "r" (&ldxr_var) : "x0"); + __asm__ __volatile__ ( + "ldxr x0, [%0]" + : + : "r" (&ldxr_var) : "x0", "memory" + ); ldxr_done = 1; lkmc_futex(&futex1, FUTEX_WAIT, futex1, NULL, NULL, 0); lkmc_futex(&futex2, FUTEX_WAIT, futex2, NULL, NULL, 0); @@ -45,7 +49,11 @@ int main(void) { /* Wait for thread1 to sleep on futex1. */ busy_loop(1000, 1); /* Wrongly wake up the thread with a SEV. */ - __asm__ __volatile__ ("mov x0, 1;ldxr x0, [%0]; stxr w1, x0, [%0]" : : "r" (&ldxr_var) : "x0", "x1"); + __asm__ __volatile__ ( + "mov x0, 1;ldxr x0, [%0]; stxr w1, x0, [%0]" + : + : "r" (&ldxr_var) : "x0", "x1", "memory" + ); /* Wait for thread1 to sleep on futex2. */ busy_loop(1000, 1); /* Wrongly wake thread from futex1 again. */ diff --git a/userland/arch/aarch64/inline_asm/wfe_ldxr_str.cpp b/userland/arch/aarch64/inline_asm/wfe_ldxr_str.cpp index 54983bd..542c9d3 100644 --- a/userland/arch/aarch64/inline_asm/wfe_ldxr_str.cpp +++ b/userland/arch/aarch64/inline_asm/wfe_ldxr_str.cpp @@ -13,7 +13,12 @@ std::atomic_ulong done; int futex = 1; void myfunc() { - __asm__ __volatile__ ("sevl;wfe;ldxr x0, [%0];wfe" : : "r" (&futex) : "x0"); + __asm__ __volatile__ ( + "sevl;wfe;ldxr x0, [%0];wfe" + : + : "r" (&futex) + : "x0", "memory" + ); done.store(futex); } @@ -27,7 +32,12 @@ int main(int argc, char **argv) { thread = std::thread(myfunc); while (!done.load()) { if (do_sev) { - __asm__ __volatile__ ("mov x0, 1;str x0, [%0]" : : "r" (&futex) : "x0"); + __asm__ __volatile__ ( + "mov x0, 1;str x0, [%0]" + : + : "r" (&futex) + : "x0", "memory" + ); } } thread.join(); diff --git a/userland/arch/aarch64/inline_asm/wfe_ldxr_stxr.cpp b/userland/arch/aarch64/inline_asm/wfe_ldxr_stxr.cpp index 9d09390..0a961bc 100644 --- a/userland/arch/aarch64/inline_asm/wfe_ldxr_stxr.cpp +++ b/userland/arch/aarch64/inline_asm/wfe_ldxr_stxr.cpp @@ -12,7 +12,11 @@ std::atomic_ulong done; int futex = 1; void myfunc() { - __asm__ __volatile__ ("sevl;wfe;ldxr x0, [%0];wfe" : : "r" (&futex) : "x0"); + __asm__ __volatile__ ( + "sevl;wfe;ldxr x0, [%0];wfe" + : + : "r" (&futex) : "x0", "memory" + ); done.store(futex); } @@ -26,7 +30,12 @@ int main(int argc, char **argv) { thread = std::thread(myfunc); while (!done.load()) { if (do_sev) { - __asm__ __volatile__ ("ldxr x0, [%0];mov x0, 1;stxr w1, x0, [%0]" : : "r" (&futex) : "x0", "x1"); + __asm__ __volatile__ ( + "ldxr x0, [%0];mov x0, 1;stxr w1, x0, [%0]" + : + : "r" (&futex) + : "x0", "x1", "memory" + ); } } thread.join();