Skip to content

RFC mm: remove nth_page()

David Hildenbrand dri-devel intel-gfx io-uring kvm linux-arm-kernel linux-crypto linux-ide linux-iommu linux-kselftest linux-mips linux-mm linux-mmc linux-riscv linux-s390 linux-scsi lkml netdev syzbot virtualization wireguard 1 version Applied

Status from this message: Applied, thanks.

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest35 patches 61 repliesApplied 1/35

Patches in v1 Applied · 1/35

#Subject and filesSizeRepliesApplied
1/35mm: stop making SPARSEMEM_VMEMMAP user-selectablemm/Kconfig+1 -23 repliesApplied
2/35arm64: Kconfig: drop superfluous "select SPARSEMEM_VMEMMAP"arch/arm64/Kconfig+0 -11 reply
3/35s390/Kconfig: drop superfluous "select SPARSEMEM_VMEMMAP"arch/s390/Kconfig+0 -11 reply
4/35x86/Kconfig: drop superfluous "select SPARSEMEM_VMEMMAP"arch/x86/Kconfig+0 -11 reply
5/35wireguard: selftests: remove CONFIG_SPARSEMEM_VMEMMAP=y from qemu kernel configtools/testing/selftests/wireguard/qemu/kernel.config+0 -12 replies
6/35mm/page_alloc: reject unreasonable folio/compound page sizes in alloc_contig_range_noprof()include/linux/mm.h mm/page_alloc.c+8 -36 replies
7/35mm/memremap: reject unreasonable folio/compound page sizes in memremap_pages()mm/memremap.c+3 -01 reply
8/35mm/hugetlb: check for unreasonable folio sizes when registering hstatemm/hugetlb.c+2 -00 replies
9/35mm/mm_init: make memmap_init_compound() look more like prep_compound_page()mm/mm_init.c+5 -82 replies
10/35mm/hugetlb: cleanup hugetlb_folio_init_tail_vmemmap()mm/hugetlb.c+10 -1112 replies
11/35mm: sanity-check maximum folio size in folio_set_order()mm/internal.h+1 -01 reply
12/35mm: limit folio/compound page sizes in problematic kernel configsinclude/linux/mm.h+18 -44 replies
13/35mm: simplify folio_page() and folio_page_idx()include/linux/mm.h include/linux/page-flags.h+18 -32 replies
14/35mm/mm/percpu-km: drop nth_page() usage within single allocationmm/percpu-km.c+1 -10 replies
15/35fs: hugetlbfs: remove nth_page() usage within folio in adjust_range_hwpoison()fs/hugetlbfs/inode.c+8 -170 replies
16/35mm/pagewalk: drop nth_page() usage within folio in folio_walk_start()mm/pagewalk.c+1 -10 replies
17/35mm/gup: drop nth_page() usage within folio when recording subpagesmm/gup.c+3 -30 replies
18/35io_uring/zcrx: remove "struct io_copy_cache" and one nth_page() usageio_uring/zcrx.c+7 -253 replies
19/35io_uring/zcrx: remove nth_page() usage within folioio_uring/zcrx.c+1 -10 replies
20/35mips: mm: convert __flush_dcache_pages() to __flush_dcache_folio_pages()arch/mips/include/asm/cacheflush.h arch/mips/mm/cache.c+11 -80 replies
21/35mm/cma: refuse handing out non-contiguous page rangesinclude/linux/mm.h mm/cma.c mm/util.c+62 -135 replies
22/35dma-remap: drop nth_page() in dma_common_contiguous_remap()kernel/dma/remap.c+1 -11 reply
23/35scatterlist: disallow non-contigous page ranges in a single SG entryinclude/linux/scatterlist.h+3 -11 reply
24/35ata: libata-eh: drop nth_page() usage within SG entrydrivers/ata/libata-sff.c+3 -32 replies
25/35drm/i915/gem: drop nth_page() usage within SG entrydrivers/gpu/drm/i915/gem/i915_gem_pages.c+1 -10 replies
26/35mspro_block: drop nth_page() usage within SG entrydrivers/memstick/core/mspro_block.c+1 -21 reply
27/35memstick: drop nth_page() usage within SG entrydrivers/memstick/host/jmb38x_ms.c drivers/memstick/host/tifm_ms.c+2 -41 reply
28/35mmc: drop nth_page() usage within SG entrydrivers/mmc/host/tifm_sd.c drivers/mmc/host/usdhi6rol0.c+4 -41 reply
29/35scsi: core: drop nth_page() usage within SG entrydrivers/scsi/scsi_lib.c drivers/scsi/sg.c+2 -42 replies
30/35vfio/pci: drop nth_page() usage within SG entrydrivers/vfio/pci/pds/lm.c drivers/vfio/pci/virtio/migrate.c+2 -40 replies
31/35crypto: remove nth_page() usage within SG entrycrypto/ahash.c crypto/scompress.c include/crypto/scatterwalk.h+8 -85 replies
32/35mm/gup: drop nth_page() usage in unpin_user_page_range_dirty_lock()mm/gup.c+6 -10 replies
33/35kfence: drop nth_page() usagemm/kfence/core.c+10 -72 replies
34/35block: update comment of "struct bio_vec" regarding nth_page()include/linux/bvec.h+2 -50 replies
35/35mm: remove nth_page()include/linux/mm.h tools/testing/scatterlist/linux/mm.h+0 -30 replies

