Skip to contentSkip to conversation

drm/amdgpu: fix dereference after null check

PATCH In review Jesse Zhang 6 participants 61 messages May 10, 2024 – May 14, 2024

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

PATCH 1/22 drm/amdgpu: fix dereference after null check

check the pointer hive before use.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
index 77f6fd50002a..00fe3c2d5431 100644
@@ -5725,7 +5725,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 	 * to put adev in the 1st position.
 	 */
 	INIT_LIST_HEAD(&device_list);
-	if (!amdgpu_sriov_vf(adev) && (adev->gmc.xgmi.num_physical_nodes > 1)) {
+	if (!amdgpu_sriov_vf(adev) && (adev->gmc.xgmi.num_physical_nodes > 1) && hive) {
 		list_for_each_entry(tmp_adev, &hive->device_list, gmc.xgmi.head) {
 			list_add_tail(&tmp_adev->reset_list, &device_list);
 			if (adev->shutdown)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/22 drm/amdgpu: the warning dereferencing obj for nbio_v7_4

if ras_manager obj null, don't print NBIO err data

---
 drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c +1 -1
index fe18df10daaa..26e5885db9b7 100644
@@ -383,7 +383,7 @@ static void nbio_v7_4_handle_ras_controller_intr_no_bifring(struct amdgpu_device
 		else
 			WREG32_SOC15(NBIO, 0, mmBIF_DOORBELL_INT_CNTL, bif_doorbell_intr_cntl);
 
-		if (!ras->disable_ras_err_cnt_harvest) {
+		if (!ras->disable_ras_err_cnt_harvest && obj) {
 			/*
 			 * clear error status after ras_controller_intr
 			 * according to hw team and count ue number
Signature · 1 line
2.25.1
#2 lore raw

RE: [PATCH 02/22] drm/amdgpu: the warning dereferencing obj for nbio_v7_4

[AMD Official Use Only - AMD Internal Distribution Only]

Ping ...

-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 02/22] drm/amdgpu: the warning dereferencing obj for nbio_v7_4

if ras_manager obj null, don't print NBIO err data

---
 drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c +1 -1
index fe18df10daaa..26e5885db9b7 100644
@@ -383,7 +383,7 @@ static void nbio_v7_4_handle_ras_controller_intr_no_bifring(struct amdgpu_device
                else
                        WREG32_SOC15(NBIO, 0, mmBIF_DOORBELL_INT_CNTL, bif_doorbell_intr_cntl);
 
-               if (!ras->disable_ras_err_cnt_harvest) {
+               if (!ras->disable_ras_err_cnt_harvest && obj) {
                        /*
                         * clear error status after ras_controller_intr
                         * according to hw team and count ue number

--
2.25.1

#3 lore raw

RE: [PATCH 02/22] drm/amdgpu: the warning dereferencing obj for nbio_v7_4

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Jesse,

Quoted 43 lines

-----Original Message-----
From: Zhang, Jesse(Jie) <[email protected]>
Sent: Monday, May 13, 2024 10:18 AM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>
Subject: RE: [PATCH 02/22] drm/amdgpu: the warning dereferencing obj for nbio_v7_4

[AMD Official Use Only - AMD Internal Distribution Only]

Ping ...

-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 02/22] drm/amdgpu: the warning dereferencing obj for nbio_v7_4

if ras_manager obj null, don't print NBIO err data

---
 drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c +0 -0
index fe18df10daaa..26e5885db9b7 100644
@@ -383,7 +383,7 @@ static void

nbio_v7_4_handle_ras_controller_intr_no_bifring(struct amdgpu_device

                else
                        WREG32_SOC15(NBIO, 0,

mmBIF_DOORBELL_INT_CNTL, bif_doorbell_intr_cntl);

drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c static void nbio_v7_4_handle_ras_controller_intr_no_bifring(struct amdgpu_device · line 386

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c +1 -1
-               if (!ras->disable_ras_err_cnt_harvest) {
+               if (!ras->disable_ras_err_cnt_harvest && obj) {

We may need to check the ras pointer as well? Such as change to " if (ras && !ras->disable_ras_err_cnt_harvest && obj) {"

Tim Huang

Quoted 6 lines

/*
* clear error status after ras_controller_intr
* according to hw team and count ue number
--
2.25.1

#4 lore raw

RE: [PATCH 02/22] drm/amdgpu: the warning dereferencing obj for nbio_v7_4

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Tim

-----Original Message-----
From: Huang, Tim <[email protected]>
Sent: Monday, May 13, 2024 12:23 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: RE: [PATCH 02/22] drm/amdgpu: the warning dereferencing obj for nbio_v7_4

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Jesse,

Quoted 44 lines

-----Original Message-----
From: Zhang, Jesse(Jie) <[email protected]>
Sent: Monday, May 13, 2024 10:18 AM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>
Subject: RE: [PATCH 02/22] drm/amdgpu: the warning dereferencing obj for
nbio_v7_4

[AMD Official Use Only - AMD Internal Distribution Only]

Ping ...

-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 02/22] drm/amdgpu: the warning dereferencing obj for nbio_v7_4

if ras_manager obj null, don't print NBIO err data

---
 drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c +0 -0
index fe18df10daaa..26e5885db9b7 100644
@@ -383,7 +383,7 @@ static void

nbio_v7_4_handle_ras_controller_intr_no_bifring(struct amdgpu_device

                else
                        WREG32_SOC15(NBIO, 0, mmBIF_DOORBELL_INT_CNTL,

bif_doorbell_intr_cntl);

drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c static void nbio_v7_4_handle_ras_controller_intr_no_bifring(struct amdgpu_device · line 386

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c +1 -1
-               if (!ras->disable_ras_err_cnt_harvest) {
+               if (!ras->disable_ras_err_cnt_harvest && obj) {

We may need to check the ras pointer as well? Such as change to " if (ras && !ras->disable_ras_err_cnt_harvest && obj) {"

[Zhang, Jesse(Jie)] Thanks, will update the patch . Tim Huang

Quoted 6 lines

/*
* clear error status after ras_controller_intr
* according to hw team and count ue number
--
2.25.1

#5 lore raw

PATCH 3/22 drm/amdgpu: fix the waring dereferencing hive

In reply to Jesse Zhang

Check the amdgpu_hive_info *hive that maybe is NULL.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +3 -0
index 37820dd03cab..5a648a657dc6 100644
@@ -1362,6 +1362,9 @@ static void psp_xgmi_reflect_topology_info(struct psp_context *psp,
 	uint8_t dst_num_links = node_info.num_links;
 
 	hive = amdgpu_get_xgmi_hive(psp->adev);
+	if (WARN_ON(!hive))
+		return;
+
 	list_for_each_entry(mirror_adev, &hive->device_list, gmc.xgmi.head) {
 		struct psp_xgmi_topology_info *mirror_top_info;
 		int j;
Signature · 1 line
2.25.1
Reviewed-by on v1 3/22
#6 lore raw

RE: [PATCH 03/22] drm/amdgpu: fix the waring dereferencing hive

[AMD Official Use Only - General]

This patch is,

Quoted 36 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 03/22] drm/amdgpu: fix the waring dereferencing hive

Check the amdgpu_hive_info *hive that maybe is NULL.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +3 -0
index 37820dd03cab..5a648a657dc6 100644
@@ -1362,6 +1362,9 @@ static void psp_xgmi_reflect_topology_info(struct
 psp_context *psp,
      uint8_t dst_num_links = node_info.num_links;
 
      hive = amdgpu_get_xgmi_hive(psp->adev);
+     if (WARN_ON(!hive))
+             return;
+
      list_for_each_entry(mirror_adev, &hive->device_list, gmc.xgmi.head) {
              struct psp_xgmi_topology_info *mirror_top_info;
              int j;

--
2.25.1

#7 lore raw

PATCH 4/22 drm/amd: fix the warning unchecking return vaule for sdma_v7

In reply to Jesse Zhang

check ring allocate success before emit preempt ib

---
 drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +5 -1
index 0b5af1c50461..7db53a96cff0 100644
@@ -1347,7 +1347,11 @@ static int sdma_v7_0_ring_preempt_ib(struct amdgpu_ring *ring)
 
 	/* emit the trailing fence */
 	ring->trail_seq += 1;
-	amdgpu_ring_alloc(ring, 10);
+	r = amdgpu_ring_alloc(ring, 10);
+	if (r) {
+		DRM_ERROR("ring %d failed to be allocated \n", ring->idx);
+		return r;
+	}
 	sdma_v7_0_ring_emit_fence(ring, ring->trail_fence_gpu_addr,
 				  ring->trail_seq, 0);
 	amdgpu_ring_commit(ring);
Signature · 1 line
2.25.1
Reviewed-by on v1 4/22
#8 lore raw

RE: [PATCH 04/22] drm/amd: fix the warning unchecking return vaule for sdma_v7

[AMD Official Use Only - General]

This patch is,

Quoted 40 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 04/22] drm/amd: fix the warning unchecking return vaule for sdma_v7

check ring allocate success before emit preempt ib

---
 drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +5 -1
index 0b5af1c50461..7db53a96cff0 100644
@@ -1347,7 +1347,11 @@ static int sdma_v7_0_ring_preempt_ib(struct
 amdgpu_ring *ring)
 
      /* emit the trailing fence */
      ring->trail_seq += 1;
-     amdgpu_ring_alloc(ring, 10);
+     r = amdgpu_ring_alloc(ring, 10);
+     if (r) {
+             DRM_ERROR("ring %d failed to be allocated \n", ring->idx);
+             return r;
+     }
      sdma_v7_0_ring_emit_fence(ring, ring->trail_fence_gpu_addr,
                                ring->trail_seq, 0);
      amdgpu_ring_commit(ring);

--
2.25.1

#9 lore raw

PATCH 5/22 drm/amd/pm: check specific index for aldebaran

In reply to Jesse Zhang

Check for specific indexes that may be invalid values.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +2 -1
index ce941fbb9cfb..a22eb6bbb05e 100644
@@ -1886,7 +1886,8 @@ static int aldebaran_mode2_reset(struct smu_context *smu)
 
 	index = smu_cmn_to_asic_specific_index(smu, CMN2ASIC_MAPPING_MSG,
 						SMU_MSG_GfxDeviceDriverReset);
-
+	if (index < 0 )
+		return -EINVAL;
 	mutex_lock(&smu->message_lock);
 	if (smu->smc_fw_version >= 0x00441400) {
 		ret = smu_cmn_send_msg_without_waiting(smu, (uint16_t)index, SMU_RESET_MODE_2);
Signature · 1 line
2.25.1
Reviewed-by on v1 5/22
#10 lore raw

RE: [PATCH 05/22] drm/amd/pm: check specific index for aldebaran

[AMD Official Use Only - General]

Best Regards,
Kevin

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 05/22] drm/amd/pm: check specific index for aldebaran

Check for specific indexes that may be invalid values.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +2 -1
index ce941fbb9cfb..a22eb6bbb05e 100644
@@ -1886,7 +1886,8 @@ static int aldebaran_mode2_reset(struct smu_context *smu)
 
        index = smu_cmn_to_asic_specific_index(smu, CMN2ASIC_MAPPING_MSG,
                                                SMU_MSG_GfxDeviceDriverReset);
-
+       if (index < 0 )
+               return -EINVAL;

[Kevin]:
Better to add a new blank line here.

Best Regards,
Kevin

        mutex_lock(&smu->message_lock);
        if (smu->smc_fw_version >= 0x00441400) {
                ret = smu_cmn_send_msg_without_waiting(smu, (uint16_t)index, SMU_RESET_MODE_2);

--
2.25.1

Reviewed-by on v1 5/22
#11 lore raw

RE: [PATCH 05/22] drm/amd/pm: check specific index for aldebaran

In reply to Jesse Zhang

[AMD Official Use Only - General]

This patch is,

Quoted 38 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 05/22] drm/amd/pm: check specific index for aldebaran

Check for specific indexes that may be invalid values.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +2 -1
index ce941fbb9cfb..a22eb6bbb05e 100644
@@ -1886,7 +1886,8 @@ static int aldebaran_mode2_reset(struct
 smu_context *smu)
 
      index = smu_cmn_to_asic_specific_index(smu,
 CMN2ASIC_MAPPING_MSG,
                                              SMU_MSG_GfxDeviceDriverReset);
-
+     if (index < 0 )
+             return -EINVAL;
      mutex_lock(&smu->message_lock);

if (smu->smc_fw_version >= 0x00441400) {
ret = smu_cmn_send_msg_without_waiting(smu, (uint16_t)index,
SMU_RESET_MODE_2);
--
2.25.1

#12 lore raw

Re: [PATCH 05/22] drm/amd/pm: check specific index for aldebaran

In reply to Jesse Zhang
Quoted 12 lines · Jesse Zhang

Check for specific indexes that may be invalid values.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +0 -0
index ce941fbb9cfb..a22eb6bbb05e 100644

drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c static int aldebaran_mode2_reset(struct smu_context *smu) · line 1890

Quoted 6 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +2 -1
@@ -1886,7 +1886,8 @@ static int aldebaran_mode2_reset(struct smu_context *smu)
 
 	index = smu_cmn_to_asic_specific_index(smu, CMN2ASIC_MAPPING_MSG,
 						SMU_MSG_GfxDeviceDriverReset);
-
+	if (index < 0 )
+		return -EINVAL;

To avoid warning problems, drop index and use PPSMC_MSG_GfxDriverReset instead of index.

Thanks,
Lijo

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +0 -0
 	mutex_lock(&smu->message_lock);
 	if (smu->smc_fw_version >= 0x00441400) {
 		ret = smu_cmn_send_msg_without_waiting(smu, (uint16_t)index, SMU_RESET_MODE_2);
#13 lore raw

PATCH 6/22 drm/amd/pm: check the return of send smc msg for sienna_cichild

In reply to Jesse Zhang

Set smu work laod mask may fail, so check return.

---
 drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +3 -1
index e426f457a017..e7ef8cb3a791 100644
@@ -1782,8 +1782,10 @@ static int sienna_cichlid_set_power_profile_mode(struct smu_context *smu, long *
 						       smu->power_profile_mode);
 	if (workload_type < 0)
 		return -EINVAL;
-	smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetWorkloadMask,
+	ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetWorkloadMask,
 				    1 << workload_type, NULL);
+	if (ret)
+		dev_err(smu->adev->dev, "[%s] Failed to set work load mask!", __func__);
 
 	return ret;
 }
Signature · 1 line
2.25.1
Reviewed-by on v1 6/22
#14 lore raw

RE: [PATCH 06/22] drm/amd/pm: check the return of send smc msg for sienna_cichild

[AMD Official Use Only - General]

This patch is,

Quoted 42 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 06/22] drm/amd/pm: check the return of send smc msg for sienna_cichild

Set smu work laod mask may fail, so check return.

---
 drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +0 -0
index e426f457a017..e7ef8cb3a791 100644
@@ -1782,8 +1782,10 @@ static int

sienna_cichlid_set_power_profile_mode(struct smu_context *smu, long *

                                                     smu->power_profile_mode);
      if (workload_type < 0)
              return -EINVAL;

- smu_cmn_send_smc_msg_with_param(smu,
SMU_MSG_SetWorkloadMask,
+ ret = smu_cmn_send_smc_msg_with_param(smu,
SMU_MSG_SetWorkloadMask,

                                  1 << workload_type, NULL);
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +2 -0
+     if (ret)
+             dev_err(smu->adev->dev, "[%s] Failed to set work load mask!",

__func__);

      return ret;

}
--
2.25.1

#15 lore raw

PATCH 7/22 drm/amd/pm: check the return of send smc msg for navi10

In reply to Jesse Zhang

Set smu work laod mask may fail, so check return.

---
 drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +4 -2
index c06e0d6e3017..f30f1facc0f6 100644
@@ -2081,9 +2081,11 @@ static int navi10_set_power_profile_mode(struct smu_context *smu, long *input, u
 						       smu->power_profile_mode);
 	if (workload_type < 0)
 		return -EINVAL;
-	smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetWorkloadMask,
+	ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetWorkloadMask,
 				    1 << workload_type, NULL);
-
+	if (ret)
+		dev_err(smu->adev->dev, "[%s] Failed to set work load mask!", __func__);
+	
 	return ret;
 }
 
Signature · 1 line
2.25.1
Reviewed-by on v1 7/22
#16 lore raw

RE: [PATCH 07/22] drm/amd/pm: check the return of send smc msg for navi10

[AMD Official Use Only - General]

This patch is,

Quoted 42 lines

-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 07/22] drm/amd/pm: check the return of send smc msg for navi10

Set smu work laod mask may fail, so check return.

---
 drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +0 -0
index c06e0d6e3017..f30f1facc0f6 100644
@@ -2081,9 +2081,11 @@ static int navi10_set_power_profile_mode(struct

smu_context *smu, long *input, u

                                                     smu->power_profile_mode);
      if (workload_type < 0)
              return -EINVAL;

- smu_cmn_send_smc_msg_with_param(smu,
SMU_MSG_SetWorkloadMask,
+ ret = smu_cmn_send_smc_msg_with_param(smu,
SMU_MSG_SetWorkloadMask,

                                  1 << workload_type, NULL);
drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +2 -1
-
+     if (ret)
+             dev_err(smu->adev->dev, "[%s] Failed to set work load mask!",

__func__);
+

      return ret;

}

--
2.25.1

#17 lore raw

PATCH 8/22 drm/amd/pm: check the return of send smc msg for smu_v13

In reply to Jesse Zhang

Set smu work laod mask may fail, so check return.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +3 -1
index e996a0a4d33e..dcb68ab51fa0 100644
@@ -2495,8 +2495,10 @@ static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *inp
 						       smu->power_profile_mode);
 	if (workload_type < 0)
 		return -EINVAL;
