Messages in this thread |  | | Date | Sun, 12 May 2019 11:28:15 -0400 | From | Jerome Glisse <> | Subject | Re: [PATCH 4/5] mm/hmm: hmm_vma_fault() doesn't always call hmm_range_unregister() |
| |
On Sun, May 12, 2019 at 11:07:24AM -0400, Jerome Glisse wrote: > On Tue, May 07, 2019 at 11:12:14AM -0700, Ralph Campbell wrote: > > > > On 5/7/19 6:15 AM, Souptick Joarder wrote: > > > On Tue, May 7, 2019 at 5:00 AM <rcampbell@nvidia.com> wrote: > > > > > > > > From: Ralph Campbell <rcampbell@nvidia.com> > > > > > > > > The helper function hmm_vma_fault() calls hmm_range_register() but is > > > > missing a call to hmm_range_unregister() in one of the error paths. > > > > This leads to a reference count leak and ultimately a memory leak on > > > > struct hmm. > > > > > > > > Always call hmm_range_unregister() if hmm_range_register() succeeded. > > > > > > How about * Call hmm_range_unregister() in error path if > > > hmm_range_register() succeeded* ? > > > > Sure, sounds good. > > I'll include that in v2. > > NAK for the patch see below why > > > > > > > > > > > Signed-off-by: Ralph Campbell <rcampbell@nvidia.com> > > > > Cc: John Hubbard <jhubbard@nvidia.com> > > > > Cc: Ira Weiny <ira.weiny@intel.com> > > > > Cc: Dan Williams <dan.j.williams@intel.com> > > > > Cc: Arnd Bergmann <arnd@arndb.de> > > > > Cc: Balbir Singh <bsingharora@gmail.com> > > > > Cc: Dan Carpenter <dan.carpenter@oracle.com> > > > > Cc: Matthew Wilcox <willy@infradead.org> > > > > Cc: Souptick Joarder <jrdr.linux@gmail.com> > > > > Cc: Andrew Morton <akpm@linux-foundation.org> > > > > --- > > > > include/linux/hmm.h | 3 ++- > > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/include/linux/hmm.h b/include/linux/hmm.h > > > > index 35a429621e1e..fa0671d67269 100644 > > > > --- a/include/linux/hmm.h > > > > +++ b/include/linux/hmm.h > > > > @@ -559,6 +559,7 @@ static inline int hmm_vma_fault(struct hmm_range *range, bool block) > > > > return (int)ret; > > > > > > > > if (!hmm_range_wait_until_valid(range, HMM_RANGE_DEFAULT_TIMEOUT)) { > > > > + hmm_range_unregister(range); > > > > /* > > > > * The mmap_sem was taken by driver we release it here and > > > > * returns -EAGAIN which correspond to mmap_sem have been > > > > @@ -570,13 +571,13 @@ static inline int hmm_vma_fault(struct hmm_range *range, bool block) > > > > > > > > ret = hmm_range_fault(range, block); > > > > if (ret <= 0) { > > > > + hmm_range_unregister(range); > > > > > > what is the reason to moved it up ? > > > > I moved it up because the normal calling pattern is: > > down_read(&mm->mmap_sem) > > hmm_vma_fault() > > hmm_range_register() > > hmm_range_fault() > > hmm_range_unregister() > > up_read(&mm->mmap_sem) > > > > I don't think it is a bug to unlock mmap_sem and then unregister, > > it is just more consistent nesting. > > So this is not the usage pattern with HMM usage pattern is: > > hmm_range_register() > hmm_range_fault() > hmm_range_unregister() > > The hmm_vma_fault() is gonne so this patch here break thing. > > See https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-5.2-v3
Sorry not enough coffee on sunday morning, so yeah this patch looks good except that you do not need to move it up.
Note that hmm_vma_fault() is a gonner once ODP to HMM is upstream and i converted nouveau/amd to new API then we can remove that one.
Cheers, Jérôme
|  |