Skip to contentSkip to conversation

drm/amdgpu: Check hive->reset_domain not NULL before releasing it.

PATCH In review Gavin Wan 2 participants 2 messages Nov 1, 2022

Subsystems (2)
lore
Share & tools
lore

Gavin Wan

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Check hive->reset_domain not NULL before releasing it.

The recent change brought a bug on SRIOV envrionment. It caused kernel crashing while unloading amdgpu on guest VM with hive configuration. The reason is that the hive->reset_domain is not used (hive->reset_domain is not initialized) for SRIOV, but the code did not check if hive->reset_domain before releasing.

The hive->reset_domain need be checked not NULL before releasing.

Fixed: d95e8e97e2d5 ("drm/amdgpu: refine create and release logic of hive info")

Change-Id I17189e4d7357e399c6b70e43c24051356c025a3a
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +9 -2
index 47159e9a0884..371c4f1aac2b 100644
@@ -217,8 +217,15 @@ static void amdgpu_xgmi_hive_release(struct kobject *kobj)
 	struct amdgpu_hive_info *hive = container_of(
 		kobj, struct amdgpu_hive_info, kobj);
 
-	amdgpu_reset_put_reset_domain(hive->reset_domain);
-	hive->reset_domain = NULL;
+	/**
+	 * The hive->reset_domain is only initialized for none SRIOV
+	 * configuration. It needs to check if hive->reset_domain is
+	 * NULL.
+	 */
+	if (hive->reset_domain) {
+		amdgpu_reset_put_reset_domain(hive->reset_domain);
+		hive->reset_domain = NULL;
+	}
 
 	mutex_destroy(&hive->hive_lock);
 	kfree(hive);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 9 lines · Gavin Wan

The recent change brought a bug on SRIOV envrionment. It caused kernel crashing while unloading amdgpu on guest VM with hive configuration. The reason is that the hive->reset_domain is not used (hive->reset_domain is not initialized) for SRIOV, but the code did not check if hive->reset_domain before releasing.

The hive->reset_domain need be checked not NULL before releasing.

Fixed: d95e8e97e2d5 ("drm/amdgpu: refine create and release logic of hive info")

The tag should be named "Fixes", not "Fixed".

Quoted 2 lines
Change-Id I17189e4d7357e399c6b70e43c24051356c025a3a

Please remove the Change-Id.

Quoted 9 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 11 +++++++++--
  1 file changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +0 -0
index 47159e9a0884..371c4f1aac2b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c static void amdgpu_xgmi_hive_release(struct kobject *kobj) · line 220

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +1 -2
@@ -217,8 +217,15 @@ static void amdgpu_xgmi_hive_release(struct kobject *kobj)
  	struct amdgpu_hive_info *hive = container_of(
  		kobj, struct amdgpu_hive_info, kobj);
 
-	amdgpu_reset_put_reset_domain(hive->reset_domain);
-	hive->reset_domain = NULL;
+	/**

Remove the extra *. /** is used to denote doc-comments, and this is not one.

drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c static void amdgpu_xgmi_hive_release(struct kobject *kobj) · line 226

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +6 -0
+	 * The hive->reset_domain is only initialized for none SRIOV
+	 * configuration. It needs to check if hive->reset_domain is
+	 * NULL.
+	 */
+	if (hive->reset_domain) {
+		amdgpu_reset_put_reset_domain(hive->reset_domain);

It may be better to do the NULL pointer check inside amdgpu_reset_put_reset_domain. In fact, current staging already has a check there, so this patch is unnecessary. Just sync your branch. It was added by this commit:

Quoted 10 lines

commit d6a7ab1e0168a96b6cb0e386399e54af4fe39af4
Author: Vignesh Chander <[email protected]>
Date:   Wed Sep 28 14:59:45 2022 -0400

    drm/amdgpu: Skip put_reset_domain if it doesn't exist

    For xgmi sriov, the reset is handled by host driver and hive->reset_domain is not initialized so need to check if it exists before doing a put.

    Regards,
  Felix

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +2 -0
+		hive->reset_domain = NULL;
+	}
 
  	mutex_destroy(&hive->hive_lock);
  	kfree(hive);