Re: [RFC 19/26] plugins/amdgpu: Use save_vma_updates for all call sites

"Francis, David" <[email protected]> Mon, 2 Mar 2026 14:54:09 +0000
Newsgroups dev.linux.lists.criu
Message-ID <SA1PR12MB81441E36D92E0AA52EC901F1EF7EA@SA1PR12MB8144.namprd12.prod.outlook.com>
Looks good to me

This patch is
Reviewed-By: David Francis <[email protected]>

________________________________________
From: Tvrtko Ursulin <[email protected]>
Sent: Friday, February 20, 2026 7:05 AM
To: [email protected]
Cc: Francis, David; Tvrtko Ursulin
Subject: [RFC 19/26] plugins/amdgpu: Use save_vma_updates for all call sites

Consolidate KFD and DRM VMA handling path to the same (existing) helper.

Signed-off-by: Tvrtko Ursulin <[email protected]>
---
 plugins/amdgpu/amdgpu_plugin.c     | 46 ++++++++++++------------------
 plugins/amdgpu/amdgpu_plugin_drm.c |  3 +-
 plugins/amdgpu/amdgpu_plugin_drm.h |  3 +-
 3 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/plugins/amdgpu/amdgpu_plugin.c b/plugins/amdgpu/amdgpu_plugin.c
index dc808fe32373..5ab3420c1371 100644
--- a/plugins/amdgpu/amdgpu_plugin.c
+++ b/plugins/amdgpu/amdgpu_plugin.c
@@ -1669,7 +1669,8 @@ static int restore_bos(struct kfd_ioctl_criu_args *args, CriuKfd *e)
        return 0;
 }

-int save_vma_updates(uint64_t offset, uint64_t addr, uint64_t restored_offset, int fd)
+int save_vma_updates(uint64_t offset, uint64_t addr, uint64_t restored_offset,
+                    int fd)
 {
        struct vma_metadata *vma_md;

@@ -1678,14 +1679,15 @@ int save_vma_updates(uint64_t offset, uint64_t addr, uint64_t restored_offset, i
                return -ENOMEM;
        }

-       memset(vma_md, 0, sizeof(*vma_md));
-
        vma_md->old_pgoff = offset;
        vma_md->vma_entry = addr;
-
        vma_md->new_pgoff = restored_offset;
        vma_md->fd = fd;

+       pr_debug("adding vma_entry:addr:%"  PRIx64 " old-off:%" PRIx64 " new_off:%" PRIx64 " fd:%d\n",
+                vma_md->vma_entry, vma_md->old_pgoff, vma_md->new_pgoff,
+                vma_md->fd);
+
        list_add_tail(&vma_md->list, &update_vma_info_list);

        return 0;
@@ -1703,37 +1705,25 @@ static int restore_bo_data(int id, struct kfd_criu_bo_bucket *bo_buckets, CriuKf

                if (bo_bucket->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM | KFD_IOC_ALLOC_MEM_FLAGS_GTT |
                                              KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP | KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL)) {
-                       struct vma_metadata *vma_md;
                        uint32_t target_gpu_id; /* actual gpu_id where the BO will be restored */

-                       vma_md = xmalloc(sizeof(*vma_md));
-                       if (!vma_md) {
-                               ret = -ENOMEM;
-                               goto exit;
-                       }
-
-                       memset(vma_md, 0, sizeof(*vma_md));
-
-                       vma_md->old_pgoff = bo_bucket->offset;
-                       vma_md->vma_entry = bo_bucket->addr;
-
-                       target_gpu_id = maps_get_dest_gpu(&restore_maps, bo_bucket->gpu_id);
-
-                       tp_node = sys_get_node_by_gpu_id(&dest_topology, target_gpu_id);
+                       target_gpu_id = maps_get_dest_gpu(&restore_maps,
+                                                         bo_bucket->gpu_id);
+                       tp_node = sys_get_node_by_gpu_id(&dest_topology,
+                                                        target_gpu_id);
                        if (!tp_node) {
-                               pr_err("Failed to find node with gpu_id:0x%04x\n", target_gpu_id);
+                               pr_err("Failed to find node with gpu_id:0x%04x\n",
+                                      target_gpu_id);
                                ret = -ENODEV;
                                goto exit;
                        }

-                       vma_md->new_pgoff = bo_bucket->restored_offset;
-                       vma_md->fd = node_get_drm_render_device(tp_node);
-
-                       pr_debug("adding vma_entry:addr:0x%lx old-off:0x%lx new_off:0x%lx new_minor:%d\n",
-                                vma_md->vma_entry, vma_md->old_pgoff,
-                                vma_md->new_pgoff, tp_node->drm_render_minor);
-
-                       list_add_tail(&vma_md->list, &update_vma_info_list);
+                       ret = save_vma_updates(bo_bucket->offset,
+                                              bo_bucket->addr,
+                                              bo_bucket->restored_offset,
+                                              node_get_drm_render_device(tp_node));
+                       if (ret)
+                               goto exit;
                }
        }

diff --git a/plugins/amdgpu/amdgpu_plugin_drm.c b/plugins/amdgpu/amdgpu_plugin_drm.c
index 070b5b19ec47..de6d6f178d51 100644
--- a/plugins/amdgpu/amdgpu_plugin_drm.c
+++ b/plugins/amdgpu/amdgpu_plugin_drm.c
@@ -557,7 +557,8 @@ int amdgpu_plugin_drm_restore_file(int fd, CriuRenderNode *rd)
                        }
                }

-               ret = save_vma_updates(boinfo->offset, boinfo->addr, mmap_args.out.addr_ptr, fd);
+               ret = save_vma_updates(boinfo->offset, boinfo->addr,
+                                      mmap_args.out.addr_ptr, fd);
                if (ret < 0)
                        goto exit;
        }
diff --git a/plugins/amdgpu/amdgpu_plugin_drm.h b/plugins/amdgpu/amdgpu_plugin_drm.h
index c766def563f6..f76e29f7f73f 100644
--- a/plugins/amdgpu/amdgpu_plugin_drm.h
+++ b/plugins/amdgpu/amdgpu_plugin_drm.h
@@ -34,7 +34,8 @@ int store_dmabuf_fd(int handle, int fd);

 int get_gem_handle(amdgpu_device_handle h_dev, int dmabuf_fd);

-int save_vma_updates(uint64_t offset, uint64_t addr, uint64_t restored_offset, int gpu_id);
+int save_vma_updates(uint64_t offset, uint64_t addr, uint64_t restored_offset,
+                    int fd);

 #endif         /* __AMDGPU_PLUGIN_DRM_H__ */

--
2.52.0