-	smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetWorkloadMask,
+	ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetWorkloadMask,
 				    1 << workload_type, NULL);
+	if (ret)
+		dev_err(smu->adev->dev, "[%s] Failed to set work load mask!", __func__);
 
 	return ret;
 }
Signature · 1 line
2.25.1
Reviewed-by on v1 8/22
#18 lore raw

RE: [PATCH 08/22] drm/amd/pm: check the return of send smc msg for smu_v13

[AMD Official Use Only - General]

This patch is,

Quoted 42 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 08/22] drm/amd/pm: check the return of send smc msg for smu_v13

Set smu work laod mask may fail, so check return.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +0 -0
index e996a0a4d33e..dcb68ab51fa0 100644
@@ -2495,8 +2495,10 @@ static int

smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *inp

                                                     smu->power_profile_mode);
      if (workload_type < 0)
              return -EINVAL;

- smu_cmn_send_smc_msg_with_param(smu,
SMU_MSG_SetWorkloadMask,
+ ret = smu_cmn_send_smc_msg_with_param(smu,
SMU_MSG_SetWorkloadMask,

                                  1 << workload_type, NULL);
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +2 -0
+     if (ret)
+             dev_err(smu->adev->dev, "[%s] Failed to set work load mask!",

__func__);

      return ret;

}
--
2.25.1