Reviews trailers per patch

18 of 35 patches have a Reviewed-by or Acked-by.

PatchZi YanMarek SzyprowskiUlf HanssonMike Rapoport (Microsoft)SeongJae ParkBart Van AsscheAlexandru EliseiPavel BegunkovBalbir Singh
1/35A-b A-b A-b
2/35R-b
3/35R-b
4/35R-b
5/35A-b
6/35A-b A-b
7/35A-b
8/35
9/35R-b
10/35
11/35R-b
12/35A-b
13/35
14/35
15/35
16/35
17/35
18/35R-b
19/35
20/35
21/35R-b
22/35A-b
23/35A-b
24/35
25/35
26/35A-b
27/35A-b
28/35A-b
29/35R-b
30/35
31/35
32/35
33/35
34/35
35/35

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 9 reviewers.

Read the v1 thread

Cover letter [PATCH RFC 00/35] mm: remove nth_page()

This is based on mm-unstable and was cross-compiled heavily.

I should probably have already dropped the RFC label but I want to hear first if I ignored some corner case (SG entries?) and I need to do at least a bit more testing.

I will only CC non-MM folks on the cover letter and the respective patch to not flood too many inboxes (the lists receive all patches).

---

As discussed recently with Linus, nth_page() is just nasty and we would like to remove it.

To recap, the reason we currently need nth_page() within a folio is because on some kernel configs (SPARSEMEM without SPARSEMEM_VMEMMAP), the memmap is allocated per memory section.

While buddy allocations cannot cross memory section boundaries, hugetlb and dax folios can.

So crossing a memory section means that "page++" could do the wrong thing. Instead, nth_page() on these problematic configs always goes from page->pfn, to the go from (++pfn)->page, which is rather nasty.

Likely, many people have no idea when nth_page() is required and when it might be dropped.

We refer to such problematic PFN ranges and "non-contiguous pages". If we only deal with "contiguous pages", there is not need for nth_page().

Besides that "obvious" folio case, we might end up using nth_page() within CMA allocations (again, could span memory sections), and in one corner case (kfence) when processing memblock allocations (again, could span memory sections).

So let's handle all that, add sanity checks, and remove nth_page().

Patch #1 -> #5 : stop making SPARSEMEM_VMEMMAP user-selectable + cleanups
Patch #6 -> #12 : disallow folios to have non-contiguous pages Patch #13 -> #20 : remove nth_page() usage within folios
Patch #21 : disallow CMA allocations of non-contiguous pages
Patch #22 -> #31 : sanity+check + remove nth_page() usage within SG entry
Patch #32 : sanity-check + remove nth_page() usage in
unpin_user_page_range_dirty_lock()

Patch #33        : remove nth_page() in kfence
Patch #34        : adjust stale comment regarding nth_page
Patch #35        : mm: remove nth_page()

A lot of this is inspired from the discussion at [1] between Linus, Jason and me, so cudos to them.

[1] https://lore.kernel.org/all/CAHk-=wiCYfNp4AJLBORU-c7ZyRBUp66W2-Et6cdQ4REx-GyQ_A@mail.gmail.com/T/#u

