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.