#19 lore raw

PATCH 9/22 drm/amd/pm: check specific index for smu13

In reply to Jesse Zhang

Check for specific indexes that may be invalid values.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +2 -0
index 051092f1b1b4..7c343dd12a7f 100644
@@ -2336,6 +2336,8 @@ static int smu_v13_0_6_mode2_reset(struct smu_context *smu)
 
 	index = smu_cmn_to_asic_specific_index(smu, CMN2ASIC_MAPPING_MSG,
 					       SMU_MSG_GfxDeviceDriverReset);
+	if (index < 0)
+		ret = -EINVAL;
 
 	mutex_lock(&smu->message_lock);
 
Signature · 1 line
2.25.1
Reviewed-by on v1 9/22
#20 lore raw

RE: [PATCH 09/22] drm/amd/pm: check specific index for smu13

[AMD Official Use Only - General]

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 09/22] drm/amd/pm: check specific index for smu13

Check for specific indexes that may be invalid values.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +2 -0
index 051092f1b1b4..7c343dd12a7f 100644
@@ -2336,6 +2336,8 @@ static int smu_v13_0_6_mode2_reset(struct smu_context *smu)
 
        index = smu_cmn_to_asic_specific_index(smu, CMN2ASIC_MAPPING_MSG,
                                               SMU_MSG_GfxDeviceDriverReset);
+       if (index < 0)
+               ret = -EINVAL;
 
        mutex_lock(&smu->message_lock);
 

--
2.25.1

#21 lore raw

RE: [PATCH 09/22] drm/amd/pm: check specific index for smu13

In reply to Jesse Zhang

[AMD Official Use Only - General]

Hi Jesse,

Quoted 24 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 09/22] drm/amd/pm: check specific index for smu13

Check for specific indexes that may be invalid values.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +0 -0
index 051092f1b1b4..7c343dd12a7f 100644

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c static int smu_v13_0_6_mode2_reset(struct · line 2342

Quoted 7 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +2 -0
@@ -2336,6 +2336,8 @@ static int smu_v13_0_6_mode2_reset(struct
 smu_context *smu)
 
      index = smu_cmn_to_asic_specific_index(smu,
 CMN2ASIC_MAPPING_MSG,
                                             SMU_MSG_GfxDeviceDriverReset);
+     if (index < 0)
+             ret = -EINVAL;

We should need to return the index here?

Tim

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +0 -1
      mutex_lock(&smu->message_lock);
 
--

2.25.1

#22 lore raw

RE: [PATCH 09/22] drm/amd/pm: check specific index for smu13

[AMD Official Use Only - General]

HI Tim

-----Original Message-----
From: Huang, Tim <[email protected]>
Sent: Friday, May 10, 2024 2:37 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: RE: [PATCH 09/22] drm/amd/pm: check specific index for smu13

[AMD Official Use Only - General]

Hi Jesse,

Quoted 24 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 09/22] drm/amd/pm: check specific index for smu13

