[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH 1/4] include/uk: do not cast away volatile in atomic.h



Many functions in include/uk/arch/atomic.h accept a volatile argument
and then cast it to something like "__u8 *". In many cases it is ok,
__atomic_*() is called inside the function. But in other cases, this
memory access is a subject to compiler optimization, and may lead to
an unexpected behavior.

Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
Reviewed-by: Florian Schmidt <florian.schmidt@xxxxxxxxx>
---
 include/uk/arch/atomic.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/uk/arch/atomic.h b/include/uk/arch/atomic.h
index d4abeb7..0964e14 100644
--- a/include/uk/arch/atomic.h
+++ b/include/uk/arch/atomic.h
@@ -96,7 +96,7 @@ extern "C" {
  */
 static inline int ukarch_test_and_clr_bit(unsigned int nr, volatile void *byte)
 {
-       __u8 *addr = ((__u8 *)byte) + (nr >> 3);
+       volatile __u8 *addr = ((__u8 *)byte) + (nr >> 3);
        __u8 bit = 1 << (nr & 7);
        __u8 orig;
 
@@ -111,7 +111,7 @@ static inline int ukarch_test_and_clr_bit(unsigned int nr, 
volatile void *byte)
  */
 static inline int ukarch_test_and_set_bit(unsigned int nr, volatile void *byte)
 {
-       __u8 *addr = ((__u8 *)byte) + (nr >> 3);
+       volatile __u8 *addr = ((__u8 *)byte) + (nr >> 3);
        __u8 bit = 1 << (nr & 7);
        __u8 orig;
 
@@ -126,7 +126,7 @@ static inline int ukarch_test_and_set_bit(unsigned int nr, 
volatile void *byte)
 static inline int ukarch_test_bit(unsigned int nr,
                                        const volatile unsigned long *byte)
 {
-       const __u8 *ptr = (const __u8 *)byte;
+       const volatile __u8 *ptr = (const __u8 *)byte;
 
        return ((1 << (nr & 7)) & (ptr[nr >> 3])) != 0;
 }
@@ -154,7 +154,7 @@ static inline void ukarch_clr_bit(unsigned int nr,
 static inline int ukarch_test_and_clr_bit_sync(unsigned int nr,
                                                volatile void *byte)
 {
-       __u8 *addr = ((__u8 *)byte) + (nr >> 3);
+       volatile __u8 *addr = ((__u8 *)byte) + (nr >> 3);
        __u8 bit = 1 << (nr & 7);
        __u8 orig;
 
@@ -167,7 +167,7 @@ static inline int ukarch_test_and_clr_bit_sync(unsigned int 
nr,
 static inline int ukarch_test_and_set_bit_sync(unsigned int nr,
                                                volatile void *byte)
 {
-       __u8 *addr = ((__u8 *)byte) + (nr >> 3);
+       volatile __u8 *addr = ((__u8 *)byte) + (nr >> 3);
        __u8 bit = 1 << (nr & 7);
        __u8 orig;
 
-- 
2.19.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.