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>

+4 -8
+1
arch/x86/include/asm/kvm_host.h
··· 780 780 u32 pkru; 781 781 u32 hflags; 782 782 u64 efer; 783 + u64 host_debugctl; 783 784 u64 apic_base; 784 785 struct kvm_lapic *apic; /* kernel irqchip context */ 785 786 bool load_eoi_exitmap_pending;
+2 -6
arch/x86/kvm/vmx/vmx.c
··· 1514 1514 */ 1515 1515 void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 1516 1516 { 1517 - struct vcpu_vmx *vmx = to_vmx(vcpu); 1518 - 1519 1517 if (vcpu->scheduled_out && !kvm_pause_in_guest(vcpu->kvm)) 1520 1518 shrink_ple_window(vcpu); 1521 1519 1522 1520 vmx_vcpu_load_vmcs(vcpu, cpu, NULL); 1523 1521 1524 1522 vmx_vcpu_pi_load(vcpu, cpu); 1525 - 1526 - vmx->host_debugctlmsr = get_debugctlmsr(); 1527 1523 } 1528 1524 1529 1525 void vmx_vcpu_put(struct kvm_vcpu *vcpu) ··· 7454 7458 } 7455 7459 7456 7460 /* MSR_IA32_DEBUGCTLMSR is zeroed on vmexit. Restore it if needed */ 7457 - if (vmx->host_debugctlmsr) 7458 - update_debugctlmsr(vmx->host_debugctlmsr); 7461 + if (vcpu->arch.host_debugctl) 7462 + update_debugctlmsr(vcpu->arch.host_debugctl); 7459 7463 7460 7464 #ifndef CONFIG_X86_64 7461 7465 /*
-2
arch/x86/kvm/vmx/vmx.h
··· 340 340 /* apic deadline value in host tsc */ 341 341 u64 hv_deadline_tsc; 342 342 343 - unsigned long host_debugctlmsr; 344 - 345 343 /* 346 344 * Only bits masked by msr_ia32_feature_control_valid_bits can be set in 347 345 * msr_ia32_feature_control. FEAT_CTL_LOCKED is always included
+1
arch/x86/kvm/x86.c
··· 4968 4968 4969 4969 /* Save host pkru register if supported */ 4970 4970 vcpu->arch.host_pkru = read_pkru(); 4971 + vcpu->arch.host_debugctl = get_debugctlmsr(); 4971 4972 4972 4973 /* Apply any externally detected TSC adjustments (due to suspend) */ 4973 4974 if (unlikely(vcpu->arch.tsc_offset_adjustment)) {