linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Zi Yan <ziy@nvidia.com>
Cc: wang lian <lianux.mm@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, David Hildenbrand <david@redhat.com>,
	Wei Yang <richard.weiyang@gmail.com>,
	Christian Brauner <brauner@kernel.org>,
	Jann Horn <jannh@google.com>, 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,
	Pedro Falcato <pfalcato@suse.de>
Subject: Re: [PATCH] selftests/mm: fix FORCE_READ to read input value correctly.
Date: Tue, 5 Aug 2025 20:21:23 +0100	[thread overview]
Message-ID: <dc139b0b-e461-4edb-ba1d-fc824f875142@lucifer.local> (raw)
In-Reply-To: <6E5CCF4D-CB63-4E4C-BEDA-6FE533E0DFCD@nvidia.com>

+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.

Yeah I won't pretend to understand _exactly_ what the compiler is doing here, if
this is working in practice across multiple compilers and read-faulting the page
that's good enough for me :)

>
> >
> > I know for some reason this form doesn't generate one currently (not sure
> > why), but we may hit that in future.
>
> Neither gcc nor clang complains without (void). My guess is that volatile
> is doing something there.

Indeed possibly, be interesting if you or Pedro who's also playing with this
could nail down exactly what's going on here.

>
> Best Regards,
> Yan, Zi

But from my point of view this patch is fine - ship it! :)

Cheers, Lorenzo


  reply	other threads:[~2025-08-05 19:21 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
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 [this message]
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=dc139b0b-e461-4edb-ba1d-fc824f875142@lucifer.local \
    --to=lorenzo.stoakes@oracle.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=pfalcato@suse.de \
    --cc=richard.weiyang@gmail.com \
    --cc=ryncsn@gmail.com \
    --cc=shuah@kernel.org \
    --cc=sj@kernel.org \
    --cc=vbabka@suse.cz \
    --cc=ziy@nvidia.com \
    /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