--- a/mm/mremap.c~mm-extend-mremap_dontunmap-to-non-anonymous-mappings +++ a/mm/mremap.c @@ -653,8 +653,8 @@ static struct vm_area_struct *vma_to_res return ERR_PTR(-EINVAL); } - if (flags & MREMAP_DONTUNMAP && (!vma_is_anonymous(vma) || - vma->vm_flags & VM_SHARED)) + if ((flags & MREMAP_DONTUNMAP) && + (vma->vm_flags & (VM_DONTEXPAND | VM_PFNMAP))) return ERR_PTR(-EINVAL); if (is_vm_hugetlb_page(vma))