[PATCH 24/25] plugins/amdgpu: amdgpu_plugin_drm_restore_file() does not need to use libdrm

Tvrtko Ursulin <[email protected]> Wed, 11 Mar 2026 09:59:13 +0000
Newsgroups dev.linux.lists.criu
Message-ID <[email protected]>
There is no need to initialize and de-initialize libdrm only to use the
duplicated fd for calls to drmPrimeFDToHandle(). From the kernel's
perspective it is exactly the same file so operation is identical to just
using the passed in file descriptor.

Signed-off-by: Tvrtko Ursulin <[email protected]>
Reviewed-By: David Francis <[email protected]>
---
 plugins/amdgpu/amdgpu_plugin_drm.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/plugins/amdgpu/amdgpu_plugin_drm.c b/plugins/amdgpu/amdgpu_plugin_drm.c
index 4f5fa49a870f..6479257d3aab 100644
--- a/plugins/amdgpu/amdgpu_plugin_drm.c
+++ b/plugins/amdgpu/amdgpu_plugin_drm.c
@@ -451,9 +451,7 @@ int amdgpu_plugin_drm_restore_file(int fd, CriuRenderNode *rd)
 {
 	int ret = 0;
 	bool retry_needed = false;
-	uint32_t major, minor;
-	amdgpu_device_handle h_dev;
-	int device_fd, *dmabufs;
+	int *dmabufs;
 
 	dmabufs = xzalloc(sizeof(int) * rd->num_of_bos);
 	if (!dmabufs) {
@@ -461,14 +459,6 @@ int amdgpu_plugin_drm_restore_file(int fd, CriuRenderNode *rd)
 		return -ENOMEM;
 	}
 
-	ret = amdgpu_device_initialize(fd, &major, &minor, &h_dev);
-	if (ret) {
-		pr_info("Error in init amdgpu device\n");
-		goto exit;
-	}
-
-	device_fd = amdgpu_device_get_fd(h_dev);
-
 	for (int i = 0; i < rd->num_of_bos; i++) {
 		DrmBoEntry *boinfo = rd->bo_entries[i];
 		int dmabuf_fd = -1;
@@ -492,7 +482,7 @@ int amdgpu_plugin_drm_restore_file(int fd, CriuRenderNode *rd)
 		}
 
 		if (boinfo->is_import) {
-			drmPrimeFDToHandle(device_fd, dmabuf_fd, &handle);
+			drmPrimeFDToHandle(fd, dmabuf_fd, &handle);
 		} else {
 			union drm_amdgpu_gem_create create_args = { 0 };
 
@@ -508,7 +498,7 @@ int amdgpu_plugin_drm_restore_file(int fd, CriuRenderNode *rd)
 			}
 			handle = create_args.out.handle;
 
-			drmPrimeHandleToFD(device_fd, handle, 0, &dmabuf_fd);
+			drmPrimeHandleToFD(fd, handle, 0, &dmabuf_fd);
 		}
 
 		change_args.handle = handle;
@@ -569,8 +559,6 @@ int amdgpu_plugin_drm_restore_file(int fd, CriuRenderNode *rd)
 	if (ret)
 		goto exit;
 
-	ret = amdgpu_device_deinitialize(h_dev);
-
 	if (rd->num_of_bos > 0) {
 		ret = restore_bo_contents_drm(rd->drm_render_minor, rd, fd, dmabufs);
 		if (ret)
-- 
2.52.0