[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ea442b14-6f74-41eb-a315-7cbee0f0eae4@lucifer.local>
Date: Tue, 5 Aug 2025 19:56:36 +0100
From: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
To: Zi Yan <ziy@...dia.com>
Cc: Jann Horn <jannh@...gle.com>, wang lian <lianux.mm@...il.com>,
Andrew Morton <akpm@...ux-foundation.org>, linux-mm@...ck.org,
David Hildenbrand <david@...hat.com>,
Wei Yang <richard.weiyang@...il.com>,
Christian Brauner <brauner@...nel.org>, Kairui Song <ryncsn@...il.com>,
Liam Howlett <liam.howlett@...cle.com>,
Mark Brown <broonie@...nel.org>, SeongJae Park <sj@...nel.org>,
Shuah Khan <shuah@...nel.org>, Vlastimil Babka <vbabka@...e.cz>,
linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org
Subject: Re: [PATCH] selftests/mm: fix FORCE_READ to read input value
correctly.
On Tue, Aug 05, 2025 at 02:48:25PM -0400, Zi Yan wrote:
> On 5 Aug 2025, at 14:38, Jann Horn wrote:
>
> > On Tue, Aug 5, 2025 at 7:51 PM Zi Yan <ziy@...dia.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. :)
We were having this discussion on IRC, generally I'm fine with it as-is,
though my version sort of intended to make life easier by passing a ptr,
but this version makes it closer to READ_ONCE() so probably semantically a
little better. :)
>
> Best Regards,
> Yan, Zi
Powered by blists - more mailing lists