* [PATCH v2] x86/sgx: Migrate to mmu_notifier_put()
@ 2019-10-03 17:04 Jarkko Sakkinen
2019-10-03 18:53 ` Jarkko Sakkinen
2019-10-03 22:07 ` Jarkko Sakkinen
0 siblings, 2 replies; 3+ messages in thread
From: Jarkko Sakkinen @ 2019-10-03 17:04 UTC (permalink / raw)
To: linux-sgx; +Cc: Jarkko Sakkinen, Sean Christopherson
Use mmu_notifier_put() to synchronize sgx_encl_mm deletion.
Cc: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
v2:
* Was not thinking clearly that we also use it for lockless
operation on the mm list. Just migrating to mmu_notifier_put().
Please ignore the previous patch!
arch/x86/kernel/cpu/sgx/encl.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
index d145360380d5..8cc9ea353bee 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)
{
@@ -161,19 +153,21 @@ static void sgx_mmu_notifier_release(struct mmu_notifier *mn,
if (tmp == encl_mm) {
synchronize_srcu(&encl_mm->encl->srcu);
-
- /*
- * 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);
+ 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);
+
+ 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,
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] x86/sgx: Migrate to mmu_notifier_put()
2019-10-03 17:04 [PATCH v2] x86/sgx: Migrate to mmu_notifier_put() Jarkko Sakkinen
@ 2019-10-03 18:53 ` Jarkko Sakkinen
2019-10-03 22:07 ` Jarkko Sakkinen
1 sibling, 0 replies; 3+ messages in thread
From: Jarkko Sakkinen @ 2019-10-03 18:53 UTC (permalink / raw)
To: linux-sgx; +Cc: Sean Christopherson
On Thu, Oct 03, 2019 at 08:04:23PM +0300, Jarkko Sakkinen wrote:
> Use mmu_notifier_put() to synchronize sgx_encl_mm deletion.
>
> Cc: Sean Christopherson <sean.j.christopherson@intel.com>
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Pushed this already to master. Not squashed yet as I'm compiling a
kernel to test it.
/Jarkko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] x86/sgx: Migrate to mmu_notifier_put()
2019-10-03 17:04 [PATCH v2] x86/sgx: Migrate to mmu_notifier_put() Jarkko Sakkinen
2019-10-03 18:53 ` Jarkko Sakkinen
@ 2019-10-03 22:07 ` Jarkko Sakkinen
1 sibling, 0 replies; 3+ messages in thread
From: Jarkko Sakkinen @ 2019-10-03 22:07 UTC (permalink / raw)
To: linux-sgx; +Cc: Sean Christopherson
On Thu, Oct 03, 2019 at 08:04:23PM +0300, Jarkko Sakkinen wrote:
> Use mmu_notifier_put() to synchronize sgx_encl_mm deletion.
>
> Cc: Sean Christopherson <sean.j.christopherson@intel.com>
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> ---
> v2:
> * Was not thinking clearly that we also use it for lockless
> operation on the mm list. Just migrating to mmu_notifier_put().
> Please ignore the previous patch!
> arch/x86/kernel/cpu/sgx/encl.c | 26 ++++++++++----------------
> 1 file changed, 10 insertions(+), 16 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
> index d145360380d5..8cc9ea353bee 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)
> {
> @@ -161,19 +153,21 @@ static void sgx_mmu_notifier_release(struct mmu_notifier *mn,
>
> if (tmp == encl_mm) {
> synchronize_srcu(&encl_mm->encl->srcu);
> -
> - /*
> - * 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);
> + 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);
> +
> + 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,
> --
> 2.20.1
>
This one I squashed (master updated).
/Jarkko
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-10-03 22:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-03 17:04 [PATCH v2] x86/sgx: Migrate to mmu_notifier_put() Jarkko Sakkinen
2019-10-03 18:53 ` Jarkko Sakkinen
2019-10-03 22:07 ` Jarkko Sakkinen
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).