Messages in this thread | | | Date | Tue, 6 Sep 2022 15:57:30 +0200 | Subject | Re: [PATCH] mm: gup: fix the fast GUP race against THP collapse | From | David Hildenbrand <> |
| |
On 06.09.22 15:47, Jason Gunthorpe wrote: > 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.
While I don't disagree with what say is, I'll refer to Documentation/memory-barriers.txt "COMPILER BARRIER".
As discussed somewhere in this thread, if we already have an atomic RWM that implies a full ordering, it implies a compile barrier.
> > 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.
As we have a full memory barrier + compile barrier, the compiler might indeed do double reads and all that stuff. BUT, it has to re-read after we incremented the refcount, and IMHO that's the important part to detect the change.
-- Thanks,
David / dhildenb
| |