From: Andrew Morton <akpm@linux-foundation.org> To: akpm@linux-foundation.org, aneesh.kumar@linux.ibm.com, dan.j.williams@intel.com, ira.weiny@intel.com, jgg@nvidia.com, jhubbard@nvidia.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, stable@vger.kernel.org, torvalds@linux-foundation.org Subject: [patch 06/14] mm/gup: use unpin_user_pages() in __gup_longterm_locked() Date: Fri, 13 Nov 2020 22:51:56 -0800 Message-ID: <20201114065156.AkB0cZWK4%akpm@linux-foundation.org> (raw) In-Reply-To: <20201113225115.b24faebc85f710d5aff55aa7@linux-foundation.org> From: Jason Gunthorpe <jgg@nvidia.com> Subject: mm/gup: use unpin_user_pages() in __gup_longterm_locked() When FOLL_PIN is passed to __get_user_pages() the page list must be put back using unpin_user_pages() otherwise the page pin reference persists in a corrupted state. There are two places in the unwind of __gup_longterm_locked() that put the pages back without checking. Normally on error this function would return the partial page list making this the caller's responsibility, but in these two cases the caller is not allowed to see these pages at all. Link: https://lkml.kernel.org/r/0-v2-3ae7d9d162e2+2a7-gup_cma_fix_jgg@nvidia.com Fixes: 3faa52c03f44 ("mm/gup: track FOLL_PIN pages") Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Reported-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: John Hubbard <jhubbard@nvidia.com> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> --- mm/gup.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) --- a/mm/gup.c~mm-gup-use-unpin_user_pages-in-__gup_longterm_locked +++ a/mm/gup.c @@ -1647,8 +1647,11 @@ check_again: /* * drop the above get_user_pages reference. */ - for (i = 0; i < nr_pages; i++) - put_page(pages[i]); + if (gup_flags & FOLL_PIN) + unpin_user_pages(pages, nr_pages); + else + for (i = 0; i < nr_pages; i++) + put_page(pages[i]); if (migrate_pages(&cma_page_list, alloc_migration_target, NULL, (unsigned long)&mtc, MIGRATE_SYNC, MR_CONTIG_RANGE)) { @@ -1728,8 +1731,11 @@ static long __gup_longterm_locked(struct goto out; if (check_dax_vmas(vmas_tmp, rc)) { - for (i = 0; i < rc; i++) - put_page(pages[i]); + if (gup_flags & FOLL_PIN) + unpin_user_pages(pages, rc); + else + for (i = 0; i < rc; i++) + put_page(pages[i]); rc = -EOPNOTSUPP; goto out; } _
next prev parent reply index Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-11-14 6:51 incoming Andrew Morton 2020-11-14 6:51 ` [patch 01/14] mm/compaction: count pages and stop correctly during page isolation Andrew Morton 2020-11-14 6:51 ` [patch 02/14] mm/compaction: stop isolation if too many pages are isolated and we have pages to migrate Andrew Morton 2020-11-14 6:51 ` [patch 03/14] mm/vmscan: fix NR_ISOLATED_FILE corruption on 64-bit Andrew Morton 2020-11-14 21:39 ` Linus Torvalds 2020-11-14 22:14 ` Matthew Wilcox 2020-11-14 6:51 ` [patch 04/14] mailmap: fix entry for Dmitry Baryshkov/Eremin-Solenikov Andrew Morton 2020-11-14 6:51 ` [patch 05/14] mm/slub: fix panic in slab_alloc_node() Andrew Morton 2020-11-14 6:51 ` Andrew Morton [this message] 2020-11-14 6:51 ` [patch 07/14] compiler.h: fix barrier_data() on clang Andrew Morton 2020-11-14 6:52 ` [patch 08/14] Revert "kernel/reboot.c: convert simple_strtoul to kstrtoint" Andrew Morton 2020-11-14 6:52 ` [patch 09/14] reboot: fix overflow parsing reboot cpu number Andrew Morton 2020-11-14 6:52 ` [patch 10/14] kernel/watchdog: fix watchdog_allowed_mask not used warning Andrew Morton 2020-11-14 6:52 ` [patch 11/14] mm: memcontrol: fix missing wakeup polling thread Andrew Morton 2020-11-14 6:52 ` [patch 12/14] hugetlbfs: fix anon huge page migration race Andrew Morton 2020-11-14 6:52 ` [patch 13/14] panic: don't dump stack twice on warn Andrew Morton 2020-11-14 6:52 ` [patch 14/14] ocfs2: initialize ip_next_orphan Andrew Morton
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=20201114065156.AkB0cZWK4%akpm@linux-foundation.org \ --to=akpm@linux-foundation.org \ --cc=aneesh.kumar@linux.ibm.com \ --cc=dan.j.williams@intel.com \ --cc=ira.weiny@intel.com \ --cc=jgg@nvidia.com \ --cc=jhubbard@nvidia.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=mm-commits@vger.kernel.org \ --cc=stable@vger.kernel.org \ --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
mm-commits Archive on lore.kernel.org Archives are clonable: git clone --mirror https://lore.kernel.org/mm-commits/0 mm-commits/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 mm-commits mm-commits/ https://lore.kernel.org/mm-commits \ mm-commits@vger.kernel.org public-inbox-index mm-commits Example config snippet for mirrors Newsgroup available over NNTP: nntp://nntp.lore.kernel.org/org.kernel.vger.mm-commits AGPL code for this site: git clone https://public-inbox.org/public-inbox.git