From 4986f4a5c27f670260e42aee44ce432207da273d Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Thu, 25 Nov 2021 15:01:10 -0500 Subject: [PATCH] libhsakmt:Add MADV_DONTFORK to device mappings Mapped memory areas become invalid after fork, and the child process is required to remap the memory areas after a fork. So we mark these device memory mappings with MADV_DONTFORK so that they are removed from the child process after fork. This was causing some issues when doing CRIU checkpoint/restore because CRIU and amdgpu_plugin were not able to handle these mappings. Change-Id: I50eb334aecea6dab7522d94da0273adcf4fb1ce0 Signed-off-by: David Yat Sin --- src/fmm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/fmm.c b/src/fmm.c index 6154606786..cdcf1e48b9 100644 --- a/src/fmm.c +++ b/src/fmm.c @@ -1629,6 +1629,8 @@ static void *fmm_allocate_host_gpu(uint32_t node_id, void *address, return NULL; } + madvise(ret, MemorySizeInBytes, MADV_DONTFORK); + if (mflags.ui32.AQLQueueMemory) { uint64_t my_buf_size = size / 2; @@ -1636,6 +1638,10 @@ static void *fmm_allocate_host_gpu(uint32_t node_id, void *address, mmap(VOID_PTR_ADD(mem, my_buf_size), MemorySizeInBytes, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, map_fd, mmap_offset); + + madvise(VOID_PTR_ADD(mem, my_buf_size), + MemorySizeInBytes, + MADV_DONTFORK); } } } @@ -2701,7 +2707,7 @@ static int _fmm_map_to_gpu_scratch(uint32_t gpu_id, manageable_aperture_t *apert return -1; } } - + madvise(mmap_ret, size, MADV_DONTFORK); /* map to GPU */ ret = _fmm_map_to_gpu(aperture, address, size, NULL, &gpu_id, sizeof(uint32_t)); @@ -3364,6 +3370,7 @@ HSAKMT_STATUS fmm_register_shared_memory(const HsaSharedMemoryHandle *SharedMemo err = HSAKMT_STATUS_ERROR; goto err_free_obj; } + madvise(ret, (SizeInPages << PAGE_SHIFT), MADV_DONTFORK); } *MemoryAddress = reservedMem;