[intel-sgx-kernel-dev,v2,1/4] intel_sgx: track SECS eviction using its epc_page
diff mbox

Message ID 1492704977-26510-2-git-send-email-sean.j.christopherson@intel.com
State New
Headers show

Commit Message

Sean Christopherson April 20, 2017, 4:16 p.m. UTC
Track whether or not the SECS is resident in the EPC based on its
epc_page pointer and remove the flag SGX_ENCL_SECS_EVICTED.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 drivers/platform/x86/intel_sgx/sgx.h            | 5 ++---
 drivers/platform/x86/intel_sgx/sgx_page_cache.c | 4 +---
 drivers/platform/x86/intel_sgx/sgx_util.c       | 3 +--
 3 files changed, 4 insertions(+), 8 deletions(-)

Patch
diff mbox

diff --git a/drivers/platform/x86/intel_sgx/sgx.h b/drivers/platform/x86/intel_sgx/sgx.h
index e59ff01..3451a56 100644
--- a/drivers/platform/x86/intel_sgx/sgx.h
+++ b/drivers/platform/x86/intel_sgx/sgx.h
@@ -122,9 +122,8 @@  struct sgx_tgid_ctx {
 enum sgx_encl_flags {
 	SGX_ENCL_INITIALIZED	= BIT(0),
 	SGX_ENCL_DEBUG		= BIT(1),
-	SGX_ENCL_SECS_EVICTED	= BIT(2),
-	SGX_ENCL_SUSPEND	= BIT(3),
-	SGX_ENCL_DEAD		= BIT(4),
+	SGX_ENCL_SUSPEND	= BIT(2),
+	SGX_ENCL_DEAD		= BIT(3),
 };
 
 struct sgx_encl {
diff --git a/drivers/platform/x86/intel_sgx/sgx_page_cache.c b/drivers/platform/x86/intel_sgx/sgx_page_cache.c
index 59a67cb..85276db 100644
--- a/drivers/platform/x86/intel_sgx/sgx_page_cache.c
+++ b/drivers/platform/x86/intel_sgx/sgx_page_cache.c
@@ -369,10 +369,8 @@  static void sgx_write_pages(struct sgx_encl *encl, struct list_head *src)
 		encl->secs_child_cnt--;
 	}
 
-	if (!encl->secs_child_cnt && (encl->flags & SGX_ENCL_INITIALIZED)) {
+	if (!encl->secs_child_cnt && (encl->flags & SGX_ENCL_INITIALIZED))
 		sgx_evict_page(&encl->secs_page, encl);
-		encl->flags |= SGX_ENCL_SECS_EVICTED;
-	}
 
 	mutex_unlock(&encl->lock);
 }
diff --git a/drivers/platform/x86/intel_sgx/sgx_util.c b/drivers/platform/x86/intel_sgx/sgx_util.c
index 1e9fa18..716c1dd 100644
--- a/drivers/platform/x86/intel_sgx/sgx_util.c
+++ b/drivers/platform/x86/intel_sgx/sgx_util.c
@@ -304,7 +304,7 @@  static struct sgx_encl_page *sgx_do_fault(struct vm_area_struct *vma,
 	}
 
 	/* If SECS is evicted then reload it first */
-	if (encl->flags & SGX_ENCL_SECS_EVICTED) {
+	if (!encl->secs_page.epc_page) {
 		secs_epc_page = sgx_alloc_page(SGX_ALLOC_ATOMIC);
 		if (IS_ERR(secs_epc_page)) {
 			rc = PTR_ERR(secs_epc_page);
@@ -317,7 +317,6 @@  static struct sgx_encl_page *sgx_do_fault(struct vm_area_struct *vma,
 			goto out;
 
 		encl->secs_page.epc_page = secs_epc_page;
-		encl->flags &= ~SGX_ENCL_SECS_EVICTED;
 
 		/* Do not free */
 		secs_epc_page = NULL;