[intel-sgx-kernel-dev,4/5] intel_sgx: do not use BUG() in sgx_free_page()
diff mbox

Message ID 20170131230308.7561-5-jarkko.sakkinen@linux.intel.com
State New
Headers show

Commit Message

Jarkko Sakkinen Jan. 31, 2017, 11:03 p.m. UTC
EREMOVE fails on non-EPC page or when a SECS page with children is to be
removed. These do not happen if the driver is working correctly. Log the
error but do not crash the driver.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 drivers/platform/x86/intel_sgx.h            | 4 ++++
 drivers/platform/x86/intel_sgx_page_cache.c | 6 ++----
 2 files changed, 6 insertions(+), 4 deletions(-)

Patch
diff mbox

diff --git a/drivers/platform/x86/intel_sgx.h b/drivers/platform/x86/intel_sgx.h
index be08346..5cfb043 100644
--- a/drivers/platform/x86/intel_sgx.h
+++ b/drivers/platform/x86/intel_sgx.h
@@ -185,6 +185,10 @@  extern atomic_t sgx_nr_pids;
 	pr_err_ratelimited("intel_sgx: [%d:0x%p] " fmt,			\
 			   pid_nr((encl)->tgid_ctx->tgid),		\
 			   (void *)(encl)->base, ##__VA_ARGS__)
+#define sgx_crit(encl, fmt, ...)					\
+	pr_crit_ratelimited("intel_sgx: [%d:0x%p] " fmt,		\
+			   pid_nr((encl)->tgid_ctx->tgid),		\
+			   (void *)(encl)->base, ##__VA_ARGS__)
 
 long sgx_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
 #ifdef CONFIG_COMPAT
diff --git a/drivers/platform/x86/intel_sgx_page_cache.c b/drivers/platform/x86/intel_sgx_page_cache.c
index 248ff71..4c4eabc 100644
--- a/drivers/platform/x86/intel_sgx_page_cache.c
+++ b/drivers/platform/x86/intel_sgx_page_cache.c
@@ -533,10 +533,8 @@  void sgx_free_page(struct sgx_epc_page *entry, struct sgx_encl *encl)
 	ret = __eremove(epc);
 	sgx_put_epc_page(epc);
 
-	if (ret) {
-		pr_err("EREMOVE returned %d\n", ret);
-		BUG();
-	}
+	if (ret)
+		sgx_crit(encl, "EREMOVE returned %d\n", ret);
 
 	spin_lock(&sgx_free_list_lock);
 	list_add(&entry->free_list, &sgx_free_list);