Skip to content

Commit a5d7700

Browse files
committed
KVM: x86/xen: Consult kvm_xen_enabled when checking for Xen MSR writes
Query kvm_xen_enabled when detecting writes to the Xen hypercall page MSR so that the check is optimized away in the likely scenario that Xen isn't enabled for the VM. Deliberately open code the check instead of using kvm_xen_msr_enabled() in order to avoid a double load of xen_hvm_config.msr (which is admittedly rather pointless given the widespread lack of READ_ONCE() usage on the plethora of vCPU-scoped accesses to kvm->arch.xen state). No functional change intended. Reviewed-by: David Woodhouse <dwmw@amazon.co.uk> Reviewed-by: Paul Durrant <paul@xen.org> Link: https://lore.kernel.org/r/20250215011437.1203084-4-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent bb0978d commit a5d7700

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

arch/x86/kvm/xen.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ static inline bool kvm_xen_msr_enabled(struct kvm *kvm)
5858

5959
static inline bool kvm_xen_is_hypercall_page_msr(struct kvm *kvm, u32 msr)
6060
{
61+
if (!static_branch_unlikely(&kvm_xen_enabled.key))
62+
return false;
63+
6164
return msr && msr == kvm->arch.xen_hvm_config.msr;
6265
}
6366

0 commit comments

Comments
 (0)