Skip to content

Commit e1ef1c5

Browse files
committed
KVM: VMX: Add a macro to track which DEBUGCTL bits are host-owned
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>
1 parent 05186d7 commit e1ef1c5

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

arch/x86/kvm/vmx/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ struct kvm_x86_ops vt_x86_ops __initdata = {
915915
.vcpu_load = vt_op(vcpu_load),
916916
.vcpu_put = vt_op(vcpu_put),
917917

918-
.HOST_OWNED_DEBUGCTL = DEBUGCTLMSR_FREEZE_IN_SMM,
918+
.HOST_OWNED_DEBUGCTL = VMX_HOST_OWNED_DEBUGCTL_BITS,
919919

920920
.update_exception_bitmap = vt_op(update_exception_bitmap),
921921
.get_feature_msr = vmx_get_feature_msr,

arch/x86/kvm/vmx/vmx.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,27 +410,29 @@ void vmx_update_cpu_dirty_logging(struct kvm_vcpu *vcpu);
410410
u64 vmx_get_supported_debugctl(struct kvm_vcpu *vcpu, bool host_initiated);
411411
bool vmx_is_valid_debugctl(struct kvm_vcpu *vcpu, u64 data, bool host_initiated);
412412

413+
#define VMX_HOST_OWNED_DEBUGCTL_BITS (DEBUGCTLMSR_FREEZE_IN_SMM)
414+
413415
static inline void vmx_guest_debugctl_write(struct kvm_vcpu *vcpu, u64 val)
414416
{
415-
WARN_ON_ONCE(val & DEBUGCTLMSR_FREEZE_IN_SMM);
417+
WARN_ON_ONCE(val & VMX_HOST_OWNED_DEBUGCTL_BITS);
416418

417-
val |= vcpu->arch.host_debugctl & DEBUGCTLMSR_FREEZE_IN_SMM;
419+
val |= vcpu->arch.host_debugctl & VMX_HOST_OWNED_DEBUGCTL_BITS;
418420
vmcs_write64(GUEST_IA32_DEBUGCTL, val);
419421
}
420422

421423
static inline u64 vmx_guest_debugctl_read(void)
422424
{
423-
return vmcs_read64(GUEST_IA32_DEBUGCTL) & ~DEBUGCTLMSR_FREEZE_IN_SMM;
425+
return vmcs_read64(GUEST_IA32_DEBUGCTL) & ~VMX_HOST_OWNED_DEBUGCTL_BITS;
424426
}
425427

426428
static inline void vmx_reload_guest_debugctl(struct kvm_vcpu *vcpu)
427429
{
428430
u64 val = vmcs_read64(GUEST_IA32_DEBUGCTL);
429431

430-
if (!((val ^ vcpu->arch.host_debugctl) & DEBUGCTLMSR_FREEZE_IN_SMM))
432+
if (!((val ^ vcpu->arch.host_debugctl) & VMX_HOST_OWNED_DEBUGCTL_BITS))
431433
return;
432434

433-
vmx_guest_debugctl_write(vcpu, val & ~DEBUGCTLMSR_FREEZE_IN_SMM);
435+
vmx_guest_debugctl_write(vcpu, val & ~VMX_HOST_OWNED_DEBUGCTL_BITS);
434436
}
435437

436438
/*

0 commit comments

Comments
 (0)