On 5 Aug 2025, at 14:38, Jann Horn wrote:

> On Tue, Aug 5, 2025 at 7:51 PM Zi Yan <z...@nvidia.com> wrote:
>> FORCE_READ() converts input value x to its pointer type then reads from
>> address x. This is wrong. If x is a non-pointer, it would be caught it
>> easily. But all FORCE_READ() callers are trying to read from a pointer and
>> FORCE_READ() basically reads a pointer to a pointer instead of the original
>> typed pointer. Almost no access violation was found, except the one from
>> split_huge_page_test.
> [...]
>> 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))
>
> So is the problem with the old code basically that it should have been
> something like
>
> #define FORCE_READ(x) (*(volatile typeof(*(x)) *)(x))
>
> to actually cast the normal pointer to a volatile pointer?

Yeah. That works too. I would rename it to FORCE_READ_PTR to avoid
misuse. :)

Best Regards,
Yan, Zi

Reply via email to