linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Oded Gabbay <oded.gabbay@amd.com>
To: j.glisse@gmail.com, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, akpm@linux-foundation.org
Cc: "Linus Torvalds" <torvalds@linux-foundation.org>,
	joro@8bytes.org, "Mel Gorman" <mgorman@suse.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Andrea Arcangeli" <aarcange@redhat.com>,
	"Johannes Weiner" <jweiner@redhat.com>,
	"Larry Woodman" <lwoodman@redhat.com>,
	"Rik van Riel" <riel@redhat.com>,
	"Dave Airlie" <airlied@redhat.com>,
	"Brendan Conoboy" <blc@redhat.com>,
	"Joe Donohue" <jdonohue@redhat.com>,
	"Duncan Poole" <dpoole@nvidia.com>,
	"Sherry Cheung" <SCheung@nvidia.com>,
	"Subhash Gutti" <sgutti@nvidia.com>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Mark Hairgrove" <mhairgrove@nvidia.com>,
	"Lucien Dunning" <ldunning@nvidia.com>,
	"Cameron Buschardt" <cabuschardt@nvidia.com>,
	"Arvind Gopalakrishnan" <arvindg@nvidia.com>,
	"Shachar Raindel" <raindel@mellanox.com>,
	"Liran Liss" <liranl@mellanox.com>,
	"Roland Dreier" <roland@purestorage.com>,
	"Ben Sander" <ben.sander@amd.com>,
	"Greg Stoner" <Greg.Stoner@amd.com>,
	"John Bridgman" <John.Bridgman@amd.com>,
	"Michael Mantor" <Michael.Mantor@amd.com>,
	"Paul Blinzer" <Paul.Blinzer@amd.com>,
	"Laurent Morichetti" <Laurent.Morichetti@amd.com>,
	"Alexander Deucher" <Alexander.Deucher@amd.com>,
	"Jérôme Glisse" <jglisse@redhat.com>
Subject: Re: [PATCH 1/7] mmu_notifier: add call_srcu and sync function for listener to delay call and sync.
Date: Mon, 21 Jul 2014 18:01:23 +0300	[thread overview]
Message-ID: <53CD2B43.3090405@amd.com> (raw)
In-Reply-To: <1405622809-3797-2-git-send-email-j.glisse@gmail.com>

On 17/07/14 21:46, j.glisse@gmail.com wrote:
> From: Peter Zijlstra <peterz@infradead.org>
>
> New mmu_notifier listener are eager to cleanup there structure after the
> mmu_notifier::release callback. In order to allow this the patch provide
> a function that allows to add a delayed call to the mmu_notifier srcu. It
> also add a function that will call barrier_srcu so those listener can sync
> with mmu_notifier.

