Determine if the VMA is anonymous early on, so we separate the logic which
invokes callbacks from the rest of the logic.

This is in order that a subsequent commit which asserts correct virtual
page offset for anonymous mappings correctly asserts this for new anonymous
mappings.

No functional change intended.

Signed-off-by: Lorenzo Stoakes <[email protected]>
---
 mm/vma.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/mm/vma.c b/mm/vma.c
index 0699fa07c40f..ec64e179d2f9 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -2587,6 +2587,8 @@ static int __mmap_new_file_vma(struct mmap_state *map,
 static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap,
        struct mmap_action *action)
 {
+       const bool is_anon = !map->file &&
+               !vma_flags_test(&map->vma_flags, VMA_SHARED_BIT);
        struct vma_iterator *vmi = map->vmi;
        int error = 0;
        struct vm_area_struct *vma;
@@ -2601,6 +2603,10 @@ static int __mmap_new_vma(struct mmap_state *map, struct 
vm_area_struct **vmap,
                return -ENOMEM;
 
        vma_iter_config(vmi, map->addr, map->end);
+
+       if (is_anon)
+               vma_set_anonymous(vma);
+
        vma_set_range(vma, map->addr, map->end, map->pgoff);
        vma->flags = map->vma_flags;
        vma->vm_page_prot = map->page_prot;
@@ -2610,12 +2616,11 @@ static int __mmap_new_vma(struct mmap_state *map, 
struct vm_area_struct **vmap,
                goto free_vma;
        }
 
+       /* Invoke callbacks. */
        if (map->file)
                error = __mmap_new_file_vma(map, vma);
-       else if (vma_flags_test(&map->vma_flags, VMA_SHARED_BIT))
+       else if (!is_anon)
                error = shmem_zero_setup(vma);
-       else
-               vma_set_anonymous(vma);
 
        if (error)
                goto free_iter_vma;

-- 
2.55.0

Reply via email to