From: Miaohe Lin <linmiaohe@huawei.com>
To: <akpm@linux-foundation.org>
Cc: <imbrenda@linux.ibm.com>, <kirill.shutemov@linux.intel.com>,
<jack@suse.cz>, <jhubbard@nvidia.com>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>, <linmiaohe@huawei.com>
Subject: [PATCH 4/5] mm: gup: fix potential pgmap refcnt leak in __gup_device_huge()
Date: Sat, 7 Aug 2021 17:36:19 +0800 [thread overview]
Message-ID: <20210807093620.21347-5-linmiaohe@huawei.com> (raw)
In-Reply-To: <20210807093620.21347-1-linmiaohe@huawei.com>
When failed to try_grab_page, put_dev_pagemap() is missed. So pgmap
refcnt will leak in this case. Also we remove the check for pgmap
against NULL as it's also checked inside the put_dev_pagemap().
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Fixes: 3faa52c03f44 ("mm/gup: track FOLL_PIN pages")
---
mm/gup.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/gup.c b/mm/gup.c
index d7e4507de6b1..8c89e614d4aa 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -2253,14 +2253,14 @@ static int __gup_device_huge(unsigned long pfn, unsigned long addr,
pages[*nr] = page;
if (unlikely(!try_grab_page(page, flags))) {
undo_dev_pagemap(nr, nr_start, flags, pages);
+ put_dev_pagemap(pgmap);
return 0;
}
(*nr)++;
pfn++;
} while (addr += PAGE_SIZE, addr != end);
- if (pgmap)
- put_dev_pagemap(pgmap);
+ put_dev_pagemap(pgmap);
return 1;
}
--
2.23.0
next prev parent reply other threads:[~2021-08-07 9:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-07 9:36 [PATCH 0/5] Cleanups and fixup for gup Miaohe Lin
2021-08-07 9:36 ` [PATCH 1/5] mm: gup: remove set but unused local variable major Miaohe Lin
2021-08-09 9:21 ` David Hildenbrand
2021-08-07 9:36 ` [PATCH 2/5] mm: gup: remove unneed local variable orig_refs Miaohe Lin
2021-08-09 9:22 ` David Hildenbrand
2021-08-07 9:36 ` [PATCH 3/5] mm: gup: remove useless BUG_ON in __get_user_pages() Miaohe Lin
2021-08-09 9:23 ` David Hildenbrand
2021-08-07 9:36 ` Miaohe Lin [this message]
2021-08-07 18:41 ` [PATCH 4/5] mm: gup: fix potential pgmap refcnt leak in __gup_device_huge() Andrew Morton
2021-08-07 18:45 ` Andrew Morton
2021-08-08 21:16 ` John Hubbard
2021-08-07 9:36 ` [PATCH 5/5] mm: gup: use helper PAGE_ALIGNED in populate_vma_page_range() Miaohe Lin
2021-08-09 9:24 ` David Hildenbrand
2021-08-08 21:13 ` [PATCH 0/5] Cleanups and fixup for gup John Hubbard
2021-08-09 9:39 ` Claudio Imbrenda
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=20210807093620.21347-5-linmiaohe@huawei.com \
--to=linmiaohe@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=imbrenda@linux.ibm.com \
--cc=jack@suse.cz \
--cc=jhubbard@nvidia.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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