On Wed, Oct 29, 2025 at 04:50:32PM +0000, Lorenzo Stoakes wrote:
It's useful to be able to force a VMA to be copied on fork outside of the parameters specified by vma_needs_copy(), which otherwise only copies page tables if:
- The destination VMA has VM_UFFD_WP set
- The mapping is a PFN or mixed map
- The mapping is anonymous and forked in (i.e. vma->anon_vma is non-NULL)
Setting this flag implies that the page tables mapping the VMA are such that simply re-faulting the VMA will not re-establish them in identical form.
We introduce VM_COPY_ON_FORK to clearly identify which flags require this behaviour, which currently is only VM_MAYBE_GUARD.
Do we want this to be sticky though? If you're looking for more granularity with this flag, the best option might be to stop merges from happening there. If not, I can imagine a VMA that merges with other VMAs far past the original guarded range, and thus you get no granularity (possibly, not even useful).
If you're _not_ looking for granularity, then maybe using a per-mm flag for guard ranges or some other solution would be superior?
The rest of the patch (superficially) looks good to me, though.