Skip to content

Commit d5998c0

Browse files
yamahatabonzini
authored andcommitted
KVM: TDX: Handle KVM hypercall with TDG.VP.VMCALL
Handle KVM hypercall for TDX according to TDX Guest-Host Communication Interface (GHCI) specification. The TDX GHCI specification defines the ABI for the guest TD to issue hypercalls. When R10 is non-zero, it indicates the TDG.VP.VMCALL is vendor-specific. KVM uses R10 as KVM hypercall number and R11-R14 as 4 arguments, while the error code is returned in R10. Morph the TDG.VP.VMCALL with KVM hypercall to EXIT_REASON_VMCALL and marshall r10~r14 from vp_enter_args to the appropriate x86 registers for KVM hypercall handling. Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com> Co-developed-by: Binbin Wu <binbin.wu@linux.intel.com> Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com> Message-ID: <20250222014225.897298-6-binbin.wu@linux.intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent c42856a commit d5998c0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

arch/x86/kvm/vmx/tdx.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,23 @@ fastpath_t tdx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate_exit)
978978
return tdx_exit_handlers_fastpath(vcpu);
979979
}
980980

981+
static int complete_hypercall_exit(struct kvm_vcpu *vcpu)
982+
{
983+
tdvmcall_set_return_code(vcpu, vcpu->run->hypercall.ret);
984+
return 1;
985+
}
986+
987+
static int tdx_emulate_vmcall(struct kvm_vcpu *vcpu)
988+
{
989+
kvm_rax_write(vcpu, to_tdx(vcpu)->vp_enter_args.r10);
990+
kvm_rbx_write(vcpu, to_tdx(vcpu)->vp_enter_args.r11);
991+
kvm_rcx_write(vcpu, to_tdx(vcpu)->vp_enter_args.r12);
992+
kvm_rdx_write(vcpu, to_tdx(vcpu)->vp_enter_args.r13);
993+
kvm_rsi_write(vcpu, to_tdx(vcpu)->vp_enter_args.r14);
994+
995+
return __kvm_emulate_hypercall(vcpu, 0, complete_hypercall_exit);
996+
}
997+
981998
static int handle_tdvmcall(struct kvm_vcpu *vcpu)
982999
{
9831000
switch (tdvmcall_leaf(vcpu)) {
@@ -1349,6 +1366,8 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath)
13491366
return 0;
13501367
case EXIT_REASON_TDCALL:
13511368
return handle_tdvmcall(vcpu);
1369+
case EXIT_REASON_VMCALL:
1370+
return tdx_emulate_vmcall(vcpu);
13521371
default:
13531372
break;
13541373
}

0 commit comments

Comments
 (0)