diff mbox

[intel-sgx-kernel-dev,3/5] intel_sgx: remove flags parameter from sgx_free_page()

Message ID 20170131230308.7561-4-jarkko.sakkinen@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jarkko Sakkinen Jan. 31, 2017, 11:03 p.m. UTC
The flags parameter is unnecessary cruft as EREMOVE has a valid and
successful code path for an unused page.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 drivers/platform/x86/intel_sgx.h            |  4 +--
 drivers/platform/x86/intel_sgx_ioctl.c      | 12 +++-----
 drivers/platform/x86/intel_sgx_page_cache.c | 47 +++++++++--------------------
 drivers/platform/x86/intel_sgx_util.c       |  6 ++--
 drivers/platform/x86/intel_sgx_vma.c        |  6 ++--
 5 files changed, 25 insertions(+), 50 deletions(-)
diff mbox

Patch

diff --git a/drivers/platform/x86/intel_sgx.h b/drivers/platform/x86/intel_sgx.h
index ed9e8e6..be08346 100644
--- a/drivers/platform/x86/intel_sgx.h
+++ b/drivers/platform/x86/intel_sgx.h
@@ -236,8 +236,6 @@  int sgx_page_cache_init(resource_size_t start, unsigned long size);
 void sgx_page_cache_teardown(void);
 struct sgx_epc_page *sgx_alloc_page(struct sgx_tgid_ctx *tgid_epc_cnt,
 				    unsigned int flags);
-void sgx_free_page(struct sgx_epc_page *entry,
-		   struct sgx_encl *encl,
-		   unsigned int flags);
+void sgx_free_page(struct sgx_epc_page *entry, struct sgx_encl *encl);
 
 #endif /* __ARCH_X86_INTEL_SGX_H__ */
diff --git a/drivers/platform/x86/intel_sgx_ioctl.c b/drivers/platform/x86/intel_sgx_ioctl.c
index f2cc2c1..a1da92a 100644
--- a/drivers/platform/x86/intel_sgx_ioctl.c
+++ b/drivers/platform/x86/intel_sgx_ioctl.c
@@ -213,7 +213,6 @@  static bool sgx_process_add_page_req(struct sgx_add_page_req *req)
 	struct sgx_epc_page *epc_page;
 	struct sgx_encl_page *encl_page = req->encl_page;
 	struct sgx_encl *encl = req->encl;
-	unsigned int free_flags = SGX_FREE_SKIP_EREMOVE;
 	struct vm_area_struct *vma;
 	int ret;
 
@@ -222,7 +221,7 @@  static bool sgx_process_add_page_req(struct sgx_add_page_req *req)
 		return false;
 
 	if (!sgx_pin_mm(encl)) {
-		sgx_free_page(epc_page, encl, free_flags);
+		sgx_free_page(epc_page, encl);
 		return false;
 	}
 
@@ -252,7 +251,6 @@  static bool sgx_process_add_page_req(struct sgx_add_page_req *req)
 			   encl_page->addr, &req->secinfo, backing);
 
 	sgx_put_backing(backing, 0);
