On Sun, Nov 17, 2024 at 01:19:09PM -0800, John Hubbard wrote: > On 11/17/24 12:33 PM, gregkh@xxxxxxxxxxxxxxxxxxx wrote: > > > > The patch below does not apply to the 6.11-stable tree. > > If someone wants it applied there, or to any other stable or longterm > > tree, then please email the backport, including the original git commit > > id to <stable@xxxxxxxxxxxxxxx>. > > > > To reproduce the conflict and resubmit, you may use the following commands: > > > > git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.11.y > > git checkout FETCH_HEAD > > git cherry-pick -x 94efde1d15399f5c88e576923db9bcd422d217f2 > > # <resolve conflicts, build, test, etc.> > > git commit -s > > git send-email --to '<stable@xxxxxxxxxxxxxxx>' --in-reply-to '2024111754-stamina-flyer-1e05@gregkh' --subject-prefix 'PATCH 6.11.y' HEAD^.. > > > > It seems that the last hunk didn't apply because it was just too far away, > as far as I can tell. I've manually applied it, resulting in the same diffs > as the original, and did a quick smoke test (boot and ran mm tests). > > Here's the updated version for 6.11.y: > > From: John Hubbard <jhubbard@xxxxxxxxxx> > Date: Sun, 17 Nov 2024 13:08:00 -0800 > Subject: [PATCH] mm/gup: avoid an unnecessary allocation call for > FOLL_LONGTERM cases > X-NVConfidentiality: public > Cc: John Hubbard <jhubbard@xxxxxxxxxx> > > commit 53ba78de064b ("mm/gup: introduce > check_and_migrate_movable_folios()") created a new constraint on the > pin_user_pages*() API family: a potentially large internal allocation must > now occur, for FOLL_LONGTERM cases. > > 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(). > > In addition to the directly visible effect described above, there is also > the problem of adding an unnecessary allocation. The **pages array > argument has already been allocated, and there is no need for a redundant > **folios array allocation in this case. > > Fix this by avoiding the new allocation entirely. This is done by > referring to either the original page[i] within **pages, or to the > associated folio. Thanks to David Hildenbrand for suggesting this > approach and for providing the initial implementation (which I've tested > and adjusted slightly) as well. > > [jhubbard@xxxxxxxxxx]: tweaked the patch to apply to linux-stable/6.11.y > [jhubbard@xxxxxxxxxx: whitespace tweak, per David] > Link: > https://lkml.kernel.org/r/131cf9c8-ebc0-4cbb-b722-22fa8527bf3c@xxxxxxxxxx > [jhubbard@xxxxxxxxxx: bypass pofs_get_folio(), per Oscar] > Link: > https://lkml.kernel.org/r/c1587c7f-9155-45be-bd62-1e36c0dd6923@xxxxxxxxxx > Link: https://lkml.kernel.org/r/20241105032944.141488-2-jhubbard@xxxxxxxxxx > Fixes: 53ba78de064b ("mm/gup: introduce check_and_migrate_movable_folios()") > Signed-off-by: John Hubbard <jhubbard@xxxxxxxxxx> > Suggested-by: David Hildenbrand <david@xxxxxxxxxx> > Acked-by: David Hildenbrand <david@xxxxxxxxxx> > Reviewed-by: Oscar Salvador <osalvador@xxxxxxx> > Cc: Vivek Kasireddy <vivek.kasireddy@xxxxxxxxx> > Cc: Dave Airlie <airlied@xxxxxxxxxx> > Cc: Gerd Hoffmann <kraxel@xxxxxxxxxx> > Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx> > Cc: Christoph Hellwig <hch@xxxxxxxxxxxxx> > Cc: Jason Gunthorpe <jgg@xxxxxxxxxx> > Cc: Peter Xu <peterx@xxxxxxxxxx> > Cc: Arnd Bergmann <arnd@xxxxxxxx> > Cc: Daniel Vetter <daniel.vetter@xxxxxxxx> > Cc: Dongwon Kim <dongwon.kim@xxxxxxxxx> > Cc: Hugh Dickins <hughd@xxxxxxxxxx> > Cc: Junxiao Chang <junxiao.chang@xxxxxxxxx> > Cc: <stable@xxxxxxxxxxxxxxx> > Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> > --- > mm/gup.c | 114 +++++++++++++++++++++++++++++++++++++------------------ > 1 file changed, 77 insertions(+), 37 deletions(-) > > diff --git a/mm/gup.c b/mm/gup.c > index 947881ff5e8f..fd3d7900c24b 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -2282,20 +2282,57 @@ struct page *get_dump_page(unsigned long addr) > #endif /* CONFIG_ELF_CORE */ > > #ifdef CONFIG_MIGRATION > + > +/* > + * An array of either pages or folios ("pofs"). Although it may seem > tempting to > + * avoid this complication, by simply interpreting a list of folios as a > list of > + * pages, that approach won't work in the longer term, because eventually > the > + * layouts of struct page and struct folio will become completely > different. > + * Furthermore, this pof approach avoids excessive page_folio() calls. Patch is line-wrapped :( Can you resend it in a format I can apply it in? thanks, greg k-h