Commit 28d1629f authored by David Woodhouse's avatar David Woodhouse Committed by Paolo Bonzini

KVM: x86/xen: Kernel acceleration for XENVER_version

Turns out this is a fast path for PV guests because they use it to
trigger the event channel upcall. So letting it bounce all the way up
to userspace is not great.
Signed-off-by: default avatarDavid Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Message-Id: <20220303154127.202856-14-dwmw2@infradead.org>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 53639526
...@@ -1026,6 +1026,7 @@ struct msr_bitmap_range { ...@@ -1026,6 +1026,7 @@ struct msr_bitmap_range {
/* Xen emulation context */ /* Xen emulation context */
struct kvm_xen { struct kvm_xen {
u32 xen_version;
bool long_mode; bool long_mode;
u8 upcall_vector; u8 upcall_vector;
struct gfn_to_pfn_cache shinfo_cache; struct gfn_to_pfn_cache shinfo_cache;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <trace/events/kvm.h> #include <trace/events/kvm.h>
#include <xen/interface/xen.h> #include <xen/interface/xen.h>
#include <xen/interface/vcpu.h> #include <xen/interface/vcpu.h>
#include <xen/interface/version.h>
#include <xen/interface/event_channel.h> #include <xen/interface/event_channel.h>
#include <xen/interface/sched.h> #include <xen/interface/sched.h>
...@@ -465,6 +466,13 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data) ...@@ -465,6 +466,13 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)
r = kvm_xen_setattr_evtchn(kvm, data); r = kvm_xen_setattr_evtchn(kvm, data);
break; break;
case KVM_XEN_ATTR_TYPE_XEN_VERSION:
mutex_lock(&kvm->lock);
kvm->arch.xen.xen_version = data->u.xen_version;
mutex_unlock(&kvm->lock);
r = 0;
break;
default: default:
break; break;
} }
...@@ -497,6 +505,11 @@ int kvm_xen_hvm_get_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data) ...@@ -497,6 +505,11 @@ int kvm_xen_hvm_get_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)
r = 0; r = 0;
break; break;
case KVM_XEN_ATTR_TYPE_XEN_VERSION:
data->u.xen_version = kvm->arch.xen.xen_version;
r = 0;
break;
default: default:
break; break;
} }
...@@ -1059,6 +1072,12 @@ int kvm_xen_hypercall(struct kvm_vcpu *vcpu) ...@@ -1059,6 +1072,12 @@ int kvm_xen_hypercall(struct kvm_vcpu *vcpu)
params[3], params[4], params[5]); params[3], params[4], params[5]);
switch (input) { switch (input) {
case __HYPERVISOR_xen_version:
if (params[0] == XENVER_version && vcpu->kvm->arch.xen.xen_version) {
r = vcpu->kvm->arch.xen.xen_version;
handled = true;
}
break;
case __HYPERVISOR_event_channel_op: case __HYPERVISOR_event_channel_op:
if (params[0] == EVTCHNOP_send) if (params[0] == EVTCHNOP_send)
handled = kvm_xen_hcall_evtchn_send(vcpu, params[1], &r); handled = kvm_xen_hcall_evtchn_send(vcpu, params[1], &r);
......
...@@ -1711,7 +1711,7 @@ struct kvm_xen_hvm_attr { ...@@ -1711,7 +1711,7 @@ struct kvm_xen_hvm_attr {
__u32 padding[4]; __u32 padding[4];
} deliver; } deliver;
} evtchn; } evtchn;
__u32 xen_version;
__u64 pad[8]; __u64 pad[8];
} u; } u;
}; };
...@@ -1722,6 +1722,7 @@ struct kvm_xen_hvm_attr { ...@@ -1722,6 +1722,7 @@ struct kvm_xen_hvm_attr {
#define KVM_XEN_ATTR_TYPE_UPCALL_VECTOR 0x2 #define KVM_XEN_ATTR_TYPE_UPCALL_VECTOR 0x2
/* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_EVTCHN_SEND */ /* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_EVTCHN_SEND */
#define KVM_XEN_ATTR_TYPE_EVTCHN 0x3 #define KVM_XEN_ATTR_TYPE_EVTCHN 0x3
#define KVM_XEN_ATTR_TYPE_XEN_VERSION 0x4
/* Per-vCPU Xen attributes */ /* Per-vCPU Xen attributes */
#define KVM_XEN_VCPU_GET_ATTR _IOWR(KVMIO, 0xca, struct kvm_xen_vcpu_attr) #define KVM_XEN_VCPU_GET_ATTR _IOWR(KVMIO, 0xca, struct kvm_xen_vcpu_attr)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment