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

Configure Feed

Select the types of activity you want to include in your feed.

mm: update secretmem to use VMA flags on mmap_prepare

This patch updates secretmem to use the new vma_flags_t type which will
soon supersede vm_flags_t altogether.

In order to make this change we also have to update mlock_future_ok(), we
replace the vm_flags_t parameter with a simple boolean is_vma_locked one,
which also simplifies the invocation here.

This is laying the groundwork for eliminating the vm_flags_t in
vm_area_desc and more broadly throughout the kernel.

No functional changes intended.

[lorenzo.stoakes@oracle.com: fix check_brk_limits(), per Chris]
Link: https://lkml.kernel.org/r/3aab9ab1-74b4-405e-9efb-08fc2500c06e@lucifer.local
Link: https://lkml.kernel.org/r/a243a09b0a5d0581e963d696de1735f61f5b2075.1769097829.git.lorenzo.stoakes@oracle.com
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Damien Le Moal <dlemoal@kernel.org>
Cc: "Darrick J. Wong" <djwong@kernel.org>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Cc: Yury Norov <ynorov@nvidia.com>
Cc: Chris Mason <clm@fb.com>
Cc: Pedro Falcato <pfalcato@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes and committed by
Andrew Morton
fd3196ee 097e8db5

+12 -12
+1 -1
mm/internal.h
··· 1046 1046 unsigned long start, unsigned long end, int *locked); 1047 1047 extern long faultin_page_range(struct mm_struct *mm, unsigned long start, 1048 1048 unsigned long end, bool write, int *locked); 1049 - bool mlock_future_ok(const struct mm_struct *mm, vm_flags_t vm_flags, 1049 + bool mlock_future_ok(const struct mm_struct *mm, bool is_vma_locked, 1050 1050 unsigned long bytes); 1051 1051 1052 1052 /*
+6 -5
mm/mmap.c
··· 108 108 if (IS_ERR_VALUE(mapped_addr)) 109 109 return mapped_addr; 110 110 111 - return mlock_future_ok(current->mm, current->mm->def_flags, len) 111 + return mlock_future_ok(current->mm, 112 + current->mm->def_flags & VM_LOCKED, len) 112 113 ? 0 : -EAGAIN; 113 114 } 114 115 ··· 226 225 return hint; 227 226 } 228 227 229 - bool mlock_future_ok(const struct mm_struct *mm, vm_flags_t vm_flags, 230 - unsigned long bytes) 228 + bool mlock_future_ok(const struct mm_struct *mm, bool is_vma_locked, 229 + unsigned long bytes) 231 230 { 232 231 unsigned long locked_pages, limit_pages; 233 232 234 - if (!(vm_flags & VM_LOCKED) || capable(CAP_IPC_LOCK)) 233 + if (!is_vma_locked || capable(CAP_IPC_LOCK)) 235 234 return true; 236 235 237 236 locked_pages = bytes >> PAGE_SHIFT; ··· 417 416 if (!can_do_mlock()) 418 417 return -EPERM; 419 418 420 - if (!mlock_future_ok(mm, vm_flags, len)) 419 + if (!mlock_future_ok(mm, vm_flags & VM_LOCKED, len)) 421 420 return -EAGAIN; 422 421 423 422 if (file) {
+1 -1
mm/mremap.c
··· 1740 1740 if (vma->vm_flags & (VM_DONTEXPAND | VM_PFNMAP)) 1741 1741 return -EFAULT; 1742 1742 1743 - if (!mlock_future_ok(mm, vma->vm_flags, vrm->delta)) 1743 + if (!mlock_future_ok(mm, vma->vm_flags & VM_LOCKED, vrm->delta)) 1744 1744 return -EAGAIN; 1745 1745 1746 1746 if (!may_expand_vm(mm, vma->vm_flags, vrm->delta >> PAGE_SHIFT))
+3 -4
mm/secretmem.c
··· 122 122 { 123 123 const unsigned long len = vma_desc_size(desc); 124 124 125 - if ((desc->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0) 125 + if (!vma_desc_test_flags(desc, VMA_SHARED_BIT, VMA_MAYSHARE_BIT)) 126 126 return -EINVAL; 127 127 128 - if (!mlock_future_ok(desc->mm, desc->vm_flags | VM_LOCKED, len)) 128 + vma_desc_set_flags(desc, VMA_LOCKED_BIT, VMA_DONTDUMP_BIT); 129 + if (!mlock_future_ok(desc->mm, /*is_vma_locked=*/ true, len)) 129 130 return -EAGAIN; 130 - 131 - desc->vm_flags |= VM_LOCKED | VM_DONTDUMP; 132 131 desc->vm_ops = &secretmem_vm_ops; 133 132 134 133 return 0;
+1 -1
mm/vma.c
··· 3053 3053 return -ENOMEM; 3054 3054 3055 3055 /* mlock limit tests */ 3056 - if (!mlock_future_ok(mm, vma->vm_flags, grow << PAGE_SHIFT)) 3056 + if (!mlock_future_ok(mm, vma->vm_flags & VM_LOCKED, grow << PAGE_SHIFT)) 3057 3057 return -ENOMEM; 3058 3058 3059 3059 /* Check to ensure the stack will not grow into a hugetlb-only region */