2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 06:15:24 +00:00

criu/plugin: Fix for FDs not allowed to mmap

On newer kernel's (> 5.13), KFD & DRM drivers will only allow the
/dev/renderD* file descriptors that were used during the CRIU_RESTORE
ioctl when calling mmap for the vma's.
During restore, after opening /dev/renderD*, amdgpu_plugin keeps the
FDs opened and instead returns a copy of the FDs to CRIU. The same FDs
are then returned during the UPDATE_VMAMAP hooks so that they can be
used by CRIU to call mmap. Duplicated FDs created using dup are
references to the same struct file inside the kernel so they are also
allowed to mmap.
To prevent the opened FDs inside amdgpu_plugin from conflicting with
FDs used by the target restore application, we make sure that the
lowest-numbered FD that amdgpu_plugin will use is greater than the
highest-numbered FD that is used by the target application.

Signed-off-by: David Yat Sin <david.yatsin@amd.com>
This commit is contained in:
David Yat Sin
2021-09-29 08:26:04 -04:00
committed by Andrei Vagin
parent bd83330095
commit 2095de9f03
3 changed files with 55 additions and 35 deletions

View File

@@ -61,10 +61,17 @@ bool kfd_numa_check = true;
/* Skip capability check */
bool kfd_capability_check = true;
/*
* During dump, we can use any fd value so fd_next is always -1.
* During restore, we have to use a fd value that does not conflict with fd values in use by the target restore process.
* fd_next is initialized as 1 greather than the highest-numbered file descriptor used by the target restore process.
*/
int fd_next = -1;
static int open_drm_render_device(int minor)
{
char path[128];
int fd;
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,
@@ -83,7 +90,16 @@ static int open_drm_render_device(int minor)
return -EBADFD;
}
return fd;
if (fd_next < 0)
return fd;
ret_fd = fcntl(fd, F_DUPFD, 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;
}
static const char *link_type(uint32_t type)