[intel-sgx-kernel-dev,3/6] intel_sgx: Track SECS eviction using its epc_page
diff mbox

Message ID 1482437735-4722-4-git-send-email-sean.j.christopherson@intel.com
State New
Headers show

Commit Message

Sean Christopherson Dec. 22, 2016, 8:15 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.h            | 5 ++---
 drivers/platform/x86/intel_sgx_page_cache.c | 1 -
 drivers/platform/x86/intel_sgx_vma.c        | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)

Comments

Jarkko Sakkinen Dec. 29, 2016, 12:56 p.m. UTC | #1
On Thu, Dec 22, 2016 at 12:15:32PM -0800, 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>

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

/Jarkko

> ---
>  drivers/platform/x86/intel_sgx.h            | 5 ++---
>  drivers/platform/x86/intel_sgx_page_cache.c | 1 -
>  drivers/platform/x86/intel_sgx_vma.c        | 3 +--
>  3 files changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/platform/x86/intel_sgx.h b/drivers/platform/x86/intel_sgx.h
> index ed9e8e6..fb5a75a 100644
> --- a/drivers/platform/x86/intel_sgx.h
> +++ b/drivers/platform/x86/intel_sgx.h
> @@ -129,9 +129,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_page_cache.c b/drivers/platform/x86/intel_sgx_page_cache.c
> index d073057..f4833a0 100644
> --- a/drivers/platform/x86/intel_sgx_page_cache.c
> +++ b/drivers/platform/x86/intel_sgx_page_cache.c
> @@ -352,7 +352,6 @@ static void sgx_write_pages(struct sgx_encl *encl, struct list_head *src)
>  		if (sgx_ewb(encl, &encl->secs_page))
>  			free_flags = SGX_FREE_SKIP_EREMOVE;
>  
> -		encl->flags |= SGX_ENCL_SECS_EVICTED;
>  		sgx_free_encl_page(&encl->secs_page, encl, free_flags);
>  	}
>  
> diff --git a/drivers/platform/x86/intel_sgx_vma.c b/drivers/platform/x86/intel_sgx_vma.c
> index bb4d5d0..db4cdcb 100644
> --- a/drivers/platform/x86/intel_sgx_vma.c
> +++ b/drivers/platform/x86/intel_sgx_vma.c
> @@ -209,7 +209,7 @@ static struct sgx_encl_page *sgx_vma_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(encl->tgid_ctx, SGX_ALLOC_ATOMIC);
>  		if (IS_ERR(secs_epc_page)) {
>  			entry = (void *)secs_epc_page;
> @@ -230,7 +230,6 @@ static struct sgx_encl_page *sgx_vma_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

Patch
diff mbox

diff --git a/drivers/platform/x86/intel_sgx.h b/drivers/platform/x86/intel_sgx.h
index ed9e8e6..fb5a75a 100644
--- a/drivers/platform/x86/intel_sgx.h
+++ b/drivers/platform/x86/intel_sgx.h
@@ -129,9 +129,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_page_cache.c b/drivers/platform/x86/intel_sgx_page_cache.c
index d073057..f4833a0 100644
--- a/drivers/platform/x86/intel_sgx_page_cache.c
+++ b/drivers/platform/x86/intel_sgx_page_cache.c
@@ -352,7 +352,6 @@  static void sgx_write_pages(struct sgx_encl *encl, struct list_head *src)
 		if (sgx_ewb(encl, &encl->secs_page))
 			free_flags = SGX_FREE_SKIP_EREMOVE;
 
-		encl->flags |= SGX_ENCL_SECS_EVICTED;
 		sgx_free_encl_page(&encl->secs_page, encl, free_flags);
 	}
 
diff --git a/drivers/platform/x86/intel_sgx_vma.c b/drivers/platform/x86/intel_sgx_vma.c
index bb4d5d0..db4cdcb 100644
--- a/drivers/platform/x86/intel_sgx_vma.c
+++ b/drivers/platform/x86/intel_sgx_vma.c
@@ -209,7 +209,7 @@  static struct sgx_encl_page *sgx_vma_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(encl->tgid_ctx, SGX_ALLOC_ATOMIC);
 		if (IS_ERR(secs_epc_page)) {
 			entry = (void *)secs_epc_page;
@@ -230,7 +230,6 @@  static struct sgx_encl_page *sgx_vma_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;