Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Revert "mremap: don't allow MREMAP_DONTUNMAP on special_mappings and aio"

This reverts commit cd544fd1dc9293c6702fab6effa63dac1cc67e99.

As discussed in [1] this commit was a no-op because the mapping type was
checked in vma_to_resize before move_vma is ever called. This meant that
vm_ops->mremap() would never be called on such mappings. Furthermore,
we've since expanded support of MREMAP_DONTUNMAP to non-anonymous
mappings, and these special mappings are still protected by the existing
check of !VM_DONTEXPAND and !VM_PFNMAP which will result in a -EINVAL.

1. https://lkml.org/lkml/2020/12/28/2340

Link: https://lkml.kernel.org/r/20210323182520.2712101-2-bgeffon@google.com
Signed-off-by: Brian Geffon <bgeffon@google.com>
Acked-by: Hugh Dickins <hughd@google.com>
Reviewed-by: Dmitry Safonov <0x7f454c46@gmail.com>
Cc: Alejandro Colomar <alx.manpages@gmail.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: "Kirill A . Shutemov" <kirill@shutemov.name>
Cc: Lokesh Gidra <lokeshgidra@google.com>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>
Cc: "Michael S . Tsirkin" <mst@redhat.com>
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: Sonny Rao <sonnyrao@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Brian Geffon and committed by
Linus Torvalds
14d07113 a4609387

+5 -12
+1 -1
arch/x86/kernel/cpu/resctrl/pseudo_lock.c
··· 1458 1458 return 0; 1459 1459 } 1460 1460 1461 - static int pseudo_lock_dev_mremap(struct vm_area_struct *area, unsigned long flags) 1461 + static int pseudo_lock_dev_mremap(struct vm_area_struct *area) 1462 1462 { 1463 1463 /* Not supported */ 1464 1464 return -EINVAL;
+1 -4
fs/aio.c
··· 323 323 } 324 324 } 325 325 326 - static int aio_ring_mremap(struct vm_area_struct *vma, unsigned long flags) 326 + static int aio_ring_mremap(struct vm_area_struct *vma) 327 327 { 328 328 struct file *file = vma->vm_file; 329 329 struct mm_struct *mm = vma->vm_mm; 330 330 struct kioctx_table *table; 331 331 int i, res = -EINVAL; 332 - 333 - if (flags & MREMAP_DONTUNMAP) 334 - return -EINVAL; 335 332 336 333 spin_lock(&mm->ioctx_lock); 337 334 rcu_read_lock();
+1 -1
include/linux/mm.h
··· 580 580 void (*close)(struct vm_area_struct * area); 581 581 /* Called any time before splitting to check if it's allowed */ 582 582 int (*may_split)(struct vm_area_struct *area, unsigned long addr); 583 - int (*mremap)(struct vm_area_struct *area, unsigned long flags); 583 + int (*mremap)(struct vm_area_struct *area); 584 584 /* 585 585 * Called by mprotect() to make driver-specific permission 586 586 * checks before mprotect() is finalised. The VMA must not
+1 -5
mm/mmap.c
··· 3409 3409 return ((struct vm_special_mapping *)vma->vm_private_data)->name; 3410 3410 } 3411 3411 3412 - static int special_mapping_mremap(struct vm_area_struct *new_vma, 3413 - unsigned long flags) 3412 + static int special_mapping_mremap(struct vm_area_struct *new_vma) 3414 3413 { 3415 3414 struct vm_special_mapping *sm = new_vma->vm_private_data; 3416 - 3417 - if (flags & MREMAP_DONTUNMAP) 3418 - return -EINVAL; 3419 3415 3420 3416 if (WARN_ON_ONCE(current->mm != new_vma->vm_mm)) 3421 3417 return -EFAULT;
+1 -1
mm/mremap.c
··· 545 545 if (moved_len < old_len) { 546 546 err = -ENOMEM; 547 547 } else if (vma->vm_ops && vma->vm_ops->mremap) { 548 - err = vma->vm_ops->mremap(new_vma, flags); 548 + err = vma->vm_ops->mremap(new_vma); 549 549 } 550 550 551 551 if (unlikely(err)) {