diff mbox series

[2/5] KVM: x86/xen: Add an #ifdef'd helper to detect writes to Xen MSR

Message ID 20250201011400.669483-3-seanjc@google.com (mailing list archive)
State New, archived
Headers show
Series KVM: x86/xen: Restrict hypercall MSR index | expand

Commit Message

Sean Christopherson Feb. 1, 2025, 1:13 a.m. UTC
Add a helper to detect writes to the Xen hypercall page MSR, and provide a
stub for CONFIG_KVM_XEN=n to optimize out the check for kernels built
without Xen support.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/x86.c |  2 +-
 arch/x86/kvm/xen.h | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

Comments

Paul Durrant Feb. 3, 2025, 9:09 a.m. UTC | #1
On 01/02/2025 01:13, Sean Christopherson wrote:
> Add a helper to detect writes to the Xen hypercall page MSR, and provide a
> stub for CONFIG_KVM_XEN=n to optimize out the check for kernels built
> without Xen support.
> 
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>   arch/x86/kvm/x86.c |  2 +-
>   arch/x86/kvm/xen.h | 10 ++++++++++
>   2 files changed, 11 insertions(+), 1 deletion(-)
> 

Reviewed-by: Paul Durrant <paul@xen.org>
David Woodhouse Feb. 6, 2025, 4:28 p.m. UTC | #2
On Fri, 2025-01-31 at 17:13 -0800, Sean Christopherson wrote:
> Add a helper to detect writes to the Xen hypercall page MSR, and provide a
> stub for CONFIG_KVM_XEN=n to optimize out the check for kernels built
> without Xen support.
> 
> Signed-off-by: Sean Christopherson <seanjc@google.com>

Reviewed-by: David Woodhouse <dwmw@amazon.co.uk>
diff mbox series

Patch

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index b2d9a16fd4d3..f13d9d3f7c60 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3733,7 +3733,7 @@  int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 	u32 msr = msr_info->index;
 	u64 data = msr_info->data;
 
-	if (msr && msr == vcpu->kvm->arch.xen_hvm_config.msr)
+	if (kvm_xen_is_hypercall_page_msr(vcpu->kvm, msr))
 		return kvm_xen_write_hypercall_page(vcpu, data);
 
 	switch (msr) {
diff --git a/arch/x86/kvm/xen.h b/arch/x86/kvm/xen.h
index f5841d9000ae..e92e06926f76 100644
--- a/arch/x86/kvm/xen.h
+++ b/arch/x86/kvm/xen.h
@@ -56,6 +56,11 @@  static inline bool kvm_xen_msr_enabled(struct kvm *kvm)
 		kvm->arch.xen_hvm_config.msr;
 }
 
+static inline bool kvm_xen_is_hypercall_page_msr(struct kvm *kvm, u32 msr)
+{
+	return msr && msr == kvm->arch.xen_hvm_config.msr;
+}
+
 static inline bool kvm_xen_hypercall_enabled(struct kvm *kvm)
 {
 	return static_branch_unlikely(&kvm_xen_enabled.key) &&
@@ -124,6 +129,11 @@  static inline bool kvm_xen_msr_enabled(struct kvm *kvm)
 	return false;
 }
 
+static inline bool kvm_xen_is_hypercall_page_msr(struct kvm *kvm, u32 msr)
+{
+	return false;
+}
+
 static inline bool kvm_xen_hypercall_enabled(struct kvm *kvm)
 {
 	return false;