Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mm: VM_WARN_ON_ONCE triggered by vm_flags_reset() in mmap hook
--
commit a356d47e4beede9d3e032c777130976d06dd5dd8
Author: Lorenzo Stoakes (ARM) [off-list ref]
infiniband: update hfi1 to use remap_vmalloc_range()
In cases which map chip memory from vmalloc()'d ranges, the hfi1 infiniband
drivers currently installs a fault handler, and then smuggles the kernel
virtual address of this range in vma->vm_pgoff.
quoted hunk ↗ jump to hunk
diff --git a/drivers/infiniband/hw/hfi1/file_ops.c b/drivers/infiniband/hw/hfi1/file_ops.c
index dc548e6802e24..b02d1f1dbb27b 100644
--- a/drivers/infiniband/hw/hfi1/file_ops.c
+++ b/drivers/infiniband/hw/hfi1/file_ops.c
[ ... ]
quoted hunk ↗ jump to hunk
@@ -422,7 +418,7 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)
ret = -EPERM;
goto done;
}
- vm_flags_clear(vma, VM_MAYWRITE);
+ vm_flags_mod(vma, VM_DONTEXPAND, VM_MAYWRITE);
/*
* Mmap multiple separate allocations into a single vma. From
* here, dma_mmap_coherent() calls dma_direct_mmap(), which
[ ... ]
quoted hunk ↗ jump to hunk
@@ -559,12 +546,10 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)
}
vm_flags_reset(vma, flags);
- mmap_cdbg(ctxt, subctxt, type, mapio, vmf, memaddr, memvirt, memdma,
+ mmap_cdbg(ctxt, subctxt, type, mapio, is_vmalloc, memaddr, memvirt, memdma,
memlen, vma);
- if (vmf) {
- vma->vm_pgoff = PFN_DOWN(memaddr);
- vma->vm_ops = &vm_ops;
- ret = 0;
+ if (is_vmalloc) {
+ ret = remap_vmalloc_range(vma, memvirt, 0);
[Severity: Medium]
Will this trigger a lockdep warning due to the VMA not being write-locked?
In hfi1_file_mmap(), modifying the VMA flags using vm_flags_reset() (and
the newly introduced vm_flags_mod() earlier in this function) enforces
write-lock assertions via vma_assert_write_locked().
Because the VMA is not yet inserted into the tree and is not write-locked
during the mmap callback, its vm_lock_seq is uninitialized (UINT_MAX) and
will not match the mm lock sequence. This triggers a VM_WARN_ON_ONCE_VMA.
Should vm_flags_init() be used instead?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013-b4-mmap-prepare-vma-flag-sanify-v6-0-1aa3c9b139f9@kernel.org?part=11