Check for specific indexes that may be invalid values.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +0 -0
index 051092f1b1b4..7c343dd12a7f 100644

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c static int smu_v13_0_6_mode2_reset(struct · line 2343

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +2 -0
@@ -2336,6 +2336,8 @@ static int smu_v13_0_6_mode2_reset(struct
 smu_context *smu)
 
      index = smu_cmn_to_asic_specific_index(smu,
 CMN2ASIC_MAPPING_MSG,
 
 SMU_MSG_GfxDeviceDriverReset);
+     if (index < 0)
+             ret = -EINVAL;

We should need to return the index here?
[Zhang, Jesse(Jie)] Thanks Tim. Yes, I will another patch for it .

Tim

Quoted 5 lines
      mutex_lock(&smu->message_lock);

--
2.25.1

#23 lore raw

Re: [PATCH 09/22] drm/amd/pm: check specific index for smu13

In reply to Jesse Zhang
Quoted 12 lines · Jesse Zhang

Check for specific indexes that may be invalid values.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +0 -0
index 051092f1b1b4..7c343dd12a7f 100644

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c static int smu_v13_0_6_mode2_reset(struct smu_context *smu) · line 2341

Quoted 6 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +2 -0
@@ -2336,6 +2336,8 @@ static int smu_v13_0_6_mode2_reset(struct smu_context *smu)
 
 	index = smu_cmn_to_asic_specific_index(smu, CMN2ASIC_MAPPING_MSG,
 					       SMU_MSG_GfxDeviceDriverReset);
+	if (index < 0)
+		ret = -EINVAL;
 

This check is unnecessary. This is IP specific logic and the index is expected to exist.

See this entry in smu_v13_0_6_message_map

MSG_MAP(GfxDeviceDriverReset, PPSMC_MSG_GfxDriverReset,

               SMU_MSG_RAS_PRI),

Thanks,
Lijo

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +0 -0
 	mutex_lock(&smu->message_lock);
 
#24 lore raw

Re: [PATCH 09/22] drm/amd/pm: check specific index for smu13

Quoted 16 lines · Lijo
Quoted 13 lines · Jesse Zhang

Check for specific indexes that may be invalid values.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +0 -0
index 051092f1b1b4..7c343dd12a7f 100644
@@ -2336,6 +2336,8 @@ static int smu_v13_0_6_mode2_reset(struct smu_context *smu)
 
Quoted 9 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c static int smu_v13_0_6_mode2_reset(struct smu_context *smu) · line 2341

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +2 -0
 	index = smu_cmn_to_asic_specific_index(smu, CMN2ASIC_MAPPING_MSG,
 					       SMU_MSG_GfxDeviceDriverReset);
+	if (index < 0)
+		ret = -EINVAL;
 

This check is unnecessary. This is IP specific logic and the index is expected to exist.

If you are seeing a warning problem because of this, drop index and use PPSMC_MSG_GfxDriverReset directly.

Thanks,
Lijo

Quoted 10 lines

See this entry in smu_v13_0_6_message_map

MSG_MAP(GfxDeviceDriverReset, PPSMC_MSG_GfxDriverReset,

               SMU_MSG_RAS_PRI),
Quoted 1 line

Thanks,
Lijo

Quoted 2 lines

mutex_lock(&smu->message_lock);

#25 lore raw

PATCH 10/22 drm/amdgpu: remove structurally dead code

In reply to Jesse Zhang

This code cannot be reached: return "UNKNOWN";.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -2
index 9a946f0e015c..109f471ff315 100644
@@ -554,8 +554,6 @@ static inline const char *amdgpu_gfx_compute_mode_desc(int mode)
 	default:
 		return "UNKNOWN";
 	}
-
-	return "UNKNOWN";
 }
 
 #endif
Signature · 1 line
2.25.1
Reviewed-by on v1 10/22
#26 lore raw

RE: [PATCH 10/22] drm/amdgpu: remove structurally dead code

[AMD Official Use Only - General]

This patch is,

Quoted 35 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 10/22] drm/amdgpu: remove structurally dead code

This code cannot be reached: return "UNKNOWN";.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -2
index 9a946f0e015c..109f471ff315 100644
@@ -554,8 +554,6 @@ static inline const char
 *amdgpu_gfx_compute_mode_desc(int mode)
      default:
              return "UNKNOWN";
      }
-
-     return "UNKNOWN";
 }
 

#endif
--
2.25.1

#27 lore raw

PATCH 11/22 drm/amdgpu: remove structurally dead code for amd_gmc

In reply to Jesse Zhang

This code cannot be reached: return sysfs_emit(buf, "UNK....)

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -2
index a5f970fec242..f8ed886ffca3 100644
@@ -1148,8 +1148,6 @@ static ssize_t current_memory_partition_show(
 	default:
 		return sysfs_emit(buf, "UNKNOWN\n");
 	}
-
-	return sysfs_emit(buf, "UNKNOWN\n");
 }
 
 static DEVICE_ATTR_RO(current_memory_partition);
Signature · 1 line
2.25.1
Reviewed-by on v1 11/22
#28 lore raw

RE: [PATCH 11/22] drm/amdgpu: remove structurally dead code for amd_gmc

[AMD Official Use Only - General]

This patch is,

Quoted 34 lines

-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 11/22] drm/amdgpu: remove structurally dead code for amd_gmc

This code cannot be reached: return sysfs_emit(buf, "UNK....)

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -3
index a5f970fec242..f8ed886ffca3 100644
@@ -1148,8 +1148,6 @@ static ssize_t current_memory_partition_show(
      default:
              return sysfs_emit(buf, "UNKNOWN\n");
      }
-
-     return sysfs_emit(buf, "UNKNOWN\n");
 }
 
 static DEVICE_ATTR_RO(current_memory_partition);
--

2.25.1

#29 lore raw

PATCH 12/22 drm/amd/pm: remove logically dead code

In reply to Jesse Zhang

Execution cannot reach this statement: case POWER_STATE_TYPE_BALAN.

---
 drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c | 9 ---------
 1 file changed, 9 deletions(-)
drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -9
index 60377747bab4..e861355ebd75 100644
@@ -831,15 +831,6 @@ static struct amdgpu_ps *amdgpu_dpm_pick_power_state(struct amdgpu_device *adev,
 					return ps;
 			}
 			break;
-		case POWER_STATE_TYPE_BALANCED:
-			if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BALANCED) {
-				if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
-					if (single_display)
-						return ps;
-				} else
-					return ps;
-			}
-			break;
 		case POWER_STATE_TYPE_PERFORMANCE:
 			if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) {
 				if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
Signature · 1 line
2.25.1
#30 lore raw

RE: [PATCH 12/22] drm/amd/pm: remove logically dead code

[AMD Official Use Only - AMD Internal Distribution Only]

Ping ...

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 12/22] drm/amd/pm: remove logically dead code

Execution cannot reach this statement: case POWER_STATE_TYPE_BALAN.

---
 drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c | 9 ---------
 1 file changed, 9 deletions(-)
drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -9
index 60377747bab4..e861355ebd75 100644
@@ -831,15 +831,6 @@ static struct amdgpu_ps *amdgpu_dpm_pick_power_state(struct amdgpu_device *adev,
                                        return ps;
                        }
                        break;
