Re: [PATCH] riscv: Use an atomic xchg in pudp_huge_get_and_clear()

From: Alexandre Ghiti

Date: Mon Sep 22 2025 - 02:24:21 EST


On 9/20/25 03:39, Paul Walmsley wrote:
Hi Alex,

On Thu, 14 Aug 2025, Alexandre Ghiti wrote:

Make sure we return the right pud value and not a value that could
have been overwritten in between by a different core.

Fixes: c3cc2a4a3a23 ("riscv: Add support for PUD THP")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Alexandre Ghiti <alexghiti@xxxxxxxxxxxx>
---
Note that this will conflict with
https://lore.kernel.org/linux-riscv/20250625063753.77511-1-ajd@xxxxxxxxxxxxx/
if applied after 6.17.
Two quick questions on this one:

- I see that you're using atomic_long_xchg() here and in some similar
functions in pgtable.h, rather than xchg(). Was curious about the
rationale for that?


Both functions amount to the same, I just used the same function as for existing similar functions.



- x86 avoids the xchg() for !CONFIG_SMP. Should we do the same?


Sounds like micro optimization to me, but up to you.



thanks,

- Paul