[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v2 35/62] x86/guest: setup event channel upcall vector



From: Roger Pau Monne <roger.pau@xxxxxxxxxx>

And a dummy event channel upcall handler.

Note that with the current code the underlying Xen (L0) must support
HVMOP_set_evtchn_upcall_vector or else event channel setup is going to
fail. This limitation can be lifted by implementing more event channel
interrupt injection methods as a backup.

Register callback_irq to trick toolstack to think the domain is
enlightened.

Signed-off-by: Sergey Dyasli <sergey.dyasli@xxxxxxxxxx>
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 xen/arch/x86/guest/xen.c              | 41 +++++++++++++++++++++++++++++++++++
 xen/include/asm-x86/guest/hypercall.h | 17 +++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/xen/arch/x86/guest/xen.c b/xen/arch/x86/guest/xen.c
index 60626ec21c..59871170c8 100644
--- a/xen/arch/x86/guest/xen.c
+++ b/xen/arch/x86/guest/xen.c
@@ -24,6 +24,7 @@
 #include <xen/rangeset.h>
 #include <xen/types.h>
 
+#include <asm/apic.h>
 #include <asm/e820.h>
 #include <asm/guest.h>
 #include <asm/msr.h>
@@ -186,6 +187,43 @@ static void __init init_memmap(void)
     }
 }
 
+static void xen_evtchn_upcall(struct cpu_user_regs *regs)
+{
+    struct vcpu_info *vcpu_info = this_cpu(vcpu_info);
+
+    vcpu_info->evtchn_upcall_pending = 0;
+    write_atomic(&vcpu_info->evtchn_pending_sel, 0);
+
+    ack_APIC_irq();
+}
+
+static void init_evtchn(void)
+{
+    static uint8_t evtchn_upcall_vector;
+    int rc;
+
+    if ( !evtchn_upcall_vector )
+        alloc_direct_apic_vector(&evtchn_upcall_vector, xen_evtchn_upcall);
+
+    ASSERT(evtchn_upcall_vector);
+
+    rc = xen_hypercall_set_evtchn_upcall_vector(this_cpu(vcpu_id),
+                                                evtchn_upcall_vector);
+    if ( rc )
+        panic("Unable to set evtchn upcall vector: %d", rc);
+
+    /* Trick toolstack to think we are enlightened */
+    {
+        struct xen_hvm_param a = {
+            .domid = DOMID_SELF,
+            .index = HVM_PARAM_CALLBACK_IRQ,
+            .value = 1,
+        };
+
+        BUG_ON(xen_hypercall_hvm_op(HVMOP_set_param, &a));
+    }
+}
+
 void __init hypervisor_setup(void)
 {
     init_memmap();
@@ -210,12 +248,15 @@ void __init hypervisor_setup(void)
                "unable to map vCPU info, limiting vCPUs to: %u\n",
                XEN_LEGACY_MAX_VCPUS);
     }
+
+    init_evtchn();
 }
 
 void hypervisor_ap_setup(void)
 {
     set_vcpu_id();
     map_vcpuinfo();
+    init_evtchn();
 }
 
 int hypervisor_alloc_unused_page(mfn_t *mfn)
diff --git a/xen/include/asm-x86/guest/hypercall.h 
b/xen/include/asm-x86/guest/hypercall.h
index dbc57a566e..b36a1cc189 100644
--- a/xen/include/asm-x86/guest/hypercall.h
+++ b/xen/include/asm-x86/guest/hypercall.h
@@ -25,6 +25,7 @@
 
 #include <public/xen.h>
 #include <public/sched.h>
+#include <public/hvm/hvm_op.h>
 
 #include <public/vcpu.h>
 
@@ -104,6 +105,11 @@ static inline int xen_hypercall_vcpu_op(unsigned int cmd, 
unsigned int vcpu,
     return _hypercall64_3(long, __HYPERVISOR_vcpu_op, cmd, vcpu, arg);
 }
 
+static inline long xen_hypercall_hvm_op(unsigned int op, void *arg)
+{
+    return _hypercall64_2(long, __HYPERVISOR_hvm_op, op, arg);
+}
+
 /*
  * Higher level hypercall helpers
  */
@@ -120,6 +126,17 @@ static inline long xen_hypercall_shutdown(unsigned int 
reason)
     return xen_hypercall_sched_op(SCHEDOP_shutdown, &s);
 }
 
+static inline long xen_hypercall_set_evtchn_upcall_vector(
+    unsigned int cpu, unsigned int vector)
+{
+    struct xen_hvm_evtchn_upcall_vector a = {
+        .vcpu = cpu,
+        .vector = vector,
+    };
+
+    return xen_hypercall_hvm_op(HVMOP_set_evtchn_upcall_vector, &a);
+}
+
 #else /* CONFIG_XEN_GUEST */
 
 #include <public/sched.h>
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.