linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/gup: restore the ability to pin more than 2GB at a time
@ 2024-10-30  3:01 John Hubbard
  2024-10-30  4:21 ` Christoph Hellwig
  0 siblings, 1 reply; 23+ messages in thread
From: John Hubbard @ 2024-10-30  3:01 UTC (permalink / raw)
  To: Andrew Morton
  Cc: LKML, linux-mm, John Hubbard, linux-stable, Vivek Kasireddy,
	David Hildenbrand, Dave Airlie, Gerd Hoffmann, Matthew Wilcox,
	Christoph Hellwig, Jason Gunthorpe, Peter Xu, Arnd Bergmann,
	Daniel Vetter, Dongwon Kim, Hugh Dickins, Junxiao Chang,
	Mike Kravetz, Oscar Salvador

commit 53ba78de064b ("mm/gup: introduce
check_and_migrate_movable_folios()") created a new constraint on the
pin_user_pages*() API family: a potentially large allocation must now
occur, internally.

A user-visible consequence has now appeared: user space can no longer
pin more than 2GB of memory anymore on x86_64. That's because, on a 4KB
PAGE_SIZE system, when user space tries to (indirectly, via a device
driver that calls pin_user_pages()) pin 2GB, this requires an allocation
of a folio pointers array of MAX_PAGE_ORDER size, which is the limit for
kmalloc().

Fix this (restore the original behavior), by using replacing
kmalloc_array() with kvmalloc_array(), which falls back to vmalloc() for
larger allocations.

Fixes: 53ba78de064b ("mm/gup: introduce check_and_migrate_movable_folios()")
Cc: linux-stable@vger.kernel.org

Cc: Vivek Kasireddy <vivek.kasireddy@intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Dongwon Kim <dongwon.kim@intel.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Junxiao Chang <junxiao.chang@intel.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Oscar Salvador <osalvador@suse.de>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---

This applies to mm-hotfixes-unstable (only), because it relies on my
earlier patch to this exact same location: commit 255231c75dcd mm/gup:
stop leaking pinned pages in low memory conditions.

thanks,
John Hubbard

 mm/gup.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index 4637dab7b54f..346186788a49 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -21,6 +21,7 @@
 #include <linux/pagevec.h>
 #include <linux/sched/mm.h>
 #include <linux/shmem_fs.h>
+#include <linux/vmalloc.h>
 
 #include <asm/mmu_context.h>
 #include <asm/tlbflush.h>
@@ -2439,7 +2440,7 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages,
 	struct folio **folios;
 	long i, ret;
 
-	folios = kmalloc_array(nr_pages, sizeof(*folios), GFP_KERNEL);
+	folios = kvmalloc_array(nr_pages, sizeof(*folios), GFP_KERNEL);
 	if (!folios) {
 		unpin_user_pages(pages, nr_pages);
 		return -ENOMEM;
@@ -2450,7 +2451,7 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages,
 
 	ret = check_and_migrate_movable_folios(nr_pages, folios);
 
-	kfree(folios);
+	kvfree(folios);
 	return ret;
 }
 #else

base-commit: b70a32bbebeae216a3e846e01965880b309ca173
-- 
2.47.0



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

end of thread, other threads:[~2024-10-31  0:47 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-30  3:01 [PATCH] mm/gup: restore the ability to pin more than 2GB at a time John Hubbard
2024-10-30  4:21 ` Christoph Hellwig
2024-10-30  4:30   ` John Hubbard
2024-10-30  4:33     ` Christoph Hellwig
2024-10-30  4:39       ` John Hubbard
2024-10-30  4:42         ` Christoph Hellwig
2024-10-30  4:44           ` John Hubbard
2024-10-30  6:18             ` Alistair Popple
2024-10-30  6:50               ` John Hubbard
2024-10-30  8:34                 ` David Hildenbrand
2024-10-30  9:01                   ` David Hildenbrand
2024-10-30 18:34                     ` John Hubbard
2024-10-31  0:02                       ` Jason Gunthorpe
2024-10-31  0:17                         ` John Hubbard
2024-10-31  0:25                           ` Jason Gunthorpe
2024-10-31  0:47                             ` John Hubbard
2024-10-30 12:04                   ` Jason Gunthorpe
2024-10-30 17:25                     ` John Hubbard
2024-10-30 11:59           ` Jason Gunthorpe
2024-10-30 11:03         ` Vlastimil Babka
2024-10-30 17:29           ` John Hubbard
2024-10-30 17:42             ` Vlastimil Babka
2024-10-30 17:49               ` John Hubbard

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