linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jerome Glisse <jglisse@redhat.com>
To: rcampbell@nvidia.com
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	John Hubbard <jhubbard@nvidia.com>
Subject: Re: [PATCH] mm/hmm: Fix struct hmm memory leak
Date: Fri, 15 Feb 2019 22:25:18 -0500	[thread overview]
Message-ID: <20190216032517.GB13561@redhat.com> (raw)
In-Reply-To: <20190215215922.29797-1-rcampbell@nvidia.com>

On Fri, Feb 15, 2019 at 01:59:22PM -0800, rcampbell@nvidia.com wrote:
> From: Ralph Campbell <rcampbell@nvidia.com>
> 
> The patch [1] introduced reference counting on struct hmm and works
> fine when calling hmm_mirror_register() and hmm_mirror_unregister().
> However, when a process exits without explicitly unregistering,
> the MMU notifier callback hmm_release() doesn't release the mirror->hmm
> reference and thus leaks the struct hmm allocation.
> Fix this by releasing the reference in hmm_release().
> 
> [1] https://marc.info/?l=linux-mm&m=154878089214597&w=2
>     ("mm/hmm: use reference counting for HMM struct")

NAK we do not want to free stuff from underneath the driver that
was the whole point of the refcounting. Instead for driver that
want to free their mirror from the release call back can call the
hmm_mirror_unregister() function safely. Sorry if that was not
clear.

> 
> Signed-off-by: Ralph Campbell <rcampbell@nvidia.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: "Jérôme Glisse" <jglisse@redhat.com>
> Cc: John Hubbard <jhubbard@nvidia.com>
> ---
>  mm/hmm.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/mm/hmm.c b/mm/hmm.c
> index 3c9781037918..50523df6ea0c 100644
> --- a/mm/hmm.c
> +++ b/mm/hmm.c
> @@ -179,6 +179,8 @@ static void hmm_release(struct mmu_notifier *mn, struct mm_struct *mm)
>  			mirror->ops->release(mirror);
>  			down_write(&hmm->mirrors_sem);
>  		}
> +		hmm_put(mirror->hmm);
> +		mirror->hmm = NULL;
>  		mirror = list_first_entry_or_null(&hmm->mirrors,
>  						  struct hmm_mirror, list);
>  	}
> -- 
> 2.17.2
> 


      reply	other threads:[~2019-02-16  3:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-15 21:59 rcampbell
2019-02-16  3:25 ` Jerome Glisse [this message]

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=20190216032517.GB13561@redhat.com \
    --to=jglisse@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=jhubbard@nvidia.com \
    --cc=linux-mm@kvack.org \
    --cc=rcampbell@nvidia.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