[patch] compiler: clarify ACCESS_ONCE() relies on compiler implementation

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

 



The dereference of a volatile-qualified pointer does not guarantee that it
cannot be optimized by the compiler to be loaded multiple times into
memory even if assigned to a local variable by C99 or any previous C
standard.

Clarify the comment of ACCESS_ONCE() to state explicitly that its current
form relies on the compiler's implementation to work correctly.

Acked-by: Paul E. McKenney <paulmck@xxxxxxxxxxxxxxxxxx>
Signed-off-by: David Rientjes <rientjes@xxxxxxxxxx>
---
 include/linux/compiler.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -348,6 +348,15 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
  * merging, or refetching absolutely anything at any time.  Its main intended
  * use is to mediate communication between process-level code and irq/NMI
  * handlers, all running on the same CPU.
+ *
+ * The current implementation of ACCESS_ONCE() works in all mainstream C
+ * compilers (including of course gcc), but is not guaranteed by the C standard.
+ * However, there is a lot of software that depends on the semantics of volatile
+ * casts, so we have good reason to believe that there will always be a way of
+ * implementing ACCESS_ONCE().  The implementation of ACCESS_ONCE() might well
+ * change to track the C standard and the mainstream C compilers, so if you copy
+ * this definition into some other code base, be sure to check back here
+ * periodically for changes.
  */
 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]