Skip to contentSkip to conversation

drm/amdgpu/pm: Check input value for power profile setting on smu13 and smu14

PATCH In review Ma Jun 3 participants 6 messages May 9, 2024 – May 10, 2024

Subsystems (3)
lore
Share & tools
lore

Ma Jun

author
#0 lore raw

PATCH 1/2 drm/amdgpu/pm: Check input value for power profile setting on smu13 and smu14

Check the input value for CUSTOM profile mode setting on smu13 and smu14. Otherwise it may cause out-of-bouds read error.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 5 +++++
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 4 ++++
 drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c | 5 +++++
 3 files changed, 14 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +5 -0
index e8b01662e164..6c24e2306383 100644
@@ -2495,6 +2495,9 @@ static int smu_v13_0_0_set_power_profile_mode(struct smu_context *smu,
 	}
 
 	if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+		if (size != 9)
+			return -EINVAL;
+
 		ret = smu_cmn_update_table(smu,
 					   SMU_TABLE_ACTIVITY_MONITOR_COEFF,
 					   WORKLOAD_PPLIB_CUSTOM_BIT,
@@ -2526,6 +2529,8 @@ static int smu_v13_0_0_set_power_profile_mode(struct smu_context *smu,
 			activity_monitor->Fclk_PD_Data_error_coeff = input[7];
 			activity_monitor->Fclk_PD_Data_error_rate_coeff = input[8];
 			break;
+		default:
+			return -EINVAL;
 		}
 
 		ret = smu_cmn_update_table(smu,
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +4 -0
index e996a0a4d33e..4f98869e0284 100644
@@ -2450,6 +2450,8 @@ static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *inp
 	}
 
 	if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+		if (size != 8)
+			return -EINVAL;
 
 		ret = smu_cmn_update_table(smu,
 				       SMU_TABLE_ACTIVITY_MONITOR_COEFF, WORKLOAD_PPLIB_CUSTOM_BIT,
@@ -2478,6 +2480,8 @@ static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *inp
 			activity_monitor->Fclk_MinActiveFreq = input[6];
 			activity_monitor->Fclk_BoosterFreq = input[7];
 			break;
+		default:
+			return -EINVAL;
 		}
 
 		ret = smu_cmn_update_table(smu,
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c +5 -0
index 0d5ad531c764..3f040a4d374e 100644
@@ -1418,6 +1418,9 @@ static int smu_v14_0_2_set_power_profile_mode(struct smu_context *smu,
 	}
 
 	if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+		if (size != 9)
+			return -EINVAL;
+
 		ret = smu_cmn_update_table(smu,
 					   SMU_TABLE_ACTIVITY_MONITOR_COEFF,
 					   WORKLOAD_PPLIB_CUSTOM_BIT,
@@ -1449,6 +1452,8 @@ static int smu_v14_0_2_set_power_profile_mode(struct smu_context *smu,
 			activity_monitor->Fclk_PD_Data_error_coeff = input[7];
 			activity_monitor->Fclk_PD_Data_error_rate_coeff = input[8];
 			break;
+		default:
+			return -EINVAL;
 		}
 
 		ret = smu_cmn_update_table(smu,
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 2/2 drm/amdgpu/pm: Check input value for CUSTOM profile mode setting on legacy SOCs

Check the input value for CUSTOM profile mode setting on legacy SOCs. Otherwise it may cause out-of-bouds read error.

---
 drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c     | 2 +-
 drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_hwmgr.c   | 8 ++++++--
 drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c       | 5 +++++
 drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c         | 4 ++++
 drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 4 ++++
 5 files changed, 20 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c +1 -1
index 5c95eda6cbd2..52ac95f8a84f 100644
@@ -5647,7 +5647,7 @@ static int smu7_set_power_profile_mode(struct pp_hwmgr *hwmgr, long *input, uint
 	mode = input[size];
 	switch (mode) {
 	case PP_SMC_POWER_PROFILE_CUSTOM:
-		if (size < 8 && size != 0)
+		if (size != 8 && size != 0)
 			return -EINVAL;
 		/* If only CUSTOM is passed in, use the saved values. Check
 		 * that we actually have a CUSTOM profile by ensuring that
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_hwmgr.c +6 -2
index bf1b829f9d68..baf251fe5d82 100644
@@ -4102,9 +4102,11 @@ static int vega20_set_power_profile_mode(struct pp_hwmgr *hwmgr, long *input, ui
 	if (power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
 		struct vega20_hwmgr *data =
 			(struct vega20_hwmgr *)(hwmgr->backend);
-		if (size == 0 && !data->is_custom_profile_set)
+
+		if (size != 10 && size != 0)
 			return -EINVAL;
-		if (size < 10 && size != 0)
+
+		if (size == 0 && !data->is_custom_profile_set)
 			return -EINVAL;
 
 		result = vega20_get_activity_monitor_coeff(hwmgr,
@@ -4166,6 +4168,8 @@ static int vega20_set_power_profile_mode(struct pp_hwmgr *hwmgr, long *input, ui
 			activity_monitor.Fclk_PD_Data_error_coeff = input[8];
 			activity_monitor.Fclk_PD_Data_error_rate_coeff = input[9];
 			break;
+		default:
+			return -EINVAL;
 		}
 
 		result = vega20_set_activity_monitor_coeff(hwmgr,
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +5 -0
index 6d334a2aff67..623f6052f97e 100644
@@ -1416,6 +1416,9 @@ static int arcturus_set_power_profile_mode(struct smu_context *smu,
 
 	if ((profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) &&
 	     (smu->smc_fw_version >= 0x360d00)) {
+		if (size != 10)
+			return -EINVAL;
+
 		ret = smu_cmn_update_table(smu,
 				       SMU_TABLE_ACTIVITY_MONITOR_COEFF,
 				       WORKLOAD_PPLIB_CUSTOM_BIT,
@@ -1449,6 +1452,8 @@ static int arcturus_set_power_profile_mode(struct smu_context *smu,
 			activity_monitor.Mem_PD_Data_error_coeff = input[8];
 			activity_monitor.Mem_PD_Data_error_rate_coeff = input[9];
 			break;
+		default:
+			return -EINVAL;
 		}
 
 		ret = smu_cmn_update_table(smu,
drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +4 -0
index c06e0d6e3017..01039cdd456b 100644
@@ -2021,6 +2021,8 @@ static int navi10_set_power_profile_mode(struct smu_context *smu, long *input, u
 	}
 
 	if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+		if (size != 10)
+			return -EINVAL;
 
 		ret = smu_cmn_update_table(smu,
 				       SMU_TABLE_ACTIVITY_MONITOR_COEFF, WORKLOAD_PPLIB_CUSTOM_BIT,
@@ -2064,6 +2066,8 @@ static int navi10_set_power_profile_mode(struct smu_context *smu, long *input, u
 			activity_monitor.Mem_PD_Data_error_coeff = input[8];
 			activity_monitor.Mem_PD_Data_error_rate_coeff = input[9];
 			break;
+		default:
+			return -EINVAL;
 		}
 
 		ret = smu_cmn_update_table(smu,
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +4 -0
index e426f457a017..d5a21d7836cc 100644
@@ -1722,6 +1722,8 @@ static int sienna_cichlid_set_power_profile_mode(struct smu_context *smu, long *
 	}
 
 	if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+		if (size != 10)
+			return -EINVAL;
 
 		ret = smu_cmn_update_table(smu,
 				       SMU_TABLE_ACTIVITY_MONITOR_COEFF, WORKLOAD_PPLIB_CUSTOM_BIT,
@@ -1765,6 +1767,8 @@ static int sienna_cichlid_set_power_profile_mode(struct smu_context *smu, long *
 			activity_monitor->Mem_PD_Data_error_coeff = input[8];
 			activity_monitor->Mem_PD_Data_error_rate_coeff = input[9];
 			break;
+		default:
+			return -EINVAL;
 		}
 
 		ret = smu_cmn_update_table(smu,
Signature · 1 line
2.34.1
#2 lore raw
In reply to Ma Jun

[AMD Official Use Only - General]

please fix similar issues in other xxx_ppt.c file together? e. g: navi10_ppt.c, etc

Best Regards,
Kevin
-----Original Message-----
From: Ma, Jun <[email protected]>
Sent: Thursday, May 9, 2024 5:37 PM
To: [email protected]
Cc: Feng, Kenneth <[email protected]>; Deucher, Alexander <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Koenig, Christian <[email protected]>; Ma, Jun <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu/pm: Check input value for power profile setting on smu13 and smu14

Check the input value for CUSTOM profile mode setting on smu13 and smu14. Otherwise it may cause out-of-bouds read error.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 5 +++++  drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 4 ++++  drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c | 5 +++++
 3 files changed, 14 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +5 -0
index e8b01662e164..6c24e2306383 100644
@@ -2495,6 +2495,9 @@ static int smu_v13_0_0_set_power_profile_mode(struct smu_context *smu,
        }
 
        if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+               if (size != 9)
+                       return -EINVAL;
+
                ret = smu_cmn_update_table(smu,
                                           SMU_TABLE_ACTIVITY_MONITOR_COEFF,
                                           WORKLOAD_PPLIB_CUSTOM_BIT,
@@ -2526,6 +2529,8 @@ static int smu_v13_0_0_set_power_profile_mode(struct smu_context *smu,
                        activity_monitor->Fclk_PD_Data_error_coeff = input[7];
                        activity_monitor->Fclk_PD_Data_error_rate_coeff = input[8];
                        break;
+               default:
+                       return -EINVAL;
                }
 
                ret = smu_cmn_update_table(smu,
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +2 -0
index e996a0a4d33e..4f98869e0284 100644
@@ -2450,6 +2450,8 @@ static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *inp
        }
 
        if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+               if (size != 8)
+                       return -EINVAL;
 
                ret = smu_cmn_update_table(smu,
                                       SMU_TABLE_ACTIVITY_MONITOR_COEFF, WORKLOAD_PPLIB_CUSTOM_BIT, @@ -2478,6 +2480,8 @@ static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *inp
                        activity_monitor->Fclk_MinActiveFreq = input[6];
                        activity_monitor->Fclk_BoosterFreq = input[7];
                        break;

+ default:
+ return -EINVAL;
}

ret = smu_cmn_update_table(smu,

drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c +5 -0
index 0d5ad531c764..3f040a4d374e 100644
@@ -1418,6 +1418,9 @@ static int smu_v14_0_2_set_power_profile_mode(struct smu_context *smu,
        }
 
        if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+               if (size != 9)
+                       return -EINVAL;
+
                ret = smu_cmn_update_table(smu,
                                           SMU_TABLE_ACTIVITY_MONITOR_COEFF,
                                           WORKLOAD_PPLIB_CUSTOM_BIT,
@@ -1449,6 +1452,8 @@ static int smu_v14_0_2_set_power_profile_mode(struct smu_context *smu,
                        activity_monitor->Fclk_PD_Data_error_coeff = input[7];
                        activity_monitor->Fclk_PD_Data_error_rate_coeff = input[8];
                        break;
+               default:
+                       return -EINVAL;
                }
 
                ret = smu_cmn_update_table(smu,

--
2.34.1

#3 lore raw
Quoted 4 lines · Yang(Kevin)

[AMD Official Use Only - General]

please fix similar issues in other xxx_ppt.c file together? e. g: navi10_ppt.c, etc

Fix codes for navi10,vega20, etc. are in the patch 2 of this serial.

Regards,
Ma Jun

Quoted 86 lines

Best Regards,
Kevin
-----Original Message-----
From: Ma, Jun <[email protected]>
Sent: Thursday, May 9, 2024 5:37 PM
To: [email protected]
Cc: Feng, Kenneth <[email protected]>; Deucher, Alexander <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Koenig, Christian <[email protected]>; Ma, Jun <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu/pm: Check input value for power profile setting on smu13 and smu14

Check the input value for CUSTOM profile mode setting on smu13 and smu14. Otherwise it may cause out-of-bouds read error.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 5 +++++  drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 4 ++++  drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c | 5 +++++
 3 files changed, 14 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +5 -0
index e8b01662e164..6c24e2306383 100644
@@ -2495,6 +2495,9 @@ static int smu_v13_0_0_set_power_profile_mode(struct smu_context *smu,
        }
 
        if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+               if (size != 9)
+                       return -EINVAL;
+
                ret = smu_cmn_update_table(smu,
                                           SMU_TABLE_ACTIVITY_MONITOR_COEFF,
                                           WORKLOAD_PPLIB_CUSTOM_BIT,
@@ -2526,6 +2529,8 @@ static int smu_v13_0_0_set_power_profile_mode(struct smu_context *smu,
                        activity_monitor->Fclk_PD_Data_error_coeff = input[7];
                        activity_monitor->Fclk_PD_Data_error_rate_coeff = input[8];
                        break;
+               default:
+                       return -EINVAL;
                }
 
                ret = smu_cmn_update_table(smu,
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +2 -0
index e996a0a4d33e..4f98869e0284 100644
@@ -2450,6 +2450,8 @@ static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *inp
        }
 
        if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+               if (size != 8)
+                       return -EINVAL;
 
                ret = smu_cmn_update_table(smu,
                                       SMU_TABLE_ACTIVITY_MONITOR_COEFF, WORKLOAD_PPLIB_CUSTOM_BIT, @@ -2478,6 +2480,8 @@ static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *inp
                        activity_monitor->Fclk_MinActiveFreq = input[6];
                        activity_monitor->Fclk_BoosterFreq = input[7];
                        break;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +2 -0
+               default:
+                       return -EINVAL;
                }
 
                ret = smu_cmn_update_table(smu,
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c +5 -1
index 0d5ad531c764..3f040a4d374e 100644
@@ -1418,6 +1418,9 @@ static int smu_v14_0_2_set_power_profile_mode(struct smu_context *smu,
        }
 
        if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+               if (size != 9)
+                       return -EINVAL;
+
                ret = smu_cmn_update_table(smu,
                                           SMU_TABLE_ACTIVITY_MONITOR_COEFF,
                                           WORKLOAD_PPLIB_CUSTOM_BIT,
@@ -1449,6 +1452,8 @@ static int smu_v14_0_2_set_power_profile_mode(struct smu_context *smu,
                        activity_monitor->Fclk_PD_Data_error_coeff = input[7];
                        activity_monitor->Fclk_PD_Data_error_rate_coeff = input[8];
                        break;
+               default:
+                       return -EINVAL;
                }
 
                ret = smu_cmn_update_table(smu,
--

2.34.1

Reviewed-by
#4 lore raw

[AMD Official Use Only - General]

Ok, I miss this patch #2.

And please merge swsmu parts in patch#1 to patch#2. (patch #1 : powerplay, patch #2: swsmu)

Best Regards,
Kevin

-----Original Message-----
From: Ma, Jun <[email protected]>
Sent: Friday, May 10, 2024 9:00 AM
To: Wang, Yang(Kevin) <[email protected]>; Ma, Jun <[email protected]>; [email protected]
Cc: Ma, Jun <[email protected]>; Feng, Kenneth <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu/pm: Check input value for power profile setting on smu13 and smu14

Quoted 5 lines · Yang(Kevin)

[AMD Official Use Only - General]

please fix similar issues in other xxx_ppt.c file together? e. g:
navi10_ppt.c, etc

Fix codes for navi10,vega20, etc. are in the patch 2 of this serial.

Regards,
Ma Jun

Quoted 95 lines

Best Regards,
Kevin
-----Original Message-----
From: Ma, Jun <[email protected]>
Sent: Thursday, May 9, 2024 5:37 PM
To: [email protected]
Cc: Feng, Kenneth <[email protected]>; Deucher, Alexander <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Koenig, Christian <[email protected]>; Ma, Jun <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu/pm: Check input value for power profile setting on smu13 and smu14

Check the input value for CUSTOM profile mode setting on smu13 and smu14. Otherwise it may cause out-of-bouds read error.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 5 +++++
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 4 ++++
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c | 5 +++++
 3 files changed, 14 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +5 -0
index e8b01662e164..6c24e2306383 100644
@@ -2495,6 +2495,9 @@ static int smu_v13_0_0_set_power_profile_mode(struct smu_context *smu,
        }
 
        if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+               if (size != 9)
+                       return -EINVAL;
+
                ret = smu_cmn_update_table(smu,
                                           SMU_TABLE_ACTIVITY_MONITOR_COEFF,
                                           WORKLOAD_PPLIB_CUSTOM_BIT,
@@ -2526,6 +2529,8 @@ static int smu_v13_0_0_set_power_profile_mode(struct smu_context *smu,
                        activity_monitor->Fclk_PD_Data_error_coeff = input[7];
                        activity_monitor->Fclk_PD_Data_error_rate_coeff = input[8];
                        break;
+               default:
+                       return -EINVAL;
                }
 
                ret = smu_cmn_update_table(smu, diff --git

a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c index e996a0a4d33e..4f98869e0284 100644

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +2 -0
@@ -2450,6 +2450,8 @@ static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *inp
        }
 
        if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+               if (size != 8)
+                       return -EINVAL;
 
                ret = smu_cmn_update_table(smu,
                                       SMU_TABLE_ACTIVITY_MONITOR_COEFF, WORKLOAD_PPLIB_CUSTOM_BIT, @@ -2478,6 +2480,8 @@ static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *inp
                        activity_monitor->Fclk_MinActiveFreq = input[6];
                        activity_monitor->Fclk_BoosterFreq = input[7];
                        break;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +2 -0
+               default:
+                       return -EINVAL;
                }
 
                ret = smu_cmn_update_table(smu, diff --git

a/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c index 0d5ad531c764..3f040a4d374e 100644

drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c +5 -1
@@ -1418,6 +1418,9 @@ static int smu_v14_0_2_set_power_profile_mode(struct smu_context *smu,
        }
 
        if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+               if (size != 9)
+                       return -EINVAL;
+
                ret = smu_cmn_update_table(smu,
                                           SMU_TABLE_ACTIVITY_MONITOR_COEFF,
                                           WORKLOAD_PPLIB_CUSTOM_BIT,
@@ -1449,6 +1452,8 @@ static int smu_v14_0_2_set_power_profile_mode(struct smu_context *smu,
                        activity_monitor->Fclk_PD_Data_error_coeff = input[7];
                        activity_monitor->Fclk_PD_Data_error_rate_coeff = input[8];
                        break;
+               default:
+                       return -EINVAL;
                }
 
                ret = smu_cmn_update_table(smu,
--

2.34.1

#5 lore raw
Quoted 5 lines · Yang(Kevin)

[AMD Official Use Only - General]

Ok, I miss this patch #2.

And please merge swsmu parts in patch#1 to patch#2. (patch #1 : powerplay, patch #2: swsmu)

Thanks, will fix this when push.

Regards,
Ma Jun

Quoted 122 lines

Best Regards,
Kevin

-----Original Message-----
From: Ma, Jun <[email protected]>
Sent: Friday, May 10, 2024 9:00 AM
To: Wang, Yang(Kevin) <[email protected]>; Ma, Jun <[email protected]>; [email protected]
Cc: Ma, Jun <[email protected]>; Feng, Kenneth <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu/pm: Check input value for power profile setting on smu13 and smu14

Quoted 5 lines · Yang(Kevin)

[AMD Official Use Only - General]

please fix similar issues in other xxx_ppt.c file together? e. g:
navi10_ppt.c, etc

Fix codes for navi10,vega20, etc. are in the patch 2 of this serial.

Regards,
Ma Jun

Quoted 95 lines

Best Regards,
Kevin
-----Original Message-----
From: Ma, Jun <[email protected]>
Sent: Thursday, May 9, 2024 5:37 PM
To: [email protected]
Cc: Feng, Kenneth <[email protected]>; Deucher, Alexander <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Koenig, Christian <[email protected]>; Ma, Jun <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu/pm: Check input value for power profile setting on smu13 and smu14

Check the input value for CUSTOM profile mode setting on smu13 and smu14. Otherwise it may cause out-of-bouds read error.

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 5 +++++
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 4 ++++
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c | 5 +++++
 3 files changed, 14 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +5 -0
index e8b01662e164..6c24e2306383 100644
@@ -2495,6 +2495,9 @@ static int smu_v13_0_0_set_power_profile_mode(struct smu_context *smu,
        }
 
        if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+               if (size != 9)
+                       return -EINVAL;
+
                ret = smu_cmn_update_table(smu,
                                           SMU_TABLE_ACTIVITY_MONITOR_COEFF,
                                           WORKLOAD_PPLIB_CUSTOM_BIT,
@@ -2526,6 +2529,8 @@ static int smu_v13_0_0_set_power_profile_mode(struct smu_context *smu,
                        activity_monitor->Fclk_PD_Data_error_coeff = input[7];
                        activity_monitor->Fclk_PD_Data_error_rate_coeff = input[8];
                        break;
+               default:
+                       return -EINVAL;
                }
 
                ret = smu_cmn_update_table(smu, diff --git

a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c index e996a0a4d33e..4f98869e0284 100644

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +2 -0
@@ -2450,6 +2450,8 @@ static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *inp
        }
 
        if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+               if (size != 8)
+                       return -EINVAL;
 
                ret = smu_cmn_update_table(smu,
                                       SMU_TABLE_ACTIVITY_MONITOR_COEFF, WORKLOAD_PPLIB_CUSTOM_BIT, @@ -2478,6 +2480,8 @@ static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *inp
                        activity_monitor->Fclk_MinActiveFreq = input[6];
                        activity_monitor->Fclk_BoosterFreq = input[7];
                        break;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +2 -0
+               default:
+                       return -EINVAL;
                }
 
                ret = smu_cmn_update_table(smu, diff --git

a/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c index 0d5ad531c764..3f040a4d374e 100644

drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c +5 -1
@@ -1418,6 +1418,9 @@ static int smu_v14_0_2_set_power_profile_mode(struct smu_context *smu,
        }
 
        if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
+               if (size != 9)
+                       return -EINVAL;
+
                ret = smu_cmn_update_table(smu,
                                           SMU_TABLE_ACTIVITY_MONITOR_COEFF,
                                           WORKLOAD_PPLIB_CUSTOM_BIT,
@@ -1449,6 +1452,8 @@ static int smu_v14_0_2_set_power_profile_mode(struct smu_context *smu,
                        activity_monitor->Fclk_PD_Data_error_coeff = input[7];
                        activity_monitor->Fclk_PD_Data_error_rate_coeff = input[8];
                        break;
+               default:
+                       return -EINVAL;
                }
 
                ret = smu_cmn_update_table(smu,
--

2.34.1