Skip to contentSkip to conversation

drm/amdgpu: only tear down an active UALink accelerator

PATCH In review Mukul Joshi 2 participants 2 messages Oct 21

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

PATCH 1/1 drm/amdgpu: only tear down an active UALink accelerator

AMDGPU_UALINK_ACCEL_STATE_ERROR is ordered after ACTIVE, so the "state < ACTIVE" check in deactivate_accelerator() lets an accelerator in the error state through to the full teardown. The NPA VM and workqueue are only created when the accelerator is activated, and an accelerator in the error state either never got there (invalid pPod or vPod configuration) or was already deactivated on the config update error path.

Tearing it down again calls destroy_workqueue() on a NULL or freed npa_wq and amdgpu_vm_fini() on an uninitialized or freed NPA VM. This is reachable from driver unload (hw_fini), a later failing config update, removal from the vPod and a pPod setup commit.

Only deactivate an accelerator that is actually active.

Fixes ccd7fa696b74 ("drm/amdgpu: Assign accel state based on ASP config")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c +1 -1
index 8d81efb28774..6ba745f37540 100644
@@ -1345,7 +1345,7 @@ static void activate_accelerator(struct amdgpu_device *adev)
 
 static void deactivate_accelerator(struct amdgpu_device *adev)
 {
-	if (adev->ualink.info->accel_state < AMDGPU_UALINK_ACCEL_STATE_ACTIVE)
+	if (adev->ualink.info->accel_state != AMDGPU_UALINK_ACCEL_STATE_ACTIVE)
 		return;
 
 	dev_info(adev->dev,
Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Mukul Joshi

AMDGPU_UALINK_ACCEL_STATE_ERROR is ordered after ACTIVE, so the "state < ACTIVE" check in deactivate_accelerator() lets an accelerator in the error state through to the full teardown. The NPA VM and workqueue are only created when the accelerator is activated, and an accelerator in the error state either never got there (invalid pPod or vPod configuration) or was already deactivated on the config update error path.

Tearing it down again calls destroy_workqueue() on a NULL or freed npa_wq and amdgpu_vm_fini() on an uninitialized or freed NPA VM. This is reachable from driver unload (hw_fini), a later failing config update, removal from the vPod and a pPod setup commit.

Quoted 4 lines

Only deactivate an accelerator that is actually active.

Fixes ccd7fa696b74 ("drm/amdgpu: Assign accel state based on ASP config")

This patch looks good to me. I see other places in the code that compare peer_info->accel_state < ...  Could they be exposed to similar issues when accelerators are in an error state? Maybe it would be safer to change the definition such that ACCEL_STATE_ERROR is less than any other state.

Either way, this patch is

Quoted 17 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c +1 -1
index 8d81efb28774..6ba745f37540 100644
@@ -1345,7 +1345,7 @@ static void activate_accelerator(struct amdgpu_device *adev)
 
  static void deactivate_accelerator(struct amdgpu_device *adev)
  {
-	if (adev->ualink.info->accel_state < AMDGPU_UALINK_ACCEL_STATE_ACTIVE)
+	if (adev->ualink.info->accel_state != AMDGPU_UALINK_ACCEL_STATE_ACTIVE)
  		return;
 
  	dev_info(adev->dev,