From nobody Tue May 13 11:38:42 2025 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675265639507857.4613693338991; Wed, 1 Feb 2023 07:33:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNEBx-00049N-C5; Wed, 01 Feb 2023 09:34:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNE9w-0001VY-Ki for qemu-devel@nongnu.org; Wed, 01 Feb 2023 09:32:24 -0500 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNE9g-00036y-QL for qemu-devel@nongnu.org; Wed, 01 Feb 2023 09:32:17 -0500 Received: from i7.infradead.org ([2001:8b0:10b:1:21e:67ff:fecb:7a92]) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNE9Q-00CMbH-Mu; Wed, 01 Feb 2023 14:31:54 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1pNE9Q-007JsZ-2H; Wed, 01 Feb 2023 14:31:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=p8VAHN/v1kgqmZm9+Bc3iOblvGOXysY7ecFGDULfqN8=; b=XthmC04OGrix7fgrzK/pDS/Jn4 w3Rj7ASEjjfWLm2tfnUPMxN3t5Vd4U976COIvyHI9A6SNMYVcIPh4S7bSIkhX3E46/7/BBmZLqrcU DKt5xtln1yu0HNfkWsPES3N/Qcq3xqTYHZYXzH1pfOs9GFFn2RArQZpD8Y30tSdLmppkhl/BC0dhQ VEWqtwYBFz0fck5hKqy+Iyk9tTzDiPq7RyvH32oG1spOOdUxnjwT4VFAp7+NgXindlEcrVKy23WQr 5zwb3eVLyexZ5LJxH2rpNed2ykmA3WL1cnyH/RAx3+CEuHi7t1xY5ncnaYIp4lMQQEqRLVoPSlxAT ZPAvkONw==; From: David Woodhouse To: Peter Maydell , qemu-devel@nongnu.org Cc: Paolo Bonzini , Paul Durrant , Joao Martins , Ankur Arora , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr . David Alan Gilbert" , Claudio Fontana , Julien Grall , "Michael S. Tsirkin" , Marcel Apfelbaum , armbru@redhat.com Subject: [PATCH v10 39/59] i386/xen: add monitor commands to test event injection Date: Wed, 1 Feb 2023 14:31:28 +0000 Message-Id: <20230201143148.1744093-40-dwmw2@infradead.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230201143148.1744093-1-dwmw2@infradead.org> References: <20230201143148.1744093-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2001:8b0:10b:1236::1; envelope-from=BATV+8c5eeea0684575598b25+7101+infradead.org+dwmw2@casper.srs.infradead.org; helo=casper.infradead.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1675265642548100003 Content-Type: text/plain; charset="utf-8" From: Joao Martins Specifically add listing, injection of event channels. Signed-off-by: Joao Martins Signed-off-by: David Woodhouse Acked-by: Dr. David Alan Gilbert Reviewed-by: Paul Durrant --- hmp-commands.hx | 29 +++++++++ hw/i386/kvm/xen_evtchn.c | 137 +++++++++++++++++++++++++++++++++++++++ include/monitor/hmp.h | 2 + qapi/misc-target.json | 116 +++++++++++++++++++++++++++++++++ 4 files changed, 284 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 =3D "xen-event-inject", + .args_type =3D "port:i", + .params =3D "port", + .help =3D "inject event channel", + .cmd =3D hmp_xen_event_inject, + }, + +SRST +``xen-event-inject`` *port* + Notify guest via event channel on port *port*. +ERST + + + { + .name =3D "xen-event-list", + .args_type =3D "", + .params =3D "", + .help =3D "list event channel state", + .cmd =3D 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 9b1fb47e85..fa54d185cd 100644 --- a/hw/i386/kvm/xen_evtchn.c +++ b/hw/i386/kvm/xen_evtchn.c @@ -15,7 +15,11 @@ #include "qemu/lockable.h" #include "qemu/main-loop.h" #include "qemu/log.h" +#include "monitor/monitor.h" +#include "monitor/hmp.h" #include "qapi/error.h" +#include "qapi/qapi-commands-misc-target.h" +#include "qapi/qmp/qdict.h" #include "qom/object.h" #include "exec/target_page.h" #include "exec/address-spaces.h" @@ -1067,3 +1071,136 @@ int xen_evtchn_send_op(struct evtchn_send *send) return ret; } =20 +EvtchnInfoList *qmp_xen_event_list(Error **errp) +{ + XenEvtchnState *s =3D xen_evtchn_singleton; + EvtchnInfoList *head =3D NULL, **tail =3D &head; + void *shinfo, *pending, *mask; + int i; + + if (!s) { + error_setg(errp, "Xen event channel emulation not enabled"); + return NULL; + } + + shinfo =3D xen_overlay_get_shinfo_ptr(); + if (!shinfo) { + error_setg(errp, "Xen shared info page not allocated"); + return NULL; + } + + if (xen_is_long_mode()) { + pending =3D shinfo + offsetof(struct shared_info, evtchn_pending); + mask =3D shinfo + offsetof(struct shared_info, evtchn_mask); + } else { + pending =3D shinfo + offsetof(struct compat_shared_info, evtchn_pe= nding); + mask =3D shinfo + offsetof(struct compat_shared_info, evtchn_mask); + } + + QEMU_LOCK_GUARD(&s->port_lock); + + for (i =3D 0; i < s->nr_ports; i++) { + XenEvtchnPort *p =3D &s->port_table[i]; + EvtchnInfo *info; + + if (p->type =3D=3D EVTCHNSTAT_closed) { + continue; + } + + info =3D g_new0(EvtchnInfo, 1); + + info->port =3D i; + qemu_build_assert(EVTCHN_PORT_TYPE_CLOSED =3D=3D EVTCHNSTAT_closed= ); + qemu_build_assert(EVTCHN_PORT_TYPE_UNBOUND =3D=3D EVTCHNSTAT_unbou= nd); + qemu_build_assert(EVTCHN_PORT_TYPE_INTERDOMAIN =3D=3D EVTCHNSTAT_i= nterdomain); + qemu_build_assert(EVTCHN_PORT_TYPE_PIRQ =3D=3D EVTCHNSTAT_pirq); + qemu_build_assert(EVTCHN_PORT_TYPE_VIRQ =3D=3D EVTCHNSTAT_virq); + qemu_build_assert(EVTCHN_PORT_TYPE_IPI =3D=3D EVTCHNSTAT_ipi); + + info->type =3D p->type; + if (p->type =3D=3D EVTCHNSTAT_interdomain) { + info->remote_domain =3D g_strdup((p->type_val & PORT_INFO_TYPE= VAL_REMOTE_QEMU) ? + "qemu" : "loopback"); + info->target =3D p->type_val & PORT_INFO_TYPEVAL_REMOTE_PORT_M= ASK; + } else { + info->target =3D p->type_val; + } + info->vcpu =3D p->vcpu; + info->pending =3D test_bit(i, pending); + info->masked =3D test_bit(i, mask); + + QAPI_LIST_APPEND(tail, info); + } + + return head; +} + +void qmp_xen_event_inject(uint32_t port, Error **errp) +{ + XenEvtchnState *s =3D xen_evtchn_singleton; + + if (!s) { + error_setg(errp, "Xen event channel emulation not enabled"); + return; + } + + if (!valid_port(port)) { + error_setg(errp, "Invalid port %u", port); + } + + QEMU_LOCK_GUARD(&s->port_lock); + + if (set_port_pending(s, port)) { + error_setg(errp, "Failed to set port %u", port); + return; + } +} + +void hmp_xen_event_list(Monitor *mon, const QDict *qdict) +{ + EvtchnInfoList *iter, *info_list; + Error *err =3D NULL; + + info_list =3D qmp_xen_event_list(&err); + if (err) { + hmp_handle_error(mon, err); + return; + } + + for (iter =3D info_list; iter; iter =3D iter->next) { + EvtchnInfo *info =3D iter->value; + + monitor_printf(mon, "port %4lu: vcpu: %ld %s", info->port, info->v= cpu, + EvtchnPortType_str(info->type)); + if (info->type !=3D EVTCHN_PORT_TYPE_IPI) { + monitor_printf(mon, "("); + if (info->remote_domain) { + monitor_printf(mon, "%s:", info->remote_domain); + } + monitor_printf(mon, "%ld)", info->target); + } + if (info->pending) { + monitor_printf(mon, " PENDING"); + } + if (info->masked) { + monitor_printf(mon, " MASKED"); + } + monitor_printf(mon, "\n"); + } + + qapi_free_EvtchnInfoList(info_list); +} + +void hmp_xen_event_inject(Monitor *mon, const QDict *qdict) +{ + int port =3D qdict_get_int(qdict, "port"); + Error *err =3D NULL; + + qmp_xen_event_inject(port, &err); + if (err) { + hmp_handle_error(mon, err); + } else { + monitor_printf(mon, "Delivered port %d\n", port); + } +} + diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 1b3bdcb446..cbc6e9bb91 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -108,6 +108,8 @@ void hmp_virtio_status(Monitor *mon, const QDict *qdict= ); void hmp_virtio_queue_status(Monitor *mon, const QDict *qdict); void hmp_vhost_queue_status(Monitor *mon, const QDict *qdict); void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict); +void hmp_xen_event_inject(Monitor *mon, const QDict *qdict); +void hmp_xen_event_list(Monitor *mon, const QDict *qdict); void object_add_completion(ReadLineState *rs, int nb_args, const char *str= ); void object_del_completion(ReadLineState *rs, int nb_args, const char *str= ); void device_add_completion(ReadLineState *rs, int nb_args, const char *str= ); diff --git a/qapi/misc-target.json b/qapi/misc-target.json index 5b6a8e9185..652e6e0b37 100644 --- a/qapi/misc-target.json +++ b/qapi/misc-target.json @@ -380,3 +380,119 @@ # ## { 'command': 'query-sgx-capabilities', 'returns': 'SGXInfo', 'if': 'TARGET= _I386' } + + +## +# @EvtchnPortType: +# +# An enumeration of Xen event channel port types. +# +# @closed: The port is unused. +# +# @unbound: The port is allocated and ready to be bound. +# +# @interdomain: The port is connected as an interdomain interrupt. +# +# @pirq: The port is bound to a physical IRQ (PIRQ). +# +# @virq: The port is bound to a virtual IRQ (VIRQ). +# +# @ipi: The post is an inter-processor interrupt (IPI). +# +# Since: 8.0.0 +## +{ 'enum': 'EvtchnPortType', + 'data': ['closed', 'unbound', 'interdomain', 'pirq', 'virq', 'ipi'], + 'if': 'TARGET_I386' } + +## +# @EvtchnInfo: +# +# Information about a Xen event channel port +# +# @port: the port number +# +# @vcpu: target vCPU for this port +# +# @type: the port type +# +# @remote-domain: remote domain for interdomain ports +# +# @target: remote port ID, or virq/pirq number +# +# @pending: port is currently active pending delivery +# +# @masked: port is masked +# +# Since: 8.0.0 +## +{ 'struct': 'EvtchnInfo', + 'data': {'port': 'int', + 'vcpu': 'int', + 'type': 'EvtchnPortType', + 'remote-domain': 'str', + 'target': 'int', + 'pending': 'bool', + 'masked': 'bool'}, + 'if': 'TARGET_I386' } + + +## +# @xen-event-list: +# +# Query the Xen event channels opened by the guest. +# +# Returns: list of open event channel ports. +# +# Since: 8.0.0 +# +# Example: +# +# -> { "execute": "xen-event-list" } +# <- { "return": [ +# { +# "pending": false, +# "port": 1, +# "vcpu": 1, +# "remote-domain": "qemu", +# "masked": false, +# "type": "interdomain", +# "target": 1 +# }, +# { +# "pending": false, +# "port": 2, +# "vcpu": 0, +# "remote-domain": "", +# "masked": false, +# "type": "virq", +# "target": 0 +# } +# ] +# } +# +## +{ 'command': 'xen-event-list', + 'returns': ['EvtchnInfo'], + 'if': 'TARGET_I386' } + +## +# @xen-event-inject: +# +# Inject a Xen event channel port (interrupt) to the guest. +# +# @port: The port number +# +# Returns: - Nothing on success. +# +# Since: 8.0.0 +# +# Example: +# +# -> { "execute": "xen-event-inject", "arguments": { "port": 1 } } +# <- { "return": { } } +# +## +{ 'command': 'xen-event-inject', + 'data': { 'port': 'uint32' }, + 'if': 'TARGET_I386' } --=20 2.39.0