From nobody Sun Apr 12 04:21:00 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=1772030789; cv=none; d=zohomail.com; s=zohoarc; b=LX/XYA/WsOJ0HQLFPZK0RPi8RrVoaeSNeiVzA6ZcobjqwbAirb+HAmweBakhfvtIMGLrkoZJhzzHI6p86cUULsP3GwgDiImERiVVSRNb4D+AfUJkxS+wpl/uNcCwOj1UQoAHJCXz3VT08H7UnNz/jMiDlz0GWMyFKH3h5slbp+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772030789; 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=KCela8AQkLSev7ljQRFJIF4piqXcUABB/3Y09CBj+Qw=; b=PGGNm9FPVWJv67no+6YH/D3DL4uo/8T3OAHmW5YWMdi7aisUbB5N6D+enrBRb4eZ0mLcsz44E00TLcFGlXZOONvketvoDHqpreVfmzyW49tiJtZ1fNLTLqGMrXNsikEERMLA5VRZ/4PCBsWQMtve0e+5WfKc+PuAWNYTZJEtcPY= 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 1772030789861622.9090621729097; Wed, 25 Feb 2026 06:46:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vvG9H-0008SW-8m; Wed, 25 Feb 2026 09:45:59 -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 1vvG9D-0008Ri-UU; Wed, 25 Feb 2026 09:45:57 -0500 Received: from pdx-out-010.esa.us-west-2.outbound.mail-perimeter.amazon.com ([52.12.53.23]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vvG98-00070U-L2; Wed, 25 Feb 2026 09:45:53 -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-010.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2026 14:45:41 +0000 Received: from EX19MTAUWC002.ant.amazon.com [205.251.233.51:3633] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.52.67:2525] with esmtp (Farcaster) id 5183695b-9ca8-468a-9051-b17fd1999a50; Wed, 25 Feb 2026 14:45:41 +0000 (UTC) Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) 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:45:41 +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:45:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1772030750; x=1803566750; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KCela8AQkLSev7ljQRFJIF4piqXcUABB/3Y09CBj+Qw=; b=QwI1cpVnrsClD7yvwbxS0WhEdZB1igrCZ0yHhPIxdbLph2MB+JAlVrCm bCMqUr6MOM3QfwJpZbFVnjr2Nwy/l5wfjfPINsEBUP5cXmtgq9sdPGAbF sA/JvPYHAhQ77DoPPiTNTGKbIUQm1JRRtPbXpkwCKu/1amZOTfnHhROO/ xY0+e5vlPsTCmJq34yg7F+ZGx6CG5dtRnnDfjJlcuMIb5lMVUgR+owk6d sfNG7ehDrd91Rs6g7rxtvsBNoFKroWqq6Vad0ssM8yBJU3F4wv8s86ZY+ h79Z+1lngv46AwQir71Ax9Yi9W1xGDclkP4s4VY+zT0s72BkYcCGGyCxE A==; X-CSE-ConnectionGUID: M5H7nu7DROSjPijvhyLG9A== X-CSE-MsgGUID: 7Q04jdrlSYuF3A3C+edLOQ== X-IronPort-AV: E=Sophos;i="6.21,310,1763424000"; d="scan'208";a="13645535" X-Farcaster-Flow-ID: 5183695b-9ca8-468a-9051-b17fd1999a50 From: Alexander Graf To: CC: , Peter Maydell , "Thomas Huth" , , , , , Cornelia Huck , , Dorjoy Chowdhury , Pierrick Bouvier , Paolo Bonzini , Tyler Fanelli , , Subject: [PATCH v2 01/11] scripts/update-linux-headers: Add Nitro Enclaves header Date: Wed, 25 Feb 2026 14:45:20 +0000 Message-ID: <20260225144532.84673-2-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: EX19D041UWA004.ant.amazon.com (10.13.139.9) To EX19D020UWC004.ant.amazon.com (10.13.138.149) 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=52.12.53.23; envelope-from=prvs=509822c20=graf@amazon.de; helo=pdx-out-010.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: 1772030790671158500 Content-Type: text/plain; charset="utf-8" We want to enable QEMU to drive the /dev/nitro_enclaves device node. Add its UAPI header into our kernel sync so we have all defines we need to drive it. Signed-off-by: Alexander Graf --- scripts/update-linux-headers.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers= .sh index d09d8cf4c6..386d7a38e7 100755 --- a/scripts/update-linux-headers.sh +++ b/scripts/update-linux-headers.sh @@ -254,6 +254,7 @@ for i in "$hdrdir"/include/linux/*virtio*.h \ "$hdrdir/include/linux/kvm_para.h" \ "$hdrdir/include/linux/vhost_types.h" \ "$hdrdir/include/linux/vmclock-abi.h" \ + "$hdrdir/include/linux/nitro_enclaves.h" \ "$hdrdir/include/linux/sysinfo.h"; do cp_portable "$i" "$output/include/standard-headers/linux" done --=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 From nobody Sun Apr 12 04:21:00 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=1772030809; cv=none; d=zohomail.com; s=zohoarc; b=MrMhIvXyPsnM3H/3/V0IACXCcepFQ/Z/Kv+dlj3tHRdXWWYKjj8tCO4QrDoj2PMFxgDWRy8TN5Ao43HuBFU7ryA5ej8WEQ5G8gV5jjm88WRoKkvyGLA89APqD2yAnRAeH8Nc7mta+bAfTDgIgtZhI27HqSwwUechr+jWL8TmavQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772030809; 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=yGwpH6mNXADUzH7l283Vcqo8pTgMS9qPjwIVA1ZPJ58=; b=QAWmt7QNP6gJTv92aUnFXy4t5CKkU4AmKrnNvlA0dB7/ezYIFWvkAKelAyPmuTigPJuDIN7UYl7fiFg0y52uO/AI9Zw7INsSIPmAm0VXkgc8E4YPUbDqJZPt+RMZA0XgcaYqn6fnqBaHmCybPna6ioSmzQWpMhyiSpajDJfPM2w= 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 1772030809169409.12012113356604; Wed, 25 Feb 2026 06:46:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vvG9H-0008T1-QN; Wed, 25 Feb 2026 09:45:59 -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 1vvG9D-0008Rg-UP; Wed, 25 Feb 2026 09:45:57 -0500 Received: from pdx-out-015.esa.us-west-2.outbound.mail-perimeter.amazon.com ([50.112.246.219]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vvG98-00070x-KP; Wed, 25 Feb 2026 09:45:54 -0500 Received: from ip-10-5-12-219.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.12.219]) by internal-pdx-out-015.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2026 14:45:45 +0000 Received: from EX19MTAUWA001.ant.amazon.com [205.251.233.182:11341] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.36.66:2525] with esmtp (Farcaster) id b508d004-cad6-4920-b63f-957dd459c2e8; Wed, 25 Feb 2026 14:45:45 +0000 (UTC) Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWA001.ant.amazon.com (10.250.64.218) 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:45:43 +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:45:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1772030750; x=1803566750; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yGwpH6mNXADUzH7l283Vcqo8pTgMS9qPjwIVA1ZPJ58=; b=SgZk/x9MQjtHC4oirTipotTthYzkOrC7QTsLJAmS081rOjF6HEQs3/H6 81COs1nGeipfpR4c1t2ixjkmqbqYttog2AqvqWPRbsUH+D63hIn6ChsJu 3lU8VLtx9X6jqwUFhyB0+irQ2zPvsY04neAxJt2bfVfIA2j6E5L6TmVeM tR7uRizJ5Ill038B27GybTgJxUxEtvjoSPrtgZWs7UA+yjfu+VVupmhSC NSVMHtgRoGtnx0gkPIqmy6lO8XVOFfWT5Sqz+PJYf0wOdCfgrZa7g8XvI 2ZFXiykPr+4JjQWfqn5XICm7IGtpDAwKMKgtu33QqCCulu6VbgDt10Ioi A==; X-CSE-ConnectionGUID: Sjs9eNzIT1+i6SzUtSu9Gg== X-CSE-MsgGUID: xiIIL/D6T0mFLUIehKrBIw== X-IronPort-AV: E=Sophos;i="6.21,310,1763424000"; d="scan'208";a="13594409" X-Farcaster-Flow-ID: b508d004-cad6-4920-b63f-957dd459c2e8 From: Alexander Graf To: CC: , Peter Maydell , "Thomas Huth" , , , , , Cornelia Huck , , Dorjoy Chowdhury , Pierrick Bouvier , Paolo Bonzini , Tyler Fanelli , , Subject: [PATCH v2 02/11] linux-headers: Add nitro_enclaves.h Date: Wed, 25 Feb 2026 14:45:21 +0000 Message-ID: <20260225144532.84673-3-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: EX19D041UWA004.ant.amazon.com (10.13.139.9) To EX19D020UWC004.ant.amazon.com (10.13.138.149) 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=50.112.246.219; envelope-from=prvs=509822c20=graf@amazon.de; helo=pdx-out-015.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: 1772030810891158500 Content-Type: text/plain; charset="utf-8" QEMU is learning to drive the /dev/nitro_enclaves device node. Include its UAPI header into our local copy of kernel headers so it has all defines we need to drive it. Signed-off-by: Alexander Graf --- .../standard-headers/linux/nitro_enclaves.h | 359 ++++++++++++++++++ 1 file changed, 359 insertions(+) create mode 100644 include/standard-headers/linux/nitro_enclaves.h diff --git a/include/standard-headers/linux/nitro_enclaves.h b/include/stan= dard-headers/linux/nitro_enclaves.h new file mode 100644 index 0000000000..5545267dd9 --- /dev/null +++ b/include/standard-headers/linux/nitro_enclaves.h @@ -0,0 +1,359 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Copyright 2020-2021 Amazon.com, Inc. or its affiliates. All Rights Rese= rved. + */ + +#ifndef _LINUX_NITRO_ENCLAVES_H_ +#define _LINUX_NITRO_ENCLAVES_H_ + +#include "standard-headers/linux/types.h" + +/** + * DOC: Nitro Enclaves (NE) Kernel Driver Interface + */ + +/** + * NE_CREATE_VM - The command is used to create a slot that is associated = with + * an enclave VM. + * The generated unique slot id is an output parameter. + * The ioctl can be invoked on the /dev/nitro_enclaves fd, before + * setting any resources, such as memory and vCPUs, for an + * enclave. Memory and vCPUs are set for the slot mapped to an enclave. + * A NE CPU pool has to be set before calling this function. The + * pool can be set after the NE driver load, using + * /sys/module/nitro_enclaves/parameters/ne_cpus. + * Its format is the detailed in the cpu-lists section: + * https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters= .html + * CPU 0 and its siblings have to remain available for the + * primary / parent VM, so they cannot be set for enclaves. Full + * CPU core(s), from the same NUMA node, need(s) to be included + * in the CPU pool. + * + * Context: Process context. + * Return: + * * Enclave file descriptor - Enclave file descriptor used with + * ioctl calls to set vCPUs and memory + * regions, then start the enclave. + * * -1 - There was a failure in the ioctl logic. + * On failure, errno is set to: + * * EFAULT - copy_to_user() failure. + * * ENOMEM - Memory allocation failure for internal + * bookkeeping variables. + * * NE_ERR_NO_CPUS_AVAIL_IN_POOL - No NE CPU pool set / no CPUs available + * in the pool. + * * Error codes from get_unused_fd_flags() and anon_inode_getfile(). + * * Error codes from the NE PCI device request. + */ +#define NE_CREATE_VM _IOR(0xAE, 0x20, uint64_t) + +/** + * NE_ADD_VCPU - The command is used to set a vCPU for an enclave. The vCP= U can + * be auto-chosen from the NE CPU pool or it can be set by the + * caller, with the note that it needs to be available in the NE + * CPU pool. Full CPU core(s), from the same NUMA node, need(s) to + * be associated with an enclave. + * The vCPU id is an input / output parameter. If its value is 0, + * then a CPU is chosen from the enclave CPU pool and returned via + * this parameter. + * The ioctl can be invoked on the enclave fd, before an enclave + * is started. + * + * Context: Process context. + * Return: + * * 0 - Logic successfully completed. + * * -1 - There was a failure in the ioctl logic. + * On failure, errno is set to: + * * EFAULT - copy_from_user() / copy_to_user() failure. + * * ENOMEM - Memory allocation failure for internal + * bookkeeping variables. + * * EIO - Current task mm is not the same as the one + * that created the enclave. + * * NE_ERR_NO_CPUS_AVAIL_IN_POOL - No CPUs available in the NE CPU pool. + * * NE_ERR_VCPU_ALREADY_USED - The provided vCPU is already used. + * * NE_ERR_VCPU_NOT_IN_CPU_POOL - The provided vCPU is not available in t= he + * NE CPU pool. + * * NE_ERR_VCPU_INVALID_CPU_CORE - The core id of the provided vCPU is in= valid + * or out of range. + * * NE_ERR_NOT_IN_INIT_STATE - The enclave is not in init state + * (init =3D before being started). + * * NE_ERR_INVALID_VCPU - The provided vCPU is not in the available + * CPUs range. + * * Error codes from the NE PCI device request. + */ +#define NE_ADD_VCPU _IOWR(0xAE, 0x21, uint32_t) + +/** + * NE_GET_IMAGE_LOAD_INFO - The command is used to get information needed = for + * in-memory enclave image loading e.g. offset in + * enclave memory to start placing the enclave image. + * The image load info is an input / output parameter. + * It includes info provided by the caller - flags - + * and returns the offset in enclave memory where to + * start placing the enclave image. + * The ioctl can be invoked on the enclave fd, before + * an enclave is started. + * + * Context: Process context. + * Return: + * * 0 - Logic successfully completed. + * * -1 - There was a failure in the ioctl logic. + * On failure, errno is set to: + * * EFAULT - copy_from_user() / copy_to_user() failure. + * * NE_ERR_NOT_IN_INIT_STATE - The enclave is not in init state (init =3D + * before being started). + * * NE_ERR_INVALID_FLAG_VALUE - The value of the provided flag is invalid. + */ +#define NE_GET_IMAGE_LOAD_INFO _IOWR(0xAE, 0x22, struct ne_image_load_inf= o) + +/** + * NE_SET_USER_MEMORY_REGION - The command is used to set a memory region = for an + * enclave, given the allocated memory from the + * userspace. Enclave memory needs to be from the + * same NUMA node as the enclave CPUs. + * The user memory region is an input parameter. It + * includes info provided by the caller - flags, + * memory size and userspace address. + * The ioctl can be invoked on the enclave fd, + * before an enclave is started. + * + * Context: Process context. + * Return: + * * 0 - Logic successfully completed. + * * -1 - There was a failure in the ioctl logic. + * On failure, errno is set to: + * * EFAULT - copy_from_user() failure. + * * EINVAL - Invalid physical memory region(s) e.g. + * unaligned address. + * * EIO - Current task mm is not the same as + * the one that created the enclave. + * * ENOMEM - Memory allocation failure for internal + * bookkeeping variables. + * * NE_ERR_NOT_IN_INIT_STATE - The enclave is not in init state + * (init =3D before being started). + * * NE_ERR_INVALID_MEM_REGION_SIZE - The memory size of the region is not + * multiple of 2 MiB. + * * NE_ERR_INVALID_MEM_REGION_ADDR - Invalid user space address given. + * * NE_ERR_UNALIGNED_MEM_REGION_ADDR - Unaligned user space address given. + * * NE_ERR_MEM_REGION_ALREADY_USED - The memory region is already used. + * * NE_ERR_MEM_NOT_HUGE_PAGE - The memory region is not backed by + * huge pages. + * * NE_ERR_MEM_DIFFERENT_NUMA_NODE - The memory region is not from the sa= me + * NUMA node as the CPUs. + * * NE_ERR_MEM_MAX_REGIONS - The number of memory regions set for + * the enclave reached maximum. + * * NE_ERR_INVALID_PAGE_SIZE - The memory region is not backed by + * pages multiple of 2 MiB. + * * NE_ERR_INVALID_FLAG_VALUE - The value of the provided flag is invali= d. + * * Error codes from get_user_pages(). + * * Error codes from the NE PCI device request. + */ +#define NE_SET_USER_MEMORY_REGION _IOW(0xAE, 0x23, struct ne_user_memory_r= egion) + +/** + * NE_START_ENCLAVE - The command is used to trigger enclave start after t= he + * enclave resources, such as memory and CPU, have been set. + * The enclave start info is an input / output parameter. It + * includes info provided by the caller - enclave cid and + * flags - and returns the cid (if input cid is 0). + * The ioctl can be invoked on the enclave fd, after an + * enclave slot is created and resources, such as memory and + * vCPUs are set for an enclave. + * + * Context: Process context. + * Return: + * * 0 - Logic successfully completed. + * * -1 - There was a failure in the ioctl logic. + * On failure, errno is set to: + * * EFAULT - copy_from_user() / copy_to_user() failure. + * * NE_ERR_NOT_IN_INIT_STATE - The enclave is not in init state + * (init =3D before being started). + * * NE_ERR_NO_MEM_REGIONS_ADDED - No memory regions are set. + * * NE_ERR_NO_VCPUS_ADDED - No vCPUs are set. + * * NE_ERR_FULL_CORES_NOT_USED - Full core(s) not set for the enclave. + * * NE_ERR_ENCLAVE_MEM_MIN_SIZE - Enclave memory is less than minimum + * memory size (64 MiB). + * * NE_ERR_INVALID_FLAG_VALUE - The value of the provided flag is invali= d. + * * NE_ERR_INVALID_ENCLAVE_CID - The provided enclave CID is invalid. + * * Error codes from the NE PCI device request. + */ +#define NE_START_ENCLAVE _IOWR(0xAE, 0x24, struct ne_enclave_start_info) + +/** + * DOC: NE specific error codes + */ + +/** + * NE_ERR_VCPU_ALREADY_USED - The provided vCPU is already used. + */ +#define NE_ERR_VCPU_ALREADY_USED (256) +/** + * NE_ERR_VCPU_NOT_IN_CPU_POOL - The provided vCPU is not available in the + * NE CPU pool. + */ +#define NE_ERR_VCPU_NOT_IN_CPU_POOL (257) +/** + * NE_ERR_VCPU_INVALID_CPU_CORE - The core id of the provided vCPU is inva= lid + * or out of range of the NE CPU pool. + */ +#define NE_ERR_VCPU_INVALID_CPU_CORE (258) +/** + * NE_ERR_INVALID_MEM_REGION_SIZE - The user space memory region size is n= ot + * multiple of 2 MiB. + */ +#define NE_ERR_INVALID_MEM_REGION_SIZE (259) +/** + * NE_ERR_INVALID_MEM_REGION_ADDR - The user space memory region address r= ange + * is invalid. + */ +#define NE_ERR_INVALID_MEM_REGION_ADDR (260) +/** + * NE_ERR_UNALIGNED_MEM_REGION_ADDR - The user space memory region address= is + * not aligned. + */ +#define NE_ERR_UNALIGNED_MEM_REGION_ADDR (261) +/** + * NE_ERR_MEM_REGION_ALREADY_USED - The user space memory region is alread= y used. + */ +#define NE_ERR_MEM_REGION_ALREADY_USED (262) +/** + * NE_ERR_MEM_NOT_HUGE_PAGE - The user space memory region is not backed by + * contiguous physical huge page(s). + */ +#define NE_ERR_MEM_NOT_HUGE_PAGE (263) +/** + * NE_ERR_MEM_DIFFERENT_NUMA_NODE - The user space memory region is backed= by + * pages from different NUMA nodes than the CPUs. + */ +#define NE_ERR_MEM_DIFFERENT_NUMA_NODE (264) +/** + * NE_ERR_MEM_MAX_REGIONS - The supported max memory regions per enclaves = has + * been reached. + */ +#define NE_ERR_MEM_MAX_REGIONS (265) +/** + * NE_ERR_NO_MEM_REGIONS_ADDED - The command to start an enclave is trigge= red + * and no memory regions are added. + */ +#define NE_ERR_NO_MEM_REGIONS_ADDED (266) +/** + * NE_ERR_NO_VCPUS_ADDED - The command to start an enclave is triggered an= d no + * vCPUs are added. + */ +#define NE_ERR_NO_VCPUS_ADDED (267) +/** + * NE_ERR_ENCLAVE_MEM_MIN_SIZE - The enclave memory size is lower than the + * minimum supported. + */ +#define NE_ERR_ENCLAVE_MEM_MIN_SIZE (268) +/** + * NE_ERR_FULL_CORES_NOT_USED - The command to start an enclave is trigger= ed and + * full CPU cores are not set. + */ +#define NE_ERR_FULL_CORES_NOT_USED (269) +/** + * NE_ERR_NOT_IN_INIT_STATE - The enclave is not in init state when setting + * resources or triggering start. + */ +#define NE_ERR_NOT_IN_INIT_STATE (270) +/** + * NE_ERR_INVALID_VCPU - The provided vCPU is out of range of the availabl= e CPUs. + */ +#define NE_ERR_INVALID_VCPU (271) +/** + * NE_ERR_NO_CPUS_AVAIL_IN_POOL - The command to create an enclave is trig= gered + * and no CPUs are available in the pool. + */ +#define NE_ERR_NO_CPUS_AVAIL_IN_POOL (272) +/** + * NE_ERR_INVALID_PAGE_SIZE - The user space memory region is not backed b= y pages + * multiple of 2 MiB. + */ +#define NE_ERR_INVALID_PAGE_SIZE (273) +/** + * NE_ERR_INVALID_FLAG_VALUE - The provided flag value is invalid. + */ +#define NE_ERR_INVALID_FLAG_VALUE (274) +/** + * NE_ERR_INVALID_ENCLAVE_CID - The provided enclave CID is invalid, either + * being a well-known value or the CID of the + * parent / primary VM. + */ +#define NE_ERR_INVALID_ENCLAVE_CID (275) + +/** + * DOC: Image load info flags + */ + +/** + * NE_EIF_IMAGE - Enclave Image Format (EIF) + */ +#define NE_EIF_IMAGE (0x01) + +#define NE_IMAGE_LOAD_MAX_FLAG_VAL (0x02) + +/** + * struct ne_image_load_info - Info necessary for in-memory enclave image + * loading (in / out). + * @flags: Flags to determine the enclave image type + * (e.g. Enclave Image Format - EIF) (in). + * @memory_offset: Offset in enclave memory where to start placing the + * enclave image (out). + */ +struct ne_image_load_info { + uint64_t flags; + uint64_t memory_offset; +}; + +/** + * DOC: User memory region flags + */ + +/** + * NE_DEFAULT_MEMORY_REGION - Memory region for enclave general usage. + */ +#define NE_DEFAULT_MEMORY_REGION (0x00) + +#define NE_MEMORY_REGION_MAX_FLAG_VAL (0x01) + +/** + * struct ne_user_memory_region - Memory region to be set for an enclave (= in). + * @flags: Flags to determine the usage for the memory region (in). + * @memory_size: The size, in bytes, of the memory region to be set for + * an enclave (in). + * @userspace_addr: The start address of the userspace allocated memory of + * the memory region to set for an enclave (in). + */ +struct ne_user_memory_region { + uint64_t flags; + uint64_t memory_size; + uint64_t userspace_addr; +}; + +/** + * DOC: Enclave start info flags + */ + +/** + * NE_ENCLAVE_PRODUCTION_MODE - Start enclave in production mode. + */ +#define NE_ENCLAVE_PRODUCTION_MODE (0x00) +/** + * NE_ENCLAVE_DEBUG_MODE - Start enclave in debug mode. + */ +#define NE_ENCLAVE_DEBUG_MODE (0x01) + +#define NE_ENCLAVE_START_MAX_FLAG_VAL (0x02) + +/** + * struct ne_enclave_start_info - Setup info necessary for enclave start (= in / out). + * @flags: Flags for the enclave to start with (e.g. debug mode) (in). + * @enclave_cid: Context ID (CID) for the enclave vsock device. If 0 as + * input, the CID is autogenerated by the hypervisor and + * returned back as output by the driver (in / out). + */ +struct ne_enclave_start_info { + uint64_t flags; + uint64_t enclave_cid; +}; + +#endif /* _LINUX_NITRO_ENCLAVES_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 From nobody Sun Apr 12 04:21:00 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=1772030918; cv=none; d=zohomail.com; s=zohoarc; b=Xohwmeza6m8H5uWP51S1QdEBDAYHQ4MNAtolsdFjiq139jks7/95MTUzFYlqgkhzxZTbW6wXwo1SoRkvePBpXgyHYTi9Zvb8fLHS/FqwyFLYr+rcWPN+jumOHtM1HtmkheCOO7gAgq2fxLwjrG4C+f15XkVhMSsr1fem0//mqD4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772030918; 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=hKg80vcjhwVyaAMjAPlJL47yWajpQhi5gfbyyrIibqE=; b=fXdDOOuk8yI5ITbf/mk++4ZKOq6tm2mYJdjh11lwWAQb1hZrMUZNkm+iwdcVRpi+20DKak0IrESUzDGQZXPOalvO/zxX+Ia/dv5MYPMMNGP4vV65priHNbXBRBHhP07y+Tsszx2tKj6ULT6prOyUAoo7Ed1FC/mvXmOQa23bfi8= 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 1772030918155422.72021683314927; Wed, 25 Feb 2026 06:48:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vvG9a-00007I-NS; Wed, 25 Feb 2026 09:46:18 -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 1vvG9X-0008Uv-KR; Wed, 25 Feb 2026 09:46:15 -0500 Received: from pdx-out-011.esa.us-west-2.outbound.mail-perimeter.amazon.com ([52.35.192.45]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vvG9V-00072u-H4; Wed, 25 Feb 2026 09:46:15 -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-011.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2026 14:46:09 +0000 Received: from EX19MTAUWC001.ant.amazon.com [205.251.233.105:31052] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.24.86:2525] with esmtp (Farcaster) id 12cfcd48-3135-4f67-ae35-18cf33c8a226; Wed, 25 Feb 2026 14:46:08 +0000 (UTC) Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) 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:08 +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:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1772030773; x=1803566773; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hKg80vcjhwVyaAMjAPlJL47yWajpQhi5gfbyyrIibqE=; b=EdJTncriHIHoRsg0w4inOs/+aVzOHY2x2fVP9J7T2TnF7Wx1lpsGdLoN Kf4KMfv5BoBKsT8lAn0gzpfxv/6naHR1jaQrN1PvY9Z4LvfJbqlZsQNNO IekvhakonS6W+aMkAA/Ft2eaMS6dhqN2ZEy8hYJpZcSPbGM64ZzdasJkB g7pwC2Q/J7BNk2POIDY9IW9JTU4JSnDk4bH6truN8PvxKVU6Zs1OxWcct h+JonyHQa+J9UI1g0Ay7Pjcxu2x+xqzd8sdTyaIYObs2l63HlX6OVHgNt 67b5P6WVvF3alR0nTVuxyS08y6McibGUEd1pf6wI95y5TNWb+gtJOxCnH Q==; X-CSE-ConnectionGUID: KKxXyajsTguQL4BYyWVdug== X-CSE-MsgGUID: 5RCZ8ANVTaaUnDZXPloiLA== X-IronPort-AV: E=Sophos;i="6.21,310,1763424000"; d="scan'208";a="13551622" X-Farcaster-Flow-ID: 12cfcd48-3135-4f67-ae35-18cf33c8a226 From: Alexander Graf To: CC: , Peter Maydell , "Thomas Huth" , , , , , Cornelia Huck , , Dorjoy Chowdhury , Pierrick Bouvier , Paolo Bonzini , Tyler Fanelli , , Subject: [PATCH v2 03/11] hw/nitro: Add Nitro Vsock Bus Date: Wed, 25 Feb 2026 14:45:22 +0000 Message-ID: <20260225144532.84673-4-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: EX19D032UWA002.ant.amazon.com (10.13.139.81) 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=52.35.192.45; envelope-from=prvs=509822c20=graf@amazon.de; helo=pdx-out-011.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: 1772030919470158500 Add a dedicated bus for Nitro Enclave vsock devices. In Nitro Enclaves, communication between parent and enclave/hypervisor happens almost exclusively through vsock. The nitro-vsock-bus models this dependency in QEMU, which allows devices in this bus to implement individual services on top of vsock. The nitro machine spawns this bus by creating the included nitro-vsock-bridge sysbus device. The nitro accel then advertises the Enclave's CID to the bus by calling nitro_vsock_bridge_start_enclave() on the bridge device as soon as it knows the CID. Nitro vsock devices can listen to that event and learn the Enclave's CID when it is available to perform actions, such as connect to the debug serial vsock port. Suggested-by: Paolo Bonzini Signed-off-by: Alexander Graf --- MAINTAINERS | 6 ++ hw/Kconfig | 1 + hw/meson.build | 1 + hw/nitro/Kconfig | 2 + hw/nitro/meson.build | 1 + hw/nitro/nitro-vsock-bus.c | 98 ++++++++++++++++++++++++++++++ hw/nitro/trace-events | 2 + hw/nitro/trace.h | 4 ++ include/hw/nitro/nitro-vsock-bus.h | 71 ++++++++++++++++++++++ meson.build | 1 + 10 files changed, 187 insertions(+) create mode 100644 hw/nitro/Kconfig create mode 100644 hw/nitro/meson.build create mode 100644 hw/nitro/nitro-vsock-bus.c create mode 100644 hw/nitro/trace-events create mode 100644 hw/nitro/trace.h create mode 100644 include/hw/nitro/nitro-vsock-bus.h diff --git a/MAINTAINERS b/MAINTAINERS index d3aa6d6732..44da7a5fc5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3016,6 +3016,12 @@ F: hw/vmapple/* F: include/hw/vmapple/* F: docs/system/arm/vmapple.rst =20 +Nitro Enclaves (native) +M: Alexander Graf +S: Maintained +F: hw/nitro/ +F: include/hw/nitro/ + Subsystems ---------- Overall Audio backends diff --git a/hw/Kconfig b/hw/Kconfig index f8f92b5d03..b3ce1520a6 100644 --- a/hw/Kconfig +++ b/hw/Kconfig @@ -22,6 +22,7 @@ source isa/Kconfig source mem/Kconfig source misc/Kconfig source net/Kconfig +source nitro/Kconfig source nubus/Kconfig source nvme/Kconfig source nvram/Kconfig diff --git a/hw/meson.build b/hw/meson.build index 66e46b8090..36da5322f7 100644 --- a/hw/meson.build +++ b/hw/meson.build @@ -44,6 +44,7 @@ subdir('isa') subdir('mem') subdir('misc') subdir('net') +subdir('nitro') subdir('nubus') subdir('nvme') subdir('nvram') diff --git a/hw/nitro/Kconfig b/hw/nitro/Kconfig new file mode 100644 index 0000000000..767472cb2c --- /dev/null +++ b/hw/nitro/Kconfig @@ -0,0 +1,2 @@ +config NITRO_VSOCK_BUS + bool diff --git a/hw/nitro/meson.build b/hw/nitro/meson.build new file mode 100644 index 0000000000..7e2807f137 --- /dev/null +++ b/hw/nitro/meson.build @@ -0,0 +1 @@ +system_ss.add(when: 'CONFIG_NITRO_VSOCK_BUS', if_true: files('nitro-vsock-= bus.c')) diff --git a/hw/nitro/nitro-vsock-bus.c b/hw/nitro/nitro-vsock-bus.c new file mode 100644 index 0000000000..eed29df512 --- /dev/null +++ b/hw/nitro/nitro-vsock-bus.c @@ -0,0 +1,98 @@ +/* + * Nitro Enclave Vsock Bus + * + * Copyright =C2=A9 2026 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * Authors: + * Alexander Graf + * + * A bus for Nitro Enclave vsock devices. In Nitro Enclaves, communication + * between parent and enclave/hypervisor happens almost exclusively through + * vsock. The nitro-vsock-bus models this dependency in QEMU, which allows + * devices in this bus to implement individual services on top of vsock. + * + * The nitro accel advertises the Enclave's CID to the bus by calling + * nitro_vsock_bridge_start_enclave() on the bridge device as soon as it + * knows the CID. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "monitor/qdev.h" +#include "hw/core/sysbus.h" +#include "hw/nitro/nitro-vsock-bus.h" + +void nitro_vsock_bridge_start_enclave(NitroVsockBridge *bridge, + uint32_t enclave_cid, Error **errp) +{ + ERRP_GUARD(); + BusState *qbus =3D BUS(&bridge->bus); + BusChild *kid; + + bridge->enclave_cid =3D enclave_cid; + + QTAILQ_FOREACH(kid, &qbus->children, sibling) { + NitroVsockDevice *ndev =3D NITRO_VSOCK_DEVICE(kid->child); + NitroVsockDeviceClass *ndc =3D NITRO_VSOCK_DEVICE_GET_CLASS(ndev); + + if (ndc->enclave_started) { + ndc->enclave_started(ndev, enclave_cid, errp); + if (*errp) { + return; + } + } + } +} + +NitroVsockBridge *nitro_vsock_bridge_create(void) +{ + DeviceState *dev =3D qdev_new(TYPE_NITRO_VSOCK_BRIDGE); + + qdev_set_id(dev, g_strdup("nitro-vsock"), &error_fatal); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + + return NITRO_VSOCK_BRIDGE(dev); +} + +static void nitro_vsock_bridge_init(Object *obj) +{ + NitroVsockBridge *s =3D NITRO_VSOCK_BRIDGE(obj); + + qbus_init(&s->bus, sizeof(s->bus), TYPE_NITRO_VSOCK_BUS, + DEVICE(s), "nitro-vsock"); + object_property_add_uint32_ptr(obj, "enclave-cid", + &s->enclave_cid, OBJ_PROP_FLAG_READ); +} + +static void nitro_vsock_device_class_init(ObjectClass *oc, const void *dat= a) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + + dc->bus_type =3D TYPE_NITRO_VSOCK_BUS; +} + +static const TypeInfo nitro_vsock_bus_types[] =3D { + { + .name =3D TYPE_NITRO_VSOCK_BUS, + .parent =3D TYPE_BUS, + .instance_size =3D sizeof(NitroVsockBus), + }, + { + .name =3D TYPE_NITRO_VSOCK_BRIDGE, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(NitroVsockBridge), + .instance_init =3D nitro_vsock_bridge_init, + }, + { + .name =3D TYPE_NITRO_VSOCK_DEVICE, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(NitroVsockDevice), + .class_size =3D sizeof(NitroVsockDeviceClass), + .class_init =3D nitro_vsock_device_class_init, + .abstract =3D true, + }, +}; + +DEFINE_TYPES(nitro_vsock_bus_types); diff --git a/hw/nitro/trace-events b/hw/nitro/trace-events new file mode 100644 index 0000000000..9ccc579048 --- /dev/null +++ b/hw/nitro/trace-events @@ -0,0 +1,2 @@ +# See docs/devel/tracing.rst for syntax documentation. + diff --git a/hw/nitro/trace.h b/hw/nitro/trace.h new file mode 100644 index 0000000000..b455d6c17b --- /dev/null +++ b/hw/nitro/trace.h @@ -0,0 +1,4 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include "trace/trace-hw_nitro.h" diff --git a/include/hw/nitro/nitro-vsock-bus.h b/include/hw/nitro/nitro-vs= ock-bus.h new file mode 100644 index 0000000000..064260aa41 --- /dev/null +++ b/include/hw/nitro/nitro-vsock-bus.h @@ -0,0 +1,71 @@ +/* + * Nitro Enclave Vsock Bus + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_NITRO_VSOCK_BUS_H +#define HW_NITRO_VSOCK_BUS_H + +#include "hw/core/qdev.h" +#include "hw/core/sysbus.h" +#include "qom/object.h" + +#define TYPE_NITRO_VSOCK_BUS "nitro-vsock-bus" +OBJECT_DECLARE_SIMPLE_TYPE(NitroVsockBus, NITRO_VSOCK_BUS) + +#define TYPE_NITRO_VSOCK_BRIDGE "nitro-vsock-bridge" +OBJECT_DECLARE_SIMPLE_TYPE(NitroVsockBridge, NITRO_VSOCK_BRIDGE) + +#define TYPE_NITRO_VSOCK_DEVICE "nitro-vsock-device" +OBJECT_DECLARE_TYPE(NitroVsockDevice, NitroVsockDeviceClass, + NITRO_VSOCK_DEVICE) + +struct NitroVsockBus { + BusState parent_obj; +}; + +struct NitroVsockBridge { + SysBusDevice parent_obj; + + NitroVsockBus bus; + uint32_t enclave_cid; +}; + +struct NitroVsockDevice { + DeviceState parent_obj; +}; + +struct NitroVsockDeviceClass { + DeviceClass parent_class; + + /* + * Called after the enclave has been started and the CID is known. + * Devices use this to establish vsock connections to the enclave. + */ + void (*enclave_started)(NitroVsockDevice *dev, uint32_t enclave_cid, + Error **errp); +}; + +/* + * Machine helper to create the Nitro vsock bridge sysbus device. + */ +NitroVsockBridge *nitro_vsock_bridge_create(void); + +/* + * Find the Nitro vsock bridge on the sysbus. + */ +static inline NitroVsockBridge *nitro_vsock_bridge_find(void) +{ + return NITRO_VSOCK_BRIDGE( + object_resolve_path_type("", TYPE_NITRO_VSOCK_BRIDGE, NULL)); +} + +/* + * Notify the bridge that the enclave has started. Dispatches + * enclave_started() to all devices on the bus. + */ +void nitro_vsock_bridge_start_enclave(NitroVsockBridge *bridge, + uint32_t enclave_cid, Error **errp); + +#endif /* HW_NITRO_VSOCK_BUS_H */ diff --git a/meson.build b/meson.build index 4af32c3e1f..b68dbae072 100644 --- a/meson.build +++ b/meson.build @@ -3623,6 +3623,7 @@ if have_system 'hw/misc/macio', 'hw/net', 'hw/net/can', + 'hw/nitro', 'hw/nubus', 'hw/nvme', 'hw/nvram', --=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 From nobody Sun Apr 12 04:21:00 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=1772030941; cv=none; d=zohomail.com; s=zohoarc; b=jtt0jdqfjK0Gytw4HSlPnc3H/OdEnPlkQn6TBaw6LtHNScONlSd7oA1GUXP53DXeg9JDcrm3GoOK2l+pLkWzdtljerDS7JoT4M28/Tg3lEDLREiQn967vjBUHz8jvpXITi/mDY30l55VsEQJ4nmEyJBp614EC/it9B45G19EkHA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772030941; 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=8hZp/EVYttZZkhYmHdcCRCp+oQfw69cfSfMA/IAoNfU=; b=AxYWXyLHPnW+KmK/c+qEQy/vLInAFzqxJedEUarv53rPANKJp+nzHkCBLn2jqYGeSsGxeDiz7VCkSRJeNs88P81WvmzEIFX5xTDsc/v4wIZw8lNbB9Lcs2mVKUYIOoBDHFsHMed4VNNLJy7MIzC+bH6m0rmWUfg6HnNj31U1ydg= 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 1772030941413753.8053036362127; Wed, 25 Feb 2026 06:49:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vvG9d-0000BY-Ay; Wed, 25 Feb 2026 09:46:21 -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 1vvG9b-00008r-D9; Wed, 25 Feb 2026 09:46:19 -0500 Received: from pdx-out-005.esa.us-west-2.outbound.mail-perimeter.amazon.com ([52.13.214.179]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vvG9Y-000736-F7; Wed, 25 Feb 2026 09:46:19 -0500 Received: from ip-10-5-12-219.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.12.219]) by internal-pdx-out-005.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2026 14:46:11 +0000 Received: from EX19MTAUWB002.ant.amazon.com [205.251.233.111:28365] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.36.66:2525] with esmtp (Farcaster) id 221666b9-1fb8-4b39-bbda-241d5ce25b09; Wed, 25 Feb 2026 14:46:11 +0000 (UTC) Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWB002.ant.amazon.com (10.250.64.231) 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:11 +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:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1772030776; x=1803566776; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8hZp/EVYttZZkhYmHdcCRCp+oQfw69cfSfMA/IAoNfU=; b=rLlSYgmB6FqaePBoF9MBEA3Un3ioJljOvp5fgTJGHvWCGSf5AWffzZVh ItQgM1KZgNkTOiA6wwsVfR9BJRWKoQDznMrazgTA0zaEI/YJOORZNWFyk IFD2t+M49Q2tXjqfN6WQlrffb61bBNSIXSBWLA2PN6ZCtpW4FDgUtY4rO vVqo5XQhyiWDvfcepwpsiSAeVXf3HNtLPcV3wwkLhE7Dq3P4efxNqBdVJ nQuq0V7yvyE7/9jOOuL8sCJyddYd9vBWw0M/eJ1bT23Tm6bbjG0u/Oyg5 632GIC+0cSpMF0iqLvHkhlACZdrfbUey4CPIGk67690Qp2KQWPT8Q1LAa Q==; X-CSE-ConnectionGUID: 80IdUcSEQmKwP8zgyQgG2Q== X-CSE-MsgGUID: In4P0eY5T7qf7PnP1WiejQ== X-IronPort-AV: E=Sophos;i="6.21,310,1763424000"; d="scan'208";a="13768558" X-Farcaster-Flow-ID: 221666b9-1fb8-4b39-bbda-241d5ce25b09 From: Alexander Graf To: CC: , Peter Maydell , "Thomas Huth" , , , , , Cornelia Huck , , Dorjoy Chowdhury , Pierrick Bouvier , Paolo Bonzini , Tyler Fanelli , , Subject: [PATCH v2 04/11] accel: Add Nitro Enclaves accelerator Date: Wed, 25 Feb 2026 14:45:23 +0000 Message-ID: <20260225144532.84673-5-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: EX19D032UWA002.ant.amazon.com (10.13.139.81) 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=52.13.214.179; envelope-from=prvs=509822c20=graf@amazon.de; helo=pdx-out-005.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: 1772030943799158500 Nitro Enclaves are a confidential compute technology which allows a parent instance to carve out resources from itself and spawn a confidential sibling VM next to itself. Similar to other confidential compute solutions, this sibling is controlled by an underlying vmm, but still has a higher level vmm (QEMU) to implement some of its I/O functionality and lifecycle. Add an accelerator to drive this interface. In combination with follow-on patches to enhance the Nitro Enclaves machine model, this will allow users to run a Nitro Enclave using QEMU. Signed-off-by: Alexander Graf --- v1 -> v2: - Use dummy, move cpu init to post - Trigger nitro-vsock-bridge instead of QOM properties --- MAINTAINERS | 6 + accel/Kconfig | 3 + accel/meson.build | 1 + accel/nitro/meson.build | 3 + accel/nitro/nitro-accel.c | 278 ++++++++++++++++++++++++++++++++++ accel/nitro/trace-events | 6 + accel/nitro/trace.h | 2 + accel/stubs/meson.build | 1 + accel/stubs/nitro-stub.c | 11 ++ include/system/hw_accel.h | 1 + include/system/nitro-accel.h | 25 +++ meson.build | 11 ++ meson_options.txt | 2 + qemu-options.hx | 8 +- scripts/meson-buildoptions.sh | 3 + 15 files changed, 357 insertions(+), 4 deletions(-) create mode 100644 accel/nitro/meson.build create mode 100644 accel/nitro/nitro-accel.c create mode 100644 accel/nitro/trace-events create mode 100644 accel/nitro/trace.h create mode 100644 accel/stubs/nitro-stub.c create mode 100644 include/system/nitro-accel.h diff --git a/MAINTAINERS b/MAINTAINERS index 44da7a5fc5..53ce075e9a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -583,6 +583,12 @@ F: include/system/mshv.h F: include/hw/hyperv/hvgdk*.h F: include/hw/hyperv/hvhdk*.h =20 +Nitro Enclaves (native) +M: Alexander Graf +S: Maintained +F: accel/nitro/ +F: include/system/nitro-accel.h + X86 MSHV CPUs M: Magnus Kulke R: Wei Liu diff --git a/accel/Kconfig b/accel/Kconfig index a60f114923..6d052875ee 100644 --- a/accel/Kconfig +++ b/accel/Kconfig @@ -16,6 +16,9 @@ config KVM config MSHV bool =20 +config NITRO + bool + config XEN bool select FSDEV_9P if VIRTFS diff --git a/accel/meson.build b/accel/meson.build index 289b7420ff..7da12b9741 100644 --- a/accel/meson.build +++ b/accel/meson.build @@ -12,6 +12,7 @@ if have_system subdir('xen') subdir('stubs') subdir('mshv') + subdir('nitro') endif =20 # qtest diff --git a/accel/nitro/meson.build b/accel/nitro/meson.build new file mode 100644 index 0000000000..e01c1bab96 --- /dev/null +++ b/accel/nitro/meson.build @@ -0,0 +1,3 @@ +nitro_ss =3D ss.source_set() +nitro_ss.add(files('nitro-accel.c')) +system_ss.add_all(when: 'CONFIG_NITRO', if_true: nitro_ss) diff --git a/accel/nitro/nitro-accel.c b/accel/nitro/nitro-accel.c new file mode 100644 index 0000000000..c92bda3227 --- /dev/null +++ b/accel/nitro/nitro-accel.c @@ -0,0 +1,278 @@ +/* + * Nitro Enclaves accelerator + * + * Copyright =C2=A9 2026 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * Authors: + * Alexander Graf + * + * Nitro Enclaves are a confidential compute technology which + * allows a parent instance to carve out resources from itself + * and spawn a confidential sibling VM next to itself. Similar + * to other confidential compute solutions, this sibling is + * controlled by an underlying vmm, but still has a higher level + * vmm (QEMU) to implement some of its I/O functionality and + * lifecycle. + * + * This accelerator drives /dev/nitro_enclaves to spawn a Nitro + * Enclave. It works in tandem with the nitro_enclaves machine + * which ensures the correct backend devices are available and + * that the initial seed (an EIF file) is loaded at the correct + * offset in memory. + * + * The accel starts the enclave when the machine starts, after + * all device setup is finished. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "qapi/error.h" +#include "qapi/visitor.h" +#include "qemu/module.h" +#include "qemu/rcu.h" +#include "qemu/accel.h" +#include "qemu/guest-random.h" +#include "qemu/main-loop.h" +#include "accel/accel-ops.h" +#include "accel/accel-cpu-ops.h" +#include "accel/dummy-cpus.h" +#include "system/cpus.h" +#include "hw/core/cpu.h" +#include "hw/core/boards.h" +#include "hw/nitro/nitro-vsock-bus.h" +#include "system/ramblock.h" +#include "system/nitro-accel.h" +#include "trace.h" + +#include +#include "standard-headers/linux/nitro_enclaves.h" + +bool nitro_allowed; + +typedef struct NitroAccelState { + AccelState parent_obj; + + int ne_fd; + int enclave_fd; + uint64_t slot_uid; + uint64_t enclave_cid; + bool debug_mode; +} NitroAccelState; + +static int nitro_init_machine(AccelState *as, MachineState *ms) +{ + NitroAccelState *s =3D NITRO_ACCEL(as); + uint64_t slot_uid =3D 0; + int ret; + + s->ne_fd =3D open("/dev/nitro_enclaves", O_RDWR | O_CLOEXEC); + if (s->ne_fd < 0) { + error_report("nitro: failed to open /dev/nitro_enclaves: %s", + strerror(errno)); + return -errno; + } + + ret =3D ioctl(s->ne_fd, NE_CREATE_VM, &slot_uid); + if (ret < 0) { + error_report("nitro: NE_CREATE_VM failed: %s", strerror(errno)); + close(s->ne_fd); + return -errno; + } + s->enclave_fd =3D ret; + s->slot_uid =3D slot_uid; + + return 0; +} + +static int nitro_donate_ram_block(RAMBlock *rb, void *opaque) +{ + NitroAccelState *s =3D opaque; + struct ne_user_memory_region region =3D { + .flags =3D 0, + .memory_size =3D rb->used_length, + .userspace_addr =3D (uint64_t)(uintptr_t)rb->host, + }; + + if (!rb->used_length) { + return 0; + } + + if (ioctl(s->enclave_fd, NE_SET_USER_MEMORY_REGION, ®ion) < 0) { + error_report("nitro: NE_SET_USER_MEMORY_REGION failed for %s " + "(%" PRIu64 " bytes): %s", rb->idstr, rb->used_length, + strerror(errno)); + return -errno; + } + return 0; +} + +/* + * Start the Enclave. At this point memory is set up and the EIF is loaded. + * This function donates memory, adds vCPUs, and starts the enclave. + */ +static void nitro_setup_post(AccelState *as) +{ + MachineState *ms =3D MACHINE(qdev_get_machine()); + NitroAccelState *s =3D NITRO_ACCEL(as); + int nr_cpus =3D ms->smp.cpus; + int i, ret; + struct ne_enclave_start_info start_info =3D { + .flags =3D s->debug_mode ? NE_ENCLAVE_DEBUG_MODE : 0, + .enclave_cid =3D s->enclave_cid, + }; + + ret =3D qemu_ram_foreach_block(nitro_donate_ram_block, s); + if (ret < 0) { + error_report("nitro: failed to donate memory"); + exit(1); + } + + for (i =3D 0; i < nr_cpus; i++) { + uint32_t cpu_id =3D 0; + if (ioctl(s->enclave_fd, NE_ADD_VCPU, &cpu_id) < 0) { + error_report("nitro: NE_ADD_VCPU failed: %s", strerror(errno)); + exit(1); + } + } + + ret =3D ioctl(s->enclave_fd, NE_START_ENCLAVE, &start_info); + if (ret < 0) { + switch (errno) { + case NE_ERR_NO_MEM_REGIONS_ADDED: + error_report("nitro: no memory regions added"); + break; + case NE_ERR_NO_VCPUS_ADDED: + error_report("nitro: no vCPUs added"); + break; + case NE_ERR_ENCLAVE_MEM_MIN_SIZE: + error_report("nitro: memory is below the minimum " + "required size. Try increasing -m"); + break; + case NE_ERR_FULL_CORES_NOT_USED: + error_report("nitro: requires full CPU cores. " + "Try increasing -smp to a multiple of threads " + "per core on this host (e.g. -smp 2)"); + break; + case NE_ERR_NOT_IN_INIT_STATE: + error_report("nitro: not in init state"); + break; + case NE_ERR_INVALID_FLAG_VALUE: + error_report("nitro: invalid flag value for NE_START_ENCLAVE"); + break; + case NE_ERR_INVALID_ENCLAVE_CID: + error_report("nitro: invalid enclave CID"); + break; + default: + error_report("nitro: NE_START_ENCLAVE failed: %s (errno %d)", + strerror(errno), errno); + break; + } + exit(1); + } + + s->enclave_cid =3D start_info.enclave_cid; + trace_nitro_enclave_started(s->enclave_cid); + + /* + * Notify all Nitro vsock bus devices that the enclave has started + * and provide them with the CID for vsock connections. + */ + { + NitroVsockBridge *bridge =3D nitro_vsock_bridge_find(); + Error *err =3D NULL; + + if (bridge) { + nitro_vsock_bridge_start_enclave(bridge, + (uint32_t)s->enclave_cid, &er= r); + if (err) { + error_report_err(err); + exit(1); + } + } + } +} + +/* QOM properties */ + +static bool nitro_get_debug_mode(Object *obj, Error **errp) +{ + return NITRO_ACCEL(obj)->debug_mode; +} + +static void nitro_set_debug_mode(Object *obj, bool value, Error **errp) +{ + NITRO_ACCEL(obj)->debug_mode =3D value; +} + +static void nitro_get_enclave_cid(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + uint64_t val =3D NITRO_ACCEL(obj)->enclave_cid; + visit_type_uint64(v, name, &val, errp); +} + +static void nitro_set_enclave_cid(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + uint64_t val; + if (visit_type_uint64(v, name, &val, errp)) { + NITRO_ACCEL(obj)->enclave_cid =3D val; + } +} + +static void nitro_accel_class_init(ObjectClass *oc, const void *data) +{ + AccelClass *ac =3D ACCEL_CLASS(oc); + ac->name =3D "Nitro"; + ac->init_machine =3D nitro_init_machine; + ac->setup_post =3D nitro_setup_post; + ac->allowed =3D &nitro_allowed; + + object_class_property_add_bool(oc, "debug-mode", + nitro_get_debug_mode, + nitro_set_debug_mode); + object_class_property_set_description(oc, "debug-mode", + "Start enclave in debug mode (enables console output)"); + + object_class_property_add(oc, "enclave-cid", "uint64", + nitro_get_enclave_cid, + nitro_set_enclave_cid, + NULL, NULL); + object_class_property_set_description(oc, "enclave-cid", + "Enclave CID (0 =3D auto-assigned by Nitro)"); +} + +static const TypeInfo nitro_accel_type =3D { + .name =3D TYPE_NITRO_ACCEL, + .parent =3D TYPE_ACCEL, + .instance_size =3D sizeof(NitroAccelState), + .class_init =3D nitro_accel_class_init, +}; +module_obj(TYPE_NITRO_ACCEL); + +static void nitro_accel_ops_class_init(ObjectClass *oc, const void *data) +{ + AccelOpsClass *ops =3D ACCEL_OPS_CLASS(oc); + ops->create_vcpu_thread =3D dummy_start_vcpu_thread; + ops->handle_interrupt =3D generic_handle_interrupt; +} + +static const TypeInfo nitro_accel_ops_type =3D { + .name =3D ACCEL_OPS_NAME("nitro"), + .parent =3D TYPE_ACCEL_OPS, + .class_init =3D nitro_accel_ops_class_init, + .abstract =3D true, +}; +module_obj(ACCEL_OPS_NAME("nitro")); + +static void nitro_type_init(void) +{ + type_register_static(&nitro_accel_type); + type_register_static(&nitro_accel_ops_type); +} + +type_init(nitro_type_init); diff --git a/accel/nitro/trace-events b/accel/nitro/trace-events new file mode 100644 index 0000000000..9673eb5aa2 --- /dev/null +++ b/accel/nitro/trace-events @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# See docs/devel/tracing.rst for syntax documentation. + +# nitro-accel.c +nitro_enclave_started(uint64_t cid) "nitro: enclave started, CID=3D%"PRIu64 diff --git a/accel/nitro/trace.h b/accel/nitro/trace.h new file mode 100644 index 0000000000..8c5564725d --- /dev/null +++ b/accel/nitro/trace.h @@ -0,0 +1,2 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#include "trace/trace-accel_nitro.h" diff --git a/accel/stubs/meson.build b/accel/stubs/meson.build index 48eccd1b86..5de4a279ff 100644 --- a/accel/stubs/meson.build +++ b/accel/stubs/meson.build @@ -3,6 +3,7 @@ system_stubs_ss.add(when: 'CONFIG_XEN', if_false: files('xe= n-stub.c')) system_stubs_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c')) system_stubs_ss.add(when: 'CONFIG_TCG', if_false: files('tcg-stub.c')) system_stubs_ss.add(when: 'CONFIG_HVF', if_false: files('hvf-stub.c')) +system_stubs_ss.add(when: 'CONFIG_NITRO', if_false: files('nitro-stub.c')) system_stubs_ss.add(when: 'CONFIG_NVMM', if_false: files('nvmm-stub.c')) system_stubs_ss.add(when: 'CONFIG_WHPX', if_false: files('whpx-stub.c')) system_stubs_ss.add(when: 'CONFIG_MSHV', if_false: files('mshv-stub.c')) diff --git a/accel/stubs/nitro-stub.c b/accel/stubs/nitro-stub.c new file mode 100644 index 0000000000..186c8444f8 --- /dev/null +++ b/accel/stubs/nitro-stub.c @@ -0,0 +1,11 @@ +/* + * Nitro accel stubs for QEMU + * + * Copyright =C2=A9 2026 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" + +bool nitro_allowed; diff --git a/include/system/hw_accel.h b/include/system/hw_accel.h index 628a50e066..f0c10b6d80 100644 --- a/include/system/hw_accel.h +++ b/include/system/hw_accel.h @@ -17,6 +17,7 @@ #include "system/mshv.h" #include "system/whpx.h" #include "system/nvmm.h" +#include "system/nitro-accel.h" =20 /** * cpu_synchronize_state: diff --git a/include/system/nitro-accel.h b/include/system/nitro-accel.h new file mode 100644 index 0000000000..a93aa6fb00 --- /dev/null +++ b/include/system/nitro-accel.h @@ -0,0 +1,25 @@ +/* + * Nitro Enclaves accelerator - public interface + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef SYSTEM_NITRO_ACCEL_H +#define SYSTEM_NITRO_ACCEL_H + +#include "qemu/accel.h" + +extern bool nitro_allowed; + +static inline bool nitro_enabled(void) +{ + return nitro_allowed; +} + +#define TYPE_NITRO_ACCEL ACCEL_CLASS_NAME("nitro") + +typedef struct NitroAccelState NitroAccelState; +DECLARE_INSTANCE_CHECKER(NitroAccelState, NITRO_ACCEL, + TYPE_NITRO_ACCEL) + +#endif /* SYSTEM_NITRO_ACCEL_H */ diff --git a/meson.build b/meson.build index b68dbae072..3c6fa7a55a 100644 --- a/meson.build +++ b/meson.build @@ -302,11 +302,13 @@ accelerator_targets +=3D { 'CONFIG_XEN': xen_targets } if cpu =3D=3D 'aarch64' accelerator_targets +=3D { 'CONFIG_HVF': ['aarch64-softmmu'], + 'CONFIG_NITRO': ['aarch64-softmmu'], 'CONFIG_WHPX': ['aarch64-softmmu'] } elif cpu =3D=3D 'x86_64' accelerator_targets +=3D { 'CONFIG_HVF': ['x86_64-softmmu'], + 'CONFIG_NITRO': ['x86_64-softmmu'], 'CONFIG_NVMM': ['i386-softmmu', 'x86_64-softmmu'], 'CONFIG_WHPX': ['i386-softmmu', 'x86_64-softmmu'], 'CONFIG_MSHV': ['x86_64-softmmu'], @@ -881,6 +883,11 @@ if get_option('hvf').allowed() endif endif =20 +nitro =3D not_found +if get_option('nitro').allowed() and host_os =3D=3D 'linux' + accelerators +=3D 'CONFIG_NITRO' +endif + nvmm =3D not_found if host_os =3D=3D 'netbsd' nvmm =3D cc.find_library('nvmm', required: get_option('nvmm')) @@ -922,6 +929,9 @@ endif if 'CONFIG_HVF' not in accelerators and get_option('hvf').enabled() error('HVF not available on this platform') endif +if 'CONFIG_NITRO' not in accelerators and get_option('nitro').enabled() + error('NITRO not available on this platform') +endif if 'CONFIG_NVMM' not in accelerators and get_option('nvmm').enabled() error('NVMM not available on this platform') endif @@ -3593,6 +3603,7 @@ if have_system 'accel/hvf', 'accel/kvm', 'accel/mshv', + 'accel/nitro', 'audio', 'backends', 'backends/tpm', diff --git a/meson_options.txt b/meson_options.txt index 2836156257..31d5916cfc 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -79,6 +79,8 @@ option('whpx', type: 'feature', value: 'auto', description: 'WHPX acceleration support') option('hvf', type: 'feature', value: 'auto', description: 'HVF acceleration support') +option('nitro', type: 'feature', value: 'auto', + description: 'Nitro acceleration support') option('nvmm', type: 'feature', value: 'auto', description: 'NVMM acceleration support') option('xen', type: 'feature', value: 'auto', diff --git a/qemu-options.hx b/qemu-options.hx index 33fcfe7ce6..9b6fb247f7 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -28,7 +28,7 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ "-machine [type=3D]name[,prop[=3Dvalue][,...]]\n" " selects emulated machine ('-machine help' for list)\n" " property accel=3Daccel1[:accel2[:...]] selects accele= rator\n" - " supported accelerators are kvm, xen, hvf, nvmm, whpx,= mshv or tcg (default: tcg)\n" + " supported accelerators are kvm, xen, hvf, nitro, nvmm= , whpx, mshv or tcg (default: tcg)\n" " vmport=3Don|off|auto controls emulation of vmport (de= fault: auto)\n" " dump-guest-core=3Don|off include guest memory in a co= re dump (default=3Don)\n" " mem-merge=3Don|off controls memory merge support (def= ault: on)\n" @@ -67,7 +67,7 @@ SRST =20 ``accel=3Daccels1[:accels2[:...]]`` This is used to enable an accelerator. Depending on the target - architecture, kvm, xen, hvf, nvmm, whpx, mshv or tcg can be + architecture, kvm, xen, hvf, nitro, nvmm, whpx, mshv or tcg can be available. By default, tcg is used. If there is more than one accelerator specified, the next one is used if the previous one fails to initialize. @@ -228,7 +228,7 @@ ERST =20 DEF("accel", HAS_ARG, QEMU_OPTION_accel, "-accel [accel=3D]accelerator[,prop[=3Dvalue][,...]]\n" - " select accelerator (kvm, xen, hvf, nvmm, whpx, mshv o= r tcg; use 'help' for a list)\n" + " select accelerator (kvm, xen, hvf, nitro, nvmm, whpx,= mshv or tcg; use 'help' for a list)\n" " igd-passthru=3Don|off (enable Xen integrated Intel gr= aphics passthrough, default=3Doff)\n" " kernel-irqchip=3Don|off|split controls accelerated ir= qchip support (default=3Don)\n" " kvm-shadow-mem=3Dsize of KVM shadow MMU in bytes\n" @@ -243,7 +243,7 @@ DEF("accel", HAS_ARG, QEMU_OPTION_accel, SRST ``-accel name[,prop=3Dvalue[,...]]`` This is used to enable an accelerator. Depending on the target - architecture, kvm, xen, hvf, nvmm, whpx, mshv or tcg can be available. + architecture, kvm, xen, hvf, nitro, nvmm, whpx, mshv or tcg can be ava= ilable. By default, tcg is used. If there is more than one accelerator specified, the next one is used if the previous one fails to initialize. diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index e8edc5252a..ca5b113119 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -158,6 +158,7 @@ meson_options_help() { printf "%s\n" ' multiprocess Out of process device emulation support' printf "%s\n" ' netmap netmap network backend support' printf "%s\n" ' nettle nettle cryptography support' + printf "%s\n" ' nitro Nitro acceleration support' printf "%s\n" ' numa libnuma support' printf "%s\n" ' nvmm NVMM acceleration support' printf "%s\n" ' opengl OpenGL support' @@ -418,6 +419,8 @@ _meson_option_parse() { --disable-netmap) printf "%s" -Dnetmap=3Ddisabled ;; --enable-nettle) printf "%s" -Dnettle=3Denabled ;; --disable-nettle) printf "%s" -Dnettle=3Ddisabled ;; + --enable-nitro) printf "%s" -Dnitro=3Denabled ;; + --disable-nitro) printf "%s" -Dnitro=3Ddisabled ;; --enable-numa) printf "%s" -Dnuma=3Denabled ;; --disable-numa) printf "%s" -Dnuma=3Ddisabled ;; --enable-nvmm) printf "%s" -Dnvmm=3Denabled ;; --=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 From nobody Sun Apr 12 04:21:00 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=1772030867; cv=none; d=zohomail.com; s=zohoarc; b=As2ouKg81pprnmiENYkdaRijeNY0miFXGJzcg/PxjuINgtZkJ0NrBaEDaMPyASDkbfi38V1l1kLZGBPaFI1aDWVFm+xUJJ5wiAHDL7vumD9Embk4NrbgwXr0vWXVoFq4G9DJ2D/zGn4P747DlSDSteWYyUaH4KMLqzxjtvfflok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772030867; 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=gz4Hts4EjwbYlP1wGBTBcf8xpl0cbCHvn3WSj/kPQI8=; b=Ogp80+tvjVhlkttv6NRvUIZViTWO6SGoqVMzhzv+IpC9GrAIwcvnXF+7jBLlzbgg/WCNuCjyBJunjaj5R2nCC0v8GrHxPl748lgDjFKlLPxXlLch3d2rFpXHDp5NkN7ZzmvLw9EzWSN8+BqXD9gyp6ERVmYZZMTAzMoKQFjJ3XQ= 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 1772030867561950.3947396678495; Wed, 25 Feb 2026 06:47:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vvG9f-0000Dl-KK; Wed, 25 Feb 2026 09:46:23 -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 1vvG9e-0000DD-4z; Wed, 25 Feb 2026 09:46:22 -0500 Received: from pdx-out-006.esa.us-west-2.outbound.mail-perimeter.amazon.com ([52.26.1.71]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vvG9c-00073M-6y; Wed, 25 Feb 2026 09:46:21 -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-006.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2026 14:46:15 +0000 Received: from EX19MTAUWA002.ant.amazon.com [205.251.233.234:28163] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.19.105:2525] with esmtp (Farcaster) id 9dd0c777-1fcc-47d3-bb5c-9db1c53d5788; Wed, 25 Feb 2026 14:46:15 +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:13 +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:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1772030780; x=1803566780; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gz4Hts4EjwbYlP1wGBTBcf8xpl0cbCHvn3WSj/kPQI8=; b=tZ6wsgswem2Ab4p0e5qSh/2zA9cfbl42aFeEQYFFBQZKW2Qs0hLkP8nb kOfhWozXrtpZWush4XPuayk9/xgMd1GXolkSL+3IbOJvqiues9XPk4Cqi dfKraoy3ES3hMddyDRkUyMkViK5n6H7OJUQiLgVGZV8xcVh27/WmXFPjJ 4ol9mfYAQ0cMWLbZB/EBdDOhC0Q92HnqUAjlYFhB8Riw7aJFtztMNBxgA mJLOORNhHoZT9NtA6Tmyon4WE5+HRwDfBhURb1zxRrzD6J73AUrQJqes/ 0tzZZWwUAQ9xV9X04gWtthG1Br24hs+mcy3WhE022RjqrJe8tu/brAGBO A==; X-CSE-ConnectionGUID: NFQQSYZRQaShdWRTszHtFw== X-CSE-MsgGUID: tbGam1vWSPeaEDjtZmpAow== X-IronPort-AV: E=Sophos;i="6.21,310,1763424000"; d="scan'208";a="13773734" X-Farcaster-Flow-ID: 9dd0c777-1fcc-47d3-bb5c-9db1c53d5788 From: Alexander Graf To: CC: , Peter Maydell , "Thomas Huth" , , , , , Cornelia Huck , , Dorjoy Chowdhury , Pierrick Bouvier , Paolo Bonzini , Tyler Fanelli , , Subject: [PATCH v2 05/11] hw/nitro/nitro-serial-vsock: Nitro Enclaves vsock console Date: Wed, 25 Feb 2026 14:45:24 +0000 Message-ID: <20260225144532.84673-6-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: EX19D032UWA002.ant.amazon.com (10.13.139.81) 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=52.26.1.71; envelope-from=prvs=509822c20=graf@amazon.de; helo=pdx-out-006.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: 1772030869300158500 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 --- 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-vs= ock.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 =C2=A9 2026 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * Authors: + * Alexander Graf + * + * 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 =3D 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 =3D 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 =3D NITRO_SERIAL_VSOCK(dev); + uint32_t port =3D enclave_cid + CONSOLE_PORT_START; + g_autofree char *chardev_id =3D 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 =3D g_strdup_printf("nitro-console-%u", enclave_cid); + + backend =3D g_new0(ChardevBackend, 1); + backend->type =3D CHARDEV_BACKEND_KIND_SOCKET; + sock =3D backend->u.socket.data =3D g_new0(ChardevSocket, 1); + sock->addr =3D g_new0(SocketAddressLegacy, 1); + sock->addr->type =3D SOCKET_ADDRESS_TYPE_VSOCK; + sock->addr->u.vsock.data =3D g_new0(VsockSocketAddress, 1); + sock->addr->u.vsock.data->cid =3D g_strdup(VMADDR_CID_HYPERVISOR_STR); + sock->addr->u.vsock.data->port =3D g_strdup_printf("%u", port); + sock->server =3D false; + sock->has_server =3D true; + + chr =3D 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[] =3D { + DEFINE_PROP_CHR("chardev", NitroSerialVsockState, output), +}; + +static void nitro_serial_vsock_class_init(ObjectClass *oc, const void *dat= a) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + NitroVsockDeviceClass *ndc =3D NITRO_VSOCK_DEVICE_CLASS(oc); + + device_class_set_props(dc, nitro_serial_vsock_props); + ndc->enclave_started =3D nitro_serial_vsock_enclave_started; +} + +static const TypeInfo nitro_serial_vsock_info =3D { + .name =3D TYPE_NITRO_SERIAL_VSOCK, + .parent =3D TYPE_NITRO_VSOCK_DEVICE, + .instance_size =3D sizeof(NitroSerialVsockState), + .class_init =3D 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. =20 +# 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-vsoc= k.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 */ --=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 From nobody Sun Apr 12 04:21:00 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=1772030837; cv=none; d=zohomail.com; s=zohoarc; b=k5cFVbtJQkH0Ow8B7xuG7+DJBchJgIXEu+WTH9cXo6Yw7oAW4d0nBVvTVL6l5PIRX6u5A+TNCDJ3KwUatXCe7evGBCv8a+6qi1NTO/Px1kwGXndvErZMy++7EXttgWsmDkdWSGtR01HM6skx/9FArMFIXjOKDOiNtTBxut5DJJg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772030837; 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=ehsU0Bf5A0MlZP4W91d1tbV1iHCoQYnxLfebYzHP7Dw=; b=UDSWR9zbnkjNnUYBvq77nIntl/F8cGvTEyPHm+rPU1k8OxA7vDxDt+z+BBxFHTypa3p0q6GwKCMwXnXeB0NEYBS3jxWmuJM7e+6rHzHphbjwhii91T7eC1OvBf0dTBdLFugV1LvO0+u93uX8TcBJOtZrsGdLRNG1cMxw82wiDAQ= 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 1772030837386747.4245133356263; Wed, 25 Feb 2026 06:47:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vvGA6-0000ZW-Ht; Wed, 25 Feb 2026 09:46:50 -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 1vvGA1-0000WO-RX; Wed, 25 Feb 2026 09:46:45 -0500 Received: from pdx-out-004.esa.us-west-2.outbound.mail-perimeter.amazon.com ([44.246.77.92]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vvG9z-00075w-58; Wed, 25 Feb 2026 09:46:44 -0500 Received: from ip-10-5-6-203.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.6.203]) by internal-pdx-out-004.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2026 14:46:38 +0000 Received: from EX19MTAUWC001.ant.amazon.com [205.251.233.105:23511] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.58.220:2525] with esmtp (Farcaster) id caa56ec1-bc1c-4648-a433-fc39859787a7; Wed, 25 Feb 2026 14:46:38 +0000 (UTC) Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) 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:37 +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:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1772030803; x=1803566803; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ehsU0Bf5A0MlZP4W91d1tbV1iHCoQYnxLfebYzHP7Dw=; b=XtCVJbutN/CJulC7awMlnszn1VKxOnc9lWcFRK92vUnRWvfd4/YIE/ax aQdUOfroxBT8zg9/H07xgoOLBmckUjD8Wnnt9eyX1gQbjd6+GD0MRN8a1 9V8gpmK4RS9AiN5AKCaFdFgwEuXAoI3FnDMO8uIxOdQ5o1zzXAIi8DjPq hq6ovg8St0TinvD+giCzfvjmp7GGPJs3WBKa1+giAThjWvcD+mh6kQ020 dZ6nj9skKYx1dkA5x1RMR6BOSNhtZTfTQ8yHlXI8u6/6v9h6EESYTN+2c CU82UMm6jg/tpAsSXTC90Vf/5zVVbIW/bBOql4QEi0o7+dcdkHSeE7znc w==; X-CSE-ConnectionGUID: T9Qu1Kt7SySACzMSi0lEKQ== X-CSE-MsgGUID: p0lPaIVqR82RzWauRkk7fg== X-IronPort-AV: E=Sophos;i="6.21,310,1763424000"; d="scan'208";a="13761460" X-Farcaster-Flow-ID: caa56ec1-bc1c-4648-a433-fc39859787a7 From: Alexander Graf To: CC: , Peter Maydell , "Thomas Huth" , , , , , Cornelia Huck , , Dorjoy Chowdhury , Pierrick Bouvier , Paolo Bonzini , Tyler Fanelli , , Subject: [PATCH v2 06/11] hw/nitro: Introduce Nitro Enclave Heartbeat device Date: Wed, 25 Feb 2026 14:45:25 +0000 Message-ID: <20260225144532.84673-7-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=44.246.77.92; envelope-from=prvs=509822c20=graf@amazon.de; helo=pdx-out-004.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: 1772030838965158501 Nitro Enclaves expect the parent instance to host a vsock heartbeat listener at port 9000. To host a Nitro Enclave with the nitro accel in QEMU, add such a heartbeat listener as device model, so that the machine can easily instantiate it. Signed-off-by: Alexander Graf --- v1 -> v2: - Convert to nitro-vsock-device --- hw/nitro/Kconfig | 4 ++ hw/nitro/heartbeat.c | 115 +++++++++++++++++++++++++++++++++++ hw/nitro/meson.build | 1 + hw/nitro/trace-events | 4 ++ include/hw/nitro/heartbeat.h | 24 ++++++++ 5 files changed, 148 insertions(+) create mode 100644 hw/nitro/heartbeat.c create mode 100644 include/hw/nitro/heartbeat.h diff --git a/hw/nitro/Kconfig b/hw/nitro/Kconfig index ce24c09c21..d3fbc7b683 100644 --- a/hw/nitro/Kconfig +++ b/hw/nitro/Kconfig @@ -4,3 +4,7 @@ config NITRO_VSOCK_BUS config NITRO_SERIAL_VSOCK bool depends on NITRO_VSOCK_BUS + +config NITRO_HEARTBEAT + bool + depends on NITRO_VSOCK_BUS diff --git a/hw/nitro/heartbeat.c b/hw/nitro/heartbeat.c new file mode 100644 index 0000000000..dc41323266 --- /dev/null +++ b/hw/nitro/heartbeat.c @@ -0,0 +1,115 @@ +/* + * Nitro Enclave Heartbeat device + * + * Copyright =C2=A9 2026 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * Authors: + * Alexander Graf + * + * The Nitro Enclave init process sends a heartbeat byte (0xB7) to + * CID 3 (parent) port 9000 on boot to signal it reached initramfs. + * The parent must accept the connection, read the byte, and echo it + * back. If the enclave init cannot reach the listener, it exits. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "chardev/char.h" +#include "chardev/char-fe.h" +#include "hw/nitro/heartbeat.h" +#include "trace.h" + +#define HEARTBEAT_PORT 9000 +#define VMADDR_CID_ANY_STR "4294967295" + +static int nitro_heartbeat_can_read(void *opaque) +{ + NitroHeartbeatState *s =3D opaque; + + /* One-shot protocol: stop reading after the first heartbeat */ + return s->done ? 0 : 1; +} + +static void nitro_heartbeat_read(void *opaque, const uint8_t *buf, int siz= e) +{ + NitroHeartbeatState *s =3D opaque; + + if (s->done || size < 1) { + return; + } + + /* Echo the heartbeat byte back and disconnect */ + qemu_chr_fe_write_all(&s->vsock, buf, 1); + s->done =3D true; + qemu_chr_fe_deinit(&s->vsock, true); + + trace_nitro_heartbeat_done(); +} + +static void nitro_heartbeat_event(void *opaque, QEMUChrEvent event) +{ + trace_nitro_heartbeat_event(event); +} + +static void nitro_heartbeat_realize(DeviceState *dev, Error **errp) +{ + NitroHeartbeatState *s =3D NITRO_HEARTBEAT(dev); + g_autofree char *chardev_id =3D NULL; + Chardev *chr; + ChardevBackend *backend; + ChardevSocket *sock; + + chardev_id =3D g_strdup_printf("nitro-heartbeat"); + + backend =3D g_new0(ChardevBackend, 1); + backend->type =3D CHARDEV_BACKEND_KIND_SOCKET; + sock =3D backend->u.socket.data =3D g_new0(ChardevSocket, 1); + sock->addr =3D g_new0(SocketAddressLegacy, 1); + sock->addr->type =3D SOCKET_ADDRESS_TYPE_VSOCK; + sock->addr->u.vsock.data =3D g_new0(VsockSocketAddress, 1); + sock->addr->u.vsock.data->cid =3D g_strdup(VMADDR_CID_ANY_STR); + sock->addr->u.vsock.data->port =3D g_strdup_printf("%u", HEARTBEAT_POR= T); + sock->server =3D true; + sock->has_server =3D true; + sock->wait =3D false; + sock->has_wait =3D true; + + chr =3D 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_heartbeat_can_read, + nitro_heartbeat_read, + nitro_heartbeat_event, + NULL, s, NULL, true); +} + +static void nitro_heartbeat_class_init(ObjectClass *oc, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + + dc->realize =3D nitro_heartbeat_realize; +} + +static const TypeInfo nitro_heartbeat_info =3D { + .name =3D TYPE_NITRO_HEARTBEAT, + .parent =3D TYPE_NITRO_VSOCK_DEVICE, + .instance_size =3D sizeof(NitroHeartbeatState), + .class_init =3D nitro_heartbeat_class_init, +}; + +static void nitro_heartbeat_register(void) +{ + type_register_static(&nitro_heartbeat_info); +} + +type_init(nitro_heartbeat_register); diff --git a/hw/nitro/meson.build b/hw/nitro/meson.build index 76399d4265..381c1ee6c1 100644 --- a/hw/nitro/meson.build +++ b/hw/nitro/meson.build @@ -1,2 +1,3 @@ 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'= )) diff --git a/hw/nitro/trace-events b/hw/nitro/trace-events index 20617a024a..311ab78e69 100644 --- a/hw/nitro/trace-events +++ b/hw/nitro/trace-events @@ -2,3 +2,7 @@ =20 # serial-vsock.c nitro_serial_vsock_event(int event) "event %d" + +# heartbeat.c +nitro_heartbeat_event(int event) "event %d" +nitro_heartbeat_done(void) "enclave heartbeat received" diff --git a/include/hw/nitro/heartbeat.h b/include/hw/nitro/heartbeat.h new file mode 100644 index 0000000000..6b9271a47d --- /dev/null +++ b/include/hw/nitro/heartbeat.h @@ -0,0 +1,24 @@ +/* + * Nitro Heartbeat device + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_MISC_NITRO_HEARTBEAT_H +#define HW_MISC_NITRO_HEARTBEAT_H + +#include "hw/nitro/nitro-vsock-bus.h" +#include "chardev/char-fe.h" +#include "qom/object.h" + +#define TYPE_NITRO_HEARTBEAT "nitro-heartbeat" +OBJECT_DECLARE_SIMPLE_TYPE(NitroHeartbeatState, NITRO_HEARTBEAT) + +struct NitroHeartbeatState { + NitroVsockDevice parent_obj; + + CharFrontend vsock; /* vsock server chardev for heartbeat */ + bool done; +}; + +#endif /* HW_MISC_NITRO_HEARTBEAT_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 From nobody Sun Apr 12 04:21:00 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=1772030858; cv=none; d=zohomail.com; s=zohoarc; b=Z7PlAZOF0V8jFZAEXh3szVUOGVOEGh1+6zddMYvbQauTujlShhSRo4et4eDHpXBBYGIsFIuJHJ/S0gzKAYQ7Oy+vYiA+5/U6ayGO8Lsg7Xrf3trvWigTds1KUHGhWxA9kdPGA7icuCAqLeYbmf11vVV7Yeh6kb2Iad2SKzvFJVg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772030858; 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=uVNVDznm7NxQ+bwTqP9jZD0VXeg2067NIquqLqqPp8k=; b=LGGrr5GuD30sV4yISQooeCehLkmE6FMBTimRJpQxbFrt9FVYsLoSbW/Yjkge1PiukzriFx8yGeThvndkSdIT4lUaAfonB6W4emSPFcaXEP25uNJ8D7upbdAsMJZiTRhmOiNNkSO+SO5FsZZ3mYQKwoQVDCj4itF9lDBafdytVtA= 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 1772030858847586.5412832425868; Wed, 25 Feb 2026 06:47:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vvGAU-0000hk-UT; 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 1vvGA2-0000Wb-H8; Wed, 25 Feb 2026 09:46:46 -0500 Received: from pdx-out-005.esa.us-west-2.outbound.mail-perimeter.amazon.com ([52.13.214.179]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vvG9z-000766-Tk; Wed, 25 Feb 2026 09:46:45 -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-005.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2026 14:46:41 +0000 Received: from EX19MTAUWB002.ant.amazon.com [205.251.233.111:20004] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.12.226:2525] with esmtp (Farcaster) id c571fd97-c8d4-4901-921b-6ca72cdfe0b7; Wed, 25 Feb 2026 14:46:41 +0000 (UTC) Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWB002.ant.amazon.com (10.250.64.231) 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 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:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1772030803; x=1803566803; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uVNVDznm7NxQ+bwTqP9jZD0VXeg2067NIquqLqqPp8k=; b=YS2SgXzrpDil1NE9uU2S1OabF2f7VN6XqJcsP+EXcWqF+kVcz8ltFY1m a1GrjqwmA2nJPBPNL/EJuFdWBuDvh4VrTqZ5NNt7sdAIDPzYAby2xe6Fb YtqWen083mJcVhidRcJfC89m9VZQVZ3nXIjbpF57aplHluUzTCN22+GaL DTtrokAJnLV2dFnM6F66HaktApyeVHR0PSHPSNR96h6mDeqM55uIUUfLc 7CXlVvKYs0bv1UgufNdpHofFkSiYvuobdGnaEhvgBlrHGOL9pe5hETRYl S8vFm04gfFnkvajgV8ME64dm2zScO0rR8cijWUVX8Qz+9MuUPhsO42F1S w==; X-CSE-ConnectionGUID: +vTHUKSqQSKNT0EyRm0YMg== X-CSE-MsgGUID: jhYyOK1UQca5uScKAuWp+g== X-IronPort-AV: E=Sophos;i="6.21,310,1763424000"; d="scan'208";a="13768594" X-Farcaster-Flow-ID: c571fd97-c8d4-4901-921b-6ca72cdfe0b7 From: Alexander Graf To: CC: , Peter Maydell , "Thomas Huth" , , , , , Cornelia Huck , , Dorjoy Chowdhury , Pierrick Bouvier , Paolo Bonzini , Tyler Fanelli , , Subject: [PATCH v2 07/11] target/arm/cpu64: Allow -host for nitro Date: Wed, 25 Feb 2026 14:45:26 +0000 Message-ID: <20260225144532.84673-8-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-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=52.13.214.179; envelope-from=prvs=509822c20=graf@amazon.de; helo=pdx-out-005.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: 1772030861320158500 Content-Type: text/plain; charset="utf-8" The nitro accel does not actually make use of CPU emulation or details: It always uses the host CPU regardless of configuration. Machines for the nitro accel select the host CPU type as default to have a clear statement of the above and to have a unified cpu type across all supported architectures. The arm64 logic on Linux currently only allows -cpu host for KVM based virtual machines. Add a special case for nitro so that when the nitro accel is active, it allows use of the host cpu type. Signed-off-by: Alexander Graf --- target/arm/cpu64.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 5d7c6b7fbb..c01051f038 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -765,6 +765,14 @@ static void aarch64_a53_initfn(Object *obj) static void aarch64_host_initfn(Object *obj) { ARMCPU *cpu =3D ARM_CPU(obj); + +#if defined(CONFIG_NITRO) + if (nitro_enabled()) { + /* The nitro accel uses -cpu host, but does not actually consume i= t */ + return; + } +#endif + #if defined(CONFIG_KVM) kvm_arm_set_cpu_features_from_host(cpu); if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { --=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 From nobody Sun Apr 12 04:21:00 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 From nobody Sun Apr 12 04:21:00 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=1772030875; cv=none; d=zohomail.com; s=zohoarc; b=jLQ/BupbQL7O/iGOfIevb466OW/0wusswHPauWWXM69J0hCk6e51xiNPJLMcVxxahzaG/X4Xo9lTyS3sQ/ZpdPCtCoMCo8QjM6cTqB/HZKITLfHbxtLrUtj5CePRLFm4rW5k8ZGLT5hC+egG8O+UBctD6QdILVvRKGyalW8xxgE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772030875; 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=aglmDwrScyQmZ1Gqv0UlX8GtgDjIcpToIs7+LnpYPK0=; b=EflsirYNJo+cVzBYWfb90uJ7Umz+p2H8ls2XkseFNPoDwf/Xd+KZZg21JxlQjt41VuOGneiyh+bUbGEIRt+RJWPQMHPN16vy+IAxiHHLpyTj6JJTF7oOGKxxI0hiv7g9G+JQ+diMvmgzWE1hWKgLvxXEBcy/Jkn9DiphCee6w7U= 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 1772030875406532.9393773690355; Wed, 25 Feb 2026 06:47:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vvGAl-00019K-1E; Wed, 25 Feb 2026 09:47:34 -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 1vvGAV-00010r-Dr; Wed, 25 Feb 2026 09:47:16 -0500 Received: from pdx-out-002.esa.us-west-2.outbound.mail-perimeter.amazon.com ([44.246.1.125]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vvGAS-00079B-NS; Wed, 25 Feb 2026 09:47:14 -0500 Received: from ip-10-5-6-203.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.6.203]) by internal-pdx-out-002.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2026 14:47:08 +0000 Received: from EX19MTAUWB001.ant.amazon.com [205.251.233.104:27851] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.36.66:2525] with esmtp (Farcaster) id d41b3886-231d-46cb-8a25-543c9499f93d; Wed, 25 Feb 2026 14:47:07 +0000 (UTC) Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWB001.ant.amazon.com (10.250.64.248) 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:47:07 +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:47:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1772030832; x=1803566832; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aglmDwrScyQmZ1Gqv0UlX8GtgDjIcpToIs7+LnpYPK0=; b=a76aYtEhqoqQsWIzzzJMyyvy+DxvEyINPiaiNdr1Q70YjqGjx+HUonES vTzjUssFcFt0TuU7uJhN6Lfb6R/rL/qG+HWiMfXF++nxEQCEIG/d80h/R yZQoW1z9ubEkdjCidRlH7uSW02SCL51DEgZbMaEu/xjGfN/KVPTwYDyEa pykcuW3Kk0O64xewh9Yt10rLNcL9zeGUpiDIxVmBDHw+c3EraErTwtXu0 1otMkdMgksv6p3RZu67vP6VDUy0qdysjBfdJyzksK77+iSZ0cYyX3aubQ wChNOfBZSB9n3OidpNUXo3AGd84HD2d5WhL6srGRVCB5zQ5KVV9bCkm9l w==; X-CSE-ConnectionGUID: HdmzPSn/TvWNs6pccJL4FA== X-CSE-MsgGUID: 0SxTbO6hT7Sniv1FMr3+zg== X-IronPort-AV: E=Sophos;i="6.21,310,1763424000"; d="scan'208";a="13763567" X-Farcaster-Flow-ID: d41b3886-231d-46cb-8a25-543c9499f93d From: Alexander Graf To: CC: , Peter Maydell , "Thomas Huth" , , , , , Cornelia Huck , , Dorjoy Chowdhury , Pierrick Bouvier , Paolo Bonzini , Tyler Fanelli , , Subject: [PATCH v2 09/11] hw/core/eif: Move definitions to header Date: Wed, 25 Feb 2026 14:45:28 +0000 Message-ID: <20260225144532.84673-10-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: EX19D039UWB003.ant.amazon.com (10.13.138.93) To EX19D020UWC004.ant.amazon.com (10.13.138.149) 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=44.246.1.125; envelope-from=prvs=509822c20=graf@amazon.de; helo=pdx-out-002.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: 1772030877119158500 Content-Type: text/plain; charset="utf-8" In follow-up patches we need some EIF file definitions that are currently in the eif.c file, but want to access them from a separate device. Move them into the header instead. Signed-off-by: Alexander Graf Reviewed-by: Dorjoy Chowdhury --- hw/core/eif.c | 38 -------------------------------------- hw/core/eif.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/hw/core/eif.c b/hw/core/eif.c index 513caec6b4..96f1d76578 100644 --- a/hw/core/eif.c +++ b/hw/core/eif.c @@ -18,44 +18,6 @@ =20 #include "hw/core/eif.h" =20 -#define MAX_SECTIONS 32 - -/* members are ordered according to field order in .eif file */ -typedef struct EifHeader { - uint8_t magic[4]; /* must be .eif in ascii i.e., [46, 101, 105, 102] = */ - uint16_t version; - uint16_t flags; - uint64_t default_memory; - uint64_t default_cpus; - uint16_t reserved; - uint16_t section_cnt; - uint64_t section_offsets[MAX_SECTIONS]; - uint64_t section_sizes[MAX_SECTIONS]; - uint32_t unused; - uint32_t eif_crc32; -} QEMU_PACKED EifHeader; - -/* members are ordered according to field order in .eif file */ -typedef struct EifSectionHeader { - /* - * 0 =3D invalid, 1 =3D kernel, 2 =3D cmdline, 3 =3D ramdisk, 4 =3D si= gnature, - * 5 =3D metadata - */ - uint16_t section_type; - uint16_t flags; - uint64_t section_size; -} QEMU_PACKED EifSectionHeader; - -enum EifSectionTypes { - EIF_SECTION_INVALID =3D 0, - EIF_SECTION_KERNEL =3D 1, - EIF_SECTION_CMDLINE =3D 2, - EIF_SECTION_RAMDISK =3D 3, - EIF_SECTION_SIGNATURE =3D 4, - EIF_SECTION_METADATA =3D 5, - EIF_SECTION_MAX =3D 6, -}; - static const char *section_type_to_string(uint16_t type) { const char *str; diff --git a/hw/core/eif.h b/hw/core/eif.h index fed3cb5514..a3412377a9 100644 --- a/hw/core/eif.h +++ b/hw/core/eif.h @@ -11,6 +11,44 @@ #ifndef HW_CORE_EIF_H #define HW_CORE_EIF_H =20 +#define MAX_SECTIONS 32 + +/* members are ordered according to field order in .eif file */ +typedef struct EifHeader { + uint8_t magic[4]; /* must be .eif in ascii i.e., [46, 101, 105, 102] = */ + uint16_t version; + uint16_t flags; + uint64_t default_memory; + uint64_t default_cpus; + uint16_t reserved; + uint16_t section_cnt; + uint64_t section_offsets[MAX_SECTIONS]; + uint64_t section_sizes[MAX_SECTIONS]; + uint32_t unused; + uint32_t eif_crc32; +} QEMU_PACKED EifHeader; + +/* members are ordered according to field order in .eif file */ +typedef struct EifSectionHeader { + /* + * 0 =3D invalid, 1 =3D kernel, 2 =3D cmdline, 3 =3D ramdisk, 4 =3D si= gnature, + * 5 =3D metadata + */ + uint16_t section_type; + uint16_t flags; + uint64_t section_size; +} QEMU_PACKED EifSectionHeader; + +enum EifSectionTypes { + EIF_SECTION_INVALID =3D 0, + EIF_SECTION_KERNEL =3D 1, + EIF_SECTION_CMDLINE =3D 2, + EIF_SECTION_RAMDISK =3D 3, + EIF_SECTION_SIGNATURE =3D 4, + EIF_SECTION_METADATA =3D 5, + EIF_SECTION_MAX =3D 6, +}; + bool read_eif_file(const char *eif_path, const char *machine_initrd, char **kernel_path, char **initrd_path, char **kernel_cmdline, uint8_t *image_sha384, --=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 From nobody Sun Apr 12 04:21:00 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=Ztdad74qW/D961fME3vHhtb5jL8awRUKyeYT1f1/g+I3HDHN+T+RG2Rr3+4J2VPEFW5329+1X+aoqz5MArC4yqSsuzuluZXZ7lbyAvV1XWbCaSPhUYpqPgCT7CKAe9s4LegfEXzth+R8SOiv4O9nb4h1soAEZQI5uC0tiTKsNzM= 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=wiFxVcGuOOQDsn9n6nHZt2xgOoJ7CV0tZ9+LBptze6g=; b=jqR+SFAbuGaJwT6dxX6TpVlf+RBprLVHYzK6682QzHgRtMqa1H/qJ2PKWPpihjp/mDrP17Q9F/LXC6zQpzXmswWsw4JBSt7ZGtIYSNVPfZorUvNW6HQye82Kgb8aV6XTCCRPfIwkV7slF7Gg6Nke32FUUfJUBPjqFEYrxTjZinw= 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 1772030921528184.20287232090345; 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 1vvGB7-0001Je-Si; Wed, 25 Feb 2026 09:47:56 -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 1vvGAX-00018J-Lz; Wed, 25 Feb 2026 09:47:19 -0500 Received: from pdx-out-003.esa.us-west-2.outbound.mail-perimeter.amazon.com ([44.246.68.102]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vvGAV-00079X-OA; Wed, 25 Feb 2026 09:47:17 -0500 Received: from ip-10-5-12-219.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.12.219]) by internal-pdx-out-003.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2026 14:47:10 +0000 Received: from EX19MTAUWC002.ant.amazon.com [205.251.233.51:9661] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.36.66:2525] with esmtp (Farcaster) id 9d510a1e-b7dd-487e-a911-877d9d388bcf; Wed, 25 Feb 2026 14:47:10 +0000 (UTC) Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) 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:47:09 +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:47:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1772030835; x=1803566835; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wiFxVcGuOOQDsn9n6nHZt2xgOoJ7CV0tZ9+LBptze6g=; b=mgoSjPM2swBxN8gQViDe/yUQKTiU0tqWoeaPH2JUayCgOmiEGKSmBK3G xP4fvDYy9AuMCd9amFkhnGi1rIPixPIAEAFMTdRMWdaQVGGx4jUoSZyWy LWXy/YEoUy+H1i6gKgkSoSoU5gLqT50rKKnevHxuN5/YoA6HtfzVSZEwO Lju/anljdbcF+1PAwt11fTRTmEDV9CN+IIhw+VPoTCt6sLYhdSiIw6lof bkW8J1jVtCWoUeSpBZJ4VY9K+3Vq1GcsOnUkRgYAT1ZkENe3Yyyn4l5Zh VPQalriCXmqoNwRNS8MwpqXgQ7hHpmwmZk1xpH3RinAUywl3CRkyUaacm w==; X-CSE-ConnectionGUID: 5HL1FQWfQnCEQg3ym/1eWw== X-CSE-MsgGUID: 4zLpn9AATy24kFVMBqsTTw== X-IronPort-AV: E=Sophos;i="6.21,310,1763424000"; d="scan'208";a="13779701" X-Farcaster-Flow-ID: 9d510a1e-b7dd-487e-a911-877d9d388bcf From: Alexander Graf To: CC: , Peter Maydell , "Thomas Huth" , , , , , Cornelia Huck , , Dorjoy Chowdhury , Pierrick Bouvier , Paolo Bonzini , Tyler Fanelli , , Subject: [PATCH v2 10/11] hw/nitro: Enable direct kernel boot Date: Wed, 25 Feb 2026 14:45:29 +0000 Message-ID: <20260225144532.84673-11-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: EX19D039UWB003.ant.amazon.com (10.13.138.93) To EX19D020UWC004.ant.amazon.com (10.13.138.149) 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=44.246.68.102; envelope-from=prvs=509822c20=graf@amazon.de; helo=pdx-out-003.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: 1772030923623158500 Content-Type: text/plain; charset="utf-8" Nitro Enclaves can only boot EIF files which are a combination of kernel, initramfs and cmdline in a single file. When the kernel image is not an EIF, treat it like a kernel image and assemble an EIF image on the fly. This way, users can call QEMU with a direct kernel/initrd/cmdline combination and everything "just works". Signed-off-by: Alexander Graf --- hw/core/eif.h | 3 ++ hw/nitro/machine.c | 116 +++++++++++++++++++++++++++++++++++++++++++ hw/nitro/meson.build | 2 +- 3 files changed, 120 insertions(+), 1 deletion(-) diff --git a/hw/core/eif.h b/hw/core/eif.h index a3412377a9..0c432dbc2d 100644 --- a/hw/core/eif.h +++ b/hw/core/eif.h @@ -12,6 +12,7 @@ #define HW_CORE_EIF_H =20 #define MAX_SECTIONS 32 +#define EIF_HDR_ARCH_ARM64 0x1 =20 /* members are ordered according to field order in .eif file */ typedef struct EifHeader { @@ -49,6 +50,8 @@ enum EifSectionTypes { EIF_SECTION_MAX =3D 6, }; =20 +#define EIF_MAGIC { '.', 'e', 'i', 'f' } + bool read_eif_file(const char *eif_path, const char *machine_initrd, char **kernel_path, char **initrd_path, char **kernel_cmdline, uint8_t *image_sha384, diff --git a/hw/nitro/machine.c b/hw/nitro/machine.c index e28c8e9bf5..8849959359 100644 --- a/hw/nitro/machine.c +++ b/hw/nitro/machine.c @@ -32,9 +32,104 @@ #include "system/nitro-accel.h" #include "qemu/accel.h" #include "hw/arm/machines-qom.h" +#include "hw/core/eif.h" +#include /* for crc32 */ =20 #define EIF_LOAD_ADDR (8 * 1024 * 1024) =20 +static bool is_eif(char *eif, gsize len) +{ + const char eif_magic[] =3D EIF_MAGIC; + + return len >=3D sizeof(eif_magic) && + !memcmp(eif, eif_magic, sizeof(eif_magic)); +} + +static void build_eif_section(EifHeader *hdr, GByteArray *buf, uint16_t ty= pe, + const char *data, uint64_t size) +{ + uint16_t section =3D be16_to_cpu(hdr->section_cnt); + EifSectionHeader shdr =3D { + .section_type =3D cpu_to_be16(type), + .flags =3D 0, + .section_size =3D cpu_to_be64(size), + }; + + hdr->section_offsets[section] =3D cpu_to_be64(buf->len); + hdr->section_sizes[section] =3D cpu_to_be64(size); + + g_byte_array_append(buf, (const uint8_t *)&shdr, sizeof(shdr)); + if (size) { + g_byte_array_append(buf, (const uint8_t *)data, size); + } + + hdr->section_cnt =3D cpu_to_be16(section + 1); +} + +/* + * Nitro Enclaves only support loading EIF files. When the user provides + * a Linux kernel, initrd and cmdline, convert them into EIF format. + */ +static char *build_eif(const char *kernel_data, gsize kernel_size, + const char *initrd_path, const char *cmdline, + gsize *out_size, Error **errp) +{ + g_autofree char *initrd_data =3D NULL; + static const char metadata[] =3D "{}"; + size_t metadata_len =3D sizeof(metadata) - 1; + gsize initrd_size =3D 0; + GByteArray *buf; + EifHeader hdr; + uint32_t crc =3D 0; + size_t cmdline_len; + + if (initrd_path) { + if (!g_file_get_contents(initrd_path, &initrd_data, + &initrd_size, NULL)) { + error_setg(errp, "Failed to read initrd '%s'", initrd_path); + return NULL; + } + } + + buf =3D g_byte_array_new(); + + cmdline_len =3D cmdline ? strlen(cmdline) : 0; + + hdr =3D (EifHeader) { + .magic =3D EIF_MAGIC, + .version =3D cpu_to_be16(4), + .flags =3D cpu_to_be16(target_aarch64() ? EIF_HDR_ARCH_ARM64 : 0), + }; + + g_byte_array_append(buf, (const uint8_t *)&hdr, sizeof(hdr)); + + /* Kernel */ + build_eif_section(&hdr, buf, EIF_SECTION_KERNEL, kernel_data, kernel_s= ize); + + /* Command line */ + build_eif_section(&hdr, buf, EIF_SECTION_CMDLINE, cmdline, cmdline_len= ); + + /* Initramfs */ + build_eif_section(&hdr, buf, EIF_SECTION_RAMDISK, initrd_data, initrd_= size); + + /* Metadata */ + build_eif_section(&hdr, buf, EIF_SECTION_METADATA, metadata, metadata_= len); + + /* + * Patch the header into the buffer first (with real section offsets + * and sizes), then compute CRC over everything except the CRC field. + */ + memcpy(buf->data, &hdr, sizeof(hdr)); + crc =3D crc32(crc, buf->data, offsetof(EifHeader, eif_crc32)); + crc =3D crc32(crc, &buf->data[sizeof(hdr)], buf->len - sizeof(hdr)); + + /* Finally write the CRC into the in-buffer header */ + ((EifHeader *)buf->data)->eif_crc32 =3D cpu_to_be32(crc); + + *out_size =3D buf->len; + return (char *)g_byte_array_free(buf, false); +} + static void nitro_machine_init(MachineState *machine) { const char *eif_path =3D machine->kernel_filename; @@ -74,6 +169,27 @@ static void nitro_machine_init(MachineState *machine) error_report("nitro: failed to read EIF '%s'", eif_path); exit(1); } + + if (!is_eif(eif_data, eif_size)) { + char *kernel_data =3D eif_data; + gsize kernel_size =3D eif_size; + Error *err =3D NULL; + + /* + * The user gave us a non-EIF kernel, likely a Linux kernel image. + * Assemble an EIF file from it, the -initrd and the -append argum= ents, + * so that users can perform a natural direct kernel boot. + */ + eif_data =3D build_eif(kernel_data, kernel_size, machine->initrd_f= ilename, + machine->kernel_cmdline, &eif_size, &err); + if (!eif_data) { + error_report_err(err); + exit(1); + } + + g_free(kernel_data); + } + address_space_write(&address_space_memory, EIF_LOAD_ADDR, MEMTXATTRS_UNSPECIFIED, eif_data, eif_size); =20 diff --git a/hw/nitro/meson.build b/hw/nitro/meson.build index e3f1895890..b9bd0d4300 100644 --- a/hw/nitro/meson.build +++ b/hw/nitro/meson.build @@ -1,4 +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')) +system_ss.add(when: 'CONFIG_NITRO_MACHINE', if_true: [files('machine.c'), = zlib]) --=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 From nobody Sun Apr 12 04:21:00 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=1772030920; cv=none; d=zohomail.com; s=zohoarc; b=K0nX+gJoRAmZDXSswER0J4khTvUCUJnlEzw0rQ1sYT4cK9YWb4b6TwbvdBwNpLkbUfvO1vpHNBZ7hjEFfcgmUJ+Se/u72gPe9JXyWdQi5+PPp43cIvbKqRyA4WNXSOE8vJ/aCpZPDhtDiFl3xXuSbt7ET48sjGuwRONF5ksUX8M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772030920; 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=+aizdLXyc6doicL/j8QKWc/fhiSn6T+aU4ZL0eEP5CQ=; b=UrYEtL/IfAStAWEzKK2qIHOqhJ5xtVV8RahlF8cilop8V71QM/3GlGITDg/oDZvTFCaG2+QiE5EXecQnj7aNg+IDZ7zDAwcvw+mp86pnUrsTyadKtS/o33FqMb/XH+8NXQZgnK9ox5JA88COnVX92GjuFn401filKGr35Iu65so= 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 1772030920431441.11837629176216; Wed, 25 Feb 2026 06:48:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vvGBh-0001mI-1R; Wed, 25 Feb 2026 09:48:30 -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 1vvGAa-00019j-12; Wed, 25 Feb 2026 09:47:23 -0500 Received: from pdx-out-015.esa.us-west-2.outbound.mail-perimeter.amazon.com ([50.112.246.219]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vvGAX-00079s-1S; Wed, 25 Feb 2026 09:47:18 -0500 Received: from ip-10-5-12-219.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.12.219]) by internal-pdx-out-015.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2026 14:47:15 +0000 Received: from EX19MTAUWA001.ant.amazon.com [205.251.233.182:28167] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.36.66:2525] with esmtp (Farcaster) id 2e12e5cc-0052-430e-b0f8-27005418b99b; Wed, 25 Feb 2026 14:47:14 +0000 (UTC) Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWA001.ant.amazon.com (10.250.64.218) 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:47:12 +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:47:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1772030837; x=1803566837; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+aizdLXyc6doicL/j8QKWc/fhiSn6T+aU4ZL0eEP5CQ=; b=QQbA4AKXfGv3Sj8bnMovwH6fK6kQP5o5Uyyo5IrxCPO3P22zfvsr0zuc 8dv8+2ew892fTiQ/8LfSWiB0K2EC65HIqA855ZcaqrMX7jZjW5lYYoV5y sbEzt3Vl0hWPWz9f5xn+d3kkvB5WIAuRMaaAZLLZxxN2kJ8GK0d6gV2Xq mkrY5UA3Q19EzECbrS2bOke/twU5L3OIn8Uz69xNWZDPIj3tVQzqFxENR XpRoENKwTOd/OW2K+wQ2iCKs/vDHyyxALPJ8Ur6dMZutbIc64UAMbZbTj aoTUtasZGzg+ShsZuNQaTgbg5ne0pGwz0R/FfrM1Zf6IoQ9AgzKDiHn46 w==; X-CSE-ConnectionGUID: 8EGA8BPBRQSuKKq1t6eCuw== X-CSE-MsgGUID: Ko1KZaXzQ7uQ3aBLoj31Dg== X-IronPort-AV: E=Sophos;i="6.21,310,1763424000"; d="scan'208";a="13594551" X-Farcaster-Flow-ID: 2e12e5cc-0052-430e-b0f8-27005418b99b From: Alexander Graf To: CC: , Peter Maydell , "Thomas Huth" , , , , , Cornelia Huck , , Dorjoy Chowdhury , Pierrick Bouvier , Paolo Bonzini , Tyler Fanelli , , Subject: [PATCH v2 11/11] docs: Add Nitro Enclaves documentation Date: Wed, 25 Feb 2026 14:45:30 +0000 Message-ID: <20260225144532.84673-12-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: EX19D039UWB003.ant.amazon.com (10.13.138.93) To EX19D020UWC004.ant.amazon.com (10.13.138.149) 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=50.112.246.219; envelope-from=prvs=509822c20=graf@amazon.de; helo=pdx-out-015.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: 1772030921406158500 Content-Type: text/plain; charset="utf-8" Now that all pieces are in place to spawn Nitro Enclaves using a special purpose accelerator and machine model, document how to use it. Signed-off-by: Alexander Graf --- v1 -> v2: - explain the nitro bus, its notification flow and topology - give example for qom-get of the enclave cid - document the accel enclave-cid property --- MAINTAINERS | 1 + docs/system/confidential-guest-support.rst | 1 + docs/system/index.rst | 1 + docs/system/nitro.rst | 133 +++++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 docs/system/nitro.rst diff --git a/MAINTAINERS b/MAINTAINERS index 53ce075e9a..5e9e429530 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3027,6 +3027,7 @@ M: Alexander Graf S: Maintained F: hw/nitro/ F: include/hw/nitro/ +F: docs/system/nitro.rst =20 Subsystems ---------- diff --git a/docs/system/confidential-guest-support.rst b/docs/system/confi= dential-guest-support.rst index 66129fbab6..562a7c3c28 100644 --- a/docs/system/confidential-guest-support.rst +++ b/docs/system/confidential-guest-support.rst @@ -41,5 +41,6 @@ Currently supported confidential guest mechanisms are: * Intel Trust Domain Extension (TDX) (see :doc:`i386/tdx`) * POWER Protected Execution Facility (PEF) (see :ref:`power-papr-protected= -execution-facility-pef`) * s390x Protected Virtualization (PV) (see :doc:`s390x/protvirt`) +* AWS Nitro Enclaves (see :doc:`nitro`) =20 Other mechanisms may be supported in future. diff --git a/docs/system/index.rst b/docs/system/index.rst index 427b020483..d297a95282 100644 --- a/docs/system/index.rst +++ b/docs/system/index.rst @@ -39,5 +39,6 @@ or Hypervisor.Framework. multi-process confidential-guest-support igvm + nitro vm-templating sriov diff --git a/docs/system/nitro.rst b/docs/system/nitro.rst new file mode 100644 index 0000000000..5907d6153e --- /dev/null +++ b/docs/system/nitro.rst @@ -0,0 +1,133 @@ +AWS Nitro Enclaves +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +`AWS Nitro Enclaves `_ +are isolated compute environments that run alongside EC2 instances. +They are created by partitioning CPU and memory resources from a parent +instance and launching a signed Enclave Image Format (EIF) file inside +a confidential VM managed by the Nitro Hypervisor. + +QEMU supports launching Nitro Enclaves on EC2 instances that have +enclave support enabled, using the ``nitro`` accelerator and the +``nitro`` machine type. + +Prerequisites +------------- + +* An EC2 instance with Nitro Enclaves enabled +* The ``nitro_enclaves`` kernel module loaded (provides ``/dev/nitro_encla= ves``) +* CPU cores allocated to the Nitro Enclaves pool via ``nitro-enclaves-allo= cator`` +* Huge pages allocated for Nitro Enclaves via ``nitro-enclaves-allocator`` + +Quick Start +----------- + +Launch a Nitro Enclave from a pre-built EIF file:: + + $ qemu-system-x86_64 -accel nitro,debug-mode=3Don -M nitro -nographic \ + -smp 2 -m 512M -kernel enclave.eif + +Launch an enclave from individual kernel and initrd files:: + + $ qemu-system-x86_64 -accel nitro,debug-mode=3Don -M nitro -nographic \ + -smp 2 -m 512M -kernel vmlinuz -initrd initrd.cpio \ + -append "console=3DttyS0" + +The same commands work with ``qemu-system-aarch64`` on Graviton based EC2 +instances. + +Accelerator +----------- + +The ``nitro`` accelerator (``-accel nitro``) drives the +``/dev/nitro_enclaves`` device to create and manage a Nitro Enclave. +It handles: + +* Creating the enclave VM slot +* Donating memory regions (must be huge page backed) +* Adding vCPUs (must be full physical cores) +* Starting the enclave +* Notifying vsock bus devices of the enclave CID + +Accelerator options: + +``debug-mode=3Don|off`` + Enable debug mode. When enabled, the Nitro Hypervisor exposes the + enclave's serial console output via a vsock port that the machine + model automatically connects to. In debug mode, PCR values are zero. + Default is ``off``. + +Machine +------- + +The ``nitro`` machine (``-M nitro``) is a minimal, architecture-independent +machine that provides only what a Nitro Enclave needs: + +* RAM (huge page backed via memfd) +* vCPUs (defaults to ``host`` CPU type) +* A Nitro vsock bus with: + + - A heartbeat device (vsock server on port 9000) + - A serial console bridge (vsock client, debug mode only) + +Communication to the Nitro Enclave is limited to virtio-vsock. The Enclave +is allocated a CID at launch at which it is reachable. A specific CID can +be requested with ``-accel nitro,enclave-cid=3D`` (0 lets the hypervisor +choose). The assigned CID is readable from the vsock bridge device:: + + (qemu) qom-get /machine/peripheral/nitro-vsock enclave-cid + +EIF Image Format +^^^^^^^^^^^^^^^^ + +Nitro Enclaves boot from EIF (Enclave Image Format) files. When +``-kernel`` points to an EIF file (detected by the ``.eif`` magic +bytes), it is loaded directly into guest memory. + +When ``-kernel`` points to a regular kernel image (e.g. a bzImage or +Image), the machine automatically assembles a minimal EIF on the fly +from ``-kernel``, ``-initrd``, and ``-append``. This allows standard +direct kernel boot without external EIF tooling. + +CPU Requirements +^^^^^^^^^^^^^^^^ + +Nitro Enclaves require full physical CPU cores. On hyperthreaded +systems, this means ``-smp`` must be a multiple of the threads per +core (typically 2). + +Nitro Enclaves can only consume cores that are donated to the Nitro Enclave +CPU pool. You can configure the CPU pool using the ``nitro-enclaves-alloca= tor`` +tool or manually by writing to the nitro_enclaves cpu pool parameter. To +allocate vCPUs 1, 2 and 3, you can call:: + + $ echo 1,2,3 | sudo tee /sys/module/nitro_enclaves/parameters/ne_cpus + +Beware that on x86-64 systems, hyperthread siblings are not consecutive +and must be added in pairs to the pool. Consult tools like ``lstopo`` +or ``lscpu`` for details about your instance's CPU topology. + +Memory Requirements +^^^^^^^^^^^^^^^^^^^ + +Enclave memory must be huge page backed. The machine automatically +creates a memfd memory backend with huge pages enabled. To make the +huge page allocation work, ensure that huge pages are reserved in +the system. To reserve 1 GiB of memory on a 4 KiB PAGE_SIZE system, +you can call:: + + $ echo 512 | sudo tee /proc/sys/vm/nr_hugepages + +Emulated Nitro Enclaves +----------------------- + +In addition to the native Nitro Enclaves invocation, you can also use +the emulated nitro-enclave machine target (see :doc:`i386/nitro-enclave`) +which implements the x86 Nitro Enclave device model. While -M nitro +delegates virtual machine device emulation to the Nitro Hypervisor, -M +nitro-enclave implements all devices itself, which means it also works +on non-EC2 instances. + +If you require NSM based attestation backed by valid AWS certificates, +you must use -M nitro. The -M nitro-enclave model does not provide +you with an AWS signed attestation document. --=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