All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhiquan Li <zhiquan1.li@intel.com>
To: 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, zhiquan1.li@intel.com
Subject: [PATCH v4 3/3] x86/sgx: Fine grained SGX MCA behavior for normal case
Date: Wed,  8 Jun 2022 11:26:54 +0800	[thread overview]
Message-ID: <20220608032654.1764936-4-zhiquan1.li@intel.com> (raw)
In-Reply-To: <20220608032654.1764936-1-zhiquan1.li@intel.com>

When the application accesses a SGX EPC page with memory failure, the
task will receive a SIGBUS signal without any extra info, unless the
EPC page has SGX_EPC_PAGE_KVM_GUEST flag. However, in some cases,
we only use SGX in sub-task and we don't expect the entire task group
be killed due to a SGX EPC page for a sub-task has memory failure.

To fix it, we extend the solution for normal case. That is, the SGX
regular EPC page with memory failure will trigger a SIGBUS signal with
code BUS_MCEERR_AR and additional info, so that the user has opportunity
to make further decision.

Suppose an enclave is shared by multiple processes, when an enclave page
triggers a machine check, the enclave will be disabled so that it
couldn't be entered again. Killing other processes with the same enclave
mapped would perhaps be overkill, but they are going to find that the
enclave is "dead" next time they try to use it. Thanks for Jarkko's head
up and Tony's clarification on this point.

Our intension is to provide additional info so that the application has
more choices. Current behavior looks gently, and we don't want to change
it.

Signed-off-by: Zhiquan Li <zhiquan1.li@intel.com>
---
No changes since V3.

Changes since V2:
- Adapted the code since struct sgx_vepc_page was discarded.
- Replace EPC page flag SGX_EPC_PAGE_IS_VEPC with
  SGX_EPC_PAGE_KVM_GUEST as they are duplicated.

Changes since V1:
- Add valuable information from Jarkko and Tony the into commit
  message.

Signed-off-by: Zhiquan Li <zhiquan1.li@intel.com>
---
 arch/x86/kernel/cpu/sgx/main.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
index faca7f73b06d..69a2a29c8957 100644
--- a/arch/x86/kernel/cpu/sgx/main.c
+++ b/arch/x86/kernel/cpu/sgx/main.c
@@ -739,12 +739,15 @@ int arch_memory_failure(unsigned long pfn, int flags)
 		 * decision but not simply kill it. This is quite useful for
 		 * virtualization case.
 		 */
-		if (page->flags & SGX_EPC_PAGE_KVM_GUEST) {
+		if (page->owner) {
 			/*
 			 * The "owner" field is repurposed as the virtual address
 			 * of virtual EPC page.
 			 */
-			vaddr = (unsigned long)page->owner & PAGE_MASK;
+			if (page->flags & SGX_EPC_PAGE_KVM_GUEST)
+				vaddr = (unsigned long)page->owner & PAGE_MASK;
+			else
+				vaddr = (unsigned long)page->owner->desc & PAGE_MASK;
 			ret = force_sig_mceerr(BUS_MCEERR_AR, (void __user *)vaddr,
 					PAGE_SHIFT);
 			if (ret < 0)
-- 
2.25.1


  parent reply	other threads:[~2022-06-08  6:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08  3:26 [PATCH v4 0/3] x86/sgx: fine grained SGX MCA behavior Zhiquan Li
2022-06-08  3:26 ` [PATCH v4 1/3] x86/sgx: Repurpose the owner field as the virtual address of virtual EPC page Zhiquan Li
2022-06-08  3:45   ` Zhiquan Li
2022-06-08  3:54   ` Kai Huang
2022-06-08  3:26 ` [PATCH v4 2/3] x86/sgx: Fine grained SGX MCA behavior for virtualization Zhiquan Li
2022-06-08  3:52   ` Kai Huang
2022-06-08  8:13     ` Jarkko Sakkinen
2022-06-08  8:33       ` Zhiquan Li
2022-06-08  3:26 ` Zhiquan Li [this message]
2022-06-08  8:10 ` [PATCH v4 0/3] x86/sgx: fine grained SGX MCA behavior Jarkko Sakkinen
2022-06-08  9:12   ` Jarkko Sakkinen
2022-06-08  9:48   ` Zhiquan Li

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=20220608032654.1764936-4-zhiquan1.li@intel.com \
    --to=zhiquan1.li@intel.com \
    --cc=cathy.zhang@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.