mm/gup: Remove an assumption of a contiguous memmap
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 7 Jan 2022 18:45:25 +0000 (13:45 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Mon, 21 Mar 2022 16:56:35 +0000 (12:56 -0400)
This assumption needs the inverse of nth_page(), which is temporarily
named page_nth() until it's renamed later in this series.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
include/linux/mm.h
mm/gup.c

index 0201d25..e3f8755 100644 (file)
@@ -212,8 +212,10 @@ int overcommit_policy_handler(struct ctl_table *, int, void *, size_t *,
 
 #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
 #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
+#define page_nth(head, tail)   (page_to_pfn(tail) - page_to_pfn(head))
 #else
 #define nth_page(page,n) ((page) + (n))
+#define page_nth(head, tail)   ((tail) - (head))
 #endif
 
 /* to align the pointer to the (next) page boundary */
index d585aa0..ad120f4 100644 (file)
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -261,8 +261,8 @@ static inline struct page *compound_range_next(struct page *start,
        next = nth_page(start, i);
        page = compound_head(next);
        if (PageHead(page))
-               nr = min_t(unsigned int,
-                          page + compound_nr(page) - next, npages - i);
+               nr = min_t(unsigned int, npages - i,
+                          compound_nr(page) - page_nth(page, next));
 
        *ntails = nr;
        return page;