Re: [PATCH] x86/sgx: Free backing memory after faulting the enclave page

From: Dave Hansen
Date: Sun Nov 07 2021 - 15:01:21 EST


On 11/7/21 11:45 AM, Jarkko Sakkinen wrote:
> On Sun, Nov 07, 2021 at 11:06:01AM -0800, Dave Hansen wrote:
>> That's true, the page cache should all be torn down along with the
>> fput(). *But*, it would be a very nice property if the backing storage
>> was empty by this point. It essentially ensures that no enclave-runtime
>> cases missed truncating the backing storage away.
>
> What if an enclave is released a point when all of its pages
> are swapped out? Or even simpler case would an enclave that is
> larger than all of EPC.

In this loop:

void sgx_encl_release(struct kref *ref)
{
...
xa_for_each(&encl->page_array, index, entry) {
if (entry->epc_page == NULL)
// truncate backing storage

> What can be made sure is that for all pages, which are in EPC,
> the backing page is truncated.

Right, and that should be utterly trivial to do.