Skip to content

Commit fa5239f

Browse files
fxkamdChristianKoenigAMD
authored andcommitted
drm/amdgpu: workaround failed COW checks for Thunk VMAs
KFD Thunk maps invisible VRAM BOs with PROT_NONE, MAP_PRIVATE. is_cow_mapping returns true for these mappings, which causes mmap to fail in ttm_bo_mmap_obj. As a workaround, clear VM_MAYWRITE for PROT_NONE-COW mappings. This should prevent the mapping from ever becoming writable and makes is_cow_mapping(vm_flags) false. Fixes: f91142c ("drm/ttm: nuke VM_MIXEDMAP on BO mappings v3") Suggested-by: Daniel Vetter <[email protected]> Tested-by: Felix Kuehling <[email protected]> Signed-off-by: Felix Kuehling <[email protected]> Reviewed-by: Christian König <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Christian König <[email protected]>
1 parent 32a19de commit fa5239f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,15 @@ static int amdgpu_gem_object_mmap(struct drm_gem_object *obj, struct vm_area_str
255255
if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)
256256
return -EPERM;
257257

258+
/* Workaround for Thunk bug creating PROT_NONE,MAP_PRIVATE mappings
259+
* for debugger access to invisible VRAM. Should have used MAP_SHARED
260+
* instead. Clearing VM_MAYWRITE prevents the mapping from ever
261+
* becoming writable and makes is_cow_mapping(vm_flags) false.
262+
*/
263+
if (is_cow_mapping(vma->vm_flags) &&
264+
!(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)))
265+
vma->vm_flags &= ~VM_MAYWRITE;
266+
258267
return drm_gem_ttm_mmap(obj, vma);
259268
}
260269

0 commit comments

Comments
 (0)