drivers/virt/nitro_enclaves/ne_misc_dev.c
Source file repositories/reference/linux-study-clean/drivers/virt/nitro_enclaves/ne_misc_dev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/virt/nitro_enclaves/ne_misc_dev.c- Extension
.c- Size
- 48378 bytes
- Lines
- 1780
- Domain
- Driver Families
- Bucket
- drivers/virt
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/anon_inodes.hlinux/capability.hlinux/cpu.hlinux/device.hlinux/file.hlinux/hugetlb.hlinux/limits.hlinux/list.hlinux/miscdevice.hlinux/mm.hlinux/mman.hlinux/module.hlinux/mutex.hlinux/nitro_enclaves.hlinux/pci.hlinux/poll.hlinux/range.hlinux/slab.hlinux/types.huapi/linux/vm_sockets.hne_misc_dev.hne_pci_dev.hne_misc_dev_test.c
Detected Declarations
struct ne_cpu_poolstruct ne_phys_contig_mem_regionsfunction ne_check_enclaves_createdfunction ne_setup_cpu_poolfunction for_each_cpufunction for_each_cpufunction enclavefunction ne_teardown_cpu_poolfunction for_each_cpufunction ne_set_kernel_paramfunction ne_donated_cpufunction ne_get_unused_core_from_cpu_poolfunction ne_set_enclave_threads_per_corefunction ne_get_cpu_from_cpu_poolfunction for_each_cpufunction ne_get_vcpu_core_from_cpu_poolfunction ne_check_cpu_in_cpu_poolfunction ne_add_vcpu_ioctlfunction ne_sanity_check_user_mem_regionfunction list_for_each_entryfunction ne_sanity_check_user_mem_region_pagefunction ne_sanity_check_phys_mem_regionfunction ne_merge_phys_contig_memory_regionsfunction ne_set_user_memory_region_ioctlfunction ne_start_enclave_ioctlfunction for_each_cpufunction ne_enclave_ioctlfunction ne_enclave_remove_all_mem_region_entriesfunction list_for_each_entry_safefunction ne_enclave_remove_all_vcpu_id_entriesfunction ne_pci_dev_remove_enclave_entryfunction list_for_each_entry_safefunction ne_enclave_releasefunction ne_enclave_pollfunction ne_create_vm_ioctlfunction ne_ioctlfunction ne_initfunction ne_exitmodule init ne_init
Annotated Snippet
static const struct file_operations ne_fops = {
.owner = THIS_MODULE,
.llseek = noop_llseek,
.unlocked_ioctl = ne_ioctl,
};
static struct miscdevice ne_misc_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "nitro_enclaves",
.fops = &ne_fops,
.mode = 0660,
};
struct ne_devs ne_devs = {
.ne_misc_dev = &ne_misc_dev,
};
/*
* TODO: Update logic to create new sysfs entries instead of using
* a kernel parameter e.g. if multiple sysfs files needed.
*/
static int ne_set_kernel_param(const char *val, const struct kernel_param *kp);
static const struct kernel_param_ops ne_cpu_pool_ops = {
.get = param_get_string,
.set = ne_set_kernel_param,
};
static char ne_cpus[NE_CPUS_SIZE];
static struct kparam_string ne_cpus_arg = {
.maxlen = sizeof(ne_cpus),
.string = ne_cpus,
};
module_param_cb(ne_cpus, &ne_cpu_pool_ops, &ne_cpus_arg, 0644);
/* https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html#cpu-lists */
MODULE_PARM_DESC(ne_cpus, "<cpu-list> - CPU pool used for Nitro Enclaves");
/**
* struct ne_cpu_pool - CPU pool used for Nitro Enclaves.
* @avail_threads_per_core: Available full CPU cores to be dedicated to
* enclave(s). The cpumasks from the array, indexed
* by core id, contain all the threads from the
* available cores, that are not set for created
* enclave(s). The full CPU cores are part of the
* NE CPU pool.
* @mutex: Mutex for the access to the NE CPU pool.
* @nr_parent_vm_cores : The size of the available threads per core array.
* The total number of CPU cores available on the
* primary / parent VM.
* @nr_threads_per_core: The number of threads that a full CPU core has.
* @numa_node: NUMA node of the CPUs in the pool.
*/
struct ne_cpu_pool {
cpumask_var_t *avail_threads_per_core;
struct mutex mutex;
unsigned int nr_parent_vm_cores;
unsigned int nr_threads_per_core;
int numa_node;
};
static struct ne_cpu_pool ne_cpu_pool;
/**
* struct ne_phys_contig_mem_regions - Contiguous physical memory regions.
* @num: The number of regions that currently has.
* @regions: The array of physical memory regions.
*/
struct ne_phys_contig_mem_regions {
unsigned long num;
struct range *regions;
};
/**
* ne_check_enclaves_created() - Verify if at least one enclave has been created.
* @void: No parameters provided.
*
* Context: Process context.
* Return:
* * True if at least one enclave is created.
* * False otherwise.
*/
static bool ne_check_enclaves_created(void)
{
struct ne_pci_dev *ne_pci_dev = ne_devs.ne_pci_dev;
bool ret = false;
if (!ne_pci_dev)
return ret;
Annotation
- Immediate include surface: `linux/anon_inodes.h`, `linux/capability.h`, `linux/cpu.h`, `linux/device.h`, `linux/file.h`, `linux/hugetlb.h`, `linux/limits.h`, `linux/list.h`.
- Detected declarations: `struct ne_cpu_pool`, `struct ne_phys_contig_mem_regions`, `function ne_check_enclaves_created`, `function ne_setup_cpu_pool`, `function for_each_cpu`, `function for_each_cpu`, `function enclave`, `function ne_teardown_cpu_pool`, `function for_each_cpu`, `function ne_set_kernel_param`.
- Atlas domain: Driver Families / drivers/virt.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.