@@ -21,6 +21,7 @@
#include <xen/interface/vcpu.h>
#include <xen/interface/version.h>
#include <xen/interface/event_channel.h>
+#include <xen/interface/hvm/hvm_op.h>
#include <xen/interface/sched.h>
#include <asm/xen/cpuid.h>
@@ -1330,6 +1331,32 @@ static bool kvm_xen_hcall_sched_op(struct kvm_vcpu *vcpu, bool longmode,
return false;
}
+static void kvm_xen_hvmop_flush_tlbs(struct kvm_vcpu *vcpu, bool longmode,
+ u64 arg, u64 *r)
+{
+ if (arg) {
+ *r = -EINVAL;
+ return;
+ }
+
+ kvm_make_all_cpus_request(kvm, KVM_REQ_TLB_FLUSH_GUEST);
+ *r = 0;
+}
+
+static bool kvm_xen_hcall_hvm_op(struct kvm_vcpu *vcpu, bool longmode,
+ int cmd, u64 arg, u64 *r)
+{
+ switch (cmd) {
+ case HVMOP_flush_tlbs:
+ kvm_xen_hvmop_flush_tlbs(vcpu, longmode, arg, r);
+ return true;
+ default:
+ break;
+ }
+
+ return false;
+}
+
struct compat_vcpu_set_singleshot_timer {
uint64_t timeout_abs_ns;
uint32_t flags;
@@ -1501,6 +1528,10 @@ int kvm_xen_hypercall(struct kvm_vcpu *vcpu)
timeout |= params[1] << 32;
handled = kvm_xen_hcall_set_timer_op(vcpu, timeout, &r);
break;
+ case __HYPERVISOR_hvm_op:
+ handled = kvm_xen_hcall_hvm_op(vcpu, longmode, params[0], params[1],
+ &r);
+ break;
}
default:
break;
@@ -16,6 +16,9 @@ struct xen_hvm_param {
};
DEFINE_GUEST_HANDLE_STRUCT(xen_hvm_param);
+/* Flushes all VCPU TLBs: @arg must be NULL. */
+#define HVMOP_flush_tlbs 5
+
/* Hint from PV drivers for pagetable destruction. */
#define HVMOP_pagetable_dying 9
struct xen_hvm_pagetable_dying {
HVMOP_flush_tlbs suboperation of hvm_op hypercall allows a guest to flush all vCPU TLBs. There is no way for the VMM to flush TLBs from userspace. Hence, this patch adds support for flushing vCPU TLBs to KVM by making a KVM_REQ_TLB_FLUSH_GUEST request for all guest vCPUs. Signed-off-by: Metin Kaya <metikaya@amazon.co.uk> CR: https://code.amazon.com/reviews/CR-89597111 --- arch/x86/kvm/xen.c | 31 ++++++++++++++++++++++++++++++ include/xen/interface/hvm/hvm_op.h | 3 +++ 2 files changed, 34 insertions(+)