]> git.baikalelectronics.ru Git - kernel.git/commit
x86/sgx: Free backing memory after faulting the enclave page
authorJarkko Sakkinen <jarkko@kernel.org>
Thu, 3 Mar 2022 22:38:58 +0000 (00:38 +0200)
committerDave Hansen <dave.hansen@linux.intel.com>
Fri, 11 Mar 2022 18:31:06 +0000 (10:31 -0800)
commitbecc18140176700aada04855a01dc429ce044b8e
tree1caeaa66ccb59a313116799eabcecf628cd602e9
parent6418d83f5c0d0dbdf3d3b3dc35b21223ba763ede
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: 77dac496e929 ("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
arch/x86/kernel/cpu/sgx/encl.c