From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: linux-sgx@vger.kernel.org, Andy Lutomirski <luto@kernel.org>
Subject: [PATCH for_v22 v2 6/8] x86/sgx: Allocate encl_page prior to taking encl->lock
Date: Mon, 12 Aug 2019 18:12:50 -0700 [thread overview]
Message-ID: <20190813011252.4121-7-sean.j.christopherson@intel.com> (raw)
In-Reply-To: <20190813011252.4121-1-sean.j.christopherson@intel.com>
Refactor sgx_encl_add_page() to allocate the encl_page prior to taking
encl->lock so that the encl_page can be used to allocate its associated
EPC page without having to drop and retake encl->lock. Removal of the
add page worker will move EPC page allocation to sgx_encl_add_page().
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
arch/x86/kernel/cpu/sgx/driver/ioctl.c | 29 ++++++++++++--------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/arch/x86/kernel/cpu/sgx/driver/ioctl.c b/arch/x86/kernel/cpu/sgx/driver/ioctl.c
index 55e0fe261b8c..49407ccb26c8 100644
--- a/arch/x86/kernel/cpu/sgx/driver/ioctl.c
+++ b/arch/x86/kernel/cpu/sgx/driver/ioctl.c
@@ -518,24 +518,22 @@ static int sgx_encl_add_page(struct sgx_encl *encl, unsigned long addr,
return ret;
}
- mutex_lock(&encl->lock);
-
- va_page = sgx_encl_grow(encl, SGX_ENCL_INITIALIZED | SGX_ENCL_DEAD);
- if (IS_ERR(va_page)) {
- ret = PTR_ERR(va_page);
- goto err_out_unlock;
- }
-
encl_page = sgx_encl_page_alloc(encl, addr, prot, page_type);
- if (IS_ERR(encl_page)) {
- ret = PTR_ERR(encl_page);
- goto err_out_shrink;
+ if (IS_ERR(encl_page))
+ return PTR_ERR(encl_page);
+
+ mutex_lock(&encl->lock);
+
+ va_page = sgx_encl_grow(encl, SGX_ENCL_INITIALIZED | SGX_ENCL_DEAD);
+ if (IS_ERR(va_page)) {
+ ret = PTR_ERR(va_page);
+ goto err_out_free;
}
ret = radix_tree_insert(&encl->page_tree, PFN_DOWN(encl_page->desc),
encl_page);
if (ret)
- goto err_out_free;
+ goto err_out_shrink;
ret = __sgx_encl_add_page(encl, encl_page, data, secinfo, mrmask);
if (ret)
@@ -547,13 +545,12 @@ static int sgx_encl_add_page(struct sgx_encl *encl, unsigned long addr,
err_out:
radix_tree_delete(&encl_page->encl->page_tree,
PFN_DOWN(encl_page->desc));
+err_out_shrink:
+ sgx_encl_shrink(encl, va_page);
+
err_out_free:
kfree(encl_page);
-err_out_shrink:
- sgx_encl_shrink(encl, va_page);
-
-err_out_unlock:
mutex_unlock(&encl->lock);
return ret;
}
--
2.22.0
next prev parent reply other threads:[~2019-08-13 1:12 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-13 1:12 [PATCH for_v22 v2 0/8] x86/sgx: Remove EADD worker and page copy Sean Christopherson
2019-08-13 1:12 ` [PATCH for_v22 v2 1/8] selftests/x86/sgx: Align enclave binary on 4k boundary Sean Christopherson
2019-08-16 13:55 ` Jarkko Sakkinen
2019-08-16 15:36 ` Jethro Beekman
2019-08-16 23:41 ` Jarkko Sakkinen
2019-08-13 1:12 ` [PATCH for_v22 v2 2/8] x86/sgx: Require EADD source to be page aligned Sean Christopherson
2019-08-16 14:15 ` Jarkko Sakkinen
2019-08-13 1:12 ` [PATCH for_v22 v2 3/8] x86/sgx: Validate generic SECINFO immediately after copying from user Sean Christopherson
2019-08-13 1:12 ` [PATCH for_v22 v2 4/8] x86/sgx: Set SGX_ENCL_PAGE_TCS when allocating encl_page Sean Christopherson
2019-08-22 12:56 ` Jarkko Sakkinen
2019-08-22 14:24 ` Sean Christopherson
2019-08-13 1:12 ` [PATCH for_v22 v2 5/8] x86/sgx: Move encl_page insertion into tree out of alloc flow Sean Christopherson
2019-08-13 1:12 ` Sean Christopherson [this message]
2019-08-13 1:12 ` [PATCH for_v22 v2 7/8] x86/sgx: Remove the EADD page worker Sean Christopherson
2019-08-13 1:12 ` [PATCH for_v22 v2 8/8] x86/sgx: Pass userspace source address directly to EADD Sean Christopherson
2019-08-22 14:37 ` Jarkko Sakkinen
2019-08-22 14:50 ` Sean Christopherson
2019-08-22 17:00 ` Jarkko Sakkinen
2019-08-23 1:25 ` Jarkko Sakkinen
2019-08-23 1:28 ` Sean Christopherson
2019-08-23 1:34 ` Sean Christopherson
2019-08-15 22:00 ` [PATCH for_v22 v2 0/8] x86/sgx: Remove EADD worker and page copy Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190813011252.4121-7-sean.j.christopherson@intel.com \
--to=sean.j.christopherson@intel.com \
--cc=jarkko.sakkinen@linux.intel.com \
--cc=linux-sgx@vger.kernel.org \
--cc=luto@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).