All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: linux-sgx@vger.kernel.org
Subject: [PATCH] x86/sgx: WARN once if EREMOVE fails when killing an enclave
Date: Mon,  7 Oct 2019 21:13:34 -0700	[thread overview]
Message-ID: <20191008041334.3235-1-sean.j.christopherson@intel.com> (raw)

WARN if EREMOVE fails when destroying an enclave.  sgx_encl_release()
uses the non-WARN __sgx_free_page() when freeing pages as some pages may
be in the process of being reclaimed, i.e. are owned by the reclaimer.
But EREMOVE should never fail as sgx_encl_destroy() is only called when
the enclave cannot have active threads, e.g. prior to EINIT and when the
enclave is being released.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/kernel/cpu/sgx/encl.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
index 54ca827e68a9..a6786e7ae40e 100644
--- a/arch/x86/kernel/cpu/sgx/encl.c
+++ b/arch/x86/kernel/cpu/sgx/encl.c
@@ -463,16 +463,23 @@ void sgx_encl_destroy(struct sgx_encl *encl)
 	struct sgx_encl_page *entry;
 	struct radix_tree_iter iter;
 	void **slot;
+	int r;
 
 	atomic_or(SGX_ENCL_DEAD, &encl->flags);
 
 	radix_tree_for_each_slot(slot, &encl->page_tree, &iter, 0) {
 		entry = *slot;
 		if (entry->epc_page) {
-			if (!__sgx_free_page(entry->epc_page)) {
+			/*
+			 * Freeing the page can fail if it's in the process of
+			 * being reclaimed (-EBUSY), but EREMOVE itself should
+			 * not fail at this point.
+			 */
+			r = __sgx_free_page(entry->epc_page);
+			WARN_ONCE(r > 0, "sgx: EREMOVE returned %d (0x%x)", r, r);
+			if (!r) {
 				encl->secs_child_cnt--;
 				entry->epc_page = NULL;
-
 			}
 
 			radix_tree_delete(&entry->encl->page_tree,
-- 
2.22.0


             reply	other threads:[~2019-10-08  4:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-08  4:13 Sean Christopherson [this message]
2019-10-08  4:15 ` [PATCH] x86/sgx: WARN once if EREMOVE fails when killing an enclave Sean Christopherson
2019-10-09  0:04 ` Jarkko Sakkinen
2019-10-10 18:35   ` Sean Christopherson
2019-10-10 18:56     ` Sean Christopherson
2019-10-10 20:52       ` Sean Christopherson

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=20191008041334.3235-1-sean.j.christopherson@intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --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 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.