On Tue, Aug 05, 2025 at 08:21:23PM +0100, Lorenzo Stoakes wrote:
+cc Pedro
On Tue, Aug 05, 2025 at 03:09:54PM -0400, Zi Yan wrote:
On 5 Aug 2025, at 15:00, Lorenzo Stoakes wrote:
On Tue, Aug 05, 2025 at 01:51:40PM -0400, Zi Yan wrote:
diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index c20298ae98ea..b55d1809debc 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -23,7 +23,7 @@
- anything with it in order to trigger a read page fault. We therefore must use
- volatile to stop the compiler from optimising this away.
*/ -#define FORCE_READ(x) (*(volatile typeof(x) *)x) +#define FORCE_READ(x) (*(const volatile typeof(x) *)&(x))
NIT: but wonder if const is necessary, and also (as discussed off-list
I just used READ_ONCE() code, but it is not necessary.
It's not end of the world though.
again :) will this work with a (void) prefixed, just to a. make it clear we're reading but discarding and b. to avoid any possible compiler warning on this?
Adding (void) makes no difference, at least from godbolt.
I disagree with adding (void), because volatile being properly propagated into the type should hide any Wunused-value warnings (because volatile reads can have side effects, so discarding a read is most definitely valid).
And as I was seeing in https://godbolt.org/z/jnWsET1vx yesterday, GCC (and clang) can silently drop the volatile qualifier For Some Reason.