-               case POWER_STATE_TYPE_BALANCED:
-                       if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BALANCED) {
-                               if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
-                                       if (single_display)
-                                               return ps;
-                               } else
-                                       return ps;
-                       }
-                       break;
                case POWER_STATE_TYPE_PERFORMANCE:
                        if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) {
                                if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {

--
2.25.1

#31 lore raw

RE: [PATCH 12/22] drm/amd/pm: remove logically dead code

[AMD Official Use Only - AMD Internal Distribution Only]

Best Regards,
Kevin

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Zhang, Jesse(Jie)
Sent: Monday, May 13, 2024 10:19 AM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>
Subject: RE: [PATCH 12/22] drm/amd/pm: remove logically dead code

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

Ping ...

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 12/22] drm/amd/pm: remove logically dead code

Execution cannot reach this statement: case POWER_STATE_TYPE_BALAN.

---
 drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c | 9 ---------
 1 file changed, 9 deletions(-)
drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -9
index 60377747bab4..e861355ebd75 100644
@@ -831,15 +831,6 @@ static struct amdgpu_ps *amdgpu_dpm_pick_power_state(struct amdgpu_device *adev,
                                        return ps;
                        }
                        break;
-               case POWER_STATE_TYPE_BALANCED:
-                       if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BALANCED) {
-                               if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
-                                       if (single_display)
-                                               return ps;
-                               } else
-                                       return ps;
-                       }
-                       break;
                case POWER_STATE_TYPE_PERFORMANCE:
                        if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) {
                                if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {

--
2.25.1

#32 lore raw

PATCH 13/22 drm/amd/pm: remove logically dead code for renoir

In reply to Jesse Zhang

The switch governing value clk_type cannot be SMU_GFXCLK and SMU_SCLK.

---
 drivers/gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c +0 -2
index aeeba0d95c9c..cc0504b063fa 100644
@@ -585,8 +585,6 @@ static int renoir_print_clk_levels(struct smu_context *smu,
 	}
 
 	switch (clk_type) {
-	case SMU_GFXCLK:
-	case SMU_SCLK:
 	case SMU_SOCCLK:
 	case SMU_MCLK:
 	case SMU_DCEFCLK:
Signature · 1 line
2.25.1
Reviewed-by on v1 13/22
#33 lore raw

RE: [PATCH 13/22] drm/amd/pm: remove logically dead code for renoir

[AMD Official Use Only - General]

Please add following information into commit message.

Fixes ca55f459f5ad ("drm/amd/pm: add the fine grain tuning function for Renoir")

Best Regards,
Kevin

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 13/22] drm/amd/pm: remove logically dead code for renoir

The switch governing value clk_type cannot be SMU_GFXCLK and SMU_SCLK.

---
 drivers/gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c +0 -2
index aeeba0d95c9c..cc0504b063fa 100644
@@ -585,8 +585,6 @@ static int renoir_print_clk_levels(struct smu_context *smu,
        }
 
        switch (clk_type) {
-       case SMU_GFXCLK:
-       case SMU_SCLK:
        case SMU_SOCCLK:
        case SMU_MCLK:
        case SMU_DCEFCLK:

--
2.25.1

#34 lore raw

PATCH 14/22 drm/amdgu: remove unused code

In reply to Jesse Zhang

The same code is executed when the condition err is true or false, because the code in the if-then branch and after the if statement is identical

---
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +0 -2
index 541dbd70d8c7..16d3deac375d 100644
@@ -963,8 +963,6 @@ static int gfx_v7_0_init_microcode(struct amdgpu_device *adev)
 
 	snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_rlc.bin", chip_name);
 	err = amdgpu_ucode_request(adev, &adev->gfx.rlc_fw, fw_name);
-	if (err)
-		goto out;
 out:
 	if (err) {
 		pr_err("gfx7: Failed to load firmware \"%s\"\n", fw_name);
Signature · 1 line
2.25.1
Reviewed-by on v1 14/22
#35 lore raw

RE: [PATCH 14/22] drm/amdgu: remove unused code

[AMD Official Use Only - General]

This patch is,

Quoted 36 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:51 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 14/22] drm/amdgu: remove unused code

The same code is executed when the condition err is true or false, because the code in the if-then branch and after the if statement is identical

---
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +0 -2
index 541dbd70d8c7..16d3deac375d 100644
@@ -963,8 +963,6 @@ static int gfx_v7_0_init_microcode(struct
 amdgpu_device *adev)
 
      snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_rlc.bin", chip_name);
      err = amdgpu_ucode_request(adev, &adev->gfx.rlc_fw, fw_name);
-     if (err)
-             goto out;
 out:
      if (err) {
              pr_err("gfx7: Failed to load firmware \"%s\"\n", fw_name);

--
2.25.1

#36 lore raw

PATCH 15/22 drm/amd/pm: fix enum feature compared against 0

In reply to Jesse Zhang

This less-than-zero comparison of an unsigned value is never true. feature < 0U

---
 drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -1
index 6d1c3af927ca..d439b95bfb79 100644
@@ -760,7 +760,7 @@ static const char *__smu_feature_names[] = {
 static const char *smu_get_feature_name(struct smu_context *smu,
 					enum smu_feature_mask feature)
 {
-	if (feature < 0 || feature >= SMU_FEATURE_COUNT)
+	if (feature >= SMU_FEATURE_COUNT)
 		return "unknown smu feature";
 	return __smu_feature_names[feature];
 }
Signature · 1 line
2.25.1
Reviewed-by on v1 15/22
#37 lore raw

RE: [PATCH 15/22] drm/amd/pm: fix enum feature compared against 0

[AMD Official Use Only - General]

Best Regards,
Kevin

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:51 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 15/22] drm/amd/pm: fix enum feature compared against 0

This less-than-zero comparison of an unsigned value is never true. feature < 0U

---
 drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -2
index 6d1c3af927ca..d439b95bfb79 100644
@@ -760,7 +760,7 @@ static const char *__smu_feature_names[] = {  static const char *smu_get_feature_name(struct smu_context *smu,
                                        enum smu_feature_mask feature)
 {
-       if (feature < 0 || feature >= SMU_FEATURE_COUNT)
+       if (feature >= SMU_FEATURE_COUNT)
                return "unknown smu feature";
        return __smu_feature_names[feature];
 }
--

2.25.1

Reviewed-by on v1 15/22
#38 lore raw

RE: [PATCH 15/22] drm/amd/pm: fix enum feature compared against 0

In reply to Jesse Zhang

[AMD Official Use Only - General]

This patch is,

Quoted 34 lines

-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Friday, May 10, 2024 10:51 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 15/22] drm/amd/pm: fix enum feature compared against 0

This less-than-zero comparison of an unsigned value is never true. feature < 0U

---
 drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -2
index 6d1c3af927ca..d439b95bfb79 100644
@@ -760,7 +760,7 @@ static const char *__smu_feature_names[] =
 {  static const char *smu_get_feature_name(struct smu_context *smu,
                                      enum smu_feature_mask feature)
 {
-     if (feature < 0 || feature >= SMU_FEATURE_COUNT)
+     if (feature >= SMU_FEATURE_COUNT)
              return "unknown smu feature";
      return __smu_feature_names[feature];
 }
--

2.25.1

#39 lore raw

PATCH 16/22 drm/amd/pm: fix enum type compared against 0

In reply to Jesse Zhang

This less-than-zero comparison of an unsigned value is never true. type < 0U

---
 drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -1
index d439b95bfb79..602aa6941231 100644
@@ -56,7 +56,7 @@ static const char * const __smu_message_names[] = {
 static const char *smu_get_message_name(struct smu_context *smu,
 					enum smu_message_type type)
 {
-	if (type < 0 || type >= SMU_MSG_MAX_COUNT)
+	if (type >= SMU_MSG_MAX_COUNT)
 		return "unknown smu message";
 
 	return __smu_message_names[type];
Signature · 1 line
2.25.1
Reviewed-by on v1 16/22
#40 lore raw

RE: [PATCH 16/22] drm/amd/pm: fix enum type compared against 0

[AMD Official Use Only - General]

This patch is,

Quoted 34 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:51 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 16/22] drm/amd/pm: fix enum type compared against 0

This less-than-zero comparison of an unsigned value is never true. type < 0U

---
 drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -2
index d439b95bfb79..602aa6941231 100644
@@ -56,7 +56,7 @@ static const char * const __smu_message_names[] =
 {  static const char *smu_get_message_name(struct smu_context *smu,
                                      enum smu_message_type type)
 {
-     if (type < 0 || type >= SMU_MSG_MAX_COUNT)
+     if (type >= SMU_MSG_MAX_COUNT)
              return "unknown smu message";
 
      return __smu_message_names[type];
--

2.25.1

#41 lore raw

PATCH 17/22 drm/amdgpu: fix the warning bad bit shift operation for aca_error_type type

In reply to Jesse Zhang

Filter invalid aca error types before performing a shift operation.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c +1 -1
index 28febf33fb1b..9e3560c190e3 100644
@@ -534,7 +534,7 @@ int amdgpu_aca_get_error_data(struct amdgpu_device *adev, struct aca_handle *han
 	if (aca_handle_is_valid(handle))
 		return -EOPNOTSUPP;
 
-	if (!(BIT(type) & handle->mask))
+	if ((type < 0) || (!(BIT(type) & handle->mask)))
 		return  0;
 
 	return __aca_get_error_data(adev, handle, type, err_data, qctx);
Signature · 1 line
2.25.1
#42 lore raw

RE: [PATCH 17/22] drm/amdgpu: fix the warning bad bit shift operation for aca_error_type type

[AMD Official Use Only - AMD Internal Distribution Only]

Ping ...

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:51 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 17/22] drm/amdgpu: fix the warning bad bit shift operation for aca_error_type type

Filter invalid aca error types before performing a shift operation.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c +1 -1
index 28febf33fb1b..9e3560c190e3 100644
@@ -534,7 +534,7 @@ int amdgpu_aca_get_error_data(struct amdgpu_device *adev, struct aca_handle *han
        if (aca_handle_is_valid(handle))
                return -EOPNOTSUPP;
 
-       if (!(BIT(type) & handle->mask))
+       if ((type < 0) || (!(BIT(type) & handle->mask)))
                return  0;
 
        return __aca_get_error_data(adev, handle, type, err_data, qctx);

--
2.25.1

Reviewed-by
#43 lore raw

RE: [PATCH 17/22] drm/amdgpu: fix the warning bad bit shift operation for aca_error_type type

[AMD Official Use Only - AMD Internal Distribution Only]

Best Regards,
Kevin

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Zhang, Jesse(Jie)
Sent: Monday, May 13, 2024 10:19 AM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>
Subject: RE: [PATCH 17/22] drm/amdgpu: fix the warning bad bit shift operation for aca_error_type type

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

Ping ...

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:51 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 17/22] drm/amdgpu: fix the warning bad bit shift operation for aca_error_type type

Filter invalid aca error types before performing a shift operation.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c +1 -1
index 28febf33fb1b..9e3560c190e3 100644
@@ -534,7 +534,7 @@ int amdgpu_aca_get_error_data(struct amdgpu_device *adev, struct aca_handle *han
        if (aca_handle_is_valid(handle))
                return -EOPNOTSUPP;
 
-       if (!(BIT(type) & handle->mask))
+       if ((type < 0) || (!(BIT(type) & handle->mask)))
                return  0;
 
        return __aca_get_error_data(adev, handle, type, err_data, qctx);

--
2.25.1

#44 lore raw

PATCH 18/22 drm/amd/pm: check negtive return for table entries

In reply to Jesse Zhang

Function hwmgr->hwmgr_func->get_num_of_pp_table_entries(hwmgr) returns a negative number

---
 drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c +2 -3
index f4bd8e9357e2..4433ec4e9cf2 100644
@@ -30,9 +30,8 @@ int psm_init_power_state_table(struct pp_hwmgr *hwmgr)
 {
 	int result;
 	unsigned int i;
-	unsigned int table_entries;
 	struct pp_power_state *state;
-	int size;
+	int size, table_entries;
 
 	if (hwmgr->hwmgr_func->get_num_of_pp_table_entries == NULL)
 		return 0;
@@ -45,7 +44,7 @@ int psm_init_power_state_table(struct pp_hwmgr *hwmgr)
 	hwmgr->ps_size = size = hwmgr->hwmgr_func->get_power_state_size(hwmgr) +
 					  sizeof(struct pp_power_state);
 
-	if (table_entries == 0 || size == 0) {
+	if (table_entries <= 0 || size == 0) {
 		pr_warn("Please check whether power state management is supported on this asic\n");
 		return 0;
 	}
Signature · 1 line
2.25.1
#45 lore raw

RE: [PATCH 18/22] drm/amd/pm: check negtive return for table entries

[AMD Official Use Only - AMD Internal Distribution Only]

Ping ...

-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Friday, May 10, 2024 10:51 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 18/22] drm/amd/pm: check negtive return for table entries

Function hwmgr->hwmgr_func->get_num_of_pp_table_entries(hwmgr) returns a negative number

---
 drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c +2 -3
index f4bd8e9357e2..4433ec4e9cf2 100644
@@ -30,9 +30,8 @@ int psm_init_power_state_table(struct pp_hwmgr *hwmgr)  {
        int result;
        unsigned int i;
-       unsigned int table_entries;
        struct pp_power_state *state;
-       int size;
+       int size, table_entries;
 
        if (hwmgr->hwmgr_func->get_num_of_pp_table_entries == NULL)
                return 0;
@@ -45,7 +44,7 @@ int psm_init_power_state_table(struct pp_hwmgr *hwmgr)
        hwmgr->ps_size = size = hwmgr->hwmgr_func->get_power_state_size(hwmgr) +
                                          sizeof(struct pp_power_state);
 
-       if (table_entries == 0 || size == 0) {
+       if (table_entries <= 0 || size == 0) {
                pr_warn("Please check whether power state management is supported on this asic\n");
                return 0;
        }

--
2.25.1

#46 lore raw

RE: [PATCH 18/22] drm/amd/pm: check negtive return for table entries

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Jesse,

Quoted 59 lines

-----Original Message-----
From: Zhang, Jesse(Jie) <[email protected]>
Sent: Monday, May 13, 2024 10:19 AM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>
Subject: RE: [PATCH 18/22] drm/amd/pm: check negtive return for table entries

[AMD Official Use Only - AMD Internal Distribution Only]

Ping ...

-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Friday, May 10, 2024 10:51 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 18/22] drm/amd/pm: check negtive return for table entries

Function hwmgr->hwmgr_func->get_num_of_pp_table_entries(hwmgr) returns a negative number

---
 drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c +1 -2
index f4bd8e9357e2..4433ec4e9cf2 100644
@@ -30,9 +30,8 @@ int psm_init_power_state_table(struct pp_hwmgr
 *hwmgr)  {
        int result;
        unsigned int i;
-       unsigned int table_entries;
        struct pp_power_state *state;
-       int size;
+       int size, table_entries;
 
        if (hwmgr->hwmgr_func->get_num_of_pp_table_entries == NULL)
                return 0;
@@ -45,7 +44,7 @@ int psm_init_power_state_table(struct pp_hwmgr
 *hwmgr)
        hwmgr->ps_size = size =

hwmgr->hwmgr_func->get_power_state_size(hwmgr) +
sizeof(struct
pp_power_state);

drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c +1 -1
-       if (table_entries == 0 || size == 0) {
+       if (table_entries <= 0 || size == 0) {
                pr_warn("Please check whether power state

management is supported on this asic\n");

Quoted 2 lines
                return 0;
        }

We should need to check this before set the hwmgr->num_ps and hwmgr->ps_size, otherwise we may have incorrect hwmgr->num_ps if meet the condition table_entries < 0.

Tim Huang

Quoted 3 lines

--
2.25.1

#47 lore raw

PATCH 19/22 drm/amdgpu: Fix the warning division or modulo by zero for the variable num_xcc_per_xcp

In reply to Jesse Zhang

Dividing expression num_xcc_per_xcp which may be zero has undefined behavior.

---
 drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +3 -0
index 414ea3f560a7..5752c6760992 100644
@@ -522,6 +522,9 @@ static int aqua_vanjaram_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr,
 		goto unlock;
 
 	num_xcc_per_xcp = __aqua_vanjaram_get_xcc_per_xcp(xcp_mgr, mode);
+	if (!num_xcc_per_xcp)
+		goto unlock;
+
 	if (adev->gfx.funcs->switch_partition_mode)
 		adev->gfx.funcs->switch_partition_mode(xcp_mgr->adev,
 						       num_xcc_per_xcp);
Signature · 1 line
2.25.1
Reviewed-by on v1 19/22
#48 lore raw

RE: [PATCH 19/22] drm/amdgpu: Fix the warning division or modulo by zero for the variable num_xcc_per_xcp

[AMD Official Use Only - General]

This patch is,

Quoted 39 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:51 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 19/22] drm/amdgpu: Fix the warning division or modulo by zero for the variable num_xcc_per_xcp

Dividing expression num_xcc_per_xcp which may be zero has undefined behavior.

---
 drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +3 -0
index 414ea3f560a7..5752c6760992 100644
@@ -522,6 +522,9 @@ static int
 aqua_vanjaram_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr,
              goto unlock;
 
      num_xcc_per_xcp = __aqua_vanjaram_get_xcc_per_xcp(xcp_mgr,
 mode);
+     if (!num_xcc_per_xcp)
+             goto unlock;
+
      if (adev->gfx.funcs->switch_partition_mode)
              adev->gfx.funcs->switch_partition_mode(xcp_mgr->adev,
                                                     num_xcc_per_xcp);

--
2.25.1

#49 lore raw

Re: [PATCH 19/22] drm/amdgpu: Fix the warning division or modulo by zero for the variable num_xcc_per_xcp

In reply to Jesse Zhang
Quoted 12 lines · Jesse Zhang

Dividing expression num_xcc_per_xcp which may be zero has undefined behavior.

---
 drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +0 -0
index 414ea3f560a7..5752c6760992 100644

drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c static int aqua_vanjaram_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr, · line 527

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +3 -0
@@ -522,6 +522,9 @@ static int aqua_vanjaram_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr,
 		goto unlock;
 
 	num_xcc_per_xcp = __aqua_vanjaram_get_xcc_per_xcp(xcp_mgr, mode);
+	if (!num_xcc_per_xcp)
+		goto unlock;
+

This won't happen as the mode is validated before and for each valid mode a non-zero num_xcc_per_xcp is expected. To satisfy the warning-checker, before going to unlock use a proper 'ret' value also (otherwise it will look odd).

Thanks,
Lijo

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +0 -0
 	if (adev->gfx.funcs->switch_partition_mode)
 		adev->gfx.funcs->switch_partition_mode(xcp_mgr->adev,
 						       num_xcc_per_xcp);
#50 lore raw

RE: [PATCH 19/22] drm/amdgpu: Fix the warning division or modulo by zero for the variable num_xcc_per_xcp

[AMD Official Use Only - General]

Hi Lijo,

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Lazar, Lijo
Sent: Friday, May 10, 2024 3:16 PM
To: [email protected]
Subject: Re: [PATCH 19/22] drm/amdgpu: Fix the warning division or modulo by zero for the variable num_xcc_per_xcp

Quoted 13 lines · Jesse Zhang

Dividing expression num_xcc_per_xcp which may be zero has undefined behavior.

---
 drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +0 -0
index 414ea3f560a7..5752c6760992 100644

drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c static int aqua_vanjaram_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr, · line 527

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +3 -0
@@ -522,6 +522,9 @@ static int aqua_vanjaram_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr,
              goto unlock;
 
      num_xcc_per_xcp = __aqua_vanjaram_get_xcc_per_xcp(xcp_mgr, mode);
+     if (!num_xcc_per_xcp)
+             goto unlock;
+

This won't happen as the mode is validated before and for each valid mode a non-zero num_xcc_per_xcp is expected. To satisfy the warning-checker, before going to unlock use a proper 'ret' value also (otherwise it will look odd).

[Zhang, Jesse(Jie)] Is that possible?
When the initialization mode is AMDGPU_AUTO_COMPUTE_PARTITION_MODE, and get AMDGPU_UNKNOWN_COMPUTE_PARTITION_MODE through __aqua_vanjaram_get_auto_mode.

If so, it will skip the valid mode function (__aqua_vanjaram_is_valid_mode).

Thanks
Jesse

Thanks,
Lijo

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +0 -0
      if (adev->gfx.funcs->switch_partition_mode)
              adev->gfx.funcs->switch_partition_mode(xcp_mgr->adev,
                                                     num_xcc_per_xcp);
#51 lore raw

Re: [PATCH 19/22] drm/amdgpu: Fix the warning division or modulo by zero for the variable num_xcc_per_xcp

Quoted 35 lines · Jesse(Jie)

[AMD Official Use Only - General]

Hi Lijo,

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Lazar, Lijo
Sent: Friday, May 10, 2024 3:16 PM
To: [email protected]
Subject: Re: [PATCH 19/22] drm/amdgpu: Fix the warning division or modulo by zero for the variable num_xcc_per_xcp

Quoted 13 lines · Jesse Zhang

Dividing expression num_xcc_per_xcp which may be zero has undefined behavior.

---
 drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +0 -0
index 414ea3f560a7..5752c6760992 100644

drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c static int aqua_vanjaram_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr, · line 527

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +3 -0
@@ -522,6 +522,9 @@ static int aqua_vanjaram_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr,
              goto unlock;
 
      num_xcc_per_xcp = __aqua_vanjaram_get_xcc_per_xcp(xcp_mgr, mode);
+     if (!num_xcc_per_xcp)
+             goto unlock;
+

This won't happen as the mode is validated before and for each valid mode a non-zero num_xcc_per_xcp is expected. To satisfy the warning-checker, before going to unlock use a proper 'ret' value also (otherwise it will look odd).

Quoted 6 lines

[Zhang, Jesse(Jie)] Is that possible?
When the initialization mode is AMDGPU_AUTO_COMPUTE_PARTITION_MODE, and get AMDGPU_UNKNOWN_COMPUTE_PARTITION_MODE through __aqua_vanjaram_get_auto_mode.

If so, it will skip the valid mode function (__aqua_vanjaram_is_valid_mode).

Yes, that is possible. If auto detection cannot figure out a valid mode, then it needs to return an error from there without proceeding further. That is a better fix.

Thanks,
Lijo

Quoted 10 lines

Thanks
Jesse

Thanks,
Lijo

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +0 -0
      if (adev->gfx.funcs->switch_partition_mode)
              adev->gfx.funcs->switch_partition_mode(xcp_mgr->adev,
                                                     num_xcc_per_xcp);
#52 lore raw

PATCH 20/22 drm/amd/pm: fix get dpm level count for smu13

In reply to Jesse Zhang

For invalid clk types, return -EINVAL to check the return.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c +1 -1
index 59854465d711..9c2c43bfed0b 100644
@@ -643,7 +643,7 @@ static int smu_v13_0_5_get_dpm_level_count(struct smu_context *smu,
 		*count = clk_table->NumDfPstatesEnabled;
 		break;
 	default:
-		break;
+		return -EINVAL;
 	}
 
 	return 0;
Signature · 1 line
2.25.1
Reviewed-by on v1 20/22
#53 lore raw

RE: [PATCH 20/22] drm/amd/pm: fix get dpm level count for smu13

[AMD Official Use Only - General]

Best Regards,
Yifan

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:51 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 20/22] drm/amd/pm: fix get dpm level count for smu13

For invalid clk types, return -EINVAL to check the return.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c +1 -1
index 59854465d711..9c2c43bfed0b 100644
@@ -643,7 +643,7 @@ static int smu_v13_0_5_get_dpm_level_count(struct smu_context *smu,
                *count = clk_table->NumDfPstatesEnabled;
                break;
        default:
-               break;
+               return -EINVAL;
        }
 
        return 0;

--
2.25.1

#54 lore raw

PATCH 21/22 drm/amd/pm: fix get dpm level count for yello carp

In reply to Jesse Zhang

For invalid clk types, return -EINVAL to check the return.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/yellow_carp_ppt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/yellow_carp_ppt.c +1 -1
index 5917c88cc87d..260c339f89c5 100644
@@ -777,7 +777,7 @@ static int yellow_carp_get_dpm_level_count(struct smu_context *smu,
 		*count = clk_table->NumDfPstatesEnabled;
 		break;
 	default:
-		break;
+		return -EINVAL;
 	}
 
 	return 0;
Signature · 1 line
2.25.1
Reviewed-by on v1 21/22
#55 lore raw

RE: [PATCH 21/22] drm/amd/pm: fix get dpm level count for yello carp

[AMD Official Use Only - General]

Best Regards,
Yifan

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:51 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 21/22] drm/amd/pm: fix get dpm level count for yello carp

For invalid clk types, return -EINVAL to check the return.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/yellow_carp_ppt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/yellow_carp_ppt.c +1 -1
index 5917c88cc87d..260c339f89c5 100644
@@ -777,7 +777,7 @@ static int yellow_carp_get_dpm_level_count(struct smu_context *smu,
                *count = clk_table->NumDfPstatesEnabled;
                break;
        default:
-               break;
+               return -EINVAL;
        }
 
        return 0;

--
2.25.1

#56 lore raw

PATCH 22/22 drm/amdgpu: clear the warning unsigned compared against 0 for xcp_id

In reply to Jesse Zhang

This greater-than-or-equal-to-zero comparison of an unsigned value is always true. fpriv->xcp_id >= 0U

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -1
index 977cde6d1362..66782be5917b 100644
@@ -618,7 +618,7 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 			return -EINVAL;
 
 		if (adev->xcp_mgr && adev->xcp_mgr->num_xcps > 0 &&
-		    fpriv->xcp_id >= 0 && fpriv->xcp_id < adev->xcp_mgr->num_xcps) {
+		    fpriv->xcp_id < adev->xcp_mgr->num_xcps) {
 			xcp = &adev->xcp_mgr->xcp[fpriv->xcp_id];
 			switch (type) {
 			case AMD_IP_BLOCK_TYPE_GFX:
Signature · 1 line
2.25.1
Reviewed-by on v1 22/22
#57 lore raw

RE: [PATCH 22/22] drm/amdgpu: clear the warning unsigned compared against 0 for xcp_id

[AMD Official Use Only - General]

This patch is,

Quoted 37 lines

-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Friday, May 10, 2024 10:51 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 22/22] drm/amdgpu: clear the warning unsigned compared against 0 for xcp_id

This greater-than-or-equal-to-zero comparison of an unsigned value is always true. fpriv->xcp_id >= 0U

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -1
index 977cde6d1362..66782be5917b 100644
@@ -618,7 +618,7 @@ int amdgpu_info_ioctl(struct drm_device *dev, void
 *data, struct drm_file *filp)
                      return -EINVAL;
 
              if (adev->xcp_mgr && adev->xcp_mgr->num_xcps > 0 &&
-                 fpriv->xcp_id >= 0 && fpriv->xcp_id <
 adev->xcp_mgr->num_xcps) {
+                 fpriv->xcp_id < adev->xcp_mgr->num_xcps) {
                      xcp = &adev->xcp_mgr->xcp[fpriv->xcp_id];
                      switch (type) {
                      case AMD_IP_BLOCK_TYPE_GFX:

--
2.25.1

Reviewed-by on v1 1/22
#58 lore raw
In reply to Jesse Zhang

[AMD Official Use Only - General]

Quoted 38 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, May 10, 2024 10:50 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 01/22] drm/amdgpu: fix dereference after null check

check the pointer hive before use.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
index 77f6fd50002a..00fe3c2d5431 100644
@@ -5725,7 +5725,7 @@ int amdgpu_device_gpu_recover(struct
 amdgpu_device *adev,
       * to put adev in the 1st position.
       */
      INIT_LIST_HEAD(&device_list);
-     if (!amdgpu_sriov_vf(adev) && (adev->gmc.xgmi.num_physical_nodes >
 1)) {
+     if (!amdgpu_sriov_vf(adev) && (adev->gmc.xgmi.num_physical_nodes >
 1) && hive) {
              list_for_each_entry(tmp_adev, &hive->device_list, gmc.xgmi.head)
{
                      list_add_tail(&tmp_adev->reset_list, &device_list);
                      if (adev->shutdown)

--
2.25.1

#59 lore raw
In reply to Jesse Zhang

Am 10.05.24 um 04:50 schrieb Jesse Zhang:

Quoted 12 lines

check the pointer hive before use.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 77f6fd50002a..00fe3c2d5431 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev, · line 5728

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -5725,7 +5725,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
  	 * to put adev in the 1st position.
  	 */
  	INIT_LIST_HEAD(&device_list);
-	if (!amdgpu_sriov_vf(adev) && (adev->gmc.xgmi.num_physical_nodes > 1)) {
+	if (!amdgpu_sriov_vf(adev) && (adev->gmc.xgmi.num_physical_nodes > 1) && hive) {

That solution looks not optimal to me.

Checking adev->gmc.xgmi.num_physical_nodes > 1 already makes sure that hive shouldn't be NULL.

If automated checkers complain about that we should probably drop the adev->gmc.xgmi.num_physical_nodes > 1 check and check for hive instead.

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
  		list_for_each_entry(tmp_adev, &hive->device_list, gmc.xgmi.head) {
  			list_add_tail(&tmp_adev->reset_list, &device_list);
  			if (adev->shutdown)
#60 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Christian,

-----Original Message-----
From: Christian König <[email protected]>
Sent: Monday, May 13, 2024 7:41 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>
Subject: Re: [PATCH 01/22] drm/amdgpu: fix dereference after null check

Am 10.05.24 um 04:50 schrieb Jesse Zhang:

Quoted 13 lines

check the pointer hive before use.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 77f6fd50002a..00fe3c2d5431 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev, · line 5729

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -1
@@ -5725,7 +5725,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
       * to put adev in the 1st position.
       */
      INIT_LIST_HEAD(&device_list);
-     if (!amdgpu_sriov_vf(adev) && (adev->gmc.xgmi.num_physical_nodes > 1)) {
+     if (!amdgpu_sriov_vf(adev) && (adev->gmc.xgmi.num_physical_nodes >
+1) && hive) {

That solution looks not optimal to me.

Checking adev->gmc.xgmi.num_physical_nodes > 1 already makes sure that hive shouldn't be NULL.

If automated checkers complain about that we should probably drop the adev->gmc.xgmi.num_physical_nodes > 1 check and check for hive instead.

[Zhang, Jesse(Jie)]
gmc.xgmi.num_physical_nodes is obtained by reading register GCMC_VM_XGMI_LFB_CNTL. But getting hive may fail because of no memory (NOMEM),
or the kobject of xgmi hive cannot be initialized in the function amdgpu_get_xgmi_hive. Is (adev->gmc.xgmi.num_physical_nodes > 1) equivalent to (!hive) here?

Regards
Jesse

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
              list_for_each_entry(tmp_adev, &hive->device_list, gmc.xgmi.head) {
                      list_add_tail(&tmp_adev->reset_list, &device_list);
                      if (adev->shutdown)