[PATCH 34/40] nitro_enclaves: Pass on the Nitro Sandbox launch flags

From: Alexander Graf

Date: Wed Nov 11 2026 - 18:37:21 EST


Nitro Sandboxes support multiple flags to enable or disable particular
bits of functionality. These bits are typically in sync with the EIF file
and need to get set already on slot creation, not only when we start the
sandbox.

Add definitions for the first batch of launch flags and make sure user
space can only set known flags:

NE_ENCLAVE_PCIE_VSOCK_MODE - Parent may add one single vsock device
NE_ENCLAVE_PCIE_VIRTIO_MODE - Parent may add (almost) any virtio device
NE_ENCLAVE_PCIE_NUMA_MODE - Slot may span multiple NUMA nodes

Signed-off-by: Alexander Graf <graf@xxxxxxxxxx>
---
drivers/virt/nitro_enclaves/ne_misc_dev.c | 2 +-
drivers/virt/nitro_enclaves/ne_misc_dev.h | 8 +++++
include/uapi/linux/nitro_enclaves.h | 38 +++++++++++++++++++++++
3 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/drivers/virt/nitro_enclaves/ne_misc_dev.c b/drivers/virt/nitro_enclaves/ne_misc_dev.c
index f3ad8ddc31e5b..961b821d6038b 100644
--- a/drivers/virt/nitro_enclaves/ne_misc_dev.c
+++ b/drivers/virt/nitro_enclaves/ne_misc_dev.c
@@ -3402,7 +3402,7 @@ static int ne_create_vm_ioctl(struct ne_pci_dev *ne_pci_dev, u64 flags,
int rc = -EINVAL;
struct slot_alloc_req slot_alloc_req = {};

- if (flags & ~(u64)NE_ENCLAVE_PCIE_MODE) {
+ if (flags & ~(u64)NE_ENCLAVE_FLAG_VALID_MASK) {
dev_err_ratelimited(ne_misc_dev.this_device,
"Unknown launch flag bit set 0x%llx\n", flags);

diff --git a/drivers/virt/nitro_enclaves/ne_misc_dev.h b/drivers/virt/nitro_enclaves/ne_misc_dev.h
index f9ef79fafa2be..b0d0438157260 100644
--- a/drivers/virt/nitro_enclaves/ne_misc_dev.h
+++ b/drivers/virt/nitro_enclaves/ne_misc_dev.h
@@ -19,6 +19,14 @@

#include "ne_pci_dev.h"

+/*
+ * NE_ENCLAVE_FLAG_VALID_MASK - Every launch flag this kernel passes on.
+ */
+#define NE_ENCLAVE_FLAG_VALID_MASK (NE_ENCLAVE_PCIE_MODE | \
+ NE_ENCLAVE_PCIE_VSOCK_MODE | \
+ NE_ENCLAVE_PCIE_VIRTIO_MODE | \
+ NE_ENCLAVE_PCIE_NUMA_MODE)
+
struct cma;

/**
diff --git a/include/uapi/linux/nitro_enclaves.h b/include/uapi/linux/nitro_enclaves.h
index 01bec4d072d6a..67be5c383c54b 100644
--- a/include/uapi/linux/nitro_enclaves.h
+++ b/include/uapi/linux/nitro_enclaves.h
@@ -58,6 +58,44 @@
*/
#define NE_ENCLAVE_PCIE_MODE (1u << 6)

+/**
+ * NE_ENCLAVE_PCIE_VSOCK_MODE - Allocate a slot whose PCIe bus holds one
+ * virtio-vsock device, attached before the enclave
+ * starts. Requires NE_ENCLAVE_PCIE_MODE and
+ * excludes NE_ENCLAVE_PCIE_VIRTIO_MODE.
+ */
+#define NE_ENCLAVE_PCIE_VSOCK_MODE (1u << 7)
+
+/**
+ * NE_ENCLAVE_PCIE_VIRTIO_MODE - Allocate a slot whose PCIe bus takes any
+ * virtio device type %NE_ADD_DEVICE offers it.
+ * Requires NE_ENCLAVE_PCIE_MODE and excludes
+ * NE_ENCLAVE_PCIE_VSOCK_MODE.
+ */
+#define NE_ENCLAVE_PCIE_VIRTIO_MODE (1u << 9)
+
+/**
+ * NE_ENCLAVE_PCIE_NUMA_MODE - Allocate a slot whose memory and vCPUs may come
+ * from more than one host NUMA node. Without it the
+ * hypervisor refuses a slot that would straddle a
+ * node boundary. Requires NE_ENCLAVE_PCIE_MODE.
+ */
+#define NE_ENCLAVE_PCIE_NUMA_MODE (1u << 13)
+
+/**
+ * NE_ENCLAVE_FLAG_UNMATCHED_MASK - The launch flags the hypervisor does not
+ * enumerate. It answers for them when a slot is
+ * allocated with them and not before.
+ */
+#define NE_ENCLAVE_FLAG_UNMATCHED_MASK (0x003fu)
+
+/**
+ * NE_ENCLAVE_FLAG_MATCHED_MASK - The launch flags the hypervisor enumerates.
+ * It answers for them before a slot is
+ * allocated with them.
+ */
+#define NE_ENCLAVE_FLAG_MATCHED_MASK (0xffc0u)
+
/**
* struct ne_create_vm_args - NE_CREATE_VM2 argument (in / out).
* @flags: Launch-time flag word (in). Flags select properties of the
--
2.47.1