Re: [PATCH] KVM: TDX: Allow userspace to return errors to guest for MAPGPA
From: Binbin Wu
Date: Wed Jan 14 2026 - 04:32:12 EST
On 1/14/2026 10:59 AM, Xiaoyao Li wrote:
> On 1/14/2026 8:30 AM, Sagi Shahar wrote:
>> From: Vishal Annapurve <vannapurve@xxxxxxxxxx>
>>
>> MAPGPA request from TDX VMs gets split into chunks by KVM using a loop
>> of userspace exits until the complete range is handled.
>>
>> In some cases userspace VMM might decide to break the MAPGPA operation
>> and continue it later. For example: in the case of intrahost migration
>> userspace might decide to continue the MAPGPA operation after the
>> migrration is completed.
>>
>> Allow userspace to signal to TDX guests that the MAPGPA operation should
>> be retried the next time the guest is scheduled.
How does the guest differentiate it from a retry due to pending events?
Will the guest retry immediately after returning back to the guest in this case?
>>
>> Signed-off-by: Vishal Annapurve <vannapurve@xxxxxxxxxx>
>> Co-developed-by: Sagi Shahar <sagis@xxxxxxxxxx>
>> Signed-off-by: Sagi Shahar <sagis@xxxxxxxxxx>
>> ---
>> arch/x86/kvm/vmx/tdx.c | 8 +++++++-
>> 1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
>> index 2d7a4d52ccfb..3244064b1a04 100644
>> --- a/arch/x86/kvm/vmx/tdx.c
>> +++ b/arch/x86/kvm/vmx/tdx.c
>> @@ -1189,7 +1189,13 @@ static int tdx_complete_vmcall_map_gpa(struct kvm_vcpu *vcpu)
>> struct vcpu_tdx *tdx = to_tdx(vcpu);
>> if (vcpu->run->hypercall.ret) {
>> - tdvmcall_set_return_code(vcpu, TDVMCALL_STATUS_INVALID_OPERAND);
>> + if (vcpu->run->hypercall.ret == -EBUSY)
>> + tdvmcall_set_return_code(vcpu, TDVMCALL_STATUS_RETRY);
>> + else if (vcpu->run->hypercall.ret == -EINVAL)
>> + tdvmcall_set_return_code(vcpu, TDVMCALL_STATUS_INVALID_OPERAND);
>> + else
>> + return -EINVAL;
>
> It's incorrect to return -EINVAL here. The -EINVAL will eventually be returned to userspace for the VCPU_RUN ioctl. It certainly breaks userspace. So it needs to be
>
> if (vcpu->run->hypercall.ret == -EBUSY)
> tdvmcall_set_return_code(vcpu, TDVMCALL_STATUS_RETRY);
> else
> tdvmcall_set_return_code(vcpu, TDVMCALL_STATUS_INVALID_OPERAND);
>
> But I'm not sure if such change breaks the userspace ABI that if needs to be opted-in.
>