David Hildenbrand (35):
mm: stop making SPARSEMEM_VMEMMAP user-selectable
arm64: Kconfig: drop superfluous "select SPARSEMEM_VMEMMAP" s390/Kconfig: drop superfluous "select SPARSEMEM_VMEMMAP" x86/Kconfig: drop superfluous "select SPARSEMEM_VMEMMAP"
wireguard: selftests: remove CONFIG_SPARSEMEM_VMEMMAP=y from qemu
kernel config
mm/page_alloc: reject unreasonable folio/compound page sizes in
alloc_contig_range_noprof()
mm/memremap: reject unreasonable folio/compound page sizes in
memremap_pages()
mm/hugetlb: check for unreasonable folio sizes when registering hstate mm/mm_init: make memmap_init_compound() look more like
prep_compound_page()
mm/hugetlb: cleanup hugetlb_folio_init_tail_vmemmap()
mm: sanity-check maximum folio size in folio_set_order()
mm: limit folio/compound page sizes in problematic kernel configs
mm: simplify folio_page() and folio_page_idx() mm/mm/percpu-km: drop nth_page() usage within single allocation
fs: hugetlbfs: remove nth_page() usage within folio in
adjust_range_hwpoison()
mm/pagewalk: drop nth_page() usage within folio in folio_walk_start() mm/gup: drop nth_page() usage within folio when recording subpages io_uring/zcrx: remove "struct io_copy_cache" and one nth_page() usage io_uring/zcrx: remove nth_page() usage within folio
mips: mm: convert __flush_dcache_pages() to
__flush_dcache_folio_pages()
mm/cma: refuse handing out non-contiguous page ranges
dma-remap: drop nth_page() in dma_common_contiguous_remap()
scatterlist: disallow non-contigous page ranges in a single SG entry
ata: libata-eh: drop nth_page() usage within SG entry drm/i915/gem: drop nth_page() usage within SG entry
mspro_block: drop nth_page() usage within SG entry
memstick: drop nth_page() usage within SG entry
mmc: drop nth_page() usage within SG entry
scsi: core: drop nth_page() usage within SG entry vfio/pci: drop nth_page() usage within SG entry
crypto: remove nth_page() usage within SG entry
mm/gup: drop nth_page() usage in unpin_user_page_range_dirty_lock()
kfence: drop nth_page() usage
block: update comment of "struct bio_vec" regarding nth_page()
mm: remove nth_page()

 arch/arm64/Kconfig                            |  1 -
 arch/mips/include/asm/cacheflush.h            | 11 +++--
 arch/mips/mm/cache.c                          |  8 ++--
 arch/s390/Kconfig                             |  1 -
 arch/x86/Kconfig                              |  1 -
 crypto/ahash.c                                |  4 +-
 crypto/scompress.c                            |  8 ++--
 drivers/ata/libata-sff.c                      |  6 +--
 drivers/gpu/drm/i915/gem/i915_gem_pages.c     |  2 +-
 drivers/memstick/core/mspro_block.c           |  3 +-
 drivers/memstick/host/jmb38x_ms.c             |  3 +-
 drivers/memstick/host/tifm_ms.c               |  3 +-
 drivers/mmc/host/tifm_sd.c                    |  4 +-
 drivers/mmc/host/usdhi6rol0.c                 |  4 +-
 drivers/scsi/scsi_lib.c                       |  3 +-
 drivers/scsi/sg.c                             |  3 +-
 drivers/vfio/pci/pds/lm.c                     |  3 +-
 drivers/vfio/pci/virtio/migrate.c             |  3 +-
 fs/hugetlbfs/inode.c                          | 25 ++++------
 include/crypto/scatterwalk.h                  |  4 +-
 include/linux/bvec.h                          |  7 +--
 include/linux/mm.h                            | 48 +++++++++++++++----
 include/linux/page-flags.h                    |  5 +-
 include/linux/scatterlist.h                   |  4 +-
 io_uring/zcrx.c                               | 34 ++++---------
 kernel/dma/remap.c                            |  2 +-
 mm/Kconfig                                    |  3 +-
 mm/cma.c                                      | 36 +++++++++-----
 mm/gup.c                                      | 13 +++--
 mm/hugetlb.c                                  | 23 ++++-----
 mm/internal.h                                 |  1 +
 mm/kfence/core.c                              | 17 ++++---
 mm/memremap.c                                 |  3 ++
 mm/mm_init.c                                  | 13 ++---
 mm/page_alloc.c                               |  5 +-
 mm/pagewalk.c                                 |  2 +-
 mm/percpu-km.c                                |  2 +-
 mm/util.c                                     | 33 +++++++++++++
 tools/testing/scatterlist/linux/mm.h          |  1 -
 .../selftests/wireguard/qemu/kernel.config    |  1 -
 40 files changed, 203 insertions(+), 150 deletions(-)

base-commit: c0e3b3f33ba7b767368de4afabaf7c1ddfdc3872

Signature · 1 line
2.50.1