Skip to content

Commit cf5f366

Browse files
yamahatabonzini
authored andcommitted
KVM: TDX: Add methods to ignore accesses to TSC
TDX protects TDX guest TSC state from VMM. Implement access methods to ignore guest TSC. Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com> Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com> Message-ID: <20250227012021.1778144-16-binbin.wu@linux.intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent a946c71 commit cf5f366

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

arch/x86/kvm/vmx/main.c

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,42 @@ static int vt_set_identity_map_addr(struct kvm *kvm, u64 ident_addr)
786786
return vmx_set_identity_map_addr(kvm, ident_addr);
787787
}
788788

789+
static u64 vt_get_l2_tsc_offset(struct kvm_vcpu *vcpu)
790+
{
791+
/* TDX doesn't support L2 guest at the moment. */
792+
if (is_td_vcpu(vcpu))
793+
return 0;
794+
795+
return vmx_get_l2_tsc_offset(vcpu);
796+
}
797+
798+
static u64 vt_get_l2_tsc_multiplier(struct kvm_vcpu *vcpu)
799+
{
800+
/* TDX doesn't support L2 guest at the moment. */
801+
if (is_td_vcpu(vcpu))
802+
return 0;
803+
804+
return vmx_get_l2_tsc_multiplier(vcpu);
805+
}
806+
807+
static void vt_write_tsc_offset(struct kvm_vcpu *vcpu)
808+
{
809+
/* In TDX, tsc offset can't be changed. */
810+
if (is_td_vcpu(vcpu))
811+
return;
812+
813+
vmx_write_tsc_offset(vcpu);
814+
}
815+
816+
static void vt_write_tsc_multiplier(struct kvm_vcpu *vcpu)
817+
{
818+
/* In TDX, tsc multiplier can't be changed. */
819+
if (is_td_vcpu(vcpu))
820+
return;
821+
822+
vmx_write_tsc_multiplier(vcpu);
823+
}
824+
789825
#ifdef CONFIG_X86_64
790826
static int vt_set_hv_timer(struct kvm_vcpu *vcpu, u64 guest_deadline_tsc,
791827
bool *expired)
@@ -944,10 +980,10 @@ struct kvm_x86_ops vt_x86_ops __initdata = {
944980

945981
.has_wbinvd_exit = cpu_has_vmx_wbinvd_exit,
946982

947-
.get_l2_tsc_offset = vmx_get_l2_tsc_offset,
948-
.get_l2_tsc_multiplier = vmx_get_l2_tsc_multiplier,
949-
.write_tsc_offset = vmx_write_tsc_offset,
950-
.write_tsc_multiplier = vmx_write_tsc_multiplier,
983+
.get_l2_tsc_offset = vt_get_l2_tsc_offset,
984+
.get_l2_tsc_multiplier = vt_get_l2_tsc_multiplier,
985+
.write_tsc_offset = vt_write_tsc_offset,
986+
.write_tsc_multiplier = vt_write_tsc_multiplier,
951987

952988
.load_mmu_pgd = vt_load_mmu_pgd,
953989

0 commit comments

Comments
 (0)