From nobody Wed Feb 5 12:50:16 2025 Delivered-To: importer@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+importer=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 1674893953423331.0416231730162; Sat, 28 Jan 2023 00:19:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLgL4-0001fe-IZ; Sat, 28 Jan 2023 03:13:31 -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 1pLgJW-0005wg-8c for qemu-devel@nongnu.org; Sat, 28 Jan 2023 03:11:55 -0500 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pLgJL-0007r2-L1 for qemu-devel@nongnu.org; Sat, 28 Jan 2023 03:11:53 -0500 Received: from i7.infradead.org ([2001:8b0:10b:1:21e:67ff:fecb:7a92]) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pLgIR-0039wT-38; Sat, 28 Jan 2023 08:10:56 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1pLgIx-006mKI-34; Sat, 28 Jan 2023 08:11:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=XEOVulkw83zZSTgsVOnn2F/MXqFUufYsoRMU2EVsNL8=; b=bRFcTj87Zcm+DoTxPfEcI4ySSe 90jYupPkG79en6DOB6uHdmzN5o9784HS8qErH6tBy+yifc/zyr8rsklehxk02jBmCxhpZ81eYwAC2 GSqUHgIRmjmJLFptEgwXj89hXQqEGjUf+U5CIzcZhHaQ7qA0m7iR6fjwXGitKH+V170BlcKmeNrtO gh8CVRAiZZ7fw08Am6iIP2QgiSigEL9BCUs3OAiRJObJl8ZIq/1UwHwVxIIUdV+NxlQi+M7dnIdWy Zn+XI98jig4CffsfHx2J5XWkzEgpHB4T+PBXDs30l1ipvv43uJTzo8OYRix5w9FkjwIHc+Aaw6YET NCdIXSuw==; 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 v9 38/58] i386/xen: add monitor commands to test event injection Date: Sat, 28 Jan 2023 08:10:53 +0000 Message-Id: <20230128081113.1615111-39-dwmw2@infradead.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230128081113.1615111-1-dwmw2@infradead.org> References: <20230128081113.1615111-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; envelope-from=BATV+e8fc867402dd322853dc+7097+infradead.org+dwmw2@desiato.srs.infradead.org; helo=desiato.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1674893954436100009 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 --- 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 bf4e3c61a8..5fdb301f54 100644 --- a/hw/i386/kvm/xen_evtchn.c +++ b/hw/i386/kvm/xen_evtchn.c @@ -14,7 +14,11 @@ #include "qemu/module.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" @@ -1066,3 +1070,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