[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJuCfpFfoPHgUcu_-S4wXVxGpEGgTH_mLpgVO5UhtDG5+L3b2A@mail.gmail.com>
Date: Tue, 13 May 2025 08:32:11 -0700
From: Suren Baghdasaryan <surenb@...gle.com>
To: "Liam R. Howlett" <Liam.Howlett@...cle.com>, Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
Andrew Morton <akpm@...ux-foundation.org>, David Hildenbrand <david@...hat.com>,
Vlastimil Babka <vbabka@...e.cz>, Mike Rapoport <rppt@...nel.org>, Suren Baghdasaryan <surenb@...gle.com>,
Michal Hocko <mhocko@...e.com>, Jann Horn <jannh@...gle.com>, Pedro Falcato <pfalcato@...e.de>,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-mm@...ck.org, Alexander Viro <viro@...iv.linux.org.uk>,
Christian Brauner <brauner@...nel.org>, Jan Kara <jack@...e.cz>, Matthew Wilcox <willy@...radead.org>
Subject: Re: [PATCH v2 2/3] mm: secretmem: convert to .mmap_prepare() hook
On Tue, May 13, 2025 at 6:23 AM Liam R. Howlett <Liam.Howlett@...cle.com> wrote:
>
> * Lorenzo Stoakes <lorenzo.stoakes@...cle.com> [250509 08:14]:
> > 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.
> >
> > Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
> > Acked-by: Mike Rapoport (Microsoft) <rppt@...nel.org>
> > Reviewed-by: David Hildenbrand <david@...hat.com>
>
> Reviewed-by: Liam R. Howlett <Liam.Howlett@...cle.com>
Reviewed-by: Suren Baghdasaryan <surenb@...gle.com>
>
> > ---
> > mm/secretmem.c | 14 +++++++-------
> > 1 file changed, 7 insertions(+), 7 deletions(-)
> >
> > diff --git a/mm/secretmem.c b/mm/secretmem.c
> > index 1b0a214ee558..589b26c2d553 100644
> > --- a/mm/secretmem.c
> > +++ b/mm/secretmem.c
> > @@ -120,18 +120,18 @@ static int secretmem_release(struct inode *inode, struct file *file)
> > return 0;
> > }
> >
> > -static int secretmem_mmap(struct file *file, struct vm_area_struct *vma)
> > +static int secretmem_mmap_prepare(struct vm_area_desc *desc)
> > {
> > - unsigned long len = vma->vm_end - vma->vm_start;
> > + const unsigned long len = desc->end - desc->start;
> >
> > - if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0)
> > + if ((desc->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0)
> > return -EINVAL;
> >
> > - if (!mlock_future_ok(vma->vm_mm, vma->vm_flags | VM_LOCKED, len))
> > + if (!mlock_future_ok(desc->mm, desc->vm_flags | VM_LOCKED, len))
> > return -EAGAIN;
> >
> > - vm_flags_set(vma, VM_LOCKED | VM_DONTDUMP);
> > - vma->vm_ops = &secretmem_vm_ops;
> > + desc->vm_flags |= VM_LOCKED | VM_DONTDUMP;
> > + desc->vm_ops = &secretmem_vm_ops;
> >
> > return 0;
> > }
> > @@ -143,7 +143,7 @@ bool vma_is_secretmem(struct vm_area_struct *vma)
> >
> > static const struct file_operations secretmem_fops = {
> > .release = secretmem_release,
> > - .mmap = secretmem_mmap,
> > + .mmap_prepare = secretmem_mmap_prepare,
> > };
> >
> > static int secretmem_migrate_folio(struct address_space *mapping,
> > --
> > 2.49.0
> >
Powered by blists - more mailing lists