-	free_flags = 0;
 	if (ret) {
 		sgx_warn(encl, "EADD returned %d\n", ret);
 		zap_vma_ptes(vma, encl_page->addr, PAGE_SIZE);
@@ -276,7 +274,7 @@  static bool sgx_process_add_page_req(struct sgx_add_page_req *req)
 	sgx_unpin_mm(encl);
 	return true;
 out:
-	sgx_free_page(epc_page, encl, free_flags);
+	sgx_free_page(epc_page, encl);
 	mutex_unlock(&encl->lock);
 	sgx_unpin_mm(encl);
 	return false;
@@ -416,8 +414,7 @@  static int sgx_init_page(struct sgx_encl *encl,
 		if (!vaddr) {
 			sgx_warn(encl, "kmap of a new VA page failed %d\n",
 				 ret);
-			sgx_free_page(epc_page, encl,
-					  SGX_FREE_SKIP_EREMOVE);
+			sgx_free_page(epc_page, encl);
 			kfree(va_page);
 			return -EFAULT;
 		}
@@ -427,8 +424,7 @@  static int sgx_init_page(struct sgx_encl *encl,
 
 		if (ret) {
 			sgx_warn(encl, "EPA returned %d\n", ret);
-			sgx_free_page(epc_page, encl,
-					  SGX_FREE_SKIP_EREMOVE);
+			sgx_free_page(epc_page, encl);
 			kfree(va_page);
 			return -EFAULT;
 		}
diff --git a/drivers/platform/x86/intel_sgx_page_cache.c b/drivers/platform/x86/intel_sgx_page_cache.c
index 3c6c7a4..248ff71 100644
--- a/drivers/platform/x86/intel_sgx_page_cache.c
+++ b/drivers/platform/x86/intel_sgx_page_cache.c
@@ -267,7 +267,7 @@  static int __sgx_ewb(struct sgx_encl *encl,
 	return ret;
 }
 
-static bool sgx_ewb(struct sgx_encl *encl,
+static void sgx_ewb(struct sgx_encl *encl,
 		    struct sgx_encl_page *entry)
 {
 	int ret = __sgx_ewb(encl, entry);
@@ -284,17 +284,13 @@  static bool sgx_ewb(struct sgx_encl *encl,
 		smp_call_function(sgx_ipi_cb, NULL, 1);
 		if (ret > 0)
 			sgx_err(encl, "EWB returned %d, enclave killed\n", ret);
-		return false;
 	}
-
-	return true;
 }
 
 static void sgx_evict_page(struct sgx_encl_page *entry,
-			   struct sgx_encl *encl,
-			   unsigned int flags)
+			   struct sgx_encl *encl)
 {
-	sgx_free_page(entry->epc_page, encl, flags);
+	sgx_free_page(entry->epc_page, encl);
 	entry->epc_page = NULL;
 	entry->flags &= ~SGX_ENCL_PAGE_RESERVED;
 }
@@ -304,7 +300,6 @@  static void sgx_write_pages(struct sgx_encl *encl, struct list_head *src)
 	struct sgx_encl_page *entry;
 	struct sgx_encl_page *tmp;
 	struct vm_area_struct *evma;
-	unsigned int free_flags;
 
 	if (list_empty(src))
 		return;
@@ -318,7 +313,7 @@  static void sgx_write_pages(struct sgx_encl *encl, struct list_head *src)
 		evma = sgx_find_vma(encl, entry->addr);
 		if (!evma) {
 			list_del(&entry->load_list);
-			sgx_evict_page(entry, encl, 0);
+			sgx_evict_page(entry, encl);
 			continue;
 		}
 
@@ -335,25 +330,20 @@  static void sgx_write_pages(struct sgx_encl *encl, struct list_head *src)
 					 load_list);
 		list_del(&entry->load_list);
 
-		free_flags = 0;
 
 		evma = sgx_find_vma(encl, entry->addr);
 		if (evma) {
-			if (sgx_ewb(encl, entry))
-				free_flags = SGX_FREE_SKIP_EREMOVE;
+			sgx_ewb(encl, entry);
 			encl->secs_child_cnt--;
 		}
 
-		sgx_evict_page(entry, encl, free_flags);
+		sgx_evict_page(entry, encl);
 	}
 
 	if (!encl->secs_child_cnt && (encl->flags & SGX_ENCL_INITIALIZED)) {
-		free_flags = 0;
-		if (sgx_ewb(encl, &encl->secs_page))
-			free_flags = SGX_FREE_SKIP_EREMOVE;
-
+		sgx_ewb(encl, &encl->secs_page);
 		encl->flags |= SGX_ENCL_SECS_EVICTED;
-		sgx_evict_page(&encl->secs_page, encl, free_flags);
+		sgx_evict_page(&encl->secs_page, encl);
 	}
 
 	mutex_unlock(&encl->lock);
@@ -532,27 +522,20 @@  struct sgx_epc_page *sgx_alloc_page(struct sgx_tgid_ctx *ctx,
  * @encl:	the enclave who owns the EPC page
  * @flags:	free flags
  */
-void sgx_free_page(struct sgx_epc_page *entry,
-		   struct sgx_encl *encl,
-		   unsigned int flags)
+void sgx_free_page(struct sgx_epc_page *entry, struct sgx_encl *encl)
 {
 	void *epc;
 	int ret;
 
 	atomic_dec(&encl->tgid_ctx->epc_cnt);
 
-	if (encl->flags & SGX_ENCL_SUSPEND)
-		flags |= SGX_FREE_SKIP_EREMOVE;
-
-	if (!(flags & SGX_FREE_SKIP_EREMOVE)) {
-		epc = sgx_get_epc_page(entry);
-		ret = __eremove(epc);
-		sgx_put_epc_page(epc);
+	epc = sgx_get_epc_page(entry);
+	ret = __eremove(epc);
+	sgx_put_epc_page(epc);
 
-		if (ret) {
-			pr_err("EREMOVE returned %d\n", ret);
-			BUG();
-		}
+	if (ret) {
+		pr_err("EREMOVE returned %d\n", ret);
+		BUG();
 	}
 
 	spin_lock(&sgx_free_list_lock);
diff --git a/drivers/platform/x86/intel_sgx_util.c b/drivers/platform/x86/intel_sgx_util.c
index 2c390c5..99356f0 100644
--- a/drivers/platform/x86/intel_sgx_util.c
+++ b/drivers/platform/x86/intel_sgx_util.c
@@ -220,7 +220,7 @@  void sgx_encl_release(struct kref *ref)
 		entry = *slot;
 		if (entry->epc_page) {
 			list_del(&entry->load_list);
-			sgx_free_page(entry->epc_page, encl, 0);
+			sgx_free_page(entry->epc_page, encl);
 		}
 		radix_tree_delete(&encl->page_tree, entry->addr >> PAGE_SHIFT);
 		kfree(entry);
@@ -230,12 +230,12 @@  void sgx_encl_release(struct kref *ref)
 		va_page = list_first_entry(&encl->va_pages,
 					   struct sgx_va_page, list);
 		list_del(&va_page->list);
-		sgx_free_page(va_page->epc_page, encl, 0);
+		sgx_free_page(va_page->epc_page, encl);
 		kfree(va_page);
 	}
 
 	if (encl->secs_page.epc_page)
-		sgx_free_page(encl->secs_page.epc_page, encl, 0);
+		sgx_free_page(encl->secs_page.epc_page, encl);
 
 	encl->secs_page.epc_page = NULL;
 
diff --git a/drivers/platform/x86/intel_sgx_vma.c b/drivers/platform/x86/intel_sgx_vma.c
index 6a23690..c339de3 100644
--- a/drivers/platform/x86/intel_sgx_vma.c
+++ b/drivers/platform/x86/intel_sgx_vma.c
@@ -143,7 +143,6 @@  static struct sgx_encl_page *sgx_vma_do_fault(struct vm_area_struct *vma,
 	struct sgx_epc_page *epc_page = NULL;
 	struct sgx_epc_page *secs_epc_page = NULL;
 	struct page *backing;
-	unsigned int free_flags = SGX_FREE_SKIP_EREMOVE;
 	int rc;
 
 	/* If process was forked, VMA is still there but vm_private_data is set
@@ -237,7 +236,6 @@  static struct sgx_encl_page *sgx_vma_do_fault(struct vm_area_struct *vma,
 	sgx_put_backing(backing, 0);
 
 	if (rc) {
-		free_flags = 0;
 		entry = ERR_PTR(rc);
 		goto out;
 	}
@@ -257,9 +255,9 @@  static struct sgx_encl_page *sgx_vma_do_fault(struct vm_area_struct *vma,
 out:
 	mutex_unlock(&encl->lock);
 	if (epc_page)
-		sgx_free_page(epc_page, encl, free_flags);
+		sgx_free_page(epc_page, encl);
 	if (secs_epc_page)
-		sgx_free_page(secs_epc_page, encl, SGX_FREE_SKIP_EREMOVE);
+		sgx_free_page(secs_epc_page, encl);
 	return entry;
 }