linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/hmm: Fix struct hmm memory leak
@ 2019-02-15 21:59 rcampbell
  2019-02-16  3:25 ` Jerome Glisse
  0 siblings, 1 reply; 2+ messages in thread
From: rcampbell @ 2019-02-15 21:59 UTC (permalink / raw)
  To: linux-mm
  Cc: Ralph Campbell, Andrew Morton, Jérôme Glisse, John Hubbard

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")

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-16  3:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-15 21:59 [PATCH] mm/hmm: Fix struct hmm memory leak rcampbell
2019-02-16  3:25 ` Jerome Glisse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox