arch/x86/kernel/cpu/sgx/encl.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/cpu/sgx/encl.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/cpu/sgx/encl.c- Extension
.c- Size
- 36162 bytes
- Lines
- 1327
- 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.
- 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/lockdep.hlinux/mm.hlinux/mman.hlinux/shmem_fs.hlinux/suspend.hlinux/sched/mm.hasm/sgx.hencl.hencls.hsgx.h
Detected Declarations
function reclaimer_writing_to_pcmdfunction sgx_encl_get_backing_page_pcmd_offsetfunction sgx_encl_truncate_backing_pagefunction __sgx_encl_eldufunction sgx_encl_eaug_pagefunction sgx_vma_faultfunction sgx_vma_openfunction sgx_encl_may_mapfunction sgx_vma_mprotectfunction sgx_encl_debug_readfunction sgx_encl_debug_writefunction sgx_vma_accessfunction kref_putfunction sgx_mmu_notifier_releasefunction sgx_mmu_notifier_freefunction list_for_each_entry_rcufunction sgx_encl_mm_addfunction sgx_encl_cpumaskfunction list_for_each_entry_rcufunction __sgx_encl_get_backingfunction list_for_each_entry_rcufunction sgx_encl_alloc_backingfunction sgx_encl_lookup_backingfunction sgx_encl_put_backingfunction sgx_encl_test_and_clear_young_cbfunction sgx_encl_test_and_clear_youngfunction sgx_zap_enclave_ptesfunction list_for_each_entry_rcufunction sgx_alloc_va_pagefunction sgx_alloc_va_slotfunction sgx_free_va_slotfunction sgx_va_page_fullfunction sgx_encl_free_epc_page
Annotated Snippet
if (~page->vm_max_prot_bits & vm_prot_bits) {
ret = -EACCES;
break;
}
/* Reschedule on every XA_CHECK_SCHED iteration. */
if (!(++count % XA_CHECK_SCHED)) {
xas_pause(&xas);
xas_unlock(&xas);
mutex_unlock(&encl->lock);
cond_resched();
mutex_lock(&encl->lock);
xas_lock(&xas);
}
}
xas_unlock(&xas);
mutex_unlock(&encl->lock);
return ret;
}
static int sgx_vma_mprotect(struct vm_area_struct *vma, unsigned long start,
unsigned long end, unsigned long newflags)
{
return sgx_encl_may_map(vma->vm_private_data, start, end, newflags);
}
static int sgx_encl_debug_read(struct sgx_encl *encl, struct sgx_encl_page *page,
unsigned long addr, void *data)
{
unsigned long offset = addr & ~PAGE_MASK;
int ret;
ret = __edbgrd(sgx_get_epc_virt_addr(page->epc_page) + offset, data);
if (ret)
return -EIO;
return 0;
}
static int sgx_encl_debug_write(struct sgx_encl *encl, struct sgx_encl_page *page,
unsigned long addr, void *data)
{
unsigned long offset = addr & ~PAGE_MASK;
int ret;
ret = __edbgwr(sgx_get_epc_virt_addr(page->epc_page) + offset, data);
if (ret)
return -EIO;
return 0;
}
/*
* Load an enclave page to EPC if required, and take encl->lock.
*/
static struct sgx_encl_page *sgx_encl_reserve_page(struct sgx_encl *encl,
unsigned long addr,
vm_flags_t vm_flags)
{
struct sgx_encl_page *entry;
for ( ; ; ) {
mutex_lock(&encl->lock);
entry = sgx_encl_load_page_in_vma(encl, addr, vm_flags);
if (PTR_ERR(entry) != -EBUSY)
break;
mutex_unlock(&encl->lock);
}
if (IS_ERR(entry))
mutex_unlock(&encl->lock);
return entry;
}
static int sgx_vma_access(struct vm_area_struct *vma, unsigned long addr,
void *buf, int len, int write)
{
struct sgx_encl *encl = vma->vm_private_data;
struct sgx_encl_page *entry = NULL;
char data[sizeof(unsigned long)];
unsigned long align;
int offset;
int cnt;
Annotation
- Immediate include surface: `linux/lockdep.h`, `linux/mm.h`, `linux/mman.h`, `linux/shmem_fs.h`, `linux/suspend.h`, `linux/sched/mm.h`, `asm/sgx.h`, `encl.h`.
- Detected declarations: `function reclaimer_writing_to_pcmd`, `function sgx_encl_get_backing_page_pcmd_offset`, `function sgx_encl_truncate_backing_page`, `function __sgx_encl_eldu`, `function sgx_encl_eaug_page`, `function sgx_vma_fault`, `function sgx_vma_open`, `function sgx_encl_may_map`, `function sgx_vma_mprotect`, `function sgx_encl_debug_read`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source implementation candidate.
- 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.