From: Alexander Graf <graf@amazon.com>
To: <qemu-devel@nongnu.org>
Cc: <qemu-arm@nongnu.org>, Peter Maydell <peter.maydell@linaro.org>,
"Thomas Huth" <thuth@redhat.com>, <alex.bennee@linaro.org>,
<philmd@linaro.org>, <berrange@redhat.com>,
<marcandre.lureau@redhat.com>, Cornelia Huck <cohuck@redhat.com>,
<mst@redhat.com>, Dorjoy Chowdhury <dorjoychy111@gmail.com>,
Pierrick Bouvier <pierrick.bouvier@linaro.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Tyler Fanelli <tfanelli@redhat.com>, <mknaust@amazon.com>,
<nh-open-source@amazon.com>
Subject: [PATCH v2 05/11] hw/nitro/nitro-serial-vsock: Nitro Enclaves vsock console
Date: Wed, 25 Feb 2026 14:45:24 +0000 [thread overview]
Message-ID: <20260225144532.84673-6-graf@amazon.com> (raw)
In-Reply-To: <20260225144532.84673-1-graf@amazon.com>
Nitro Enclaves support a special "debug" mode. When in debug mode, the
Nitro Hypervisor provides a vsock port that the parent can connect to to
receive serial console output of the Enclave. Add a new nitro-serial-vsock
driver that implements short-circuit logic to establish the vsock
connection to that port and feed its data into a chardev, so that a machine
model can use it as serial device.
Signed-off-by: Alexander Graf <graf@amazon.com>
---
v1 -> v2:
- Convert to nitro-vsock-device
- Use enclave_started() callback instead of enclave-cid QOM property
- Move directory infrastructure to bus patch
---
hw/nitro/Kconfig | 4 ++
hw/nitro/meson.build | 1 +
hw/nitro/serial-vsock.c | 123 ++++++++++++++++++++++++++++++++
hw/nitro/trace-events | 2 +
include/hw/nitro/serial-vsock.h | 24 +++++++
5 files changed, 154 insertions(+)
create mode 100644 hw/nitro/serial-vsock.c
create mode 100644 include/hw/nitro/serial-vsock.h
diff --git a/hw/nitro/Kconfig b/hw/nitro/Kconfig
index 767472cb2c..ce24c09c21 100644
--- a/hw/nitro/Kconfig
+++ b/hw/nitro/Kconfig
@@ -1,2 +1,6 @@
config NITRO_VSOCK_BUS
bool
+
+config NITRO_SERIAL_VSOCK
+ bool
+ depends on NITRO_VSOCK_BUS
diff --git a/hw/nitro/meson.build b/hw/nitro/meson.build
index 7e2807f137..76399d4265 100644
--- a/hw/nitro/meson.build
+++ b/hw/nitro/meson.build
@@ -1 +1,2 @@
system_ss.add(when: 'CONFIG_NITRO_VSOCK_BUS', if_true: files('nitro-vsock-bus.c'))
+system_ss.add(when: 'CONFIG_NITRO_SERIAL_VSOCK', if_true: files('serial-vsock.c'))
diff --git a/hw/nitro/serial-vsock.c b/hw/nitro/serial-vsock.c
new file mode 100644
index 0000000000..1d56c33804
--- /dev/null
+++ b/hw/nitro/serial-vsock.c
@@ -0,0 +1,123 @@
+/*
+ * Nitro Enclave Vsock Serial
+ *
+ * Copyright © 2026 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Authors:
+ * Alexander Graf <graf@amazon.com>
+ *
+ * With Nitro Enclaves in debug mode, the Nitro Hypervisor provides a vsock
+ * port that the parent can connect to to receive serial console output of
+ * the Enclave. This driver implements short-circuit logic to establish the
+ * vsock connection to that port and feed its data into a chardev, so that
+ * a machine model can use it as serial device.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/error-report.h"
+#include "qapi/error.h"
+#include "chardev/char.h"
+#include "chardev/char-fe.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/core/qdev-properties-system.h"
+#include "hw/nitro/serial-vsock.h"
+#include "trace.h"
+
+#define CONSOLE_PORT_START 10000
+#define VMADDR_CID_HYPERVISOR_STR "0"
+
+static int nitro_serial_vsock_can_read(void *opaque)
+{
+ NitroSerialVsockState *s = opaque;
+
+ /* Refuse vsock input until the output backend is ready */
+ return qemu_chr_fe_backend_open(&s->output) ? 4096 : 0;
+}
+
+static void nitro_serial_vsock_read(void *opaque, const uint8_t *buf, int size)
+{
+ NitroSerialVsockState *s = opaque;
+
+ /* Forward all vsock data to the output chardev */
+ qemu_chr_fe_write_all(&s->output, buf, size);
+}
+
+static void nitro_serial_vsock_event(void *opaque, QEMUChrEvent event)
+{
+ /* No need to action on connect/disconnect events, but trace for debug */
+ trace_nitro_serial_vsock_event(event);
+}
+
+static void nitro_serial_vsock_enclave_started(NitroVsockDevice *dev,
+ uint32_t enclave_cid,
+ Error **errp)
+{
+ NitroSerialVsockState *s = NITRO_SERIAL_VSOCK(dev);
+ uint32_t port = enclave_cid + CONSOLE_PORT_START;
+ g_autofree char *chardev_id = NULL;
+ Chardev *chr;
+ ChardevBackend *backend;
+ ChardevSocket *sock;
+
+ /*
+ * We know the Enclave CID to connect to now. Create a vsock
+ * client chardev that connects to the Enclave's console.
+ */
+ chardev_id = g_strdup_printf("nitro-console-%u", enclave_cid);
+
+ backend = g_new0(ChardevBackend, 1);
+ backend->type = CHARDEV_BACKEND_KIND_SOCKET;
+ sock = backend->u.socket.data = g_new0(ChardevSocket, 1);
+ sock->addr = g_new0(SocketAddressLegacy, 1);
+ sock->addr->type = SOCKET_ADDRESS_TYPE_VSOCK;
+ sock->addr->u.vsock.data = g_new0(VsockSocketAddress, 1);
+ sock->addr->u.vsock.data->cid = g_strdup(VMADDR_CID_HYPERVISOR_STR);
+ sock->addr->u.vsock.data->port = g_strdup_printf("%u", port);
+ sock->server = false;
+ sock->has_server = true;
+
+ chr = qemu_chardev_new(chardev_id, TYPE_CHARDEV_SOCKET,
+ backend, NULL, errp);
+ if (!chr) {
+ return;
+ }
+
+ if (!qemu_chr_fe_init(&s->vsock, chr, errp)) {
+ return;
+ }
+
+ qemu_chr_fe_set_handlers(&s->vsock,
+ nitro_serial_vsock_can_read,
+ nitro_serial_vsock_read,
+ nitro_serial_vsock_event,
+ NULL, s, NULL, true);
+}
+
+static const Property nitro_serial_vsock_props[] = {
+ DEFINE_PROP_CHR("chardev", NitroSerialVsockState, output),
+};
+
+static void nitro_serial_vsock_class_init(ObjectClass *oc, const void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(oc);
+ NitroVsockDeviceClass *ndc = NITRO_VSOCK_DEVICE_CLASS(oc);
+
+ device_class_set_props(dc, nitro_serial_vsock_props);
+ ndc->enclave_started = nitro_serial_vsock_enclave_started;
+}
+
+static const TypeInfo nitro_serial_vsock_info = {
+ .name = TYPE_NITRO_SERIAL_VSOCK,
+ .parent = TYPE_NITRO_VSOCK_DEVICE,
+ .instance_size = sizeof(NitroSerialVsockState),
+ .class_init = nitro_serial_vsock_class_init,
+};
+
+static void nitro_serial_vsock_register(void)
+{
+ type_register_static(&nitro_serial_vsock_info);
+}
+
+type_init(nitro_serial_vsock_register);
diff --git a/hw/nitro/trace-events b/hw/nitro/trace-events
index 9ccc579048..20617a024a 100644
--- a/hw/nitro/trace-events
+++ b/hw/nitro/trace-events
@@ -1,2 +1,4 @@
# See docs/devel/tracing.rst for syntax documentation.
+# serial-vsock.c
+nitro_serial_vsock_event(int event) "event %d"
diff --git a/include/hw/nitro/serial-vsock.h b/include/hw/nitro/serial-vsock.h
new file mode 100644
index 0000000000..c365880e11
--- /dev/null
+++ b/include/hw/nitro/serial-vsock.h
@@ -0,0 +1,24 @@
+/*
+ * Nitro Enclave Serial (vsock)
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_CHAR_NITRO_SERIAL_VSOCK_H
+#define HW_CHAR_NITRO_SERIAL_VSOCK_H
+
+#include "hw/nitro/nitro-vsock-bus.h"
+#include "chardev/char-fe.h"
+#include "qom/object.h"
+
+#define TYPE_NITRO_SERIAL_VSOCK "nitro-serial-vsock"
+OBJECT_DECLARE_SIMPLE_TYPE(NitroSerialVsockState, NITRO_SERIAL_VSOCK)
+
+struct NitroSerialVsockState {
+ NitroVsockDevice parent_obj;
+
+ CharFrontend output; /* chardev to write console output to */
+ CharFrontend vsock; /* vsock chardev to enclave console */
+};
+
+#endif /* HW_CHAR_NITRO_SERIAL_VSOCK_H */
--
2.47.1
Amazon Web Services Development Center Germany GmbH
Tamara-Danz-Str. 13
10243 Berlin
Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger
Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597
next prev parent reply other threads:[~2026-02-25 14:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-25 14:45 [PATCH v2 00/11] Native Nitro Enclaves support Alexander Graf
2026-02-25 14:45 ` [PATCH v2 01/11] scripts/update-linux-headers: Add Nitro Enclaves header Alexander Graf
2026-02-25 14:45 ` [PATCH v2 02/11] linux-headers: Add nitro_enclaves.h Alexander Graf
2026-02-25 14:45 ` [PATCH v2 03/11] hw/nitro: Add Nitro Vsock Bus Alexander Graf
2026-02-25 14:45 ` [PATCH v2 04/11] accel: Add Nitro Enclaves accelerator Alexander Graf
2026-02-25 14:45 ` Alexander Graf [this message]
2026-02-25 14:45 ` [PATCH v2 06/11] hw/nitro: Introduce Nitro Enclave Heartbeat device Alexander Graf
2026-02-25 17:24 ` Paolo Bonzini
2026-02-25 14:45 ` [PATCH v2 07/11] target/arm/cpu64: Allow -host for nitro Alexander Graf
2026-02-25 14:45 ` [PATCH v2 08/11] hw/nitro: Add nitro machine Alexander Graf
2026-02-25 14:45 ` [PATCH v2 09/11] hw/core/eif: Move definitions to header Alexander Graf
2026-02-25 14:45 ` [PATCH v2 10/11] hw/nitro: Enable direct kernel boot Alexander Graf
2026-02-25 16:28 ` Dorjoy Chowdhury
2026-02-25 22:01 ` Alexander Graf
2026-02-25 14:45 ` [PATCH v2 11/11] docs: Add Nitro Enclaves documentation Alexander Graf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260225144532.84673-6-graf@amazon.com \
--to=graf@amazon.com \
--cc=alex.bennee@linaro.org \
--cc=berrange@redhat.com \
--cc=cohuck@redhat.com \
--cc=dorjoychy111@gmail.com \
--cc=marcandre.lureau@redhat.com \
--cc=mknaust@amazon.com \
--cc=mst@redhat.com \
--cc=nh-open-source@amazon.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=tfanelli@redhat.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox