public inbox for linux-sgx@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Jarkko Sakkinen <jarkko@kernel.org>
Cc: Dave Hansen <dave.hansen@linux.intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Jethro Beekman <jethro@fortanix.com>,
	Sean Christopherson <seanjc@google.com>,
	reinette.chatre@intel.com, tony.luck@intel.com,
	nathaniel@profian.com, stable@vger.kernel.org,
	Borislav Petkov <bp@suse.de>,
	linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86/sgx: Free backing memory after faulting the enclave page
Date: Sun, 7 Nov 2021 11:06:01 -0800	[thread overview]
Message-ID: <984bc7a4-1c7a-f2c0-5885-0dc7fad3d2b6@intel.com> (raw)
In-Reply-To: <YYgVsi7y4TNuSRLc@iki.fi>

On 11/7/21 10:06 AM, Jarkko Sakkinen wrote:
> On Thu, Nov 04, 2021 at 03:38:55PM -0700, Dave Hansen wrote:
>> On 11/3/21 4:22 PM, Jarkko Sakkinen wrote:
>>> --- a/arch/x86/kernel/cpu/sgx/encl.c
>>> +++ b/arch/x86/kernel/cpu/sgx/encl.c
>>> @@ -22,6 +22,7 @@ static int __sgx_encl_eldu(struct sgx_encl_page *encl_page,
>>>  {
>>>  	unsigned long va_offset = encl_page->desc & SGX_ENCL_PAGE_VA_OFFSET_MASK;
>>>  	struct sgx_encl *encl = encl_page->encl;
>>> +	struct inode *inode = file_inode(encl->backing);
>>>  	struct sgx_pageinfo pginfo;
>>>  	struct sgx_backing b;
>>>  	pgoff_t page_index;
>>> @@ -60,6 +61,9 @@ static int __sgx_encl_eldu(struct sgx_encl_page *encl_page,
>>>  
>>>  	sgx_encl_put_backing(&b, false);
>>>  
>>> +	/* Free the backing memory. */
>>> +	shmem_truncate_range(inode, PFN_PHYS(page_index), PFN_PHYS(page_index) + PAGE_SIZE - 1);
>>> +
>>>  	return ret;
>>>  }
>>
>> This also misses tearing down the backing storage if it is in place at
>> sgx_encl_release().
> 
> Hmm... sgx_encl_release() does fput(). Isn't that enough to tear it down,
> or does it require explicit truncate, i.e. something like
> 
>         shmem_truncate_range(file_inode(encl->backing), encl->base, encl->size - 1);

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.

>> Does a entry->epc_page==NULL page in there guarantee that it has backing
>> storage?
> 
> Yes, it is an invariant. That what I was thinking to use for PCMD: iterate
> 32 pages and check if they have a faulted page.

I think the rule should be that entry->epc_page==NULL enclave pages have
backing storage.  All entry->epc_page!=NULL do *not* have backing storage.

  reply	other threads:[~2021-11-07 19:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-03 23:22 [PATCH] x86/sgx: Free backing memory after faulting the enclave page Jarkko Sakkinen
2021-11-04 13:50 ` Dave Hansen
2021-11-04 15:04   ` Jarkko Sakkinen
2021-11-04 15:09     ` Jarkko Sakkinen
2021-11-04 15:13     ` Dave Hansen
2021-11-04 15:25       ` Jarkko Sakkinen
2021-11-04 15:29         ` Dave Hansen
2021-11-07 19:42           ` Jarkko Sakkinen
2021-11-07 19:51             ` Dave Hansen
2021-11-07 22:28               ` Jarkko Sakkinen
2021-11-08  6:34                 ` Dave Hansen
2021-11-08 20:07                   ` Jarkko Sakkinen
2021-11-04 22:38 ` Dave Hansen
2021-11-07 18:06   ` Jarkko Sakkinen
2021-11-07 19:06     ` Dave Hansen [this message]
2021-11-07 19:45       ` Jarkko Sakkinen
2021-11-07 19:58         ` Dave Hansen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=984bc7a4-1c7a-f2c0-5885-0dc7fad3d2b6@intel.com \
    --to=dave.hansen@intel.com \
    --cc=bp@alien8.de \
    --cc=bp@suse.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jarkko@kernel.org \
    --cc=jethro@fortanix.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nathaniel@profian.com \
    --cc=reinette.chatre@intel.com \
    --cc=seanjc@google.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox