[for_v24] x86/sgx: Mark all regular and TCS pages as reclaimable
diff mbox series

Message ID 20191030105138.13509-1-sean.j.christopherson@intel.com
State New
Headers show
Series
  • [for_v24] x86/sgx: Mark all regular and TCS pages as reclaimable
Related show

Commit Message

Sean Christopherson Oct. 30, 2019, 10:51 a.m. UTC
Mark all EADDed pages as reclaimable, not just those that are measured.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/kernel/cpu/sgx/ioctl.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Comments

Jarkko Sakkinen Oct. 31, 2019, 9:29 p.m. UTC | #1
On Wed, Oct 30, 2019 at 03:51:38AM -0700, Sean Christopherson wrote:
> Mark all EADDed pages as reclaimable, not just those that are measured.
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>

Thanks, I merged this.

Resulted also cleaner diff between the driver and reclaimer patch:

        /*
         * Insert prior to EADD in case of OOM.  EADD modifies MRENCLAVE, i.e.
         * can't be gracefully unwound, while failure on EADD/EXTEND is limited
@@ -374,6 +438,8 @@ static int sgx_encl_add_page(struct sgx_encl *encl,
                }
        }

+       sgx_mark_page_reclaimable(encl_page->epc_page);
+
 out_unlock:
        mutex_unlock(&encl->lock);
        up_read(&current->mm->mmap_sem);

/Jarkko

Patch
diff mbox series

diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c
index 5b82670bb79a..5b28a9c0cb68 100644
--- a/arch/x86/kernel/cpu/sgx/ioctl.c
+++ b/arch/x86/kernel/cpu/sgx/ioctl.c
@@ -427,12 +427,20 @@  static int sgx_encl_add_page(struct sgx_encl *encl,
 
 	if (addp->flags & SGX_PAGE_MEASURE) {
 		ret = __sgx_encl_extend(encl, epc_page);
-		if (ret)
+
+		/*
+		 * Destroy the enclave if EEXTEND fails, EADD can't be undone.
+		 * Note, destroy() also frees the resources for the added page.
+		 */
+		if (ret) {
 			sgx_encl_destroy(encl);
-		else
-			sgx_mark_page_reclaimable(encl_page->epc_page);
+			goto out_unlock;
+		}
 	}
 
+	sgx_mark_page_reclaimable(encl_page->epc_page);
+
+out_unlock:
 	mutex_unlock(&encl->lock);
 	up_read(&current->mm->mmap_sem);
 	return ret;