x86/sgx: rip off the refcount from sgx_encl_add_page flow
PATCH 1/1 x86/sgx: rip off the refcount from sgx_encl_add_page flow
With the file bound approach we can flush the work queue when the file is closed.
--- arch/x86/kernel/cpu/sgx/driver/ioctl.c | 3 +-- arch/x86/kernel/cpu/sgx/driver/main.c | 1 + 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/sgx/driver/ioctl.c +1 -2
@@ -172,7 +172,7 @@ static void sgx_add_page_worker(struct work_struct *work) next:kfree (req); - }while (!kref_put (&encl->refcount, sgx_encl_release) && !is_empty); + }while (!is_empty); }static u32 sgx_calc_ssaframesize (u32 miscselect,u64 xfrm)
@@ -520,7 +520,6 @@ static int __sgx_encl_add_page(struct sgx_encl *encl, req->encl_page = encl_page; req->mrmask = mrmask; empty =list_empty (&encl->add_page_reqs); -kref_get (&encl->refcount);list_add_tail (&req->list, &encl->add_page_reqs);if (empty)queue_work (sgx_encl_wq, &encl->work);
arch/x86/kernel/cpu/sgx/driver/main.c +1 -0
@@ -47,6 +47,7 @@ static int sgx_release(struct inode *inode, struct file *file) {struct sgx_encl *encl = file->private_data; +flush_work (&encl->work);kref_put (&encl->refcount, sgx_encl_release);return 0 ;
Signature · 1 line
2.20.1
Quoted 35 lines · Jarkko Sakkinen
With the file bound approach we can flush the work queue when the file is closed.
Signed-off-by Jarkko Sakkinen <[email protected]>--- arch/x86/kernel/cpu/sgx/driver/ioctl.c | 3 +-- arch/x86/kernel/cpu/sgx/driver/main.c | 1 + 2 files changed, 2 insertions(+), 2 deletions(-)arch/x86/kernel/cpu/sgx/driver/ioctl.c +1
-2@@ -172,7 +172,7 @@ static void sgx_add_page_worker(struct work_struct *work) next:kfree (req); - }while (!kref_put (&encl->refcount, sgx_encl_release) && !is_empty); + }while (!is_empty); }static u32 sgx_calc_ssaframesize (u32 miscselect,u64 xfrm)@@ -520,7 +520,6 @@ static int __sgx_encl_add_page(struct sgx_encl *encl, req->encl_page = encl_page; req->mrmask = mrmask; empty =list_empty (&encl->add_page_reqs); -kref_get (&encl->refcount);list_add_tail (&req->list, &encl->add_page_reqs);if (empty)queue_work (sgx_encl_wq, &encl->work);arch/x86/kernel/cpu/sgx/driver/main.c +0
-0
arch/x86/kernel/cpu/sgx/driver/main.c static int sgx_release(struct inode *inode, struct file *file) · line 50
Quoted 4 lines
arch/x86/kernel/cpu/sgx/driver/main.c +1
-0@@ -47,6 +47,7 @@ static int sgx_release(struct inode *inode, struct file *file) {struct sgx_encl *encl = file->private_data; +flush_work (&encl->work);
We should set SGX_ENCL_DEAD before flush_work(). Other than that I can't think of any issues with this approach. Though hopefully we can purge the worker altogether and make it a moot point :-).
Quoted 6 lines
arch/x86/kernel/cpu/sgx/driver/main.c +0
-0kref_put (&encl->refcount, sgx_encl_release);return 0 ;Signature · 1 line
2.20.1
Quoted 3 lines · Sean Christopherson
We should set
SGX_ENCL_DEADbeforeflush_work(). Other than that I can't think of any issues with this approach. Though hopefully we can purge the worker altogether and make it a moot point :-).
Thanks, I squashed the change now. And definitely we can considere to completely purge that. This change probably won't make it more difficult :-)
I also removed PM notifier and SGX_ENCL_SUSPEND. Did not bother to cycle that change here because on that we've already made conclusions. Just have forgot to do that change.
/Jarkko