linux-stable/arch/x86/kernel/cpu/sgx
Jarkko Sakkinen 1728ab54b4 x86/sgx: Add a page reclaimer
Just like normal RAM, there is a limited amount of enclave memory available
and overcommitting it is a very valuable tool to reduce resource use.
Introduce a simple reclaim mechanism for enclave pages.

In contrast to normal page reclaim, the kernel cannot directly access
enclave memory.  To get around this, the SGX architecture provides a set of
functions to help.  Among other things, these functions copy enclave memory
to and from normal memory, encrypting it and protecting its integrity in
the process.

Implement a page reclaimer by using these functions. Picks victim pages in
LRU fashion from all the enclaves running in the system.  A new kernel
thread (ksgxswapd) reclaims pages in the background based on watermarks,
similar to normal kswapd.

All enclave pages can be reclaimed, architecturally.  But, there are some
limits to this, such as the special SECS metadata page which must be
reclaimed last.  The page version array (used to mitigate replaying old
reclaimed pages) is also architecturally reclaimable, but not yet
implemented.  The end result is that the vast majority of enclave pages are
currently reclaimable.

Co-developed-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Jethro Beekman <jethro@fortanix.com>
Link: https://lkml.kernel.org/r/20201112220135.165028-22-jarkko@kernel.org
2020-11-18 18:04:11 +01:00
..
arch.h
driver.c x86/sgx: Add a page reclaimer 2020-11-18 18:04:11 +01:00
driver.h x86/sgx: Add SGX_IOC_ENCLAVE_PROVISION 2020-11-18 18:02:50 +01:00
encl.c x86/sgx: Add a page reclaimer 2020-11-18 18:04:11 +01:00
encl.h x86/sgx: Add a page reclaimer 2020-11-18 18:04:11 +01:00
encls.h
ioctl.c x86/sgx: Add a page reclaimer 2020-11-18 18:04:11 +01:00
main.c x86/sgx: Add a page reclaimer 2020-11-18 18:04:11 +01:00
Makefile x86/sgx: Add SGX_IOC_ENCLAVE_CREATE 2020-11-18 18:02:49 +01:00
sgx.h x86/sgx: Add a page reclaimer 2020-11-18 18:04:11 +01:00