]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: VMX: Add a macro to track which DEBUGCTL bits are host-owned
authorSean Christopherson <seanjc@google.com>
Thu, 26 Jun 2025 16:14:20 +0000 (09:14 -0700)
committerSean Christopherson <seanjc@google.com>
Wed, 9 Jul 2025 16:30:52 +0000 (09:30 -0700)
Add VMX_HOST_OWNED_DEBUGCTL_BITS to track which bits are host-owned, i.e.
need to be preserved when running the guest, to dedup the logic without
having to incur a memory load to get at kvm_x86_ops.HOST_OWNED_DEBUGCTL.

No functional change intended.

Suggested-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Link: https://lore.kernel.org/all/aF1yni8U6XNkyfRf@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/vmx/main.c
arch/x86/kvm/vmx/vmx.h

index 047d314fa4e46d834358b7f593fe226a00a04fea..f46bdd97b9683fbf664f71cf6274821dbf562dc2 100644 (file)
@@ -915,7 +915,7 @@ struct kvm_x86_ops vt_x86_ops __initdata = {
        .vcpu_load = vt_op(vcpu_load),
        .vcpu_put = vt_op(vcpu_put),
 
-       .HOST_OWNED_DEBUGCTL = DEBUGCTLMSR_FREEZE_IN_SMM,
+       .HOST_OWNED_DEBUGCTL = VMX_HOST_OWNED_DEBUGCTL_BITS,
 
        .update_exception_bitmap = vt_op(update_exception_bitmap),
        .get_feature_msr = vmx_get_feature_msr,
index 87174d961c85b17123d61130bf3116fce733d6f4..d3389baf3ab3d2bb0507a4d838961460f4a6037d 100644 (file)
@@ -410,27 +410,29 @@ void vmx_update_cpu_dirty_logging(struct kvm_vcpu *vcpu);
 u64 vmx_get_supported_debugctl(struct kvm_vcpu *vcpu, bool host_initiated);
 bool vmx_is_valid_debugctl(struct kvm_vcpu *vcpu, u64 data, bool host_initiated);
 
+#define VMX_HOST_OWNED_DEBUGCTL_BITS   (DEBUGCTLMSR_FREEZE_IN_SMM)
+
 static inline void vmx_guest_debugctl_write(struct kvm_vcpu *vcpu, u64 val)
 {
-       WARN_ON_ONCE(val & DEBUGCTLMSR_FREEZE_IN_SMM);
+       WARN_ON_ONCE(val & VMX_HOST_OWNED_DEBUGCTL_BITS);
 
-       val |= vcpu->arch.host_debugctl & DEBUGCTLMSR_FREEZE_IN_SMM;
+       val |= vcpu->arch.host_debugctl & VMX_HOST_OWNED_DEBUGCTL_BITS;
        vmcs_write64(GUEST_IA32_DEBUGCTL, val);
 }
 
 static inline u64 vmx_guest_debugctl_read(void)
 {
-       return vmcs_read64(GUEST_IA32_DEBUGCTL) & ~DEBUGCTLMSR_FREEZE_IN_SMM;
+       return vmcs_read64(GUEST_IA32_DEBUGCTL) & ~VMX_HOST_OWNED_DEBUGCTL_BITS;
 }
 
 static inline void vmx_reload_guest_debugctl(struct kvm_vcpu *vcpu)
 {
        u64 val = vmcs_read64(GUEST_IA32_DEBUGCTL);
 
-       if (!((val ^ vcpu->arch.host_debugctl) & DEBUGCTLMSR_FREEZE_IN_SMM))
+       if (!((val ^ vcpu->arch.host_debugctl) & VMX_HOST_OWNED_DEBUGCTL_BITS))
                return;
 
-       vmx_guest_debugctl_write(vcpu, val & ~DEBUGCTLMSR_FREEZE_IN_SMM);
+       vmx_guest_debugctl_write(vcpu, val & ~VMX_HOST_OWNED_DEBUGCTL_BITS);
 }
 
 /*