Skip to content

Commit 8af0990

Browse files
ahunter6bonzini
authored andcommitted
KVM: TDX: Save and restore IA32_DEBUGCTL
Save the IA32_DEBUGCTL MSR before entering a TDX VCPU and restore it afterwards. The TDX Module preserves bits 1, 12, and 14, so if no other bits are set, no restore is done. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Message-ID: <20250129095902.16391-12-adrian.hunter@intel.com> Reviewed-by: Xiayao Li <xiaoyao.li@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 6d41577 commit 8af0990

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

arch/x86/kvm/vmx/tdx.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,8 @@ void tdx_prepare_switch_to_guest(struct kvm_vcpu *vcpu)
688688
else
689689
vt->msr_host_kernel_gs_base = read_msr(MSR_KERNEL_GS_BASE);
690690

691+
vt->host_debugctlmsr = get_debugctlmsr();
692+
691693
vt->guest_state_loaded = true;
692694
}
693695

@@ -831,11 +833,15 @@ static void tdx_load_host_xsave_state(struct kvm_vcpu *vcpu)
831833
if (kvm_host.xss != (kvm_tdx->xfam & kvm_caps.supported_xss))
832834
wrmsrl(MSR_IA32_XSS, kvm_host.xss);
833835
}
834-
EXPORT_SYMBOL_GPL(kvm_load_host_xsave_state);
836+
837+
#define TDX_DEBUGCTL_PRESERVED (DEBUGCTLMSR_BTF | \
838+
DEBUGCTLMSR_FREEZE_PERFMON_ON_PMI | \
839+
DEBUGCTLMSR_FREEZE_IN_SMM)
835840

836841
fastpath_t tdx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate_exit)
837842
{
838843
struct vcpu_tdx *tdx = to_tdx(vcpu);
844+
struct vcpu_vt *vt = to_vt(vcpu);
839845

840846
/*
841847
* force_immediate_exit requires vCPU entering for events injection with
@@ -851,6 +857,9 @@ fastpath_t tdx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate_exit)
851857

852858
tdx_vcpu_enter_exit(vcpu);
853859

860+
if (vt->host_debugctlmsr & ~TDX_DEBUGCTL_PRESERVED)
861+
update_debugctlmsr(vt->host_debugctlmsr);
862+
854863
tdx_load_host_xsave_state(vcpu);
855864
tdx->guest_entered = true;
856865

0 commit comments

Comments
 (0)