Skip to content

Commit fd3196e

Browse files
ljskernelakpm00
authored andcommitted
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>
1 parent 097e8db commit fd3196e

5 files changed

Lines changed: 12 additions & 12 deletions

File tree

mm/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ extern long populate_vma_page_range(struct vm_area_struct *vma,
10461046
unsigned long start, unsigned long end, int *locked);
10471047
extern long faultin_page_range(struct mm_struct *mm, unsigned long start,
10481048
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,
10501050
unsigned long bytes);
10511051

10521052
/*

mm/mmap.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ static int check_brk_limits(unsigned long addr, unsigned long len)
108108
if (IS_ERR_VALUE(mapped_addr))
109109
return mapped_addr;
110110

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)
112113
? 0 : -EAGAIN;
113114
}
114115

@@ -225,12 +226,12 @@ static inline unsigned long round_hint_to_min(unsigned long hint)
225226
return hint;
226227
}
227228

228-
bool mlock_future_ok(const struct mm_struct *mm, vm_flags_t vm_flags,
229-
unsigned long bytes)
229+
bool mlock_future_ok(const struct mm_struct *mm, bool is_vma_locked,
230+
unsigned long bytes)
230231
{
231232
unsigned long locked_pages, limit_pages;
232233

233-
if (!(vm_flags & VM_LOCKED) || capable(CAP_IPC_LOCK))
234+
if (!is_vma_locked || capable(CAP_IPC_LOCK))
234235
return true;
235236

236237
locked_pages = bytes >> PAGE_SHIFT;
@@ -416,7 +417,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
416417
if (!can_do_mlock())
417418
return -EPERM;
418419

419-
if (!mlock_future_ok(mm, vm_flags, len))
420+
if (!mlock_future_ok(mm, vm_flags & VM_LOCKED, len))
420421
return -EAGAIN;
421422

422423
if (file) {

mm/mremap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ static int check_prep_vma(struct vma_remap_struct *vrm)
17401740
if (vma->vm_flags & (VM_DONTEXPAND | VM_PFNMAP))
17411741
return -EFAULT;
17421742

1743-
if (!mlock_future_ok(mm, vma->vm_flags, vrm->delta))
1743+
if (!mlock_future_ok(mm, vma->vm_flags & VM_LOCKED, vrm->delta))
17441744
return -EAGAIN;
17451745

17461746
if (!may_expand_vm(mm, vma->vm_flags, vrm->delta >> PAGE_SHIFT))

mm/secretmem.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,12 @@ static int secretmem_mmap_prepare(struct vm_area_desc *desc)
122122
{
123123
const unsigned long len = vma_desc_size(desc);
124124

125-
if ((desc->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0)
125+
if (!vma_desc_test_flags(desc, VMA_SHARED_BIT, VMA_MAYSHARE_BIT))
126126
return -EINVAL;
127127

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))
129130
return -EAGAIN;
130-
131-
desc->vm_flags |= VM_LOCKED | VM_DONTDUMP;
132131
desc->vm_ops = &secretmem_vm_ops;
133132

134133
return 0;

mm/vma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3053,7 +3053,7 @@ static int acct_stack_growth(struct vm_area_struct *vma,
30533053
return -ENOMEM;
30543054

30553055
/* 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))
30573057
return -ENOMEM;
30583058

30593059
/* Check to ensure the stack will not grow into a hugetlb-only region */

0 commit comments

Comments
 (0)