From 76a6a3da6be53621d017416bfd81f1fda265ac7c Mon Sep 17 00:00:00 2001 From: sigsegv7 Date: Thu, 28 Sep 2023 15:37:15 -0400 Subject: kernel: mmio: Add memory barriers to helpers This commit introduces memory barriers to MMIO read/write helpers to ensure the compiler does not re-order these critical memory accesses which would in turn result in very strange behaviour if it were to be re-ordered. Signed-off-by: sigsegv7 --- sys/include/sys/mmio.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/include/sys/mmio.h b/sys/include/sys/mmio.h index f840bf8..0cc1983 100644 --- a/sys/include/sys/mmio.h +++ b/sys/include/sys/mmio.h @@ -31,6 +31,7 @@ #define _SYS_MMIO_H_ #include +#include #include /* @@ -57,6 +58,7 @@ tmp += VM_HIGHER_HALF; \ } \ *(volatile TYPE *)tmp = val; \ + __mem_barrier(); \ } /* @@ -74,6 +76,8 @@ if (tmp < VM_HIGHER_HALF) { \ tmp += VM_HIGHER_HALF; \ } \ + \ + __mem_barrier(); /* Ensure writes complete */ \ return *(volatile TYPE *)tmp; \ } -- cgit v1.2.3