Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ so — run `probe-versions.sh` locally against a full clone for the real split.

**Proven here:**

- The series applies **12/12 to the pristine v11.1.0 tarball with strict context**
- The series applies **13/13 to the pristine v11.1.0 tarball with strict context**
(`git am`, no `--3way`) and reproduces the recorded tree.
- The gate catches corruption that still applies: corrupting one line of `0012`
still passes 12/12 on step 2 and fails on step 3.
Expand Down
2 changes: 1 addition & 1 deletion base.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"url": "https://download.qemu.org/qemu-11.1.0.tar.xz",
"hash": "sha256-buHRph9oISR2snEIwm2l9EncCbYm1C+CeboNwuCPqFg=",
"sha256": "6ee1d1a61f68212476b27108c26da5f449dc09b626d42f8279ba0dc2e08fa858",
"patchedTree": "1b1a352f65bfe14e1b7cfe4c7c5890cdaf7f939c"
"patchedTree": "bc704b70a9efa57784203553fa2e2bb2dfd70056"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Luke Craig <lacraig3@gmail.com>
Date: Wed, 14 Oct 2026 18:35:05 -0400
Subject: [PATCH] monitor: build Penguin's raw QMP event emitter

penguin_qmp_emit_event() (system/penguin.h) pushes an unsolicited QMP event
of any name to every connected QMP monitor: the outbound counterpart to the
QMP command callback. It walks mon_list the way monitor_qapi_event_emit()
does, so it needs monitor-internal.h and lives in monitor/penguin-event.c
(vendored) rather than beside the other hooks in system/penguin.c. This is
the only upstream file it touches: add it to the qmp source set.

