Skip to contentSkip to conversation

drm/amdgpu: add safeguards for accessing mmhub CG registers

PATCH In review Lang Yu 4 participants 8 messages Jan 26, 2022 – Jan 27, 2022

Subsystems (2)
lore
Share & tools
lore

Lang Yu

author
#0 lore raw

PATCH 1/1 drm/amdgpu: add safeguards for accessing mmhub CG registers

We observed a gpu hang when querying mmhub CG status(i.e., cat amdgpu_pm_info) on cyan skillfish. Acctually, cyan skillfish doesn't support any CG features.

Only allow asics which support CG features accessing related registers. Will add similar safeguards for other IPs in the furture.

---
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c | 3 +++
 5 files changed, 15 insertions(+)
drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c +3 -0
index 4c9f0c0f3116..1869e2019461 100644
@@ -550,6 +550,9 @@ static void mmhub_v1_0_get_clockgating(struct amdgpu_device *adev, u32 *flags)
 {
 	int data, data1;
 
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
 	if (amdgpu_sriov_vf(adev))
 		*flags = 0;
 
drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c +3 -0
index 3b901f941627..f7b9843b36e6 100644
@@ -546,6 +546,9 @@ static void mmhub_v1_7_get_clockgating(struct amdgpu_device *adev, u32 *flags)
 {
 	int data, data1;
 
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
 	if (amdgpu_sriov_vf(adev))
 		*flags = 0;
 
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +3 -0
index 3718ff610ab2..3f5f326379b7 100644
@@ -686,6 +686,9 @@ static void mmhub_v2_0_get_clockgating(struct amdgpu_device *adev, u32 *flags)
 {
 	int data, data1;
 
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
 	if (amdgpu_sriov_vf(adev))
 		*flags = 0;
 
drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c +3 -0
index 9e16da28505a..b23dd9ddfb5c 100644
@@ -580,6 +580,9 @@ static void mmhub_v2_3_get_clockgating(struct amdgpu_device *adev, u32 *flags)
 {
 	int data, data1, data2, data3;
 
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
 	if (amdgpu_sriov_vf(adev))
 		*flags = 0;
 
drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c +3 -0
index 619106f7d23d..a2d5c8424e2b 100644
@@ -651,6 +651,9 @@ static void mmhub_v9_4_get_clockgating(struct amdgpu_device *adev, u32 *flags)
 {
 	int data, data1;
 
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
 	if (amdgpu_sriov_vf(adev))
 		*flags = 0;
 
Signature · 1 line
2.25.1
#1 lore raw

Am 26.01.22 um 08:53 schrieb Lang Yu:

Quoted 7 lines

We observed a gpu hang when querying mmhub CG status(i.e., cat amdgpu_pm_info) on cyan skillfish. Acctually, cyan skillfish doesn't support any CG features.

Only allow asics which support CG features accessing related registers. Will add similar safeguards for other IPs in the furture.

I think you should probably add a macro or function for this check, apart from that looks good to me.

Christian.

Quoted 80 lines
---
  drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c | 3 +++
  drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c | 3 +++
  drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c | 3 +++
  drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c | 3 +++
  drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c | 3 +++
  5 files changed, 15 insertions(+)
drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c +3 -0
index 4c9f0c0f3116..1869e2019461 100644
@@ -550,6 +550,9 @@ static void mmhub_v1_0_get_clockgating(struct amdgpu_device *adev, u32 *flags)
  {
  	int data, data1;
 
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
  	if (amdgpu_sriov_vf(adev))
  		*flags = 0;
 
drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c +3 -0
index 3b901f941627..f7b9843b36e6 100644
@@ -546,6 +546,9 @@ static void mmhub_v1_7_get_clockgating(struct amdgpu_device *adev, u32 *flags)
  {
  	int data, data1;
 
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
  	if (amdgpu_sriov_vf(adev))
  		*flags = 0;
 
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +3 -0
index 3718ff610ab2..3f5f326379b7 100644
@@ -686,6 +686,9 @@ static void mmhub_v2_0_get_clockgating(struct amdgpu_device *adev, u32 *flags)
  {
  	int data, data1;
 
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
  	if (amdgpu_sriov_vf(adev))
  		*flags = 0;
 
drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c +3 -0
index 9e16da28505a..b23dd9ddfb5c 100644
@@ -580,6 +580,9 @@ static void mmhub_v2_3_get_clockgating(struct amdgpu_device *adev, u32 *flags)
  {
  	int data, data1, data2, data3;
 
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
  	if (amdgpu_sriov_vf(adev))
  		*flags = 0;
 
drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c +3 -0
index 619106f7d23d..a2d5c8424e2b 100644
@@ -651,6 +651,9 @@ static void mmhub_v9_4_get_clockgating(struct amdgpu_device *adev, u32 *flags)
  {
  	int data, data1;
 
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
  	if (amdgpu_sriov_vf(adev))
  		*flags = 0;
 
author
#2 lore raw
Quoted 11 lines · Christian König

Am 26.01.22 um 08:53 schrieb Lang Yu:

Quoted 7 lines

We observed a gpu hang when querying mmhub CG status(i.e., cat amdgpu_pm_info) on cyan skillfish. Acctually, cyan skillfish doesn't support any CG features.

Only allow asics which support CG features accessing related registers. Will add similar safeguards for other IPs in the furture.

I think you should probably add a macro or function for this check, apart from that looks good to me.

Thanks for you advice. Is it fine to use such a macro?

#define amdgpu_device_cg_flag_isset(flag) ((adev->cg_flags) & (flag))

Regards,
Lang

Quoted 73 lines

Christian.

Quoted 70 lines
---
  drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c | 3 +++
  drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c | 3 +++
  drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c | 3 +++
  drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c | 3 +++
  drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c | 3 +++
  5 files changed, 15 insertions(+)
drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c +3 -0
index 4c9f0c0f3116..1869e2019461 100644
@@ -550,6 +550,9 @@ static void mmhub_v1_0_get_clockgating(struct amdgpu_device *adev, u32 *flags)
  {
  	int data, data1;
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
  	if (amdgpu_sriov_vf(adev))
  		*flags = 0;
drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c +3 -0
index 3b901f941627..f7b9843b36e6 100644
@@ -546,6 +546,9 @@ static void mmhub_v1_7_get_clockgating(struct amdgpu_device *adev, u32 *flags)
  {
  	int data, data1;
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
  	if (amdgpu_sriov_vf(adev))
  		*flags = 0;
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +3 -0
index 3718ff610ab2..3f5f326379b7 100644
@@ -686,6 +686,9 @@ static void mmhub_v2_0_get_clockgating(struct amdgpu_device *adev, u32 *flags)
  {
  	int data, data1;
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
  	if (amdgpu_sriov_vf(adev))
  		*flags = 0;
drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c +3 -0
index 9e16da28505a..b23dd9ddfb5c 100644
@@ -580,6 +580,9 @@ static void mmhub_v2_3_get_clockgating(struct amdgpu_device *adev, u32 *flags)
  {
  	int data, data1, data2, data3;
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
  	if (amdgpu_sriov_vf(adev))
  		*flags = 0;
drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c +3 -0
index 619106f7d23d..a2d5c8424e2b 100644
@@ -651,6 +651,9 @@ static void mmhub_v9_4_get_clockgating(struct amdgpu_device *adev, u32 *flags)
  {
  	int data, data1;
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
  	if (amdgpu_sriov_vf(adev))
  		*flags = 0;
#3 lore raw

Am 26.01.22 um 12:02 schrieb Lang Yu:

Quoted 6 lines · Christian König
Quoted 5 lines

Am 26.01.22 um 08:53 schrieb Lang Yu:

Quoted 4 lines

We observed a gpu hang when querying mmhub CG status(i.e., cat amdgpu_pm_info) on cyan skillfish. Acctually, cyan skillfish doesn't support any CG features.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Only allow asics which support CG features accessing related registers. Will add similar safeguards for other IPs in the furture.

I think you should probably add a macro or function for this check, apart from that looks good to me.

Thanks for you advice. Is it fine to use such a macro?

#define amdgpu_device_cg_flag_isset(flag) ((adev->cg_flags) & (flag))

No, first of all that can also be a function and doesn't need to be a macro.

Then we should probably encapsulate more functionality or otherwise it is rather usless.

Think more about a function like amdgpu_gmc_cg_enabled() instead.

Regards,
Christian.

Quoted 75 lines

Regards,
Lang

Quoted 71 lines

Christian.

Quoted 69 lines
---
   drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c | 3 +++
   drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c | 3 +++
   drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c | 3 +++
   drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c | 3 +++
   drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c | 3 +++
   5 files changed, 15 insertions(+)
drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c +3 -0
index 4c9f0c0f3116..1869e2019461 100644
@@ -550,6 +550,9 @@ static void mmhub_v1_0_get_clockgating(struct amdgpu_device *adev, u32 *flags)
   {
   	int data, data1;
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
   	if (amdgpu_sriov_vf(adev))
   		*flags = 0;
drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c +3 -0
index 3b901f941627..f7b9843b36e6 100644
@@ -546,6 +546,9 @@ static void mmhub_v1_7_get_clockgating(struct amdgpu_device *adev, u32 *flags)
   {
   	int data, data1;
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
   	if (amdgpu_sriov_vf(adev))
   		*flags = 0;
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +3 -0
index 3718ff610ab2..3f5f326379b7 100644
@@ -686,6 +686,9 @@ static void mmhub_v2_0_get_clockgating(struct amdgpu_device *adev, u32 *flags)
   {
   	int data, data1;
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
   	if (amdgpu_sriov_vf(adev))
   		*flags = 0;
drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c +3 -0
index 9e16da28505a..b23dd9ddfb5c 100644
@@ -580,6 +580,9 @@ static void mmhub_v2_3_get_clockgating(struct amdgpu_device *adev, u32 *flags)
   {
   	int data, data1, data2, data3;
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
   	if (amdgpu_sriov_vf(adev))
   		*flags = 0;
drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c +3 -0
index 619106f7d23d..a2d5c8424e2b 100644
@@ -651,6 +651,9 @@ static void mmhub_v9_4_get_clockgating(struct amdgpu_device *adev, u32 *flags)
   {
   	int data, data1;
+	if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+		return;
+
   	if (amdgpu_sriov_vf(adev))
   		*flags = 0;
#4 lore raw
In reply to Lang Yu

[Public]

Hi Lang,

There are ASICs in which driver doesn't enable CG, and then these flags will be false. However, the CG will be enabled by another component like VBIOS. Driver still reports the CG status eventhough driver doesn't enable it. For those, this logic doesn't work.

BTW, could you check if it's some sort of PG which causes the issue?

Thanks,
Lijo

author
#5 lore raw

[Public]

Hi Lijo,

For cyan skillfish, both adev->cg_flags and adev->pg_flags are zero. I just found "RREG32_SOC15(MMHUB, 0, mmMM_ATC_L2_MISC_CG);" in mmhub_v2_0_get_clockgating() caused a gpu hang(cat amdgpu_pm_info). I didn't check if it's some sort of PG which causes the issue.

Regards,
Lang

From: Lazar, Lijo <[email protected]>
Sent: Wednesday, January 26, 2022 8:06 PM
To: Yu, Lang <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Huang, Ray <[email protected]>; Yu, Lang <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: add safeguards for accessing mmhub CG registers

[Public]

Hi Lang,

There are ASICs in which driver doesn't enable CG, and then these flags will be false. However, the CG will be enabled by another component like VBIOS. Driver still reports the CG status eventhough driver doesn't enable it. For those, this logic doesn't work.

BTW, could you check if it's some sort of PG which causes the issue?

Thanks,
Lijo

#6 lore raw
In reply to Lang Yu

[Public]

Should we set *flags = 0 before we return?

Alex

________________________________
From: Yu, Lang <[email protected]>
Sent: Wednesday, January 26, 2022 2:53 AM
To: [email protected] <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Lazar, Lijo <[email protected]>; Huang, Ray <[email protected]>; Yu, Lang <[email protected]>
Subject: [PATCH] drm/amdgpu: add safeguards for accessing mmhub CG registers

We observed a gpu hang when querying mmhub CG status(i.e., cat amdgpu_pm_info) on cyan skillfish. Acctually, cyan skillfish doesn't support any CG features.

Only allow asics which support CG features accessing related registers. Will add similar safeguards for other IPs in the furture.

---
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c | 3 +++
 5 files changed, 15 insertions(+)
drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c +3 -0
index 4c9f0c0f3116..1869e2019461 100644
@@ -550,6 +550,9 @@ static void mmhub_v1_0_get_clockgating(struct amdgpu_device *adev, u32 *flags)
 {
         int data, data1;
 
+       if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+               return;
+
         if (amdgpu_sriov_vf(adev))
                 *flags = 0;
 
drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c +3 -0
index 3b901f941627..f7b9843b36e6 100644
@@ -546,6 +546,9 @@ static void mmhub_v1_7_get_clockgating(struct amdgpu_device *adev, u32 *flags)
 {
         int data, data1;
 
+       if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+               return;
+
         if (amdgpu_sriov_vf(adev))
                 *flags = 0;
 
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +3 -0
index 3718ff610ab2..3f5f326379b7 100644
@@ -686,6 +686,9 @@ static void mmhub_v2_0_get_clockgating(struct amdgpu_device *adev, u32 *flags)
 {
         int data, data1;
 
+       if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+               return;
+
         if (amdgpu_sriov_vf(adev))
                 *flags = 0;
 
drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c +3 -0
index 9e16da28505a..b23dd9ddfb5c 100644
@@ -580,6 +580,9 @@ static void mmhub_v2_3_get_clockgating(struct amdgpu_device *adev, u32 *flags)
 {
         int data, data1, data2, data3;
 
+       if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+               return;
+
         if (amdgpu_sriov_vf(adev))
                 *flags = 0;
 
drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c +3 -0
index 619106f7d23d..a2d5c8424e2b 100644
@@ -651,6 +651,9 @@ static void mmhub_v9_4_get_clockgating(struct amdgpu_device *adev, u32 *flags)
 {
         int data, data1;
 
+       if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+               return;
+
         if (amdgpu_sriov_vf(adev))
                 *flags = 0;
 

--
2.25.1

author
#7 lore raw

[Public]

Quoted 1 line

Should we set *flags = 0 before we return?

That will clear other bit masks. Actually, the caller initialize flags to 0, we can just return. Or just *flags &= ~( AMD_CG_SUPPORT_XXX) before we return.

Regards,
Lang

From: Deucher, Alexander <[email protected]>
Sent: Thursday, January 27, 2022 4:27 AM
To: Yu, Lang <[email protected]>; [email protected]
Cc: Lazar, Lijo <[email protected]>; Huang, Ray <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: add safeguards for accessing mmhub CG registers

[Public]

Should we set *flags = 0 before we return?

Alex

________________________________
From: Yu, Lang <[email protected]<mailto:[email protected]>>
Sent: Wednesday, January 26, 2022 2:53 AM
To: [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>
Cc: Deucher, Alexander <[email protected]<mailto:[email protected]>>; Lazar, Lijo <[email protected]<mailto:[email protected]>>; Huang, Ray <[email protected]<mailto:[email protected]>>; Yu, Lang <[email protected]<mailto:[email protected]>>
Subject: [PATCH] drm/amdgpu: add safeguards for accessing mmhub CG registers

We observed a gpu hang when querying mmhub CG status(i.e., cat amdgpu_pm_info) on cyan skillfish. Acctually, cyan skillfish doesn't support any CG features.

Only allow asics which support CG features accessing related registers. Will add similar safeguards for other IPs in the furture.

---
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c | 3 +++
 5 files changed, 15 insertions(+)
drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c +3 -0
index 4c9f0c0f3116..1869e2019461 100644
@@ -550,6 +550,9 @@ static void mmhub_v1_0_get_clockgating(struct amdgpu_device *adev, u32 *flags)
 {
         int data, data1;
 
+       if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+               return;
+
         if (amdgpu_sriov_vf(adev))
                 *flags = 0;
 
drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c +3 -0
index 3b901f941627..f7b9843b36e6 100644
@@ -546,6 +546,9 @@ static void mmhub_v1_7_get_clockgating(struct amdgpu_device *adev, u32 *flags)
 {
         int data, data1;
 
+       if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+               return;
+
         if (amdgpu_sriov_vf(adev))
                 *flags = 0;
 
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +3 -0
index 3718ff610ab2..3f5f326379b7 100644
@@ -686,6 +686,9 @@ static void mmhub_v2_0_get_clockgating(struct amdgpu_device *adev, u32 *flags)
 {
         int data, data1;
 
+       if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+               return;
+
         if (amdgpu_sriov_vf(adev))
                 *flags = 0;
 
drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c +3 -0
index 9e16da28505a..b23dd9ddfb5c 100644
@@ -580,6 +580,9 @@ static void mmhub_v2_3_get_clockgating(struct amdgpu_device *adev, u32 *flags)
 {
         int data, data1, data2, data3;
 
+       if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+               return;
+
         if (amdgpu_sriov_vf(adev))
                 *flags = 0;
 
drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c +3 -0
index 619106f7d23d..a2d5c8424e2b 100644
@@ -651,6 +651,9 @@ static void mmhub_v9_4_get_clockgating(struct amdgpu_device *adev, u32 *flags)
 {
         int data, data1;
 
+       if (!(adev->cg_flags & (AMD_CG_SUPPORT_MC_MGCG | AMD_CG_SUPPORT_MC_LS)))
+               return;
+
         if (amdgpu_sriov_vf(adev))
                 *flags = 0;
 

--
2.25.1