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 09/23] plugins/amdgpu: Flatten amdgpu_restore_init a bit
Date: Fri, 10 Apr 2026 19:55:00 +0100 [thread overview]
Message-ID: <20260410185514.51153-10-tvrtko.ursulin@igalia.com> (raw)
In-Reply-To: <20260410185514.51153-1-tvrtko.ursulin@igalia.com>
Shallower indentation makes a heavily indented function hopefully a bit
more readable.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Reviewed-By: David Francis <David.Francis@amd.com>
---
plugins/amdgpu/amdgpu_plugin.c | 115 +++++++++++++++++----------------
1 file changed, 60 insertions(+), 55 deletions(-)
diff --git a/plugins/amdgpu/amdgpu_plugin.c b/plugins/amdgpu/amdgpu_plugin.c
index 1d95c04d1dbd..821881149d6c 100644
--- a/plugins/amdgpu/amdgpu_plugin.c
+++ b/plugins/amdgpu/amdgpu_plugin.c
@@ -1159,67 +1159,72 @@ out:
int amdgpu_restore_init(void)
{
- if (!shared_memory) {
- int protection = PROT_READ | PROT_WRITE;
- int visibility = MAP_SHARED | MAP_ANONYMOUS;
- int num_handles = 0;
- CriuRenderNode *rd = NULL;
- CriuKfd *e = NULL;
-
- DIR *d;
- struct dirent *dir;
- d = opendir(".");
- if (d) {
- while ((dir = readdir(d)) != NULL) {
- unsigned char *buf;
- size_t img_size;
- int ret;
-
- if (strncmp("amdgpu-kfd-", dir->d_name, strlen("amdgpu-kfd-")) == 0) {
- ret = load_img(dir->d_name, &buf, &img_size);
- if (ret < 0) {
- closedir(d);
- return ret;
- }
-
- e = criu_kfd__unpack(NULL, img_size, buf);
- num_handles += e->num_of_bos;
- criu_kfd__free_unpacked(e, NULL);
- xfree(buf);
- }
- if (strncmp("amdgpu-renderD-", dir->d_name, strlen("amdgpu-renderD-")) == 0) {
- ret = load_img(dir->d_name, &buf, &img_size);
- if (ret < 0) {
- closedir(d);
- return ret;
- }
-
- rd = criu_render_node__unpack(NULL, img_size, buf);
- num_handles += rd->num_of_bos;
- criu_render_node__free_unpacked(rd, NULL);
- xfree(buf);
- }
- }
- closedir(d);
- }
+ int num_handles = 0;
+ struct dirent *dir;
+ DIR *d;
+
+ if (shared_memory)
+ return 0;
+
+ d = opendir(".");
+ if (!d)
+ return -1;
- if (num_handles > 0) {
- shared_memory = mmap(NULL, sizeof(shared_memory), protection, visibility, -1, 0);
- shared_memory->num_handles = num_handles;
- shared_memory->handles = mmap(NULL, sizeof(struct handle_id) * num_handles, protection, visibility, -1, 0);
+ while ((dir = readdir(d)) != NULL) {
+ unsigned char *buf;
+ size_t img_size;
+ int ret;
- for (int i = 0; i < num_handles; i++) {
- shared_memory->handles[i].handle = -1;
- shared_memory->handles[i].fdstore_id = -1;
+ if (strncmp("amdgpu-kfd-", dir->d_name, strlen("amdgpu-kfd-")) == 0) {
+ CriuKfd *e;
+
+ ret = load_img(dir->d_name, &buf, &img_size);
+ if (ret < 0) {
+ closedir(d);
+ return ret;
}
- shared_memory_mutex = shmalloc(sizeof(*shared_memory_mutex));
- if (!shared_memory_mutex) {
- pr_err("Can't create amdgpu mutex\n");
- return -1;
+ e = criu_kfd__unpack(NULL, img_size, buf);
+ num_handles += e->num_of_bos;
+ criu_kfd__free_unpacked(e, NULL);
+ xfree(buf);
+ }
+ if (strncmp("amdgpu-renderD-", dir->d_name, strlen("amdgpu-renderD-")) == 0) {
+ CriuRenderNode *rd;
+
+ ret = load_img(dir->d_name, &buf, &img_size);
+ if (ret < 0) {
+ closedir(d);
+ return ret;
}
- mutex_init(shared_memory_mutex);
+
+ rd = criu_render_node__unpack(NULL, img_size, buf);
+ num_handles += rd->num_of_bos;
+ criu_render_node__free_unpacked(rd, NULL);
+ xfree(buf);
+ }
+ }
+ closedir(d);
+
+ if (num_handles > 0) {
+ const int protection = PROT_READ | PROT_WRITE;
+ const int visibility = MAP_SHARED | MAP_ANONYMOUS;
+
+ shared_memory = mmap(NULL, sizeof(shared_memory), protection, visibility, -1, 0);
+ shared_memory->num_handles = num_handles;
+ shared_memory->handles = mmap(NULL, sizeof(struct handle_id) * num_handles, protection, visibility, -1, 0);
+
+ for (int i = 0; i < num_handles; i++) {
+ shared_memory->handles[i].handle = -1;
+ shared_memory->handles[i].fdstore_id = -1;
+ }
+
+ shared_memory_mutex = shmalloc(sizeof(*shared_memory_mutex));
+ if (!shared_memory_mutex) {
+ pr_err("Can't create amdgpu mutex\n");
+ return -1;
}
+ mutex_init(shared_memory_mutex);
}
return 0;
--
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 ` Tvrtko Ursulin [this message]
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 ` [PATCH v2 15/23] plugins/amdgpu: Fix open_drm_render_device() Tvrtko Ursulin
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-10-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