Ported from rehosting/qemu 862d4fb74f (#22).

Co-authored-by: Benjamin Levy <153011444+be32826@users.noreply.github.com>
---
monitor/meson.build | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/monitor/meson.build b/monitor/meson.build
index 4c58dd148c0496156b93feeb66cee2cfb27e07fd..b058dbca7040a68775d1d6ac9312b5d94307b12f 100644
--- a/monitor/meson.build
+++ b/monitor/meson.build
@@ -1,4 +1,5 @@
-qmp_ss.add(files('monitor.c', 'qmp.c', 'qmp-cmds-control.c'))
+qmp_ss.add(files('monitor.c', 'penguin-event.c', 'qmp.c',
+ 'qmp-cmds-control.c'))

system_ss.add(files(
'fds.c',
1 change: 1 addition & 0 deletions patches/11.1.0/series
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
11.1.0/0010-penguin-snapshot-ABI-and-a-migratable-vhost-user-vso.patch
11.1.0/0011-penguin-reset-request-and-QMP-command-callbacks.patch
11.1.0/0012-hw-mips-malta-enlarge-the-prom-env-slot-so-the-cmdli.patch
11.1.0/0013-monitor-build-Penguin-s-raw-QMP-event-emitter.patch
1 change: 1 addition & 0 deletions scripts/check-delta-present.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ CORE_SYMS=(
penguin_cpu_env
penguin_handle_qmp
penguin_invoke_reset_request_callback
penguin_qmp_emit_event
)
TCG_SYM=helper_penguin_guest_hypercall # every target EXCEPT x86
IOPORT_STR=penguin-hypercall # x86 only: the port-0x88 MemoryRegion name
Expand Down
26 changes: 26 additions & 0 deletions src/include/system/penguin.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,30 @@ void set_penguin_qmp_callback(penguin_qmp_cb_t cb, void *opaque);
*/
bool penguin_handle_qmp(const char *command, const char *args, char **result);

/*
* Emit an arbitrary QMP event to every connected QMP monitor. This is the
* outbound counterpart to the QMP command callback above: the callback lets a
* plugin answer commands, this lets a plugin push an unsolicited notification.
*
* @name becomes the QMP "event" member verbatim, so a plugin can emit any event
* name without a QAPI schema entry. Because there is no schema entry there is
* no QAPIEvent ordinal, so these events bypass the rate limiting in
* monitor_qapi_event_conf[] and are never throttled or coalesced.
*
* @data_json is an optional JSON-encoded payload, or NULL/"" for none. It must
* decode to a JSON *object*: the QMP spec defines the "data" member as a
* json-object, so a scalar or array is rejected. The timestamp is added
* automatically, as for any QMP event.
*
* Safe to call from any thread, including a vCPU thread inside a guest
* hypercall handler: the work is deferred to a main-loop bottom half, so the
* caller does not need the BQL and does not block on JSON parsing or the
* monitor write. Fire-and-forget; an empty @name or a malformed or non-object
* @data_json is reported to QEMU stderr and the event is dropped.
*
* Note that an arbitrary @name can collide with a built-in QEMU event (e.g.
* "STOP"); choosing a distinctive name is the caller's responsibility.
*/
void penguin_qmp_emit_event(const char *name, const char *data_json);

#endif /* QEMU_SYSTEM_PENGUIN_H */
148 changes: 148 additions & 0 deletions src/monitor/penguin-event.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* Penguin raw QMP event emission.
*
* Lets a Penguin plugin push an unsolicited QMP event of any name to every
* connected monitor -- the outbound counterpart to the QMP command callback in
* system/penguin.c.
*
* This lives under monitor/ rather than next to the other Penguin hooks
* because it needs monitor-internal.h: emitting an event by name means walking
* mon_list directly instead of going through qapi_event_emit(), which is keyed
* by QAPIEvent ordinal.
*/

#include "qemu/osdep.h"
#include "monitor-internal.h"
#include "qapi/error.h"
#include "qapi/qmp-event.h"
#include "qemu/error-report.h"
#include "qemu/main-loop.h"
#include "qobject/qdict.h"
#include "qobject/qjson.h"
#include "system/penguin.h"

/*
* Broadcast an already-built event dict to every QMP monitor in command mode.
*
* Mirrors monitor_qapi_event_emit() and the QMP class's emit_event hook
* (monitor_qmp_emit_event() in monitor/qmp.c), but deliberately bypasses
* qapi_event_queue()/monitor_qapi_event_conf[]: those are keyed by QAPIEvent
* ordinals, and a Penguin plugin emits events by name, with no schema entry and
* so no ordinal. Rate limiting is therefore not applied -- Penguin events are
* never throttled or coalesced.
*
* @qdict must already be a complete event object. The caller retains its
* reference.
*/
static void penguin_monitor_broadcast_event(QDict *qdict)
{
Monitor *mon;
MonitorQMP *qmp_mon;

QEMU_LOCK_GUARD(&monitor_lock);

QTAILQ_FOREACH(mon, &mon_list, entry) {
qmp_mon = MONITOR_QMP(
object_dynamic_cast(OBJECT(mon), TYPE_MONITOR_QMP));
if (!qmp_mon) {
continue;
}

{
QEMU_LOCK_GUARD(&mon->mon_lock);
/*
* Still negotiating capabilities: the client has not sent
* qmp_capabilities yet and must not receive events.
*/
if (qmp_mon->commands == &qmp_cap_negotiation_commands) {
continue;
}
}
qmp_send_response(qmp_mon, qdict);
}
}

/*
* A deferred emission: the event name plus its optional JSON payload. Two
* fields, so a struct rather than a bare pointer for the bottom half's opaque.
*/
typedef struct PenguinEventReq {
char *name;
char *data_json;
} PenguinEventReq;

/*
* Main-loop half of penguin_qmp_emit_event(). Parses and validates the payload,
* then broadcasts the event.
*
* Ownership of @opaque transfers here, so this frees it on every path.
*/
static void penguin_qmp_emit_event_bh(void *opaque)
{
PenguinEventReq *req = opaque;
QObject *data = NULL;
QDict *event = NULL;
Error *err = NULL;

if (req->data_json && req->data_json[0]) {
data = qobject_from_json(req->data_json, &err);
if (err) {
error_reportf_err(err, "penguin: dropping QMP event \"%s\": "
"invalid JSON payload: ", req->name);
goto out;
}
/*
* The QMP spec defines an event's "data" member as a json-object (see
* docs/interop/qmp-spec.rst), so reject a scalar or array rather than
* emitting something no conforming client can parse.
*/
if (qobject_type(data) != QTYPE_QDICT) {
error_report("penguin: dropping QMP event \"%s\": payload must be "
"a JSON object, not a scalar or array", req->name);
goto out;
}
}

/*
* Build through the normal helper, so the "event" member and the timestamp
* are formatted exactly as they are for a schema-defined event.
*/
event = qmp_event_build_dict(req->name);
if (data) {
/* Ownership of @data transfers into @event. */
qdict_put_obj(event, "data", data);
data = NULL;
}

penguin_monitor_broadcast_event(event);

out:
qobject_unref(event);
qobject_unref(data);
g_free(req->name);
g_free(req->data_json);
g_free(req);
}

void __attribute__((visibility("default")))
penguin_qmp_emit_event(const char *name, const char *data_json)
{
PenguinEventReq *req;

if (!name || !name[0]) {
error_report("penguin: refusing to emit QMP event with empty name");
return;
}

req = g_new0(PenguinEventReq, 1);
req->name = g_strdup(name);
req->data_json = g_strdup(data_json);

/*
* Defer to the main loop: the broadcast takes monitor_lock and writes to
* each monitor chardev, and deferring keeps the calling vCPU thread from
* blocking on JSON parsing + write.
*/
aio_bh_schedule_oneshot(qemu_get_aio_context(),
penguin_qmp_emit_event_bh, req);
}
1 change: 1 addition & 0 deletions src/scripts/penguin-cffi-gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
void set_penguin_reset_request_callback(penguin_reset_request_cb_t cb, void *opaque);
void set_penguin_qmp_callback(penguin_qmp_cb_t cb, void *opaque);
bool penguin_handle_qmp(const char *command, const char *args, char **result);
void penguin_qmp_emit_event(const char *name, const char *data_json);
"""


Expand Down
Loading