Skip to content

Commit 53f1d93

Browse files
ljskernelakpm00
authored andcommitted
mm: make vm_area_desc utilise vma_flags_t only
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>
1 parent 5bd2c06 commit 53f1d93

7 files changed

Lines changed: 25 additions & 16 deletions

File tree

include/linux/mm.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,15 +1290,20 @@ static inline bool vma_is_accessible(const struct vm_area_struct *vma)
12901290
return vma->vm_flags & VM_ACCESS_FLAGS;
12911291
}
12921292

1293-
static inline bool is_shared_maywrite(vm_flags_t vm_flags)
1293+
static inline bool is_shared_maywrite_vm_flags(vm_flags_t vm_flags)
12941294
{
12951295
return (vm_flags & (VM_SHARED | VM_MAYWRITE)) ==
12961296
(VM_SHARED | VM_MAYWRITE);
12971297
}
12981298

1299+
static inline bool is_shared_maywrite(const vma_flags_t *flags)
1300+
{
1301+
return vma_flags_test_all(flags, VMA_SHARED_BIT, VMA_MAYWRITE_BIT);
1302+
}
1303+
12991304
static inline bool vma_is_shared_maywrite(const struct vm_area_struct *vma)
13001305
{
1301-
return is_shared_maywrite(vma->vm_flags);
1306+
return is_shared_maywrite(&vma->flags);
13021307
}
13031308

13041309
static inline

include/linux/mm_types.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -887,10 +887,7 @@ struct vm_area_desc {
887887
/* Mutable fields. Populated with initial state. */
888888
pgoff_t pgoff;
889889
struct file *vm_file;
890-
union {
891-
vm_flags_t vm_flags;
892-
vma_flags_t vma_flags;
893-
};
890+
vma_flags_t vma_flags;
894891
pgprot_t page_prot;
895892

896893
/* Write-only fields. */

mm/filemap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4012,7 +4012,7 @@ int generic_file_readonly_mmap(struct file *file, struct vm_area_struct *vma)
40124012

40134013
int generic_file_readonly_mmap_prepare(struct vm_area_desc *desc)
40144014
{
4015-
if (is_shared_maywrite(desc->vm_flags))
4015+
if (is_shared_maywrite(&desc->vma_flags))
40164016
return -EINVAL;
40174017
return generic_file_mmap_prepare(desc);
40184018
}

mm/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ int __compat_vma_mmap(const struct file_operations *f_op,
11541154

11551155
.pgoff = vma->vm_pgoff,
11561156
.vm_file = vma->vm_file,
1157-
.vm_flags = vma->vm_flags,
1157+
.vma_flags = vma->flags,
11581158
.page_prot = vma->vm_page_prot,
11591159

11601160
.action.type = MMAP_NOTHING, /* Default */

mm/vma.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ struct mmap_state {
1515
unsigned long end;
1616
pgoff_t pgoff;
1717
unsigned long pglen;
18-
vm_flags_t vm_flags;
18+
union {
19+
vm_flags_t vm_flags;
20+
vma_flags_t vma_flags;
21+
};
1922
struct file *file;
2023
pgprot_t page_prot;
2124

@@ -2369,7 +2372,7 @@ static void set_desc_from_map(struct vm_area_desc *desc,
23692372

23702373
desc->pgoff = map->pgoff;
23712374
desc->vm_file = map->file;
2372-
desc->vm_flags = map->vm_flags;
2375+
desc->vma_flags = map->vma_flags;
23732376
desc->page_prot = map->page_prot;
23742377
}
23752378

@@ -2650,7 +2653,7 @@ static int call_mmap_prepare(struct mmap_state *map,
26502653
map->file_doesnt_need_get = true;
26512654
map->file = desc->vm_file;
26522655
}
2653-
map->vm_flags = desc->vm_flags;
2656+
map->vma_flags = desc->vma_flags;
26542657
map->page_prot = desc->page_prot;
26552658
/* User-defined fields. */
26562659
map->vm_ops = desc->vm_ops;
@@ -2823,7 +2826,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
28232826
return -EINVAL;
28242827

28252828
/* Map writable and ensure this isn't a sealed memfd. */
2826-
if (file && is_shared_maywrite(vm_flags)) {
2829+
if (file && is_shared_maywrite_vm_flags(vm_flags)) {
28272830
int error = mapping_map_writable(file->f_mapping);
28282831

28292832
if (error)

mm/vma.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ static inline void set_vma_from_desc(struct vm_area_struct *vma,
309309
vma->vm_pgoff = desc->pgoff;
310310
if (desc->vm_file != vma->vm_file)
311311
vma_set_file(vma, desc->vm_file);
312-
if (desc->vm_flags != vma->vm_flags)
313-
vm_flags_set(vma, desc->vm_flags);
312+
vma->flags = desc->vma_flags;
314313
vma->vm_page_prot = desc->page_prot;
315314

316315
/* User-defined fields. */

tools/testing/vma/vma_internal.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,15 +1009,20 @@ static inline void vma_desc_clear_flags_mask(struct vm_area_desc *desc,
10091009
#define vma_desc_clear_flags(desc, ...) \
10101010
vma_desc_clear_flags_mask(desc, mk_vma_flags(__VA_ARGS__))
10111011

1012-
static inline bool is_shared_maywrite(vm_flags_t vm_flags)
1012+
static inline bool is_shared_maywrite_vm_flags(vm_flags_t vm_flags)
10131013
{
10141014
return (vm_flags & (VM_SHARED | VM_MAYWRITE)) ==
10151015
(VM_SHARED | VM_MAYWRITE);
10161016
}
10171017

1018+
static inline bool is_shared_maywrite(const vma_flags_t *flags)
1019+
{
1020+
return vma_flags_test_all(flags, VMA_SHARED_BIT, VMA_MAYWRITE_BIT);
1021+
}
1022+
10181023
static inline bool vma_is_shared_maywrite(struct vm_area_struct *vma)
10191024
{
1020-
return is_shared_maywrite(vma->vm_flags);
1025+
return is_shared_maywrite(&vma->flags);
10211026
}
10221027

10231028
static inline struct vm_area_struct *vma_next(struct vma_iterator *vmi)

0 commit comments

Comments
 (0)