]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
scatterlist: disallow non-contigous page ranges in a single SG entry
authorDavid Hildenbrand <david@redhat.com>
Mon, 1 Sep 2025 15:03:45 +0000 (17:03 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 21 Sep 2025 21:22:06 +0000 (14:22 -0700)
commit80e7bb74d4ff24725f0ddb1c72d8de45a3d975f6
tree33bc0d3e966f6a54c909be8221d2f95ac87db75d
parenta16c46c2402026162111ed9fd1fc28d25223443e
scatterlist: disallow non-contigous page ranges in a single SG entry

The expectation is that there is currently no user that would pass in
non-contigous page ranges: no allocator, not even VMA, will hand these
out.

The only problematic part would be if someone would provide a range
obtained directly from memblock, or manually merge problematic ranges.  If
we find such cases, we should fix them to create separate SG entries.

Let's check in sg_set_page() that this is really the case.  No need to
check in sg_set_folio(), as pages in a folio are guaranteed to be
contiguous.  As sg_set_page() gets inlined into modules, we have to export
the page_range_contiguous() helper -- use EXPORT_SYMBOL, there is nothing
special about this helper such that we would want to enforce GPL-only
modules.

We can now drop the nth_page() usage in sg_page_iter_page().

Link: https://lkml.kernel.org/r/20250901150359.867252-25-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/scatterlist.h
mm/util.c