Skip to content

Commit 4e5e47f

Browse files
sean-jcgregkh
authored andcommitted
KVM: x86: Snapshot the host's DEBUGCTL in common x86
commit fb71c79 upstream. Move KVM's snapshot of DEBUGCTL to kvm_vcpu_arch and take the snapshot in common x86, so that SVM can also use the snapshot. Opportunistically change the field to a u64. While bits 63:32 are reserved on AMD, not mentioned at all in Intel's SDM, and managed as an "unsigned long" by the kernel, DEBUGCTL is an MSR and therefore a 64-bit value. Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> Cc: stable@vger.kernel.org Reviewed-and-tested-by: Ravi Bangoria <ravi.bangoria@amd.com> Link: https://lore.kernel.org/r/20250227222411.3490595-4-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 96d7dbf commit 4e5e47f

4 files changed

Lines changed: 4 additions & 8 deletions

File tree

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ struct kvm_vcpu_arch {
761761
u32 pkru;
762762
u32 hflags;
763763
u64 efer;
764+
u64 host_debugctl;
764765
u64 apic_base;
765766
struct kvm_lapic *apic; /* kernel irqchip context */
766767
bool load_eoi_exitmap_pending;

arch/x86/kvm/vmx/vmx.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,16 +1514,12 @@ void vmx_vcpu_load_vmcs(struct kvm_vcpu *vcpu, int cpu,
15141514
*/
15151515
void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
15161516
{
1517-
struct vcpu_vmx *vmx = to_vmx(vcpu);
1518-
15191517
if (vcpu->scheduled_out && !kvm_pause_in_guest(vcpu->kvm))
15201518
shrink_ple_window(vcpu);
15211519

15221520
vmx_vcpu_load_vmcs(vcpu, cpu, NULL);
15231521

15241522
vmx_vcpu_pi_load(vcpu, cpu);
1525-
1526-
vmx->host_debugctlmsr = get_debugctlmsr();
15271523
}
15281524

15291525
void vmx_vcpu_put(struct kvm_vcpu *vcpu)
@@ -7469,8 +7465,8 @@ fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate_exit)
74697465
}
74707466

74717467
/* MSR_IA32_DEBUGCTLMSR is zeroed on vmexit. Restore it if needed */
7472-
if (vmx->host_debugctlmsr)
7473-
update_debugctlmsr(vmx->host_debugctlmsr);
7468+
if (vcpu->arch.host_debugctl)
7469+
update_debugctlmsr(vcpu->arch.host_debugctl);
74747470

74757471
#ifndef CONFIG_X86_64
74767472
/*

arch/x86/kvm/vmx/vmx.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,6 @@ struct vcpu_vmx {
337337
/* apic deadline value in host tsc */
338338
u64 hv_deadline_tsc;
339339

340-
unsigned long host_debugctlmsr;
341-
342340
/*
343341
* Only bits masked by msr_ia32_feature_control_valid_bits can be set in
344342
* msr_ia32_feature_control. FEAT_CTL_LOCKED is always included

arch/x86/kvm/x86.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4976,6 +4976,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
49764976

49774977
/* Save host pkru register if supported */
49784978
vcpu->arch.host_pkru = read_pkru();
4979+
vcpu->arch.host_debugctl = get_debugctlmsr();
49794980

49804981
/* Apply any externally detected TSC adjustments (due to suspend) */
49814982
if (unlikely(vcpu->arch.tsc_offset_adjustment)) {

0 commit comments

Comments
 (0)