[PATCH 10/40] nitro_enclaves: Add NE_CREATE_VM2 with a launch flag word
From: Alexander Graf
Date: Wed Nov 11 2026 - 17:53:25 EST
In preparation to support Nitro Sandboxes, whose properties the
hypervisor needs before it allocates a slot, add NE_CREATE_VM2. It takes
a word of launch flags for the slot. The slot id comes back in the
same struct ne_create_vm_args.
No flag is defined in this patch, so any set bit fails with
-NE_ERR_INVALID_FLAG_VALUE.
Signed-off-by: Alexander Graf <graf@xxxxxxxxxx>
---
drivers/virt/nitro_enclaves/ne_misc_dev.c | 53 +++++++++++++++++++++--
include/uapi/linux/nitro_enclaves.h | 48 ++++++++++++++++++++
2 files changed, 97 insertions(+), 4 deletions(-)
diff --git a/drivers/virt/nitro_enclaves/ne_misc_dev.c b/drivers/virt/nitro_enclaves/ne_misc_dev.c
index 38345ad7c7985..68c497df4f14b 100644
--- a/drivers/virt/nitro_enclaves/ne_misc_dev.c
+++ b/drivers/virt/nitro_enclaves/ne_misc_dev.c
@@ -2452,6 +2452,8 @@ static const struct file_operations ne_enclave_fops = {
* enclave file descriptor to be further used for enclave
* resources handling e.g. memory regions and CPUs.
* @ne_pci_dev : Private data associated with the PCI device.
+ * @flags: Launch-time flag word from NE_CREATE_VM2, or zero when
+ * the caller used the flag-less NE_CREATE_VM.
* @slot_uid: User pointer to store the generated unique slot id
* associated with an enclave to.
*
@@ -2461,7 +2463,8 @@ static const struct file_operations ne_enclave_fops = {
* * Enclave fd on success.
* * Negative return value on failure.
*/
-static int ne_create_vm_ioctl(struct ne_pci_dev *ne_pci_dev, u64 __user *slot_uid)
+static int ne_create_vm_ioctl(struct ne_pci_dev *ne_pci_dev, u64 flags,
+ u64 __user *slot_uid)
{
struct ne_pci_dev_cmd_reply cmd_reply = {};
int enclave_fd = -1;
@@ -2472,6 +2475,13 @@ static int ne_create_vm_ioctl(struct ne_pci_dev *ne_pci_dev, u64 __user *slot_ui
int rc = -EINVAL;
struct slot_alloc_req slot_alloc_req = {};
+ if (flags) {
+ dev_err_ratelimited(ne_misc_dev.this_device,
+ "Unknown launch flag bit set 0x%llx\n", flags);
+
+ return -NE_ERR_INVALID_FLAG_VALUE;
+ }
+
mutex_lock(&ne_cpu_pool.mutex);
for (i = 0; i < ne_cpu_pool.nr_parent_vm_cores; i++)
@@ -2626,7 +2636,44 @@ static long ne_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
if (ne_pci_dev) {
rc = mutex_lock_killable(&ne_pci_dev->enclaves_list_mutex);
if (!rc) {
- rc = ne_create_vm_ioctl(ne_pci_dev, slot_uid);
+ rc = ne_create_vm_ioctl(ne_pci_dev, 0, slot_uid);
+ mutex_unlock(&ne_pci_dev->enclaves_list_mutex);
+ }
+ }
+
+ up_read(&ne_devs.lock);
+
+ return rc;
+ }
+ }
+
+ /* Extensible Argument ioctls */
+ switch (NE_EA_IOCTL(cmd)) {
+ case NE_EA_IOCTL(NE_CREATE_VM2): {
+ struct ne_create_vm_args args;
+ struct ne_create_vm_args __user *uargs = (void __user *)arg;
+ unsigned int usize = _IOC_SIZE(cmd);
+ struct ne_pci_dev *ne_pci_dev;
+ int rc;
+
+ if (usize < offsetofend(struct ne_create_vm_args, slot_uid))
+ return -EINVAL;
+
+ rc = copy_struct_from_user(&args, sizeof(args), uargs, usize);
+ if (rc)
+ return rc;
+
+ rc = down_read_killable(&ne_devs.lock);
+ if (rc)
+ return rc;
+
+ rc = -ENODEV;
+ ne_pci_dev = ne_devs.ne_pci_dev;
+ if (ne_pci_dev) {
+ rc = mutex_lock_killable(&ne_pci_dev->enclaves_list_mutex);
+ if (!rc) {
+ rc = ne_create_vm_ioctl(ne_pci_dev, args.flags,
+ &uargs->slot_uid);
mutex_unlock(&ne_pci_dev->enclaves_list_mutex);
}
}
@@ -2639,8 +2686,6 @@ static long ne_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
default:
return -ENOTTY;
}
-
- return 0;
}
/*
diff --git a/include/uapi/linux/nitro_enclaves.h b/include/uapi/linux/nitro_enclaves.h
index 16515fe27b692..8e43be9a0a1fa 100644
--- a/include/uapi/linux/nitro_enclaves.h
+++ b/include/uapi/linux/nitro_enclaves.h
@@ -46,6 +46,54 @@
*/
#define NE_CREATE_VM _IOR(0xAE, 0x20, __u64)
+/**
+ * struct ne_create_vm_args - NE_CREATE_VM2 argument (in / out).
+ * @flags: Launch-time flag word (in). Flags select properties of the
+ * enclave slot that the hypervisor has to know at allocation
+ * time. NE_ENCLAVE_DEBUG_MODE stays a start-time property and
+ * is rejected here.
+ * @slot_uid: Generated unique slot id associated with an enclave (out).
+ */
+struct ne_create_vm_args {
+ __u64 flags;
+ __u64 slot_uid;
+};
+
+/**
+ * NE_CREATE_VM2 - As NE_CREATE_VM, additionally taking a launch-time flag
+ * word. The flags carry properties of the slot that have to
+ * be decided when the slot is allocated rather than when the
+ * enclave starts.
+ *
+ * NE_CREATE_VM continues to work; calling it is equivalent
+ * to calling NE_CREATE_VM2 with a zero flag word.
+ *
+ * The argument is read with copy_struct_from_user(), so a
+ * caller built against a header that predates a field this
+ * kernel knows leaves that field zero, and a caller that
+ * sets a field this kernel does not know is refused.
+ *
+ * Context: Process context.
+ * Return:
+ * * Enclave file descriptor - As for NE_CREATE_VM.
+ * * -1 - There was a failure in the ioctl logic.
+ * On failure, errno is set to:
+ * * ENODEV - The NE PCI device is not available.
+ * * EFAULT - Argument read or write failure.
+ * * NE_ERR_INVALID_FLAG_VALUE - Unknown flag bit set, or
+ * NE_ENCLAVE_DEBUG_MODE set.
+ * * EINVAL - The argument stops before @slot_uid.
+ * * E2BIG - The argument carries a field this kernel
+ * does not know, set to a non-zero value.
+ * * 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_VM2 _IOWR(0xAE, 0x30, struct ne_create_vm_args)
+
/**
* NE_ADD_VCPU - The command is used to set a vCPU for an enclave. The vCPU can
* be auto-chosen from the NE CPU pool or it can be set by the
--
2.47.1