[PATCH v3 0/5] mm, uio: huge PFN mappings for /dev/mem and UIO

From: Eliav Farber

Date: Tue Nov 24 2026 - 08:15:39 EST


/dev/mem and UIO map large physical regions with 4KiB PTEs, even where a
2MiB or 1GiB entry would do. vfio-pci fixed that in commit f9e54c3a2f5b
("vfio/pci: implement huge_fault support") by populating on fault. This
series does the same for /dev/mem and UIO.

Patches 1 and 3 add the two things a driver needs outside vfio-pci: a way
to reserve a range's memory type without populating it, and the order
dispatch vfio-pci open-codes. Patch 2 fixes a window and pfn check in
huge_memory that the new callers reach. Patches 4 and 5 are the users.

Applies on top of Lorenzo Stoakes' fixes for races between huge and
non-huge faults in PFN mappings, queued in mm for 7.5:
https://lore.kernel.org/all/20261117-huge-pfnmap-fault-races-v2-0-276007e73bcb@xxxxxxxxxx/

Changes in v3:

- Patch 2 is new: the window and pfn checks moved into mm, where every
caller gets them.
- /dev/mem keeps the eager mapping under CONFIG_IO_STRICT_DEVMEM.
- Renamed pfn_range_track() to track_pfn_range(), and dropped its addr
and size arguments.
- Shorter commit messages and comments.

Changes in v2:

- vmf_insert_pfn_order() maps a write fault writable at every
order. (Sashiko)
- COW mappings get their own vm_operations_struct, instead of a COW test
inside the fault handler. (Sashiko)
- Corrected the L1TF claim in the /dev/mem and UIO patches, and dropped
the claim that uffd-wp can write-protect such a mapping.

An LLM helped me find corner cases and fix them in the code, write tests
and run them under QEMU. The runs on real hardware are mine.

v1: https://lore.kernel.org/all/20261111113045.35368-1-farbere@xxxxxxxxxx/
v2: https://lore.kernel.org/all/20261112125638.12209-1-farbere@xxxxxxxxxx/

Eliav Farber (5):
mm: add MMAP_TRACK_PFN action and track_pfn_range() for lazy PFN maps
mm/huge_memory: check the window and the pfn alignment before
inserting
mm: add vmf_insert_pfn_order()
mm/char-mem: implement huge_fault support for /dev/mem
uio: implement huge_fault support for physical mappings

drivers/uio/uio.c | 99 +++++++++++++++--
include/linux/mm.h | 18 ++++
include/linux/mm_types.h | 1 +
mm/char-mem.c | 81 +++++++++++++-
mm/huge_memory.c | 18 +++-
mm/internal.h | 3 +
mm/memory.c | 182 +++++++++++++++++++++++++++-----
mm/util.c | 7 ++
tools/testing/vma/include/dup.h | 1 +
9 files changed, 369 insertions(+), 41 deletions(-)


base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
--
2.47.3