-
Notifications
You must be signed in to change notification settings - Fork 664
Dmabuf IPC support for amdgpu plugin (v2) #2613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: criu-dev
Are you sure you want to change the base?
Conversation
A friendly reminder that this PR had no activity for 30 days. |
@fdavid-amd how is it going? Let me know if you need help with this pr. |
|
||
message criu_render_node { | ||
required uint32 gpu_id = 1; | ||
required uint32 id = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like these changes break compatibility - a newer version of CRIU would not be able to restore a checkpoint created with a previous version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true - I wasn't aware that was a type of backwards-compatibility we committed to.
b057779
to
456978a
Compare
amdgpu represents allocated device memory as a memory mapping of the device file. This is a non-standard VMA that must be handled by the plugin, not the normal VMA code. Ignore all VMAs on device files. Signed-off-by: David Francis <David.Francis@amd.com>
amdgpu dmabuf CRIU requires the ability of the amdgpu plugin to retry. Change files_ext.c to read a response of 1 from a plugin restore function to mean retry. Signed-off-by: David Francis <David.Francis@amd.com>
45f796c
to
878a313
Compare
@avagin |
Some of the build failures I don't understand - they might be an issue with this patch set or they might be an issue with the CI. There's a lot of 'Error: ipv6: address already assigned.', which could possibly be a result of the way that I'm allocating the plugin socket but seems unlikely. |
@avagin sorry for the repeat ping, but there is something of a rush on my part to get kernel patch https://lists.freedesktop.org/archives/dri-devel/2025-July/514922.html merged in the next week or so (it adds the CHANGE_HANDLE ioctl). As part of merging that patch, I need to demonstrate that it has written and reasonably stable userspace code that uses it (which would be these CRIU patches). It would be a big help to me if you could say if the general approach taken by these patches is acceptable or unacceptable. |
BTW we can merge the current version to the criu-dev branch and do all other adjustments on top of it. |
This code is currently not functional because it relies on ioctls that are not merged into any kernel branch; is is still okay to merge? |
3bace7e
to
84fb396
Compare
The way we usually handle this problem in CRIU is by checking if the required kernel functionality is available and disabling features that are not supported. However, it might be better to wait until the ioctls are merged. |
84fb396
to
1dc9e9a
Compare
For amdgpu plugin to call the new amdgpu drm CRIU ioctls, it needs the amdgpu drm header file, copied from the kernel's includes. Signed-off-by: David Francis <David.Francis@amd.com>
The amdgpu plugin usually calls drm ioctls through the libdrm wrappers. However, amdgpu restore requires dealing with dmabufs and gem handles directly, which means drm ioctls must be called directly. Add the drm.h header (from the kernel's uapi). Signed-off-by: David Francis <David.Francis@amd.com>
Buffer objects held by the amdgpu drm driver are checkpointed with the new BO_INFO and MAPPING_INFO ioctls/ioctl options. Handling is in amdgpu_plugin_drm.h Handling of imported buffer objects may require dmabuf fds to be transferred between processes. These occur over fdstore, with the handle-fstore id relationships kept in shread memory. There is a new plugin callback: RESTORE_INIT to create the shared memory. During checkpoint, track shared buffer objects, so that buffer objects that are shared across processes can be identified. During restore, track which buffer objects have been restored. Retry restore of a drm file if a buffer object is imported and the original has not been exported yet. Skip buffer objects that have already been completed or cannot be completed in the current restore. So drm code can use sdma_copy_bo, that function no longer requires kfd bo structs Update the protobuf messages with new amdgpu drm information. Signed-off-by: David Francis <David.Francis@amd.com>
The amdgpu plugin was counting how many files were checkpointed to determine when it should close the device files. The number of device files is not consistent; a process may have multiple copies of the drm device files open. Instead of doing this counting, add a new callback after all files are checkpointed, so plugins can clean up their resources at an appropriate time. Signed-off-by: David Francis <David.Francis@amd.com>
1dc9e9a
to
e90ffcd
Compare
Some of these compilation tests seem to be failing at a install phase; is that something my code is doing or is it a problem with the test? |
@avagin There's now an additional patch in this patch set (Support for Open dmabuf handles) to handle the case where a dmabuf fd is open during checkpoint. It involves some changes to core CRIU, what do you think of the approach? |
Add new ioctl DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES. This ioctl returns a list of bos with their handles, sizes, and flags and domains. This ioctl is meant to be used during CRIU checkpoint and provide information needed to reconstruct the bos in CRIU restore. Userspace for this and the next change can be found at checkpoint-restore/criu#2613 Signed-off-by: David Francis <David.Francis@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Add new GEM_OP_IOCTL option GET_MAPPING_INFO, which returns a list of mappings associated with a given bo, along with their positions and offsets. Userspace for this and the previous change can be found at: checkpoint-restore/criu#2613 Signed-off-by: David Francis <David.Francis@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
e90ffcd
to
a155b84
Compare
The kernel code this relies in is now merged (into Alex Deucher's topic branch, not an official kernel release), and the CRIU code does test for the presence of the kernel changes and fallback to the old way if they're not present. |
…p.org/agd5f/linux into drm-next amd-drm-next-6.18-2025-09-09: amdgpu: - Add CRIU support for gem objects - SI UVD fix - SI DPM fixes - Misc code cleanups - RAS updates - GPUVM debugfs fixes - Cyan Skillfish updates - UserQ updates - OEM i2c fix - SMU 13.0.x updates - DPCD probe quirk fix - Make vbios build number available in sysfs - HDCP updates - Brightness curve fixes - eDP updates - Vblank fixes - DCN 3.5 PG fix - PBN calcution fix amdkfd: - Add CRIU support for gem objects - Flexible array fix - P2P topology fix - APU memlimit fixes - Misc code cleanups UAPI: - Add CRIU support for gem objects Proposed userspace: checkpoint-restore/criu#2613 radeon: - Use dev_warn_once() in CS parsers Signed-off-by: Dave Airlie <airlied@redhat.com> From: Alex Deucher <alexander.deucher@amd.com> Link: https://lore.kernel.org/r/20250909161928.942785-1-alexander.deucher@amd.com
Given that the ioctls have been merged into at least one kernel branch, could this now happen? |
@fdavid-amd Thank you for the update!
Would it be possible to add a |
criu/files.c
Outdated
int do_dump_gen_file(struct fd_parms *p, int lfd, const struct fdtype_ops *ops, FdinfoEntry *e) | ||
/* Use "force" to override cache */ | ||
int do_dump_gen_file(struct fd_parms *p, int lfd, | ||
const struct fdtype_ops *ops, FdinfoEntry *e, bool force) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to provide more information about why do we need to "override cache"? For example, can you share with us an example where CRIU needs to handle open dmabuf file descriptors. We usually implement tests to very that such functionality works as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CRIU has always dealt with dependencies between restoring files, but dmabuf fd adds dependencies between dumping files. A dmabuf fd can't be dumped until we've dumped the device file it was exported from. For this reason this patch set adds a retry system to file dumping. Files that are being retried should have the appropriate dump call made even if there is no new file descriptor for them.
I have implemented tests for internal testing, which can be found here. The DmabufDelayTest in this branch pauses while a dmabuf fd is active to trigger this code.
https://github.com/fdavid-amd/ROCT-Thunk-Interface-CRIU#
a155b84
to
1a5f191
Compare
I think you need to split this patch. Changes in the criu core part should be made in separate patches with clear descriptions why they are required. |
if (ret) | ||
break; | ||
} | ||
/* Dmabuf FDs cannot be dumped unless we have first dumped the device file that exported them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the proper device file already be closed? Could it be opened in another process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under the impression that CRIU didn't close the files it was dumping with until later in the process.
The earlier patches in this pr allow the amdgpu plugin to find the dmabuf fd even if it was exported by another process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under the impression that CRIU didn't close the files it was dumping with until later in the process.
The earlier patches in this pr allow the amdgpu plugin to find the dmabuf fd even if it was exported by another process.
ret = dump_one_file(item->pid, dfds->fds[i + off], lfds[i], opts + i, ctl, &e, dfds); | ||
ret = dump_one_file(item->pid, dfds->fds[i + off], lfds[i], opts + i, ctl, &e, dfds, false); | ||
if (ret == -EAGAIN) { | ||
retry_indices[retry_count++] = i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i+off?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this addition is performed a few lines later
1a5f191
to
87059a8
Compare
Patch has been split. The approach to dump retries does propagate these "force" variable all over the place, which is not the prettiest, but I can't think of a better way of doing it. |
dmabuf fd files cannot be dumped until the device file they were exported from is dumped. This introduces the concept of dependencies bewteen dumping files. During checkpoint, track files that fail to dump, then retry them. A new flag "is_retry" is needed so these dump can occur on files that already received a file id. Signed-off-by: David Francis <David.Francis@amd.com>
amdgpu libraries that use dmabuf fd to share GPU memory between processes close the dmabuf fds immediately after using them. However, it is possible that checkpoint of a process catches one of the dmabuf fds open. In that case, the amdgpu plugin needs to handle it. The checkpoint of the dmabuf fd does require the device file it was exported from to have already been dumped To identify which device this dmabuf fd was exprted from, attempt to import it on each device, then record the dmabuf handle it imports as. This handle can be used to restore it. Signed-off-by: David Francis <David.Francis@amd.com>
87059a8
to
3d40e7a
Compare
This patch set, in combination with the accompanying kernel patch set, is the
second draft of work to support amdgpu dmabuf IPC. Since the first post, the
patches have been split to make them more readable and made
backwards-compatible.