From: Reinette Chatre <reinette.chatre@intel.com>
To: Dave Hansen <dave.hansen@intel.com>,
<dave.hansen@linux.intel.com>, <jarkko@kernel.org>,
<linux-sgx@vger.kernel.org>
Cc: <haitao.huang@intel.com>
Subject: Re: [PATCH V2 1/5] x86/sgx: Disconnect backing page references from dirty status
Date: Tue, 10 May 2022 16:00:10 -0700 [thread overview]
Message-ID: <e7e2952a-113d-fff7-6312-464aa6355466@intel.com> (raw)
In-Reply-To: <8922e48f-6646-c7cc-6393-7c78dcf23d23@intel.com>
Hi Dave,
On 5/10/2022 1:12 PM, Dave Hansen wrote:
> On 5/9/22 14:47, Reinette Chatre wrote:
>> --- a/arch/x86/kernel/cpu/sgx/main.c
>> +++ b/arch/x86/kernel/cpu/sgx/main.c
>> @@ -190,6 +190,8 @@ static int __sgx_encl_ewb(struct sgx_epc_page *epc_page, void *va_slot,
>> pginfo.metadata = (unsigned long)kmap_atomic(backing->pcmd) +
>> backing->pcmd_offset;
>>
>> + set_page_dirty(backing->pcmd);
>> + set_page_dirty(backing->contents);
>> ret = __ewb(&pginfo, sgx_get_epc_virt_addr(epc_page), va_slot);
>
> I think I may have led you astray on this. It's typical to do:
>
> lock_page(page)
> set_page_dirty(backing->contents);
> // modify page
> unlock_page(page)
>
> That's safe because laundering the page requires locking it. But, the
> page lock isn't held in this case. So, it's possible to do:
>
> get_page(page) // page can be truncated, but not reclaimed
> set_page_dirty(page)
> // race: something launders page here
> __ewb(page)
> put_page(page)
> // page is reclaimed, __ewb() contents were thrown away
>
> __shmem_rw() has a similar pattern to what __sgx_encl_ewb() uses. It
> doesn't hold a lock_page(), but does dirty the page *after* its memset()
> writes to the page.
>
> In other words, I think the page dirtying order in the previous (before
> this patch) SGX code was correct. The concept of this patch is correct,
> but let's just change the dirtying order, please.
>
> Could you also please add a cc: stable@ and a Link: to either this
> message or the original message where I suggested this, like this
> (temporary) commit has:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/daveh/devel.git/commit/?h=testme&id=5ee32d5d3f3cdb943b01992d2ffc5093b139d023
Will do. Thank you very much.
Reinette
next prev parent reply other threads:[~2022-05-10 23:00 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-09 21:47 [PATCH V2 0/5] SGX shmem backing store issue Reinette Chatre
2022-05-09 21:47 ` [PATCH V2 1/5] x86/sgx: Disconnect backing page references from dirty status Reinette Chatre
2022-05-10 20:12 ` Dave Hansen
2022-05-10 23:00 ` Reinette Chatre [this message]
2022-05-09 21:48 ` [PATCH V2 2/5] x86/sgx: Mark PCMD page as dirty when modifying contents Reinette Chatre
2022-05-11 10:43 ` Jarkko Sakkinen
2022-05-11 18:01 ` Reinette Chatre
2022-05-12 14:15 ` Jarkko Sakkinen
2022-05-09 21:48 ` [PATCH V2 3/5] x86/sgx: Obtain backing storage page with enclave mutex held Reinette Chatre
2022-05-11 11:13 ` Jarkko Sakkinen
2022-05-11 18:02 ` Reinette Chatre
2022-05-12 14:14 ` Jarkko Sakkinen
2022-05-09 21:48 ` [PATCH V2 4/5] x86/sgx: Fix race between reclaimer and page fault handler Reinette Chatre
2022-05-10 21:55 ` Dave Hansen
2022-05-10 23:01 ` Reinette Chatre
2022-05-09 21:48 ` [PATCH V2 5/5] x86/sgx: Ensure no data in PCMD page after truncate Reinette Chatre
2022-05-11 10:36 ` Jarkko Sakkinen
2022-05-11 18:02 ` Reinette Chatre
2022-05-11 15:00 ` [PATCH V2 0/5] SGX shmem backing store issue Haitao Huang
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=e7e2952a-113d-fff7-6312-464aa6355466@intel.com \
--to=reinette.chatre@intel.com \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=haitao.huang@intel.com \
--cc=jarkko@kernel.org \
--cc=linux-sgx@vger.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