Skip to content

Commit 3bf31b5

Browse files
yamahatabonzini
authored andcommitted
KVM: TDX: Handle TDX PV CPUID hypercall
Handle TDX PV CPUID hypercall for the CPUIDs virtualized by VMM according to TDX Guest Host Communication Interface (GHCI). For TDX, most CPUID leaf/sub-leaf combinations are virtualized by the TDX module while some trigger #VE. On #VE, TDX guest can issue TDG.VP.VMCALL<INSTRUCTION.CPUID> (same value as EXIT_REASON_CPUID) to request VMM to emulate CPUID operation. Morph PV CPUID hypercall to EXIT_REASON_CPUID and wire up to the KVM backend function. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com> [binbin: rewrite changelog] Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com> Message-ID: <20250227012021.1778144-6-binbin.wu@linux.intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 4b2abc4 commit 3bf31b5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

arch/x86/kvm/vmx/tdx.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ int tdx_vcpu_pre_run(struct kvm_vcpu *vcpu)
844844
static __always_inline u32 tdcall_to_vmx_exit_reason(struct kvm_vcpu *vcpu)
845845
{
846846
switch (tdvmcall_leaf(vcpu)) {
847+
case EXIT_REASON_CPUID:
847848
case EXIT_REASON_IO_INSTRUCTION:
848849
return tdvmcall_leaf(vcpu);
849850
case EXIT_REASON_EPT_VIOLATION:
@@ -1238,6 +1239,25 @@ static int tdx_report_fatal_error(struct kvm_vcpu *vcpu)
12381239
return 0;
12391240
}
12401241

1242+
static int tdx_emulate_cpuid(struct kvm_vcpu *vcpu)
1243+
{
1244+
u32 eax, ebx, ecx, edx;
1245+
struct vcpu_tdx *tdx = to_tdx(vcpu);
1246+
1247+
/* EAX and ECX for cpuid is stored in R12 and R13. */
1248+
eax = tdx->vp_enter_args.r12;
1249+
ecx = tdx->vp_enter_args.r13;
1250+
1251+
kvm_cpuid(vcpu, &eax, &ebx, &ecx, &edx, false);
1252+
1253+
tdx->vp_enter_args.r12 = eax;
1254+
tdx->vp_enter_args.r13 = ebx;
1255+
tdx->vp_enter_args.r14 = ecx;
1256+
tdx->vp_enter_args.r15 = edx;
1257+
1258+
return 1;
1259+
}
1260+
12411261
static int tdx_complete_pio_out(struct kvm_vcpu *vcpu)
12421262
{
12431263
vcpu->arch.pio.count = 0;
@@ -1912,6 +1932,8 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath)
19121932
case EXIT_REASON_EXTERNAL_INTERRUPT:
19131933
++vcpu->stat.irq_exits;
19141934
return 1;
1935+
case EXIT_REASON_CPUID:
1936+
return tdx_emulate_cpuid(vcpu);
19151937
case EXIT_REASON_TDCALL:
19161938
return handle_tdvmcall(vcpu);
19171939
case EXIT_REASON_VMCALL:

0 commit comments

Comments
 (0)