]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
i386/xen: add monitor commands to test event injection
authorJoao Martins <joao.m.martins@oracle.com>
Tue, 21 Aug 2018 16:16:19 +0000 (12:16 -0400)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Thu, 15 Dec 2022 10:41:59 +0000 (10:41 +0000)
Specifically add listing, injection of event channels.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
hmp-commands.hx
hw/i386/kvm/xen_evtchn.c
hw/i386/kvm/xen_evtchn.h
monitor/misc.c

index 673e39a69797b8418c421b622934a86c86943ee5..a36516c28748f495d9286d99eaf4d0f98f588fa1 100644 (file)
@@ -1815,3 +1815,33 @@ SRST
   Dump the FDT in dtb format to *filename*.
 ERST
 #endif
+
+#if defined(CONFIG_XEN_EMU)
+
+    {
+        .name       = "xen-event-inject",
+        .args_type  = "port:i",
+        .params     = "port",
+        .help       = "inject event channel",
+        .cmd        = hmp_xen_event_inject,
+    },
+
+SRST
+``xen-event-inject`` *port*
+  Notify guest via event channel on port *port*.
+ERST
+
+
+    {
+        .name       = "xen-event-list",
+        .args_type  = "",
+        .params     = "",
+        .help       = "list event channel state",
+        .cmd        = hmp_xen_event_list,
+    },
+
+SRST
+``xen-event-list``
+  List event channels in the guest
+ERST
+#endif
index 225d9843718e13a5b2062f87c86a33032ca5696c..9292602c09dee294331fe25891f8a5f314c0a0f7 100644 (file)
@@ -19,6 +19,8 @@
 #include "exec/target_page.h"
 #include "exec/address-spaces.h"
 #include "migration/vmstate.h"
+#include "monitor/monitor.h"
+#include "qapi/qmp/qdict.h"
 
 #include "hw/sysbus.h"
 #include "hw/xen/xen.h"
@@ -955,3 +957,84 @@ int xen_evtchn_send_op(struct evtchn_send *send)
     return ret;
 }
 
+static const char *type_names[] = {
+    "closed",
+    "unbound",
+    "interdomain",
+    "pirq",
+    "virq",
+    "ipi"
+};
+
+void hmp_xen_event_list(Monitor *mon, const QDict *qdict)
+{
+    XenEvtchnState *s = xen_evtchn_singleton;
+    void *shinfo, *pending, *mask;
+    int i;
+
+    if (!s) {
+        monitor_printf(mon, "Xen event channel emulation not enabled\n");
+        return;
+    }
+
+    shinfo = xen_overlay_page_ptr(XENMAPSPACE_shared_info, 0);
+    if (!shinfo) {
+        monitor_printf(mon, "Xen shared info page not allocated\n");
+        return;
+    }
+    if (xen_is_long_mode()) {
+        pending = shinfo + offsetof(struct shared_info, evtchn_pending);
+        mask = shinfo + offsetof(struct shared_info, evtchn_mask);
+    } else {
+        pending = shinfo + offsetof(struct compat_shared_info, evtchn_pending);
+        mask = shinfo + offsetof(struct compat_shared_info, evtchn_mask);
+    }
+
+    qemu_mutex_lock(&s->port_lock);
+
+    for (i = 0; i < s->nr_ports; i++) {
+        XenEvtchnPort *p = &s->port_table[i];
+
+        if (p->type == EVTCHNSTAT_closed) {
+            continue;
+        }
+
+        monitor_printf(mon, "port %4u %s/%d vcpu:%d pending:%d mask:%d\n", i,
+                       type_names[p->type], p->type_val, p->vcpu,
+                       test_bit(i, pending), test_bit(i, mask));
+    }
+
+    qemu_mutex_unlock(&s->port_lock);
+}
+
+void hmp_xen_event_inject(Monitor *mon, const QDict *qdict)
+{
+    XenEvtchnState *s = xen_evtchn_singleton;
+    int port = qdict_get_int(qdict, "port");
+    XenEvtchnPort *p;
+
+    if (!s) {
+        monitor_printf(mon, "Xen event channel emulation not enabled\n");
+        return;
+    }
+
+    if (!valid_port(port)) {
+        monitor_printf(mon, "Invalid port %d\n", port);
+        return;
+    }
+    p = &s->port_table[port];
+
+    qemu_mutex_lock(&s->port_lock);
+
+    monitor_printf(mon, "port %4u %s/%d vcpu:%d\n", port,
+                   type_names[p->type], p->type_val, p->vcpu);
+
+    if (set_port_pending(s, port)) {
+        monitor_printf(mon, "Failed to set port %d\n", port);
+    } else {
+        monitor_printf(mon, "Delivered port %d\n", port);
+    }
+
+    qemu_mutex_unlock(&s->port_lock);
+}
+
index b93f534beecdba6b88c5c11e1e4709bf4fdeb0c7..2acbaeabaaf55b7105f8be375ae13512e677db63 100644 (file)
@@ -13,6 +13,9 @@
 void xen_evtchn_create(void);
 int xen_evtchn_set_callback_param(uint64_t param);
 
+void hmp_xen_event_list(Monitor *mon, const QDict *qdict);
+void hmp_xen_event_inject(Monitor *mon, const QDict *qdict);
+
 struct evtchn_status;
 struct evtchn_close;
 struct evtchn_unmask;
index 205487e2b9ed6f5841f5f0faa796a1b16a6d9271..2b11c0f86ad2c3ded1ebc854988604621468fdc6 100644 (file)
 /* Make devices configuration available for use in hmp-commands*.hx templates */
 #include CONFIG_DEVICES
 
+#ifdef CONFIG_XEN_EMU
+#include "hw/i386/kvm/xen_evtchn.h"
+#endif
+
 /* file descriptors passed via SCM_RIGHTS */
 typedef struct mon_fd_t mon_fd_t;
 struct mon_fd_t {