]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
mm: make vm_area_desc utilise vma_flags_t only
authorLorenzo Stoakes <lorenzo.stoakes@oracle.com>
Thu, 22 Jan 2026 16:06:19 +0000 (16:06 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 12 Feb 2026 23:42:59 +0000 (15:42 -0800)
Now we have eliminated all uses of vm_area_desc->vm_flags, eliminate this
field, and have mmap_prepare users utilise the vma_flags_t
vm_area_desc->vma_flags field only.

As part of this change we alter is_shared_maywrite() to accept a
vma_flags_t parameter, and introduce is_shared_maywrite_vm_flags() for use
with legacy vm_flags_t flags.

We also update struct mmap_state to add a union between vma_flags and
vm_flags temporarily until the mmap logic is also converted to using
vma_flags_t.

Also update the VMA userland tests to reflect this change.

Link: https://lkml.kernel.org/r/fd2a2938b246b4505321954062b1caba7acfc77a.1769097829.git.lorenzo.stoakes@oracle.com
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
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>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/mm.h
include/linux/mm_types.h
mm/filemap.c
mm/util.c
mm/vma.c
mm/vma.h
tools/testing/vma/vma_internal.h

index 05d950805701d06c87a97e3d5b7b9b82935f6728..f8a8fd47399c4aa6b2d275540971bfcd6660cf00 100644 (file)
@@ -1290,15 +1290,20 @@ static inline bool vma_is_accessible(const struct vm_area_struct *vma)
        return vma->vm_flags & VM_ACCESS_FLAGS;
 }
 
-static inline bool is_shared_maywrite(vm_flags_t vm_flags)
+static inline bool is_shared_maywrite_vm_flags(vm_flags_t vm_flags)
 {
        return (vm_flags & (VM_SHARED | VM_MAYWRITE)) ==
                (VM_SHARED | VM_MAYWRITE);
 }
 
+static inline bool is_shared_maywrite(const vma_flags_t *flags)
+{
+       return vma_flags_test_all(flags, VMA_SHARED_BIT, VMA_MAYWRITE_BIT);
+}
+
 static inline bool vma_is_shared_maywrite(const struct vm_area_struct *vma)
 {
-       return is_shared_maywrite(vma->vm_flags);
+       return is_shared_maywrite(&vma->flags);
 }
 
 static inline
index 9b4311cfd5e85b29f3191583cd89a62fa0540b01..3cc8ae722886012594076f41a5a82581fe420956 100644 (file)
@@ -887,10 +887,7 @@ struct vm_area_desc {
        /* Mutable fields. Populated with initial state. */
        pgoff_t pgoff;
        struct file *vm_file;
-       union {
-               vm_flags_t vm_flags;
-               vma_flags_t vma_flags;
-       };
+       vma_flags_t vma_flags;
        pgprot_t page_prot;
 
        /* Write-only fields. */
index ebd75684cb0a7cf41efc486d0151bd9f3746e6c8..6cd7974d4adab22957c43aff4a10672d34675425 100644 (file)
@@ -4012,7 +4012,7 @@ int generic_file_readonly_mmap(struct file *file, struct vm_area_struct *vma)
 
 int generic_file_readonly_mmap_prepare(struct vm_area_desc *desc)
 {
-       if (is_shared_maywrite(desc->vm_flags))
+       if (is_shared_maywrite(&desc->vma_flags))
                return -EINVAL;
        return generic_file_mmap_prepare(desc);
 }
index 97cae40c0209e8c39370703467bc21917fd935d8..b05ab6f97e1108c39ea2c4b84e77f2f712a77439 100644 (file)
--- a/mm/util.c
+++ b/mm/util.c
@@ -1154,7 +1154,7 @@ int __compat_vma_mmap(const struct file_operations *f_op,
 
                .pgoff = vma->vm_pgoff,
                .vm_file = vma->vm_file,
-               .vm_flags = vma->vm_flags,
+               .vma_flags = vma->flags,
                .page_prot = vma->vm_page_prot,
 
                .action.type = MMAP_NOTHING, /* Default */
index 39dcd9ddd4bab3bfeb3105f568a1d228de00783d..be64f781a3aa748b5424598462cce99889b2492e 100644 (file)
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -15,7 +15,10 @@ struct mmap_state {
        unsigned long end;
        pgoff_t pgoff;
        unsigned long pglen;
-       vm_flags_t vm_flags;
+       union {
+               vm_flags_t vm_flags;
+               vma_flags_t vma_flags;
+       };
        struct file *file;
        pgprot_t page_prot;
 
@@ -2369,7 +2372,7 @@ static void set_desc_from_map(struct vm_area_desc *desc,
 
        desc->pgoff = map->pgoff;
        desc->vm_file = map->file;
-       desc->vm_flags = map->vm_flags;
+       desc->vma_flags = map->vma_flags;
        desc->page_prot = map->page_prot;
 }
 
@@ -2650,7 +2653,7 @@ static int call_mmap_prepare(struct mmap_state *map,
                map->file_doesnt_need_get = true;
                map->file = desc->vm_file;
        }
-       map->vm_flags = desc->vm_flags;
+       map->vma_flags = desc->vma_flags;
        map->page_prot = desc->page_prot;
        /* User-defined fields. */
        map->vm_ops = desc->vm_ops;
@@ -2823,7 +2826,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
                return -EINVAL;
 
        /* Map writable and ensure this isn't a sealed memfd. */
-       if (file && is_shared_maywrite(vm_flags)) {
+       if (file && is_shared_maywrite_vm_flags(vm_flags)) {
                int error = mapping_map_writable(file->f_mapping);
 
                if (error)
index de30c69bceaf7262d6832051c2b356ba0f14101d..eba388c61ef422a121367750b691860f1a44102c 100644 (file)
--- a/mm/vma.h
+++ b/mm/vma.h
@@ -309,8 +309,7 @@ static inline void set_vma_from_desc(struct vm_area_struct *vma,
        vma->vm_pgoff = desc->pgoff;
        if (desc->vm_file != vma->vm_file)
                vma_set_file(vma, desc->vm_file);
-       if (desc->vm_flags != vma->vm_flags)
-               vm_flags_set(vma, desc->vm_flags);
+       vma->flags = desc->vma_flags;
        vma->vm_page_prot = desc->page_prot;
 
        /* User-defined fields. */
index 2b01794cbd6122632542b46021915e5b4266507e..2743f12ecf328955c32a6145b93412338a2d8cf0 100644 (file)
@@ -1009,15 +1009,20 @@ static inline void vma_desc_clear_flags_mask(struct vm_area_desc *desc,
 #define vma_desc_clear_flags(desc, ...) \
        vma_desc_clear_flags_mask(desc, mk_vma_flags(__VA_ARGS__))
 
-static inline bool is_shared_maywrite(vm_flags_t vm_flags)
+static inline bool is_shared_maywrite_vm_flags(vm_flags_t vm_flags)
 {
        return (vm_flags & (VM_SHARED | VM_MAYWRITE)) ==
                (VM_SHARED | VM_MAYWRITE);
 }
 
+static inline bool is_shared_maywrite(const vma_flags_t *flags)
+{
+       return vma_flags_test_all(flags, VMA_SHARED_BIT, VMA_MAYWRITE_BIT);
+}
+
 static inline bool vma_is_shared_maywrite(struct vm_area_struct *vma)
 {
-       return is_shared_maywrite(vma->vm_flags);
+       return is_shared_maywrite(&vma->flags);
 }
 
 static inline struct vm_area_struct *vma_next(struct vma_iterator *vmi)