Re: [PATCHv2 04/12] x86/virt/tdx: Add tdx_alloc/free_page() helpers
From: Edgecombe, Rick P
Date: Tue Sep 16 2025 - 13:10:29 EST
On Tue, 2025-09-16 at 10:22 +0100, Kiryl Shutsemau wrote:
> My git has comment for the check:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/kas/linux.git/tree/arch/x86/virt/vmx/tdx/tdx.c?h=tdx/dpamt&id=375706fe73a8499dbdddb22c13d19d7286280ad6#n2160
>
Yes, I saw but wasn't enough for me.
> Consider the following scenario
>
> CPU0 CPU1
> tdx_pamt_put()
> atomic_dec_and_test() == true
> tdx_pamt_get()
> atomic_inc_not_zero() == false
> tdx_pamt_add()
> <takes pamt_lock>
> // CPU0 never removed PAMT memory
> tdh_phymem_pamt_add() == HPA_RANGE_NOT_FREE
> atomic_set(1);
> <drops pamt_lock>
> <takes pamt_lock>
> // Lost the race to CPU1
> atomic_read() > 0
> <drop pamt_lock>
>
> Does it make sense?
Ah, yes thanks. It falls out from the asymmetry of when the inc/dec happens
between get/put.