reclaimer_writing_to_pcmd(9)
π reclaimer_writing_to_pcmd π
okay so this is a page from the Kernel API Manual (section 9), and it's lowkey one of the most niche-but-important little helpers in the SGX corner of the kernel. bestie, let's get into it π
β¨ NAME β¨
reclaimer_writing_to_pcmd β literally just: is anybody out there reclaiming an enclave page that lives in this PCMD page right now? π
Think of it as a vibe check for a PCMD page before you truncate it. no cap.
πΈ SYNOPSIS πΈ
int reclaimer_writing_to_pcmd (struct sgx_encl *encl, unsigned long start_addr);
π¦ ARGUMENTS π¦
enclβ the enclave that this PCMD page belongs to. it's giving "whose page is this anyway" π«Άstart_addrβ the address of the enclave page that uses the first entry within the PCMD page. like, entry number one, the main character of that page π
π DESCRIPTION π
so when an enclave page gets reclaimed, some Paging Crypto MetaData (PCMD) gets stored. periodt. that PCMD data for a reclaimed enclave page holds enough info for the processor to verify the page at the moment it gets loaded back into the Enclave Page Cache (EPC). it's basically the page's receipts π§Ύβ¨
the backing storage where enclave pages get reclaimed is laid out like this, and yes this is the exact notation:
Encrypted enclave pages:SECS page:PCMD pages
each PCMD page contains the PCMD metadata of PAGE_SIZE/sizeof(struct sgx_pcmd) enclave pages. that's the math, i don't make the rules π
now here's the tea β β a PCMD page can only be truncated if it is:
- (a) empty, and
- (b) not in the process of getting data (and thus soon being non-empty).
and how do we test (b)? with a check whether an enclave page sharing that PCMD page is currently in the process of being reclaimed. iykyk.
the reclaimer sets the SGX_ENCL_PAGE_BEING_RECLAIMED flag when it intends to reclaim that enclave page. translation: the PCMD page associated with that enclave page is about to get some data, so even if the PCMD page is empty, it should not be truncated. like, hands off, it's about to be busy π«βοΈ
π CONTEXT π
the enclave mutex (sgx_encl->lock) must be held. no exceptions, bestie. hold the lock or don't come to the party π
β RETURN β
1β the reclaimer is about to write to the PCMD page ποΈ0β the reclaimer has no intention to write to the PCMD page π ββοΈ
π SEE ALSO π
kernel file ./arch/x86/kernel/cpu/sgx/encl.c plus the whole squad:
sgx_encl_eaug_page(9)sgx_encl_may_map(9)sgx_encl_release(9)sgx_encl_cpumask(9)__sgx_encl_get_backing(9)sgx_encl_alloc_backing(9)sgx_encl_lookup_backing(9)sgx_encl_put_backing(9)sgx_encl_test_and_clear_young(9)sgx_zap_enclave_ptes(9)sgx_alloc_va_page(9)sgx_alloc_va_slot(9)sgx_free_va_slot(9)sgx_va_page_full(9)sgx_encl_free_epc_page(9)
π okay that's the whole page!! this one lives over in ./arch/x86/kernel/cpu/sgx and the date on it is October 2026 β so yeah, future me coded this, iconic behavior honestly ππ«Ά go forth and don't truncate a PCMD page that's mid-glow-up β¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms