Skip to content

Commit 439b3fb

Browse files
lorenzo-stoakesakpm00
authored andcommitted
mm: secretmem: convert to .mmap_prepare() hook
Secretmem has a simple .mmap() hook which is easily converted to the new .mmap_prepare() callback. Importantly, it's a rare instance of an driver that manipulates a VMA which is mergeable (that is, not a VM_SPECIAL mapping) while also adjusting VMA flags which may adjust mergeability, meaning the retry merge logic might impact whether or not the VMA is merged. By using .mmap_prepare() there's no longer any need to retry the merge later as we can simply set the correct flags from the start. This change therefore allows us to remove the retry merge logic in a subsequent commit. Link: https://lkml.kernel.org/r/0f758474fa6a30197bdf25ba62f898a69d84eef3.1746792520.git.lorenzo.stoakes@oracle.com Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Reviewed-by: David Hildenbrand <david@redhat.com> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Christian Brauner <brauner@kernel.org> Cc: Jan Kara <jack@suse.cz> Cc: Jann Horn <jannh@google.com> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Suren Baghdasaryan <surenb@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent c84bf6d commit 439b3fb

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

mm/secretmem.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,18 @@ static int secretmem_release(struct inode *inode, struct file *file)
120120
return 0;
121121
}
122122

123-
static int secretmem_mmap(struct file *file, struct vm_area_struct *vma)
123+
static int secretmem_mmap_prepare(struct vm_area_desc *desc)
124124
{
125-
unsigned long len = vma->vm_end - vma->vm_start;
125+
const unsigned long len = desc->end - desc->start;
126126

127-
if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0)
127+
if ((desc->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0)
128128
return -EINVAL;
129129

130-
if (!mlock_future_ok(vma->vm_mm, vma->vm_flags | VM_LOCKED, len))
130+
if (!mlock_future_ok(desc->mm, desc->vm_flags | VM_LOCKED, len))
131131
return -EAGAIN;
132132

133-
vm_flags_set(vma, VM_LOCKED | VM_DONTDUMP);
134-
vma->vm_ops = &secretmem_vm_ops;
133+
desc->vm_flags |= VM_LOCKED | VM_DONTDUMP;
134+
desc->vm_ops = &secretmem_vm_ops;
135135

136136
return 0;
137137
}
@@ -143,7 +143,7 @@ bool vma_is_secretmem(struct vm_area_struct *vma)
143143

144144
static const struct file_operations secretmem_fops = {
145145
.release = secretmem_release,
146-
.mmap = secretmem_mmap,
146+
.mmap_prepare = secretmem_mmap_prepare,
147147
};
148148

149149
static int secretmem_migrate_folio(struct address_space *mapping,

0 commit comments

Comments
 (0)