[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v4 39/47] i386/xen: add monitor commands to test event inject
From: |
David Woodhouse |
Subject: |
[RFC PATCH v4 39/47] i386/xen: add monitor commands to test event injection |
Date: |
Wed, 21 Dec 2022 01:06:15 +0000 |
From: Joao Martins <joao.m.martins@oracle.com>
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 | 29 ++++++++++++++
hw/i386/kvm/xen_evtchn.c | 83 ++++++++++++++++++++++++++++++++++++++++
hw/i386/kvm/xen_evtchn.h | 3 ++
monitor/misc.c | 4 ++
4 files changed, 119 insertions(+)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 673e39a697..fd77c432c0 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1815,3 +1815,32 @@ 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
diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c
index a394f124e9..b49e622275 100644
--- a/hw/i386/kvm/xen_evtchn.c
+++ b/hw/i386/kvm/xen_evtchn.c
@@ -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"
@@ -1036,3 +1038,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_get_shinfo_ptr();
+ 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);
+}
+
diff --git a/hw/i386/kvm/xen_evtchn.h b/hw/i386/kvm/xen_evtchn.h
index 5d3e03553f..1de53daa52 100644
--- a/hw/i386/kvm/xen_evtchn.h
+++ b/hw/i386/kvm/xen_evtchn.h
@@ -16,6 +16,9 @@ void xen_evtchn_create(void);
int xen_evtchn_soft_reset(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;
diff --git a/monitor/misc.c b/monitor/misc.c
index 205487e2b9..2b11c0f86a 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -88,6 +88,10 @@
/* 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 {
--
2.35.3
- [RFC PATCH v4 40/47] hw/xen: Support HVM_PARAM_CALLBACK_TYPE_GSI callback, (continued)
- [RFC PATCH v4 40/47] hw/xen: Support HVM_PARAM_CALLBACK_TYPE_GSI callback, David Woodhouse, 2022/12/20
- [RFC PATCH v4 22/47] i386/xen: handle VCPUOP_register_vcpu_time_info, David Woodhouse, 2022/12/20
- [RFC PATCH v4 34/47] hw/xen: Implement EVTCHNOP_send, David Woodhouse, 2022/12/20
- [RFC PATCH v4 46/47] hw/xen: Implement GNTTABOP_query_size, David Woodhouse, 2022/12/20
- [RFC PATCH v4 20/47] i386/xen: implement HYPERVISOR_vcpu_op, David Woodhouse, 2022/12/20
- [RFC PATCH v4 31/47] hw/xen: Implement EVTCHNOP_unmask, David Woodhouse, 2022/12/20
- [RFC PATCH v4 27/47] hw/xen: Add xen_evtchn device for event channel emulation, David Woodhouse, 2022/12/20
- [RFC PATCH v4 33/47] hw/xen: Implement EVTCHNOP_bind_ipi, David Woodhouse, 2022/12/20
- [RFC PATCH v4 25/47] i386/xen: implement HVMOP_set_evtchn_upcall_vector, David Woodhouse, 2022/12/20
- [RFC PATCH v4 47/47] i386/xen: handle PV timer hypercalls, David Woodhouse, 2022/12/20
- [RFC PATCH v4 39/47] i386/xen: add monitor commands to test event injection,
David Woodhouse <=
- [RFC PATCH v4 30/47] hw/xen: Implement EVTCHNOP_close, David Woodhouse, 2022/12/20
- [RFC PATCH v4 43/47] hw/xen: Add xen_gnttab device for grant table emulation, David Woodhouse, 2022/12/20
- [RFC PATCH v4 06/47] i386/hvm: Set Xen vCPU ID in KVM, David Woodhouse, 2022/12/20
- [RFC PATCH v4 36/47] hw/xen: Implement EVTCHNOP_bind_interdomain, David Woodhouse, 2022/12/20
- [RFC PATCH v4 07/47] xen-platform: exclude vfio-pci from the PCI platform unplug, David Woodhouse, 2022/12/20
- [RFC PATCH v4 10/47] i386/xen: handle guest hypercalls, David Woodhouse, 2022/12/20
- [RFC PATCH v4 42/47] kvm/i386: Add xen-gnttab-max-frames property, David Woodhouse, 2022/12/20
- [RFC PATCH v4 28/47] i386/xen: Add support for Xen event channel delivery to vCPU, David Woodhouse, 2022/12/20
- [RFC PATCH v4 18/47] i386/xen: implement XENMEM_add_to_physmap_batch, David Woodhouse, 2022/12/20