[PATCH v6 25/39] mm/vma: enforce that mm-managed mappings may not set VMA_IO_BIT
flat view
COOLING7d
IN LINUX-NEXT: 1 (1M)
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Date: 2026-10-13 15:19:07
Also in:
bpf, dri-devel, fuse-devel, kvm, kvm-riscv, kvmarm, linux-arch, linux-doc, linux-fbdev, linux-fsdevel, linux-mm, linux-perf-users, linux-rdma, linux-riscv, linux-s390, linux-scsi, linux-sound, linux-usb, linuxppc-dev, lkml, selinux, sparclinux
Subsystem:
memory management, memory mapping, the rest · Maintainers:
Andrew Morton, Liam R. Howlett, Lorenzo Stoakes, Linus Torvalds
It makes no sense for a mapping whose contents the kernel does not own to
specify that the range is MMIO.
Prior to this patch, all in-tree drivers which did so have been updated
such that they are marked as not being mm-managed. The check WARNs and
fails the mmap for any out-of-tree driver that still sets VMA_IO_BIT
without a kernel mapping.
Here VMA_PFNMAP_BIT, VMA_MIXEDMAP are tested individually rather than using
vma_flags_is_mm_managed().
This is because vma_flags_is_mm_managed() still checks for VMA_IO_BIT.
The very next commit in this series removes this, and the check is then
converted to use vma_flags_is_mm_managed().
No functional change intended for in-tree code.
Reviewed-by: Zi Yan <ziy@nvidia.com>
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
---
mm/vma.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/mm/vma.c b/mm/vma.c
index 6cfda4575997..affe464a7c92 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -2794,6 +2794,12 @@ static int mmap_validate_vma_flags(const vma_flags_t *flags)
return -EINVAL;
#endif
+ if (!vma_flags_test_any(flags, VMA_PFNMAP_BIT, VMA_MIXEDMAP_BIT)) {
+ /* mm-managed mappings may not set VMA_IO_BIT. */
+ if (WARN_ON_ONCE(vma_flags_test(flags, VMA_IO_BIT)))
+ return -EINVAL;
+ }
+
return 0;
}
--
2.55.0