Re: [PATCH v3 5/5] uio: implement huge_fault support for physical mappings

From: Greg Kroah-Hartman

Date: Tue Nov 24 2026 - 09:14:35 EST


On Tue, Nov 24, 2026 at 01:15:10PM +0000, Eliav Farber wrote:
> uio_mmap_physical() maps UIO_MEM_PHYS and UIO_MEM_IOVA regions at mmap()
> time with 4KiB PTEs, however large and aligned they are. Populate on
> fault instead, as vfio-pci does since commit f9e54c3a2f5b ("vfio/pci:
> implement huge_fault support"): call track_pfn_range() rather than
> remap_pfn_range(), and add ->fault and ->huge_fault handlers using
> vmf_insert_pfn_order(). A large enough aligned region is then mapped with
> PMD or PUD entries.
>
> Like uio_vma_fault(), both handlers take idev->info_lock and fail with
> SIGBUS once the device is gone. COW mappings keep the eager remap.
>
> The fault handler needs the base pfn, so vm_pgoff now holds that instead
> of the map index, as remap_pfn_range() does for COW mappings.
> /proc/pid/maps reports it as the offset of these mappings.
>
> Once the device is unregistered, an untouched page gets SIGBUS. The
> eager remap used to keep it mapped. A remote read through ptrace or
> /proc/pid/mem of a mapping with no VM_READ now fails too, where the
> eager remap used to leave a present pte.

Why in the world are you using UIO for this? Why not do the right thing
and put your driver in the kernel in the kernel itself if it needs to
access large mappings like this instead of hacking around the
"limitations" of /dev/mem and uio?

Do it right please.

thanks,

greg k-h