[PATCH v6 33/39] mm/madvise: use predicates for madvise(..., MADV_DOFORK)

Lorenzo Stoakes (ARM) ljs at kernel.org
Tue Oct 13 08:05:13 PDT 2026


Make it clear what we're blocking in MADV_DOFORK. Previously we simply
disallowed VM_SPECIAL i.e. mappings not managed by core mm, fixed mappings
and VMA_IO_BIT.

Now the invariant is established that mm-managed mappings may not set
VMA_IO_BIT, the VMA_IO_BIT check is redundant.

The rest is equivalent to testing for a fixed or non-mm-managed mapping,
i.e. a mapping which is not mm-backed, or hugetlb, which is specifically
excluded.

This was established by commit 0b2758f48f22 ("Require (reasonably) normal
mappings for MADV_DOFORK") containing my hands-down favourite call out of
all time.

Express the same thing using the predicates - only mm-backed mappings may
have their copy-on-fork behaviour changed, retaining the eternal exception
to all rules, hugetlb.

No functional change intended.

Acked-by: Zi Yan <ziy at nvidia.com>
Acked-by: David Hildenbrand (Arm) <david at kernel.org>
Signed-off-by: Lorenzo Stoakes (ARM) <ljs at kernel.org>
---
 mm/madvise.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/madvise.c b/mm/madvise.c
index 7e14b3fd92f6..e050a21e4db1 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -1565,7 +1565,7 @@ static int madvise_vma_behavior(struct madvise_behavior *madv_behavior)
 		new_flags |= VM_DONTCOPY;
 		break;
 	case MADV_DOFORK:
-		if (new_flags & VM_SPECIAL)
+		if (!vma_is_mm_backed(vma) || vma_is_hugetlb(vma))
 			return -EINVAL;
 		new_flags &= ~VM_DONTCOPY;
 		break;

-- 
2.55.0




More information about the kvm-riscv mailing list