Skip to content

Commit fb71c79

Browse files
committed
KVM: x86: Snapshot the host's DEBUGCTL in common x86
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>
1 parent d0eac42 commit fb71c79

File tree

4 files changed

+4
-8
lines changed

4 files changed

+4
-8
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ struct kvm_vcpu_arch {
780780
u32 pkru;
781781
u32 hflags;
782782
u64 efer;
783+
u64 host_debugctl;
783784
u64 apic_base;
784785
struct kvm_lapic *apic; /* kernel irqchip context */
785786
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)
@@ -7458,8 +7454,8 @@ fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate_exit)
74587454
}
74597455

74607456
/* MSR_IA32_DEBUGCTLMSR is zeroed on vmexit. Restore it if needed */
7461-
if (vmx->host_debugctlmsr)
7462-
update_debugctlmsr(vmx->host_debugctlmsr);
7457+
if (vcpu->arch.host_debugctl)
7458+
update_debugctlmsr(vcpu->arch.host_debugctl);
74637459

74647460
#ifndef CONFIG_X86_64
74657461
/*

arch/x86/kvm/vmx/vmx.h

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

343-
unsigned long host_debugctlmsr;
344-
345343
/*
346344
* Only bits masked by msr_ia32_feature_control_valid_bits can be set in
347345
* 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
@@ -4968,6 +4968,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
49684968

49694969
/* Save host pkru register if supported */
49704970
vcpu->arch.host_pkru = read_pkru();
4971+
vcpu->arch.host_debugctl = get_debugctlmsr();
49714972

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

0 commit comments

Comments
 (0)