mm/mremap: do not set vrm->vma NULL immediately prior to checking it
authorLorenzo Stoakes <lorenzo.stoakes@oracle.com>
Sun, 30 Mar 2025 16:20:48 +0000 (17:20 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 1 Apr 2025 22:17:09 +0000 (15:17 -0700)
This seems rather unwise.  If we cannot merge, extend, then we need to
recall the original VMA to see if we need to uncharge.

If we do need to, do so.

Link: https://lkml.kernel.org/r/b2fb6b9c-376d-4e9b-905e-26d847fd3865@lucifer.local
Fixes: d5c8aec0542e ("mm/mremap: initial refactor of move_vma()")
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reported-=by: "Lai, Yi" <yi1.lai@linux.intel.com>
Closes: https://lore.kernel.org/linux-mm/Z+lcvEIHMLiKVR1i@ly-workstation/
Cc: Liam R. Howlett <Liam.Howlett@Oracle.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Harry Yoo <harry.yoo@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/mremap.c

index 0865387..7db9da6 100644 (file)
@@ -1561,11 +1561,12 @@ static unsigned long expand_vma_in_place(struct vma_remap_struct *vrm)
         * adjacent to the expanded vma and otherwise
         * compatible.
         */
-       vma = vrm->vma = vma_merge_extend(&vmi, vma, vrm->delta);
+       vma = vma_merge_extend(&vmi, vma, vrm->delta);
        if (!vma) {
                vrm_uncharge(vrm);
                return -ENOMEM;
        }
+       vrm->vma = vma;
 
        vrm_stat_account(vrm, vrm->delta);