Tested with amdkfd and iommuv2 driver
So,
Tested-by: Oded Gabbay <oded.gabbay@amd.com>
>
> Signed-off-by: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Jérôme Glisse <jglisse@redhat.com>
> ---
>   include/linux/mmu_notifier.h |  6 ++++++
>   mm/mmu_notifier.c            | 40 +++++++++++++++++++++++++++++++++++++++-
>   2 files changed, 45 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
> index deca874..2728869 100644
> --- a/include/linux/mmu_notifier.h
> +++ b/include/linux/mmu_notifier.h
> @@ -170,6 +170,8 @@ extern int __mmu_notifier_register(struct mmu_notifier *mn,
>   				   struct mm_struct *mm);
>   extern void mmu_notifier_unregister(struct mmu_notifier *mn,
>   				    struct mm_struct *mm);
> +extern void mmu_notifier_unregister_no_release(struct mmu_notifier *mn,
> +					       struct mm_struct *mm);
>   extern void __mmu_notifier_mm_destroy(struct mm_struct *mm);
>   extern void __mmu_notifier_release(struct mm_struct *mm);
>   extern int __mmu_notifier_clear_flush_young(struct mm_struct *mm,
> @@ -288,6 +290,10 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
>   	set_pte_at(___mm, ___address, __ptep, ___pte);			\
>   })
>
> +extern void mmu_notifier_call_srcu(struct rcu_head *rcu,
> +				   void (*func)(struct rcu_head *rcu));
> +extern void mmu_notifier_synchronize(void);
> +
>   #else /* CONFIG_MMU_NOTIFIER */
>
>   static inline void mmu_notifier_release(struct mm_struct *mm)
> diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c
> index 41cefdf..950813b 100644
> --- a/mm/mmu_notifier.c
> +++ b/mm/mmu_notifier.c
> @@ -23,6 +23,25 @@
>   static struct srcu_struct srcu;
>
>   /*
> + * This function allows mmu_notifier::release callback to delay a call to
> + * a function that will free appropriate resources. The function must be
> + * quick and must not block.
> + */
> +void mmu_notifier_call_srcu(struct rcu_head *rcu,
> +			    void (*func)(struct rcu_head *rcu))
> +{
> +	call_srcu(&srcu, rcu, func);
> +}
> +EXPORT_SYMBOL_GPL(mmu_notifier_call_srcu);
> +
> +void mmu_notifier_synchronize(void)
> +{
> +	/* Wait for any running method to finish. */
> +	srcu_barrier(&srcu);
> +}
> +EXPORT_SYMBOL_GPL(mmu_notifier_synchronize);
> +
> +/*
>    * This function can't run concurrently against mmu_notifier_register
>    * because mm->mm_users > 0 during mmu_notifier_register and exit_mmap
>    * runs with mm_users == 0. Other tasks may still invoke mmu notifiers
> @@ -53,7 +72,6 @@ void __mmu_notifier_release(struct mm_struct *mm)
>   		 */
>   		if (mn->ops->release)
>   			mn->ops->release(mn, mm);
> -	srcu_read_unlock(&srcu, id);
>
>   	spin_lock(&mm->mmu_notifier_mm->lock);
>   	while (unlikely(!hlist_empty(&mm->mmu_notifier_mm->list))) {
> @@ -69,6 +87,7 @@ void __mmu_notifier_release(struct mm_struct *mm)
>   		hlist_del_init_rcu(&mn->hlist);
>   	}
>   	spin_unlock(&mm->mmu_notifier_mm->lock);
> +	srcu_read_unlock(&srcu, id);
>
>   	/*
>   	 * synchronize_srcu here prevents mmu_notifier_release from returning to
> @@ -325,6 +344,25 @@ void mmu_notifier_unregister(struct mmu_notifier *mn, struct mm_struct *mm)
>   }
>   EXPORT_SYMBOL_GPL(mmu_notifier_unregister);
>
> +/*
> + * Same as mmu_notifier_unregister but no callback and no srcu synchronization.
> + */
> +void mmu_notifier_unregister_no_release(struct mmu_notifier *mn,
> +					struct mm_struct *mm)
> +{
> +	spin_lock(&mm->mmu_notifier_mm->lock);
> +	/*
> +	 * Can not use list_del_rcu() since __mmu_notifier_release
> +	 * can delete it before we hold the lock.
> +	 */
> +	hlist_del_init_rcu(&mn->hlist);
> +	spin_unlock(&mm->mmu_notifier_mm->lock);
> +
> +	BUG_ON(atomic_read(&mm->mm_count) <= 0);
> +	mmdrop(mm);
> +}
> +EXPORT_SYMBOL_GPL(mmu_notifier_unregister_no_release);
> +
>   static int __init mmu_notifier_init(void)
>   {
>   	return init_srcu_struct(&srcu);
>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2014-07-21 15:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-17 18:46 mmu_notifier: preparatory patches for hmm and or iommuv2 v6 j.glisse
2014-07-17 18:46 ` [PATCH 1/7] mmu_notifier: add call_srcu and sync function for listener to delay call and sync j.glisse
2014-07-21 15:01   ` Oded Gabbay [this message]
2014-07-29 15:04     ` Oded Gabbay
2014-07-29 20:48       ` Andrew Morton
2014-07-29 21:04         ` Oded Gabbay
2014-08-02 18:54         ` Oded Gabbay
2014-07-17 18:46 ` [PATCH 2/7] mmu_notifier: add event information to address invalidation v3 j.glisse
2014-07-17 18:46 ` [PATCH 3/7] mmu_notifier: pass through vma to invalidate_range and invalidate_page v3 j.glisse
2014-07-24 22:51   ` Andrew Morton
2014-07-25 15:14     ` Jerome Glisse
2014-07-24 15:46 ` mmu_notifier: preparatory patches for hmm and or iommuv2 v6 Jerome Glisse
2014-07-24 18:41   ` Oded Gabbay

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=53CD2B43.3090405@amd.com \
    --to=oded.gabbay@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Greg.Stoner@amd.com \
    --cc=John.Bridgman@amd.com \
    --cc=Laurent.Morichetti@amd.com \
    --cc=Michael.Mantor@amd.com \
    --cc=Paul.Blinzer@amd.com \
    --cc=SCheung@nvidia.com \
    --cc=aarcange@redhat.com \
    --cc=airlied@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=arvindg@nvidia.com \
    --cc=ben.sander@amd.com \
    --cc=blc@redhat.com \
    --cc=cabuschardt@nvidia.com \
    --cc=dpoole@nvidia.com \
    --cc=hpa@zytor.com \
    --cc=j.glisse@gmail.com \
    --cc=jdonohue@redhat.com \
    --cc=jglisse@redhat.com \
    --cc=jhubbard@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=jweiner@redhat.com \
    --cc=ldunning@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liranl@mellanox.com \
    --cc=lwoodman@redhat.com \
    --cc=mgorman@suse.de \
    --cc=mhairgrove@nvidia.com \
    --cc=peterz@infradead.org \
    --cc=raindel@mellanox.com \
    --cc=riel@redhat.com \
    --cc=roland@purestorage.com \
    --cc=sgutti@nvidia.com \
    --cc=torvalds@linux-foundation.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