[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YxdPi2E63aO0Dgyd@nvidia.com>
Date: Tue, 6 Sep 2022 10:47:55 -0300
From: Jason Gunthorpe <jgg@...dia.com>
To: David Hildenbrand <david@...hat.com>
Cc: John Hubbard <jhubbard@...dia.com>, Yang Shi <shy828301@...il.com>,
peterx@...hat.com, kirill.shutemov@...ux.intel.com,
hughd@...gle.com, akpm@...ux-foundation.org, linux-mm@...ck.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] mm: gup: fix the fast GUP race against THP collapse
On Mon, Sep 05, 2022 at 09:59:47AM +0200, David Hildenbrand wrote:
> > That should be READ_ONCE() for the *pmdp and *ptep reads. Because this
> > whole lockless house of cards may fall apart if we try reading the
> > page table values without READ_ONCE().
>
> I came to the conclusion that the implicit memory barrier when grabbing a
> reference on the page is sufficient such that we don't need READ_ONCE here.
READ_ONCE is not about barriers or ordering, you still need the
acquire inside the atomic to make the algorithm work.
READ_ONCE primarily is a marker that the data being read is unstable
and that the compiler must avoid all instability when reading it. eg
in this case the compiler could insanely double read the value, even
though the 'if' requires only a single read. This would result in
corrupt calculation.
> If we still intend to change that code, we should fixup all GUP-fast
> functions in a similar way.
This is correct, IMHO we have been slowly modernizing the mm approach
to the memory model to include things like this. While it would be
nice to do everything I think small bits are welcomed as the are
discovered.
Jason
Powered by blists - more mailing lists