Re: [PATCH v7 08/11] KVM: TDX: Get/put PAMT pages when (un)mapping private memory

Nikolay Borisov <[email protected]> Thu, 23 Jul 2026 10:17:22 +0300
Newsgroups dev.linux.lists.linux-coco,org.kernel.vger.kvm,org.kernel.vger.linux-doc,org.kernel.vger.linux-kernel
Message-ID <[email protected]>

On 7/22/26 22:34, Sean Christopherson wrote:
> On Wed, Jul 22, 2026, Rick P Edgecombe wrote:
>> On Wed, 2026-07-22 at 16:46 +0300, Nikolay Borisov wrote:
>>>> +static int tdx_topup_external_pamt_cache(struct kvm_vcpu *vcpu, int
>>>> min_nr_spts)
>>>> +{
>>>> +	/*
>>>> +	 * Don't cover the root SPT, but cover a possible 4KB private
>>>> +	 * page in addition to the SPTs. So -1 to exclude the root
>>>> +	 * SPT, and +1 for the guest page cancel out.
>>>> +	 */
>>>
>>> That comment here doesn't seem to correspond to the code in anyway.
>>> There are no +-1 adjustments.
>>
>> The +1 and -1 cancel each other out. Hmm, how about:
>> 	/*
>> 	 * Don't cover the root SPT, but cover a possible 4KB private
>> 	 * page in addition to the SPTs. The -1 to exclude the root
>> 	 * SPT and +1 for the guest page cancel each other out. So
>> 	 * make no adjustments.
>> 	 */
> 
> Maybe put it in code?  E.g.
> 
> 	/*
> 	 * Minus one page to exclude the root SPT, but plus one page for a
> 	 * possible 4KiB private mapping.
> 	 */
> 	min_nr_spts += -1 + 1;

Makes sense
> 
> 	return tdx_topup_pamt_cache(&to_tdx(vcpu)->pamt_cache, min_nr_spts);