rwonce.h 812 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2019 Google LLC.
  4. */
  5. #ifndef __ASM_RWONCE_H
  6. #define __ASM_RWONCE_H
  7. #ifdef CONFIG_SMP
  8. #include <asm/barrier.h>
  9. /*
  10. * Alpha is apparently daft enough to reorder address-dependent loads
  11. * on some CPU implementations. Knock some common sense into it with
  12. * a memory barrier in READ_ONCE().
  13. *
  14. * For the curious, more information about this unusual reordering is
  15. * available in chapter 15 of the "perfbook":
  16. *
  17. * https://kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook.html
  18. *
  19. */
  20. #define __READ_ONCE(x) \
  21. ({ \
  22. __unqual_scalar_typeof(x) __x = \
  23. (*(volatile typeof(__x) *)(&(x))); \
  24. mb(); \
  25. (typeof(x))__x; \
  26. })
  27. #endif /* CONFIG_SMP */
  28. #include <asm-generic/rwonce.h>
  29. #endif /* __ASM_RWONCE_H */