linux/arch/x86/kernel/cpu/sgx
Jarkko Sakkinen 08999b2489 x86/sgx: Free backing memory after faulting the enclave page
There is a limited amount of SGX memory (EPC) on each system.  When that
memory is used up, SGX has its own swapping mechanism which is similar
in concept but totally separate from the core mm/* code.  Instead of
swapping to disk, SGX swaps from EPC to normal RAM.  That normal RAM
comes from a shared memory pseudo-file and can itself be swapped by the
core mm code.  There is a hierarchy like this:

	EPC <-> shmem <-> disk

After data is swapped back in from shmem to EPC, the shmem backing
storage needs to be freed.  Currently, the backing shmem is not freed.
This effectively wastes the shmem while the enclave is running.  The
memory is recovered when the enclave is destroyed and the backing
storage freed.

Sort this out by freeing memory with shmem_truncate_range(), as soon as
a page is faulted back to the EPC.  In addition, free the memory for
PCMD pages as soon as all PCMD's in a page have been marked as unused
by zeroing its contents.

Cc: stable@vger.kernel.org
Fixes: 1728ab54b4 ("x86/sgx: Add a page reclaimer")
Reported-by: Dave Hansen <dave.hansen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Link: https://lkml.kernel.org/r/20220303223859.273187-1-jarkko@kernel.org
2022-03-11 10:31:06 -08:00
..
driver.c x86/sgx: Move provisioning device creation out of SGX driver 2021-04-06 19:18:46 +02:00
driver.h x86/sgx: Add SGX_IOC_ENCLAVE_PROVISION 2020-11-18 18:02:50 +01:00
encl.c x86/sgx: Free backing memory after faulting the enclave page 2022-03-11 10:31:06 -08:00
encl.h x86/sgx: use vma_lookup() in sgx_encl_find() 2021-06-29 10:53:51 -07:00
encls.h x86/sgx: Remove .fixup usage 2021-12-11 09:09:49 +01:00
ioctl.c x86/sgx: Move provisioning device creation out of SGX driver 2021-04-06 19:18:46 +02:00
main.c x86/sgx: Fix missing poison handling in reclaimer 2022-02-17 10:24:50 -08:00
Makefile x86/sgx: Introduce virtual EPC for use by KVM guests 2021-04-06 09:43:17 +02:00
sgx.h x86/sgx: Add an attribute for the amount of SGX memory in a NUMA node 2021-12-09 07:02:22 -08:00
virt.c x86/sgx/virt: implement SGX_IOC_VEPC_REMOVE ioctl 2021-10-22 08:32:12 -07:00