From: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
To: criu@lists.linux.dev
Cc: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>,
David Francis <David.Francis@amd.com>
Subject: [PATCH v2 15/23] plugins/amdgpu: Fix open_drm_render_device()
Date: Fri, 10 Apr 2026 19:55:06 +0100 [thread overview]
Message-ID: <20260410185514.51153-16-tvrtko.ursulin@igalia.com> (raw)
In-Reply-To: <20260410185514.51153-1-tvrtko.ursulin@igalia.com>
Open_drm_render_device() is a little bit confused. It can log confusing
errors using errno which hasn't been set, or it has been overwritten. It
can also inspect errno after it had reset it creating effectively
unreachable code. And finally it sometimes returns the negative errno, and
sometimes a plain -1. Fix it all up and make it consistent, while at the
same time correcting two calls site incorrectly using pr_perror(), while
the function does not guarantee a valid errno.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Reviewed-By: David Francis <David.Francis@amd.com>
---
plugins/amdgpu/amdgpu_plugin.c | 9 +++++----
plugins/amdgpu/amdgpu_plugin_topology.c | 21 ++++++++++-----------
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/plugins/amdgpu/amdgpu_plugin.c b/plugins/amdgpu/amdgpu_plugin.c
index 2f63dcfa30a9..f2d1bcf44cab 100644
--- a/plugins/amdgpu/amdgpu_plugin.c
+++ b/plugins/amdgpu/amdgpu_plugin.c
@@ -1599,7 +1599,8 @@ static int restore_devices(struct kfd_ioctl_criu_args *args, CriuKfd *e)
drm_fd = node_get_drm_render_device(tp_node);
if (drm_fd < 0) {
- pr_perror("Can't open drm render fd %d", tp_node->drm_render_minor);
+ pr_err("Can't open drm render fd for minor %d - %s",
+ tp_node->drm_render_minor, strerror(-drm_fd));
goto exit;
} else {
pr_info("passing drm render fd = %d to driver\n", drm_fd);
@@ -1907,7 +1908,8 @@ int amdgpu_plugin_restore_file(int id, bool *retry_needed)
fd = node_get_drm_render_device(tp_node);
if (fd < 0) {
- pr_err("Failed to open render device (minor:%d)\n", tp_node->drm_render_minor);
+ pr_err("Failed to open render device (minor:%d) - %s\n",
+ tp_node->drm_render_minor, strerror(-fd));
return -1;
}
@@ -2201,9 +2203,8 @@ int init_dev(int dev_minor, amdgpu_device_handle *h_dev, uint64_t *max_copy_size
struct amdgpu_gpu_info gpu_info = { 0 };
drm_fd = open_drm_render_device(dev_minor);
- if (drm_fd < 0) {
+ if (drm_fd < 0)
return drm_fd;
- }
ret = amdgpu_device_initialize(drm_fd, &major, &minor, h_dev);
if (ret) {
diff --git a/plugins/amdgpu/amdgpu_plugin_topology.c b/plugins/amdgpu/amdgpu_plugin_topology.c
index 730f2e028430..c576cdfa4825 100644
--- a/plugins/amdgpu/amdgpu_plugin_topology.c
+++ b/plugins/amdgpu/amdgpu_plugin_topology.c
@@ -51,31 +51,30 @@ int open_drm_render_device(int minor)
int fd, ret_fd;
if (minor < DRM_FIRST_RENDER_NODE || minor > DRM_LAST_RENDER_NODE) {
- pr_perror("DRM render minor %d out of range [%d, %d]", minor, DRM_FIRST_RENDER_NODE,
- DRM_LAST_RENDER_NODE);
+ pr_err("DRM render minor %d out of range [%d, %d]",
+ minor, DRM_FIRST_RENDER_NODE, DRM_LAST_RENDER_NODE);
return -EINVAL;
}
snprintf(path, sizeof(path), "/dev/dri/renderD%d", minor);
fd = open(path, O_RDWR | O_CLOEXEC);
if (fd < 0) {
- if (errno != ENOENT && errno != EPERM) {
- pr_err("Failed to open %s: %s\n", path, strerror(errno));
- if (errno == EACCES)
- pr_err("Check user is in \"video\" group\n");
- }
- return -EBADFD;
+ fd = -errno;
+ pr_perror("Failed to open %s", path);
+ return fd;
}
if (fd_next < 0)
return fd;
ret_fd = fcntl(fd, F_DUPFD, fd_next++);
+ if (ret_fd < 0) {
+ ret_fd = -errno;
+ pr_perror("Failed to duplicate fd for minor:%d (fd_next:%d)",
+ minor, fd_next);
+ }
close(fd);
- if (ret_fd < 0)
- pr_perror("Failed to duplicate fd for minor:%d (fd_next:%d)", minor, fd_next);
-
return ret_fd;
}
--
2.52.0
next prev parent reply other threads:[~2026-04-10 18:55 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-10 18:54 [PATCH v2 00/23] Amdgpu plugin cleanups and fixes Tvrtko Ursulin
2026-04-10 18:54 ` [PATCH v2 01/23] plugins/amgdpu: Fix one error message Tvrtko Ursulin
2026-04-10 18:54 ` [PATCH v2 02/23] plugins/amdgpu: Remove unused current_pid global variable Tvrtko Ursulin
2026-04-10 18:54 ` [PATCH v2 03/23] plugins/amdgpu: Remove unused new_minor from struct vma_metadata Tvrtko Ursulin
2026-04-10 18:54 ` [PATCH v2 04/23] plugins/amdgpu: Fix drm pages size header Tvrtko Ursulin
2026-04-10 18:54 ` [PATCH v2 05/23] plugins/amdgpu: Fix logging of failures to open files during restore init Tvrtko Ursulin
2026-04-10 18:54 ` [PATCH v2 06/23] plugins/amdgpu: Propagate failure to save buffer object content Tvrtko Ursulin
2026-04-10 18:54 ` [PATCH v2 07/23] plugins/amdgpu: Close the directory when image probing fails Tvrtko Ursulin
2026-04-10 18:54 ` [PATCH v2 08/23] plugins/amdgpu: Close dma-buf image file if the read fails Tvrtko Ursulin
2026-04-10 18:55 ` [PATCH v2 09/23] plugins/amdgpu: Flatten amdgpu_restore_init a bit Tvrtko Ursulin
2026-04-10 18:55 ` [PATCH v2 10/23] plugins/amdgpu: Add error handling for seek operations Tvrtko Ursulin
2026-04-10 18:55 ` [PATCH v2 11/23] plugins/amdgpu: Consolidate vm_info collection Tvrtko Ursulin
2026-04-10 18:55 ` [PATCH v2 12/23] plugins/amdgpu: Remove plugin_log_msg() Tvrtko Ursulin
2026-04-10 18:55 ` [PATCH v2 13/23] plugins/amdgpu: Reduce amount of debug logging a little bit Tvrtko Ursulin
2026-04-10 18:55 ` [PATCH v2 14/23] plugins/amdgpu: Do not eat the errno in kmtIoctl Tvrtko Ursulin
2026-04-10 18:55 ` Tvrtko Ursulin [this message]
2026-04-10 18:55 ` [PATCH v2 16/23] plugins/amdgpu: Check sdma operation type early and once Tvrtko Ursulin
2026-04-10 18:55 ` [PATCH v2 17/23] plugins/amdgpu: Add plugin to inventory even if process has no vmas Tvrtko Ursulin
2026-04-10 18:55 ` [PATCH v2 18/23] plugins/amdgpu: Move drm file dump and restore into helpers Tvrtko Ursulin
2026-04-10 18:55 ` [PATCH v2 19/23] plugins/amdgpu: Use the load_img helper in drm file restore Tvrtko Ursulin
2026-04-10 18:55 ` [PATCH v2 20/23] plugins/amdgpu: Convert away from libc buffered file IO Tvrtko Ursulin
2026-04-10 18:55 ` [PATCH v2 21/23] plugins/amdgpu: Use save_vma_updates for all call sites Tvrtko Ursulin
2026-04-10 18:55 ` [PATCH v2 22/23] plugins/amdgpu: amdgpu_plugin_drm_restore_file() does not need to use libdrm Tvrtko Ursulin
2026-04-10 18:55 ` [PATCH v2 23/23] plugins/amdgpu: Fix remaining wrong usages of pr_perror Tvrtko Ursulin
2026-04-13 18:23 ` [PATCH v2 00/23] Amdgpu plugin cleanups and fixes Andrei Vagin
2026-04-13 19:47 ` Tvrtko Ursulin
2026-04-13 20:03 ` Andrei Vagin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260410185514.51153-16-tvrtko.ursulin@igalia.com \
--to=tvrtko.ursulin@igalia.com \
--cc=David.Francis@amd.com \
--cc=criu@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox