arch/x86/kernel/cpu/sgx/ioctl.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/cpu/sgx/ioctl.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/cpu/sgx/ioctl.c- Extension
.c- Size
- 31936 bytes
- Lines
- 1245
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- 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
asm/mman.hasm/sgx.hcrypto/sha2.hlinux/mman.hlinux/delay.hlinux/file.hlinux/hashtable.hlinux/highmem.hlinux/ratelimit.hlinux/sched/signal.hlinux/shmem_fs.hlinux/slab.hlinux/suspend.hdriver.hencl.hencls.h
Detected Declarations
function sgx_encl_shrinkfunction sgx_encl_createfunction sgx_ioc_enclave_createfunction sgx_validate_secinfofunction __sgx_encl_add_pagefunction __sgx_encl_extendfunction sgx_encl_add_pagefunction sgx_validate_offset_lengthfunction sgx_ioc_enclave_add_pagesfunction sgx_encl_initfunction sgx_ioc_enclave_initfunction sgx_ioc_enclave_provisionfunction sgx_ioc_sgx2_readyfunction sgx_enclave_etrackfunction sgx_enclave_restrict_permissionsfunction sgx_ioc_enclave_restrict_permissionsfunction sgx_enclave_modify_typesfunction sgx_ioc_enclave_modify_typesfunction sgx_encl_remove_pagesfunction sgx_ioc_enclave_remove_pagesfunction sgx_ioctl
Annotated Snippet
if (IS_ERR(va_page->epc_page)) {
err = ERR_CAST(va_page->epc_page);
kfree(va_page);
return err;
}
WARN_ON_ONCE(encl->page_cnt % SGX_VA_SLOT_COUNT);
}
encl->page_cnt++;
return va_page;
}
void sgx_encl_shrink(struct sgx_encl *encl, struct sgx_va_page *va_page)
{
encl->page_cnt--;
if (va_page) {
sgx_encl_free_epc_page(va_page->epc_page);
list_del(&va_page->list);
kfree(va_page);
}
}
static int sgx_encl_create(struct sgx_encl *encl, struct sgx_secs *secs)
{
struct sgx_epc_page *secs_epc;
struct sgx_va_page *va_page;
struct sgx_pageinfo pginfo;
struct sgx_secinfo secinfo;
unsigned long encl_size;
struct file *backing;
long ret;
/*
* ECREATE would detect this too, but checking here also ensures
* that the 'encl_size' calculations below can never overflow.
*/
if (!is_power_of_2(secs->size))
return -EINVAL;
va_page = sgx_encl_grow(encl, true);
if (IS_ERR(va_page))
return PTR_ERR(va_page);
else if (va_page)
list_add(&va_page->list, &encl->va_pages);
/* else the tail page of the VA page list had free slots. */
/* The extra page goes to SECS. */
encl_size = secs->size + PAGE_SIZE;
backing = shmem_file_setup("SGX backing", encl_size + (encl_size >> 5),
mk_vma_flags(VMA_NORESERVE_BIT));
if (IS_ERR(backing)) {
ret = PTR_ERR(backing);
goto err_out_shrink;
}
encl->backing = backing;
secs_epc = sgx_alloc_epc_page(&encl->secs, true);
if (IS_ERR(secs_epc)) {
ret = PTR_ERR(secs_epc);
goto err_out_backing;
}
encl->secs.epc_page = secs_epc;
pginfo.addr = 0;
pginfo.contents = (unsigned long)secs;
pginfo.metadata = (unsigned long)&secinfo;
pginfo.secs = 0;
memset(&secinfo, 0, sizeof(secinfo));
ret = __ecreate((void *)&pginfo, sgx_get_epc_virt_addr(secs_epc));
if (ret) {
ret = -EIO;
goto err_out;
}
if (secs->attributes & SGX_ATTR_DEBUG)
set_bit(SGX_ENCL_DEBUG, &encl->flags);
encl->secs.encl = encl;
encl->secs.type = SGX_PAGE_TYPE_SECS;
encl->base = secs->base;
encl->size = secs->size;
encl->attributes = secs->attributes;
encl->attributes_mask = SGX_ATTR_UNPRIV_MASK;
/* Set only after completion, as encl->lock has not been taken. */
Annotation
- Immediate include surface: `asm/mman.h`, `asm/sgx.h`, `crypto/sha2.h`, `linux/mman.h`, `linux/delay.h`, `linux/file.h`, `linux/hashtable.h`, `linux/highmem.h`.
- Detected declarations: `function sgx_encl_shrink`, `function sgx_encl_create`, `function sgx_ioc_enclave_create`, `function sgx_validate_secinfo`, `function __sgx_encl_add_page`, `function __sgx_encl_extend`, `function sgx_encl_add_page`, `function sgx_validate_offset_length`, `function sgx_ioc_enclave_add_pages`, `function sgx_encl_init`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source 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.