From: Zhiquan Li <zhiquan1.li@intel.com>
To: Dave Hansen <dave.hansen@intel.com>, <linux-sgx@vger.kernel.org>,
<tony.luck@intel.com>, <jarkko@kernel.org>,
<dave.hansen@linux.intel.com>
Cc: <seanjc@google.com>, <kai.huang@intel.com>, <fan.du@intel.com>,
<cathy.zhang@intel.com>
Subject: Re: [PATCH v5 2/3] x86/sgx: Fine grained SGX MCA behavior for virtualization
Date: Sat, 23 Jul 2022 00:21:21 +0800 [thread overview]
Message-ID: <a854e953-6e0c-e753-d331-e84098abb46b@intel.com> (raw)
In-Reply-To: <32429523-3a71-2743-02b4-ea6ad1d99002@intel.com>
On 2022/7/22 00:54, Dave Hansen wrote:
> On 6/22/22 02:37, Zhiquan Li wrote:
>> When VM guest access a SGX EPC page with memory failure, current
>> behavior will kill the guest, expected only kill the SGX application
>> inside it.
> Can we please clean this up? This is generally readable, but _hard_ to
> read. Perhaps:
>
> Today, if a guest accesses an SGX EPC page with memory failure,
> the kernel will behavior will kill the entire guest. This blast
> radius is too large. It would be idea to kill only the SGX
> application inside the guest.
>
>> To fix it we send SIGBUS with code BUS_MCEERR_AR and some extra
> ^ No "we's".
>
>> information for hypervisor to inject #MC information to guest, which is
>> helpful in SGX case.
> To fix this, send a SIGBUS to host userspace (like QEMU) which can
> follow up by injecting a #MC to the guest.
>
>> The rest of things are guest side. Currently the hypervisor like Qemu
>> already has mature facility to convert HVA to GPA and inject #MC to
>> the guest OS.
>>
>> Unlike host enclaves, virtual EPC instance cannot be shared by multiple
>> VMs. It is because how enclaves are created is totally up to the guest.
>> Sharing virtual EPC instance will be very likely to unexpectedly break
>> enclaves in all VMs.
> I'm not sure why this is here or why it is important to this patch.
>
>> SGX virtual EPC driver doesn't explicitly prevent virtual EPC instance
>> being shared by multiple VMs via fork(). However KVM doesn't support
>> running a VM across multiple mm structures, and the de facto userspace
>> hypervisor (Qemu) doesn't use fork() to create a new VM, so in practice
>> this should not happen.
>
>> diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
>> index ab4ec54bbdd9..4507c2302348 100644
>> --- a/arch/x86/kernel/cpu/sgx/main.c
>> +++ b/arch/x86/kernel/cpu/sgx/main.c
>> @@ -715,6 +715,8 @@ int arch_memory_failure(unsigned long pfn, int flags)
>> struct sgx_epc_page *page = sgx_paddr_to_page(pfn << PAGE_SHIFT);
>> struct sgx_epc_section *section;
>> struct sgx_numa_node *node;
>> + unsigned long vaddr;
>> + int ret;
>>
>> /*
>> * mm/memory-failure.c calls this routine for all errors
>> @@ -731,8 +733,26 @@ int arch_memory_failure(unsigned long pfn, int flags)
>> * error. The signal may help the task understand why the
>> * enclave is broken.
>> */
>> - if (flags & MF_ACTION_REQUIRED)
>> - force_sig(SIGBUS);
>> + if (flags & MF_ACTION_REQUIRED) {
>> + /*
>> + * Provide extra info to the task so that it can make further
>> + * decision but not simply kill it. This is quite useful for
>> + * virtualization case.
>> + */
>> + if (page->flags & SGX_EPC_PAGE_KVM_GUEST) {
>> + /*
>> + * The "owner" field is repurposed as the virtual address
>> + * of virtual EPC page.
>> + */
>> + vaddr = (unsigned long)page->owner & PAGE_MASK;
> I really don't like repurposing page->owner like this. It requires
> casting on *both* sides of a type that we have full control over.
>
> struct sgx_epc_page {
> unsigned int section;
> u16 flags;
> u16 poison;
> union {
> struct sgx_encl_page *encl_owner;
> // Use when SGX_EPC_PAGE_KVM_GUEST
> // set in ->flags:
> void __user *vepc_vaddr;
> };
> struct list_head list;
> };
>
> There is zero reason to play casting games instead of doing that ^
>
Many thanks for your review, Dave.
I will send V6 patch set as per your suggestion.
Best Regards,
Zhiquan
next prev parent reply other threads:[~2022-07-22 16:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-22 9:37 [PATCH v5 0/3] x86/sgx: fine grained SGX MCA behavior Zhiquan Li
2022-06-22 9:37 ` [PATCH v5 1/3] x86/sgx: Repurpose the owner field as the virtual address of virtual EPC page Zhiquan Li
2022-07-21 16:42 ` Dave Hansen
2022-07-21 23:27 ` Kai Huang
2022-06-22 9:37 ` [PATCH v5 2/3] x86/sgx: Fine grained SGX MCA behavior for virtualization Zhiquan Li
2022-07-21 16:54 ` Dave Hansen
2022-07-22 16:21 ` Zhiquan Li [this message]
2022-06-22 9:37 ` [PATCH v5 3/3] x86/sgx: Fine grained SGX MCA behavior for normal case Zhiquan Li
2022-07-21 16:57 ` Dave Hansen
2022-07-22 17:28 ` Zhiquan Li
2022-06-26 6:04 ` [PATCH v5 0/3] x86/sgx: fine grained SGX MCA behavior Jarkko Sakkinen
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=a854e953-6e0c-e753-d331-e84098abb46b@intel.com \
--to=zhiquan1.li@intel.com \
--cc=cathy.zhang@intel.com \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=fan.du@intel.com \
--cc=jarkko@kernel.org \
--cc=kai.huang@intel.com \
--cc=linux-sgx@vger.kernel.org \
--cc=seanjc@google.com \
--cc=tony.luck@intel.com \
/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