From: Zi Yan <ziy@nvidia.com>
To: Jann Horn <jannh@google.com>
Cc: wang lian <lianux.mm@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
David Hildenbrand <david@redhat.com>,
Wei Yang <richard.weiyang@gmail.com>,
Christian Brauner <brauner@kernel.org>,
Kairui Song <ryncsn@gmail.com>,
Liam Howlett <liam.howlett@oracle.com>,
Mark Brown <broonie@kernel.org>, SeongJae Park <sj@kernel.org>,
Shuah Khan <shuah@kernel.org>, Vlastimil Babka <vbabka@suse.cz>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH] selftests/mm: fix FORCE_READ to read input value correctly.
Date: Tue, 05 Aug 2025 14:48:25 -0400 [thread overview]
Message-ID: <76EE266A-7E9B-484F-AF97-85A99D109005@nvidia.com> (raw)
In-Reply-To: <CAG48ez1wKqyCKZX7J2eJekTuzRshVE2btPEWQEm2hW9Ri46Uuw@mail.gmail.com>
On 5 Aug 2025, at 14:38, Jann Horn wrote:
> On Tue, Aug 5, 2025 at 7:51 PM Zi Yan <ziy@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
next prev parent reply other threads:[~2025-08-05 18:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-05 17:51 Zi Yan
2025-08-05 18:38 ` Jann Horn
2025-08-05 18:48 ` Zi Yan [this message]
2025-08-05 18:56 ` Lorenzo Stoakes
2025-08-05 19:00 ` Lorenzo Stoakes
2025-08-05 19:09 ` Zi Yan
2025-08-05 19:21 ` Lorenzo Stoakes
2025-08-06 10:34 ` Pedro Falcato
2025-08-06 10:37 ` Lorenzo Stoakes
2025-08-06 1:44 ` wang lian
2025-08-05 21:05 ` David Hildenbrand
2025-08-06 2:07 ` Wei Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=76EE266A-7E9B-484F-AF97-85A99D109005@nvidia.com \
--to=ziy@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=broonie@kernel.org \
--cc=david@redhat.com \
--cc=jannh@google.com \
--cc=liam.howlett@oracle.com \
--cc=lianux.mm@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=richard.weiyang@gmail.com \
--cc=ryncsn@gmail.com \
--cc=shuah@kernel.org \
--cc=sj@kernel.org \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox