diff mbox

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

Message ID 1492009821-22428-2-git-send-email-sean.j.christopherson@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sean Christopherson April 12, 2017, 3:10 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(-)

Comments

Jarkko Sakkinen April 13, 2017, 1:10 p.m. UTC | #1
On Wed, Apr 12, 2017 at 08:10:18AM -0700, Sean Christopherson wrote:
> 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>

Not much say about this.

Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

/Jarkko

> ---
>  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(-)
> 
> diff --git a/drivers/platform/x86/intel_sgx/sgx.h b/drivers/platform/x86/intel_sgx/sgx.h
> index 82355bb..0397141 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 4ffde27..26b845b 100644
> --- a/drivers/platform/x86/intel_sgx/sgx_page_cache.c
> +++ b/drivers/platform/x86/intel_sgx/sgx_page_cache.c
> @@ -381,10 +381,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 25e949d..420f96f 100644
> --- a/drivers/platform/x86/intel_sgx/sgx_util.c
> +++ b/drivers/platform/x86/intel_sgx/sgx_util.c
> @@ -292,7 +292,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);
> @@ -305,7 +305,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;
> -- 
> 2.7.4
> 
> _______________________________________________
> intel-sgx-kernel-dev mailing list
> intel-sgx-kernel-dev@lists.01.org
> https://lists.01.org/mailman/listinfo/intel-sgx-kernel-dev
diff mbox

Patch

diff --git a/drivers/platform/x86/intel_sgx/sgx.h b/drivers/platform/x86/intel_sgx/sgx.h
index 82355bb..0397141 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 4ffde27..26b845b 100644
--- a/drivers/platform/x86/intel_sgx/sgx_page_cache.c
+++ b/drivers/platform/x86/intel_sgx/sgx_page_cache.c
@@ -381,10 +381,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 25e949d..420f96f 100644
--- a/drivers/platform/x86/intel_sgx/sgx_util.c
+++ b/drivers/platform/x86/intel_sgx/sgx_util.c
@@ -292,7 +292,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);
@@ -305,7 +305,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;