Skip to contentSkip to conversation

drm/amdgpu: Remove hidden double memset from amdgpu_vm_pt_clear()

PATCH In review Tvrtko Ursulin 2 participants 2 messages Aug 13, 2024

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

PATCH 1/1 drm/amdgpu: Remove hidden double memset from amdgpu_vm_pt_clear()

From: Tvrtko Ursulin <[email protected]>

When CONFIG_INIT_STACK_ALL_ZERO is set and so -ftrivial-auto-var-init=zero compiler option active, compiler fails to notice that later in amdgpu_vm_pt_clear() there is a second memset to clear the same on stack struct amdgpu_vm_update_params.

If we replace this memset with an explicit automatic variable initializer, compiler can then see it and avoid clearing this struct twice.

---
This is perhaps a bit questionable, regardless of how annoying it is to know there is this double memset.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +1 -2
index e39d6e7643bf..ecdc8fffe941 100644
@@ -361,7 +361,7 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 {
 	unsigned int level = adev->vm_manager.root_level;
 	struct ttm_operation_ctx ctx = { true, false };
-	struct amdgpu_vm_update_params params;
+	struct amdgpu_vm_update_params params = { };
 	struct amdgpu_bo *ancestor = &vmbo->bo;
 	unsigned int entries;
 	struct amdgpu_bo *bo = &vmbo->bo;
@@ -398,7 +398,6 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	if (r)
 		goto exit;
 
-	memset(&params, 0, sizeof(params));
 	params.adev = adev;
 	params.vm = vm;
 	params.immediate = immediate;
Signature · 1 line
2.44.0
#1 lore raw
Quoted 32 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

When CONFIG_INIT_STACK_ALL_ZERO is set and so -ftrivial-auto-var-init=zero compiler option active, compiler fails to notice that later in amdgpu_vm_pt_clear() there is a second memset to clear the same on stack struct amdgpu_vm_update_params.

If we replace this memset with an explicit automatic variable initializer, compiler can then see it and avoid clearing this struct twice.

---
This is perhaps a bit questionable, regardless of how annoying it is to know there is this double memset.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +1 -1
index e39d6e7643bf..ecdc8fffe941 100644
@@ -361,7 +361,7 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  {
  	unsigned int level = adev->vm_manager.root_level;
  	struct ttm_operation_ctx ctx = { true, false };
-	struct amdgpu_vm_update_params params;
+	struct amdgpu_vm_update_params params = { };
  	struct amdgpu_bo *ancestor = &vmbo->bo;
  	unsigned int entries;
  	struct amdgpu_bo *bo = &vmbo->bo;

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 403

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +0 -1
@@ -398,7 +398,6 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  	if (r)
  		goto exit;
 
-	memset(&params, 0, sizeof(params));
  	params.adev = adev;
  	params.vm = vm;
  	params.immediate = immediate;

Or even move all above three into the automatic initializer since all are the function input arguments.

Regards,

Tvrtko