linux-sgx.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: linux-sgx@vger.kernel.org
Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
	Sean Christopherson <sean.j.christopherson@intel.com>
Subject: [PATCH] x86/sgx: Migrate to mmu_notifier_put()
Date: Thu,  3 Oct 2019 19:55:11 +0300	[thread overview]
Message-ID: <20191003165511.3563-1-jarkko.sakkinen@linux.intel.com> (raw)

Use mmu_notifier_put() to synchronize sgx_encl_mm usage, which means
that we can drop our own RCU.

Cc: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 arch/x86/kernel/cpu/sgx/encl.c | 30 ++++++++++--------------------
 arch/x86/kernel/cpu/sgx/encl.h |  1 -
 2 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
index d145360380d5..25b210f57295 100644
--- a/arch/x86/kernel/cpu/sgx/encl.c
+++ b/arch/x86/kernel/cpu/sgx/encl.c
@@ -131,14 +131,6 @@ static struct sgx_encl_page *sgx_encl_load_page(struct sgx_encl *encl,
 	return entry;
 }
 
-static void sgx_encl_mm_release_deferred(struct rcu_head *rcu)
-{
-	struct sgx_encl_mm *encl_mm =
-		container_of(rcu, struct sgx_encl_mm, rcu);
-
-	kfree(encl_mm);
-}
-
 static void sgx_mmu_notifier_release(struct mmu_notifier *mn,
 				     struct mm_struct *mm)
 {
@@ -159,21 +151,21 @@ static void sgx_mmu_notifier_release(struct mmu_notifier *mn,
 	}
 	spin_unlock(&encl_mm->encl->mm_lock);
 
-	if (tmp == encl_mm) {
-		synchronize_srcu(&encl_mm->encl->srcu);
+	if (tmp == encl_mm)
+		mmu_notifier_put(mn);
+}
+
+static void sgx_mmu_notifier_free(struct mmu_notifier *mn)
+{
+	struct sgx_encl_mm *encl_mm =
+		container_of(mn, struct sgx_encl_mm, mmu_notifier);
 
-		/*
-		 * Delay freeing encl_mm until after mmu_notifier synchronizes
-		 * its SRCU to ensure encl_mm cannot be dereferenced.
-		 */
-		mmu_notifier_unregister_no_release(mn, mm);
-		mmu_notifier_call_srcu(&encl_mm->rcu,
-				       &sgx_encl_mm_release_deferred);
-	}
+	kfree(encl_mm);
 }
 
 static const struct mmu_notifier_ops sgx_mmu_notifier_ops = {
 	.release		= sgx_mmu_notifier_release,
+	.free_notifier		= sgx_mmu_notifier_free,
 };
 
 static struct sgx_encl_mm *sgx_encl_find_mm(struct sgx_encl *encl,
@@ -231,8 +223,6 @@ int sgx_encl_mm_add(struct sgx_encl *encl, struct mm_struct *mm)
 	list_add_rcu(&encl_mm->list, &encl->mm_list);
 	spin_unlock(&encl->mm_lock);
 
-	synchronize_srcu(&encl->srcu);
-
 	return 0;
 }
 
diff --git a/arch/x86/kernel/cpu/sgx/encl.h b/arch/x86/kernel/cpu/sgx/encl.h
index 71454f059b99..b8ecffe27c93 100644
--- a/arch/x86/kernel/cpu/sgx/encl.h
+++ b/arch/x86/kernel/cpu/sgx/encl.h
@@ -63,7 +63,6 @@ struct sgx_encl_mm {
 	struct mm_struct *mm;
 	struct list_head list;
 	struct mmu_notifier mmu_notifier;
-	struct rcu_head rcu;
 };
 
 struct sgx_encl {
-- 
2.20.1


             reply	other threads:[~2019-10-03 16:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-03 16:55 Jarkko Sakkinen [this message]
2019-10-03 22:07 ` [PATCH] x86/sgx: Migrate to mmu_notifier_put() 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=20191003165511.3563-1-jarkko.sakkinen@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=linux-sgx@vger.kernel.org \
    --cc=sean.j.christopherson@intel.com \
    /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).