From nobody Sun Apr 12 05:50:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@amazon.com; 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; dmarc=pass(p=quarantine dis=none) header.from=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1772030921; cv=none; d=zohomail.com; s=zohoarc; b=i2fOUxWlzAd++yKs6fUZJAsOsQIuAt3dVv/AhZpwp5JvYq7KvFz4uEs64vFVUf0xlpj3Ey2gswC+DtLK9r14NqT/eS/4iLiuwwpJphVCGsizwJpPXAheybluP2EzqZkS7lcvK4Ik3jwoqS/0/a6/tlqVOFre8Att+pFLOQAQ2Zo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772030921; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=c/NejmK1x/oFC32QyVn6pWsLyl8z6texd9tR/MOfMxE=; b=HaBmPjbPROOR+6yv1cE8Y6+1da3+xx8LkzX3chkqtfSzYazCuLqp4vLIJoxHDBRAIycbXcbS5gebRKVJfXg8zBeTYYBJHhEI6QVrVUHac1EuZFVbtH4smx98Q1WK4TcTn8U4ycgtfxgDE8BJi6Cou48316JED5Wwv3W6Ser1V+E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@amazon.com; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772030921437490.42250252547785; Wed, 25 Feb 2026 06:48:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vvGAW-0000xI-JP; Wed, 25 Feb 2026 09:47:16 -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 1vvGA4-0000YP-WF; Wed, 25 Feb 2026 09:46:49 -0500 Received: from pdx-out-013.esa.us-west-2.outbound.mail-perimeter.amazon.com ([34.218.115.239]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vvGA2-00076S-RA; Wed, 25 Feb 2026 09:46:48 -0500 Received: from ip-10-5-0-115.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.0.115]) by internal-pdx-out-013.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2026 14:46:44 +0000 Received: from EX19MTAUWA002.ant.amazon.com [205.251.233.234:22892] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.50.69:2525] with esmtp (Farcaster) id 4316065a-3fe7-4daa-9181-25244cb82b28; Wed, 25 Feb 2026 14:46:43 +0000 (UTC) Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.37; Wed, 25 Feb 2026 14:46:42 +0000 Received: from ip-10-253-83-51.amazon.com (172.19.99.218) by EX19D020UWC004.ant.amazon.com (10.13.138.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.37; Wed, 25 Feb 2026 14:46:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1772030806; x=1803566806; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c/NejmK1x/oFC32QyVn6pWsLyl8z6texd9tR/MOfMxE=; b=i0vyBHHOjl/2mMYMBurHPu/uBzHBx9NruHjA/30cJWz05huzLVo64Y9P P1bj3+hZhfC5q++MHdVn+rskUpTxjHbeCXf+EhsmUfx3IRibWJvUtDoET O/SVAcKIDvDbe6fO/pyoT32SkTkSD/lNcNr8JNSKf9ODvPHwWeiTPQkio EYKNx02qsqPf0rMm+Omna4MpsK8rTsJo1kbWQk2g4SgyT9qaTLe+D755r X1e5WY8J5aW7z4UUF8l95C+7iSVk8jXFLu35HQKCnmYjyYHf00Sbcde+W 9nc+/P4wSCsyB0ggmwfiM+GBKpXXYxKJu0u3s9RyIAd+rbFCzAwsGIcao g==; X-CSE-ConnectionGUID: aFyfBTPbQXiDYX1izQplGw== X-CSE-MsgGUID: hScZCEoUSsOu2W/0HLqPiA== X-IronPort-AV: E=Sophos;i="6.21,310,1763424000"; d="scan'208";a="13578250" X-Farcaster-Flow-ID: 4316065a-3fe7-4daa-9181-25244cb82b28 From: Alexander Graf To: CC: , Peter Maydell , "Thomas Huth" , , , , , Cornelia Huck , , Dorjoy Chowdhury , Pierrick Bouvier , Paolo Bonzini , Tyler Fanelli , , Subject: [PATCH v2 08/11] hw/nitro: Add nitro machine Date: Wed, 25 Feb 2026 14:45:27 +0000 Message-ID: <20260225144532.84673-9-graf@amazon.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20260225144532.84673-1-graf@amazon.com> References: <20260225144532.84673-1-graf@amazon.com> MIME-Version: 1.0 X-Originating-IP: [172.19.99.218] X-ClientProxiedBy: EX19D035UWA001.ant.amazon.com (10.13.139.101) To EX19D020UWC004.ant.amazon.com (10.13.138.149) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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: pass client-ip=34.218.115.239; envelope-from=prvs=509822c20=graf@amazon.de; helo=pdx-out-013.esa.us-west-2.outbound.mail-perimeter.amazon.com X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.734, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.78, SPF_HELO_NONE=0.001, T_SPF_PERMERROR=0.01, UNPARSEABLE_RELAY=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: pass (identity @amazon.com) X-ZM-MESSAGEID: 1772030923654158500 Add a machine model to spawn a Nitro Enclave. Unlike the existing -M nitro-enclave, this machine model works exclusively with the -accel nitro accelerator to drive real Nitro Enclave creation. It supports memory allocation, number of CPU selection, both x86_64 as well as aarch64, implements the Enclave heartbeat logic and debug serial console. To use it, create an EIF file and run $ qemu-system-x86_64 -accel nitro,debug-mode=3Don -M nitro -nographic \ -kernel test.eif or $ qemu-system-aarch64 -accel nitro,debug-mode=3Don -M nitro -nographic \ -kernel test.eif Signed-off-by: Alexander Graf --- v1 -> v2: - support -nodefaults - spawn nitro-vsock-bridge for nitro vsock devices - use nitro vsock devices instead of their old sysbus equivalents - remove vcpu creation --- hw/nitro/Kconfig | 8 ++ hw/nitro/machine.c | 161 +++++++++++++++++++++++++++++++++++++ hw/nitro/meson.build | 1 + include/hw/nitro/machine.h | 20 +++++ 4 files changed, 190 insertions(+) create mode 100644 hw/nitro/machine.c create mode 100644 include/hw/nitro/machine.h diff --git a/hw/nitro/Kconfig b/hw/nitro/Kconfig index d3fbc7b683..cfae85920a 100644 --- a/hw/nitro/Kconfig +++ b/hw/nitro/Kconfig @@ -8,3 +8,11 @@ config NITRO_SERIAL_VSOCK config NITRO_HEARTBEAT bool depends on NITRO_VSOCK_BUS + +config NITRO_MACHINE + bool + default y + depends on NITRO + select NITRO_VSOCK_BUS + select NITRO_HEARTBEAT + select NITRO_SERIAL_VSOCK diff --git a/hw/nitro/machine.c b/hw/nitro/machine.c new file mode 100644 index 0000000000..e28c8e9bf5 --- /dev/null +++ b/hw/nitro/machine.c @@ -0,0 +1,161 @@ +/* + * Nitro Enclaves (accel) machine + * + * Copyright =C2=A9 2026 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * Authors: + * Alexander Graf + * + * Nitro Enclaves machine model for -accel nitro. This machine behaves + * like the nitro-enclave machine, but uses the real Nitro Enclaves + * backend to launch the virtual machine. It requires use of the -accel + * nitro. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "qapi/error.h" +#include "qom/object_interfaces.h" +#include "chardev/char.h" +#include "hw/core/boards.h" +#include "hw/core/cpu.h" +#include "hw/core/qdev-properties-system.h" +#include "hw/nitro/heartbeat.h" +#include "hw/nitro/machine.h" +#include "hw/nitro/nitro-vsock-bus.h" +#include "hw/nitro/serial-vsock.h" +#include "system/address-spaces.h" +#include "system/hostmem.h" +#include "system/system.h" +#include "system/nitro-accel.h" +#include "qemu/accel.h" +#include "hw/arm/machines-qom.h" + +#define EIF_LOAD_ADDR (8 * 1024 * 1024) + +static void nitro_machine_init(MachineState *machine) +{ + const char *eif_path =3D machine->kernel_filename; + const char *cpu_type =3D machine->cpu_type; + g_autofree char *eif_data =3D NULL; + gsize eif_size; + + if (!nitro_enabled()) { + error_report("The 'nitro' machine requires -accel nitro"); + exit(1); + } + + if (!cpu_type) { + ObjectClass *oc =3D cpu_class_by_name(target_cpu_type(), "host"); + + if (!oc) { + error_report("nitro: no 'host' CPU available"); + exit(1); + } + cpu_type =3D object_class_get_name(oc); + } + + if (!eif_path) { + error_report("nitro: -kernel is required"); + exit(1); + } + + /* Expose memory as normal QEMU RAM. Needs to be huge page backed. */ + memory_region_add_subregion(get_system_memory(), 0, machine->ram); + + /* + * Load EIF (-kernel) as raw blob at the EIF_LOAD_ADDR into guest RAM. + * The Nitro Hypervisor will extract its contents and bootstrap the + * Enclave from it. + */ + if (!g_file_get_contents(eif_path, &eif_data, &eif_size, NULL)) { + error_report("nitro: failed to read EIF '%s'", eif_path); + exit(1); + } + address_space_write(&address_space_memory, EIF_LOAD_ADDR, + MEMTXATTRS_UNSPECIFIED, eif_data, eif_size); + + if (defaults_enabled()) { + NitroVsockBridge *bridge =3D nitro_vsock_bridge_create(); + + /* Nitro Enclaves require a heartbeat device. Provide one. */ + qdev_realize(qdev_new(TYPE_NITRO_HEARTBEAT), + BUS(&bridge->bus), &error_fatal); + + /* + * In debug mode, Nitro Enclaves expose the guest's serial output = via + * vsock. When the accel is in debug mode, wire the vsock serial to + * the machine's serial port so that -nographic automatically works + */ + if (object_property_get_bool(OBJECT(current_accel()), "debug-mode"= , NULL)) { + Chardev *chr =3D serial_hd(0); + + if (chr) { + DeviceState *dev =3D qdev_new(TYPE_NITRO_SERIAL_VSOCK); + + qdev_prop_set_chr(dev, "chardev", chr); + qdev_realize(dev, BUS(&bridge->bus), &error_fatal); + } + } + } +} + +static bool nitro_create_memfd_backend(MachineState *ms, const char *path, + Error **errp) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + Object *root =3D object_get_objects_root(); + Object *obj; + bool r =3D false; + + obj =3D object_new(TYPE_MEMORY_BACKEND_MEMFD); + + /* Nitro Enclaves require huge page backing */ + if (!object_property_set_int(obj, "size", ms->ram_size, errp) || + !object_property_set_bool(obj, "hugetlb", true, errp)) { + goto out; + } + + object_property_add_child(root, mc->default_ram_id, obj); + + if (!user_creatable_complete(USER_CREATABLE(obj), errp)) { + goto out; + } + r =3D object_property_set_link(OBJECT(ms), "memory-backend", obj, errp= ); + +out: + object_unref(obj); + return r; +} + +static void nitro_machine_class_init(ObjectClass *oc, const void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + + mc->desc =3D "Nitro Enclave"; + mc->init =3D nitro_machine_init; + mc->create_default_memdev =3D nitro_create_memfd_backend; + mc->default_ram_id =3D "ram"; + mc->max_cpus =3D 4096; +} + +static const TypeInfo nitro_machine_info =3D { + .name =3D TYPE_NITRO_MACHINE, + .parent =3D TYPE_MACHINE, + .instance_size =3D sizeof(NitroMachineState), + .class_init =3D nitro_machine_class_init, + .interfaces =3D (const InterfaceInfo[]) { + /* x86_64 and aarch64 only */ + { TYPE_TARGET_AARCH64_MACHINE }, + { } + }, +}; + +static void nitro_machine_register(void) +{ + type_register_static(&nitro_machine_info); +} + +type_init(nitro_machine_register); diff --git a/hw/nitro/meson.build b/hw/nitro/meson.build index 381c1ee6c1..e3f1895890 100644 --- a/hw/nitro/meson.build +++ b/hw/nitro/meson.build @@ -1,3 +1,4 @@ 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-vs= ock.c')) system_ss.add(when: 'CONFIG_NITRO_HEARTBEAT', if_true: files('heartbeat.c'= )) +system_ss.add(when: 'CONFIG_NITRO_MACHINE', if_true: files('machine.c')) diff --git a/include/hw/nitro/machine.h b/include/hw/nitro/machine.h new file mode 100644 index 0000000000..d78ba7d6dc --- /dev/null +++ b/include/hw/nitro/machine.h @@ -0,0 +1,20 @@ +/* + * Nitro Enclaves (accel) machine + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_NITRO_MACHINE_H +#define HW_NITRO_MACHINE_H + +#include "hw/core/boards.h" +#include "qom/object.h" + +#define TYPE_NITRO_MACHINE MACHINE_TYPE_NAME("nitro") +OBJECT_DECLARE_SIMPLE_TYPE(NitroMachineState, NITRO_MACHINE) + +struct NitroMachineState { + MachineState parent; +}; + +#endif /* HW_NITRO_MACHINE_H */ --=20 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