diff mbox series

[RFC] x86/sgx: Do not increase encl->refcount for VMAs

Message ID 20190613163008.4060-1-jarkko.sakkinen@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [RFC] x86/sgx: Do not increase encl->refcount for VMAs | expand

Commit Message

Jarkko Sakkinen June 13, 2019, 4:30 p.m. UTC
Since the device file stays open up until all VMAs have been closed
we do not need to increase encl->refcount for VMAs. sgx_open() will
increase it once and sgx_release() will decrease at a point where
the device file is not mapped. anymore.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
Based on the commentary from Andy and Cedric.
 arch/x86/kernel/cpu/sgx/driver/main.c | 2 --
 arch/x86/kernel/cpu/sgx/encl.c        | 3 ---
 2 files changed, 5 deletions(-)

Comments

Jarkko Sakkinen June 17, 2019, 4:40 p.m. UTC | #1
On Thu, Jun 13, 2019 at 07:30:07PM +0300, Jarkko Sakkinen wrote:
> Since the device file stays open up until all VMAs have been closed
> we do not need to increase encl->refcount for VMAs. sgx_open() will
> increase it once and sgx_release() will decrease at a point where
> the device file is not mapped. anymore.
> 
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

Cool if I merge this one?

/Jarkko
Sean Christopherson June 17, 2019, 4:52 p.m. UTC | #2
On Mon, Jun 17, 2019 at 07:40:25PM +0300, Jarkko Sakkinen wrote:
> On Thu, Jun 13, 2019 at 07:30:07PM +0300, Jarkko Sakkinen wrote:
> > Since the device file stays open up until all VMAs have been closed
> > we do not need to increase encl->refcount for VMAs. sgx_open() will
> > increase it once and sgx_release() will decrease at a point where
> > the device file is not mapped. anymore.
> > 
> > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> 
> Cool if I merge this one?

LGTM
Jarkko Sakkinen June 19, 2019, 12:46 p.m. UTC | #3
On Mon, 2019-06-17 at 09:52 -0700, Sean Christopherson wrote:
> On Mon, Jun 17, 2019 at 07:40:25PM +0300, Jarkko Sakkinen wrote:
> > On Thu, Jun 13, 2019 at 07:30:07PM +0300, Jarkko Sakkinen wrote:
> > > Since the device file stays open up until all VMAs have been closed
> > > we do not need to increase encl->refcount for VMAs. sgx_open() will
> > > increase it once and sgx_release() will decrease at a point where
> > > the device file is not mapped. anymore.
> > > 
> > > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > 
> > Cool if I merge this one?
> 
> LGTM

Awesome, merged.

Sent another similar change just now for the page adder. Can you
check that so I can merge.

I have a change in progress that will make the reclaimer also the
reaper and remove the need for the refcount altogether. Try to
get it possibly tonight out (i.e. daytime for you).

/Jarkko
Sean Christopherson June 19, 2019, 3:34 p.m. UTC | #4
On Wed, Jun 19, 2019 at 03:46:38PM +0300, Jarkko Sakkinen wrote:
> On Mon, 2019-06-17 at 09:52 -0700, Sean Christopherson wrote:
> > On Mon, Jun 17, 2019 at 07:40:25PM +0300, Jarkko Sakkinen wrote:
> > > On Thu, Jun 13, 2019 at 07:30:07PM +0300, Jarkko Sakkinen wrote:
> > > > Since the device file stays open up until all VMAs have been closed
> > > > we do not need to increase encl->refcount for VMAs. sgx_open() will
> > > > increase it once and sgx_release() will decrease at a point where
> > > > the device file is not mapped. anymore.
> > > > 
> > > > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > 
> > > Cool if I merge this one?
> > 
> > LGTM
> 
> Awesome, merged.
> 
> Sent another similar change just now for the page adder. Can you
> check that so I can merge.
> 
> I have a change in progress that will make the reclaimer also the
> reaper and remove the need for the refcount altogether. Try to
> get it possibly tonight out (i.e. daytime for you).

I'm about to disappear on vacation for two weeks, can you post whatever
you have, even if it's half baked?

I have a working patch to use mmu_notifier.release() instead of per-vma
refcounting, I'll post an RFC today.  It'd be nice to have both approaches
posted so that folks can weigh in on the options for dropping .vm_close().
Jarkko Sakkinen June 20, 2019, 7:08 p.m. UTC | #5
On Wed, Jun 19, 2019 at 08:34:19AM -0700, Sean Christopherson wrote:
> > Sent another similar change just now for the page adder. Can you
> > check that so I can merge.
> > 
> > I have a change in progress that will make the reclaimer also the
> > reaper and remove the need for the refcount altogether. Try to
> > get it possibly tonight out (i.e. daytime for you).
> 
> I'm about to disappear on vacation for two weeks, can you post whatever
> you have, even if it's half baked?
> 
> I have a working patch to use mmu_notifier.release() instead of per-vma
> refcounting, I'll post an RFC today.  It'd be nice to have both approaches
> posted so that folks can weigh in on the options for dropping .vm_close().

I peeked your patch and it deals with the encl_mm->refcount. My changes
deal with the encl->refcount (consolidating the driver to only use
file's refcount).

/Jarkko
diff mbox series

Patch

diff --git a/arch/x86/kernel/cpu/sgx/driver/main.c b/arch/x86/kernel/cpu/sgx/driver/main.c
index 87735ce8b5ba..0c831ee5e2de 100644
--- a/arch/x86/kernel/cpu/sgx/driver/main.c
+++ b/arch/x86/kernel/cpu/sgx/driver/main.c
@@ -68,8 +68,6 @@  static int sgx_mmap(struct file *file, struct vm_area_struct *vma)
 	vma->vm_flags |= VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP | VM_IO;
 	vma->vm_private_data = encl;
 
-	kref_get(&encl->refcount);
-
 	return 0;
 }
 
diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
index 6b190eccd02e..9566eb72d417 100644
--- a/arch/x86/kernel/cpu/sgx/encl.c
+++ b/arch/x86/kernel/cpu/sgx/encl.c
@@ -208,7 +208,6 @@  static void sgx_vma_open(struct vm_area_struct *vma)
 			goto error;
 	}
 
-	kref_get(&encl->refcount);
 	return;
 
 error:
@@ -230,8 +229,6 @@  static void sgx_vma_close(struct vm_area_struct *vma)
 		/* Release kref for the VMA. */
 		kref_put(&encl_mm->refcount, sgx_encl_mm_release);
 	}
-
-	kref_put(&encl->refcount, sgx_encl_release);
 }
 
 static unsigned int sgx_vma_fault(struct vm_fault *vmf)