From: Alexander Graf <graf@amazon.com>
To: <linux-kernel@vger.kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Arnd Bergmann <arnd@arndb.de>
Cc: The AWS Nitro Enclaves Team <aws-nitro-enclaves-devel@amazon.com>,
"Shuah Khan" <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Robin Murphy <robin.murphy@arm.com>, <linux-doc@vger.kernel.org>,
<iommu@lists.linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Mike Rapoport <rppt@kernel.org>, <nh-open-source@amazon.com>,
<linux-mm@kvack.org>, Jonathan Corbet <corbet@lwn.net>
Subject: [PATCH 23/40] nitro_enclaves: Add the device add command
Date: Wed, 11 Nov 2026 22:59:27 +0000 [thread overview]
Message-ID: <94acc8f58f24e29912b8859859d739460cb74406.1794393490.git.graf@amazon.com> (raw)
In-Reply-To: <cover.1794300002.git.graf@amazon.com>
In preparation to support Nitro Sandboxes, which allow the parent to
back arbitrary virtio devices, add the command definition for adding
devices to a slot.
The device add command specifies the virtio device shape (type, nr VQs,
features, config space), but also allows to specify backing ranges for
DMB or SHM regions.
The full response with the device information is part of the info page
at the returned offset.
Signed-off-by: Alexander Graf <graf@amazon.com>
---
drivers/virt/nitro_enclaves/ne_pci_dev.h | 88 ++++++++++++++++++++++++
1 file changed, 88 insertions(+)
diff --git a/drivers/virt/nitro_enclaves/ne_pci_dev.h b/drivers/virt/nitro_enclaves/ne_pci_dev.h
index f5cb24312d442..3445318b84672 100644
--- a/drivers/virt/nitro_enclaves/ne_pci_dev.h
+++ b/drivers/virt/nitro_enclaves/ne_pci_dev.h
@@ -161,6 +161,7 @@
* @SLOT_ADD_BULK_VCPUS: Add a number of vCPUs, not providing CPU ids.
* @SLOT_ADD_INFO_PAGE: Give a slot the info page, a memory region the
* device writes.
+ * @SLOT_ADD_DEVICE: Give a slot a device the enclave will drive.
* @SLOT_POOL_DONATE: Donate one page of parent memory to the slot
* pool.
* @SLOT_POOL_SHUTDOWN: Give the whole slot pool back.
@@ -186,6 +187,7 @@ enum ne_pci_dev_cmd_type {
SLOT_ADD_BULK_VCPUS = 11,
/* 12 is a command this driver does not implement. */
SLOT_ADD_INFO_PAGE = 13,
+ SLOT_ADD_DEVICE = 14,
SLOT_POOL_DONATE = 16,
SLOT_POOL_SHUTDOWN = 17,
SLOT_POOL_BASE_DONATE = 25,
@@ -333,6 +335,73 @@ struct slot_add_info_page_req {
u64 info_size;
};
+/**
+ * NE_MAX_VQS_PER_DEVICE - Highest number of virtqueues one device may have.
+ */
+#define NE_MAX_VQS_PER_DEVICE (64)
+
+/**
+ * NE_MAX_BACKING_RANGES - Highest number of memory ranges one device may be
+ * backed by.
+ */
+#define NE_MAX_BACKING_RANGES (4)
+
+/**
+ * struct ne_backing_range - One run of enclave memory a device works out of.
+ * @phys_addr: Physical address of the run, in the parent's address space.
+ * @size: Size, in bytes, of the run.
+ */
+struct ne_backing_range {
+ u64 phys_addr;
+ u64 size;
+};
+
+/**
+ * struct ne_vq_wiring - How the enclave reaches one virtqueue of a device.
+ * @msix_vector: Interrupt vector the device raises for the queue.
+ * @notify_index: Index the enclave writes to notify the device.
+ * @msix_entry: Entry in the enclave's interrupt table holding
+ * @msix_vector.
+ * @doorbell_offset: Offset of the queue's doorbell in the device's
+ * doorbell window.
+ */
+struct ne_vq_wiring {
+ u16 msix_vector;
+ u16 notify_index;
+ u16 msix_entry;
+ u16 doorbell_offset;
+};
+
+static_assert(sizeof(struct ne_vq_wiring) == 8);
+
+/**
+ * struct slot_add_device_req - SLOT_ADD_DEVICE request.
+ * @slot_uid: Slot unique id mapped to the slot to give the
+ * device to.
+ * @device_type: Type of device to give the slot.
+ * @num_vqs: Number of virtqueues the device has, at most
+ * NE_MAX_VQS_PER_DEVICE.
+ * @device_features: Feature bits the parent offers the enclave for
+ * the device.
+ * @config_size: Number of bytes of @device_config the device
+ * reads.
+ * @num_backing_ranges: Number of entries of @backing_ranges the
+ * device reads, at most NE_MAX_BACKING_RANGES.
+ * @device_config: Type-specific configuration of the device.
+ * @backing_ranges: Runs of enclave memory the device works out of.
+ */
+struct slot_add_device_req {
+ u64 slot_uid;
+ u32 device_type;
+ u32 num_vqs;
+ u8 device_features[64];
+ u32 config_size;
+ u32 num_backing_ranges;
+ u8 device_config[64];
+ struct ne_backing_range backing_ranges[NE_MAX_BACKING_RANGES];
+} __packed;
+static_assert(sizeof(struct slot_add_device_req) <= NE_SEND_DATA_SIZE);
+
/**
* struct slot_pool_donate_req - SLOT_POOL_DONATE and SLOT_POOL_BASE_DONATE
* request.
@@ -408,6 +477,15 @@ struct slot_pool_mem_donate_req {
* slot out of.
* @limits.reserved14: SLOT_POOL_GET_LIMITS. Bytes the device writes as
* zero.
+ * @add_device: Fields SLOT_ADD_DEVICE fills.
+ * @add_device.device_uid: SLOT_ADD_DEVICE. Unique id of the new device.
+ * @add_device.num_vqs: SLOT_ADD_DEVICE. Number of entries of wiring
+ * the device wrote to the info page.
+ * @add_device.reserved12: SLOT_ADD_DEVICE. Bytes owned by other
+ * commands.
+ * @add_device.vq_wiring_offset: SLOT_ADD_DEVICE. Offset into the info
+ * page at which @num_vqs entries of struct
+ * ne_vq_wiring start.
*/
struct ne_pci_dev_cmd_reply {
s32 rc;
@@ -443,6 +521,12 @@ struct ne_pci_dev_cmd_reply {
u16 slots_per_donation;
u16 reserved14;
} limits;
+ struct {
+ u64 device_uid;
+ u32 num_vqs;
+ u32 reserved12;
+ u64 vq_wiring_offset;
+ } add_device;
};
};
@@ -452,6 +536,10 @@ static_assert(offsetof(struct ne_pci_dev_cmd_reply, start.enclave_cid) == 16);
static_assert(offsetof(struct ne_pci_dev_cmd_reply, alloc.slot_uid) == 8);
static_assert(offsetof(struct ne_pci_dev_cmd_reply, alloc.mem_regions) == 32);
static_assert(offsetof(struct ne_pci_dev_cmd_reply, info.slot_uid) == 8);
+static_assert(offsetof(struct ne_pci_dev_cmd_reply, add_device.device_uid) == 8);
+static_assert(offsetof(struct ne_pci_dev_cmd_reply, add_device.num_vqs) == 16);
+static_assert(offsetof(struct ne_pci_dev_cmd_reply,
+ add_device.vq_wiring_offset) == 24);
static_assert(offsetof(struct ne_pci_dev_cmd_reply, info.enclave_cid) == 16);
static_assert(offsetof(struct ne_pci_dev_cmd_reply, info.mem_regions) == 32);
static_assert(offsetof(struct ne_pci_dev_cmd_reply, info.mem_size) == 40);
--
2.47.1
next prev parent reply other threads:[~2026-11-11 23:04 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 22:41 [PATCH 00/40] nitro_enclaves: Add support for Nitro Sandboxes Alexander Graf
2026-11-11 22:41 ` [PATCH 01/40] nitro_enclaves: Allow the CPU pool to span NUMA nodes Alexander Graf
2026-11-11 22:41 ` [PATCH 02/40] nitro_enclaves: Add NE_ADD_ANY_VCPU Alexander Graf
2026-11-11 22:41 ` [PATCH 03/40] nitro_enclaves: Expose CPU pool state under sysfs Alexander Graf
2026-11-11 22:41 ` [PATCH 04/40] nitro_enclaves: Document multi-NUMA CPU pools Alexander Graf
2026-11-11 22:41 ` [PATCH 05/40] dma-contiguous: add dma_get_numa_cma_area() accessor Alexander Graf
2026-11-11 22:41 ` [PATCH 06/40] nitro_enclaves: Add NE_ALLOC_MEMORY ioctl Alexander Graf
2026-11-11 22:41 ` [PATCH 07/40] nitro_enclaves: Add NE_MEMORY_SHARED Alexander Graf
2026-11-11 22:41 ` [PATCH 08/40] nitro_enclaves: Add NE_ADD_MEMORY_REGION Alexander Graf
2026-11-11 22:41 ` [PATCH 09/40] nitro_enclaves: Document the memory pool Alexander Graf
2026-11-11 22:41 ` [PATCH 10/40] nitro_enclaves: Add NE_CREATE_VM2 with a launch flag word Alexander Graf
2026-11-11 22:41 ` [PATCH 11/40] nitro_enclaves: Add NE_ENCLAVE_PCIE_MODE launch flag Alexander Graf
2026-11-11 22:41 ` [PATCH 12/40] nitro_enclaves: Name the device's error codes in the UAPI header Alexander Graf
2026-11-11 22:41 ` [PATCH 13/40] nitro_enclaves: Log a reached device limit at info level Alexander Graf
2026-11-11 22:56 ` [PATCH 14/40] nitro_enclaves: Add NE_SET_INFO_PAGE Alexander Graf
2026-11-11 22:59 ` [PATCH 15/40] nitro_enclaves: Document the info page in the memory pool Alexander Graf
2026-11-11 22:59 ` [PATCH 16/40] nitro_enclaves: Turn the command reply into a per-command union Alexander Graf
2026-11-11 22:59 ` [PATCH 17/40] nitro_enclaves: Add the slot pool donation commands Alexander Graf
2026-11-11 22:59 ` [PATCH 18/40] nitro_enclaves: Donate memory for the slot pool Alexander Graf
2026-11-11 22:59 ` [PATCH 19/40] nitro_enclaves: Add the slot pool growth commands Alexander Graf
2026-11-11 22:59 ` [PATCH 20/40] nitro_enclaves: Add a helper to grow the slot pool Alexander Graf
2026-11-11 22:59 ` [PATCH 21/40] nitro_enclaves: Document " Alexander Graf
2026-11-11 22:59 ` [PATCH 22/40] nitro_enclaves: Expose slot pool state under sysfs Alexander Graf
2026-11-11 22:59 ` Alexander Graf [this message]
2026-11-11 22:59 ` [PATCH 24/40] nitro_enclaves: Add NE_ADD_DEVICE Alexander Graf
2026-11-11 22:59 ` [PATCH 25/40] nitro_enclaves: Read the interrupt multiplexer geometry at probe Alexander Graf
2026-11-11 22:59 ` [PATCH 26/40] nitro_enclaves: Donate a bitmap page per multiplexed vector Alexander Graf
2026-11-11 22:59 ` [PATCH 27/40] nitro_enclaves: Dispatch multiplexed interrupts to per-queue bindings Alexander Graf
2026-11-11 22:59 ` [PATCH 28/40] nitro_enclaves: Add NE_SET_NOTIFY_EVENTFD Alexander Graf
2026-11-11 22:59 ` [PATCH 29/40] nitro_enclaves: Report the device's info notification Alexander Graf
2026-11-11 22:59 ` [PATCH 30/40] nitro_enclaves: Count multiplexed interrupts under debugfs Alexander Graf
2026-11-11 22:59 ` [PATCH 31/40] nitro_enclaves: Map the doorbell window at probe Alexander Graf
2026-11-11 22:59 ` [PATCH 32/40] nitro_enclaves: Add NE_SET_VRING_CALL Alexander Graf
2026-11-11 22:59 ` [PATCH 33/40] nitro_enclaves: Assert the layout of the ioctl argument structs Alexander Graf
2026-11-11 22:59 ` [PATCH 34/40] nitro_enclaves: Pass on the Nitro Sandbox launch flags Alexander Graf
2026-11-11 22:59 ` [PATCH 35/40] nitro_enclaves: Add NE_ENCLAVE_DIRECT_MODE Alexander Graf
2026-11-11 22:59 ` [PATCH 36/40] nitro_enclaves: Add NE_ENCLAVE_PCIE_HOTPLUG_MODE Alexander Graf
2026-11-11 22:59 ` [PATCH 37/40] nitro_enclaves: Add NE_ENCLAVE_CPU_OVERCOMMIT_MODE Alexander Graf
2026-11-11 22:59 ` [PATCH 38/40] nitro_enclaves: Add NE_GET_CAPS Alexander Graf
2026-11-11 22:59 ` [PATCH 39/40] nitro_enclaves: Add NE_UPDATE_DEVICE_CONFIG Alexander Graf
2026-11-11 22:59 ` [PATCH 40/40] nitro_enclaves: Document the driver side of Nitro Sandboxes Alexander Graf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=94acc8f58f24e29912b8859859d739460cb74406.1794393490.git.graf@amazon.com \
--to=graf@amazon.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=aws-nitro-enclaves-devel@amazon.com \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=iommu@lists.linux.dev \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=m.szyprowski@samsung.com \
--cc=nh-open-source@amazon.com \
--cc=rdunlap@infradead.org \
--cc=robin.murphy@arm.com \
--cc=rppt@kernel.org \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®