Skip to contentSkip to conversation

drm/amdgpu: Clear VRAM for all user mode allocations

PATCH In review Amir Shetaia 3 participants 3 messages Apr 9 – Apr 10

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: Clear VRAM for all user mode allocations

amdgpu_gem_object_create() sets AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE but not AMDGPU_GEM_CREATE_VRAM_CLEARED. While the GEM ioctl adds VRAM_CLEARED separately, other callers such as KFD do not, leaving freshly allocated VRAM with stale data observable by user mode.

This causes crashes in applications that expect zero-initialized VRAM, such as RCCL P2P transport where stale page table remnants corrupt protocol handshake fields.

Add AMDGPU_GEM_CREATE_VRAM_CLEARED alongside VRAM_WIPE_ON_RELEASE in amdgpu_gem_object_create() to cover all user mode VRAM paths.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b0ba2bdaf43a..c704bc53946c 100644
@@ -175,7 +175,8 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 
 	memset(&bp, 0, sizeof(bp));
 	*obj = NULL;
-	flags |= AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE;
+	flags |= AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE |
+		 AMDGPU_GEM_CREATE_VRAM_CLEARED;
 
 	bp.size = size;
 	bp.byte_align = alignment;
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Amir Shetaia

amdgpu_gem_object_create() sets AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE but not AMDGPU_GEM_CREATE_VRAM_CLEARED. While the GEM ioctl adds VRAM_CLEARED separately, other callers such as KFD do not, leaving freshly allocated VRAM with stale data observable by user mode.

Quoted 8 lines

This causes crashes in applications that expect zero-initialized VRAM, such as RCCL P2P transport where stale page table remnants corrupt protocol handshake fields.

Add AMDGPU_GEM_CREATE_VRAM_CLEARED alongside VRAM_WIPE_ON_RELEASE in amdgpu_gem_object_create() to cover all user mode VRAM paths.

Please also wait for Christian's OK for this patch.

Thanks,
  Felix

Quoted 18 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index b0ba2bdaf43a..c704bc53946c 100644
@@ -175,7 +175,8 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 
  	memset(&bp, 0, sizeof(bp));
  	*obj = NULL;
-	flags |= AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE;
+	flags |= AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE |
+		 AMDGPU_GEM_CREATE_VRAM_CLEARED;
 
  	bp.size = size;
  	bp.byte_align = alignment;
maintainer
#2 lore raw
In reply to Amir Shetaia
Quoted 22 lines · Amir Shetaia

amdgpu_gem_object_create() sets AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE but not AMDGPU_GEM_CREATE_VRAM_CLEARED. While the GEM ioctl adds VRAM_CLEARED separately, other callers such as KFD do not, leaving freshly allocated VRAM with stale data observable by user mode.

This causes crashes in applications that expect zero-initialized VRAM, such as RCCL P2P transport where stale page table remnants corrupt protocol handshake fields.

Add AMDGPU_GEM_CREATE_VRAM_CLEARED alongside VRAM_WIPE_ON_RELEASE in amdgpu_gem_object_create() to cover all user mode VRAM paths.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0 -0
index b0ba2bdaf43a..c704bc53946c 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, · line 179

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
@@ -175,7 +175,8 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 
 	memset(&bp, 0, sizeof(bp));
 	*obj = NULL;
-	flags |= AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE;
+	flags |= AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE |
+		 AMDGPU_GEM_CREATE_VRAM_CLEARED;

Clear NAK.

This is intentionally not done here so that we are able to create a dumb buffer for the boot up console before all IP blocks are initialized.

It is already set for all other userspace GEM allocations. See functions amdgpu_mode_dumb_create() and amdgpu_gem_create_ioctl().

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0 -0
 	bp.size = size;
 	bp.byte_align = alignment;