Re: [PATCH v2 09/13] mm/gup: Cache *pudp in follow_pud_mask()

From: Jason Gunthorpe
Date: Mon Jan 15 2024 - 13:41:15 EST


On Wed, Jan 03, 2024 at 05:14:19PM +0800, peterx@xxxxxxxxxx wrote:
> From: Peter Xu <peterx@xxxxxxxxxx>
>
> Introduce "pud_t pud" in the function, so the code won't dereference *pudp
> multiple time. Not only because that looks less straightforward, but also
> because if the dereference really happened, it's not clear whether there
> can be race to see different *pudp values if it's being modified at the
> same time.
>
> Acked-by: James Houghton <jthoughton@xxxxxxxxxx>
> Signed-off-by: Peter Xu <peterx@xxxxxxxxxx>
> ---
> mm/gup.c | 17 +++++++++--------
> 1 file changed, 9 insertions(+), 8 deletions(-)

I think we have several more case like this, and I ceratinly agree
code should not access a READ_ONCE variable more than once :(

Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxx>

Jason