Skip to contentSkip to conversation

drm/amdgpu/mes: keep enforce isolation up to date

PATCH In review Alex Deucher 3 participants 6 messages Feb 14, 2025 – Feb 21, 2025

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amdgpu/mes: keep enforce isolation up to date

Re-send the mes message on resume to make sure the mes state is up to date.

Fixes 8521e3c5f058 ("drm/amd/amdgpu: limit single process inside MES")
Cc Shaoyun Liu <[email protected]>
Cc Srinivasan Shanmugam <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 13 ++++---------
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 20 +++++++++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h |  2 +-
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c  |  4 ++++
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c  |  4 ++++
 5 files changed, 32 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +4 -9
index b9bd6654f3172..a194bf3347cbc 100644
@@ -1665,24 +1665,19 @@ static ssize_t amdgpu_gfx_set_enforce_isolation(struct device *dev,
 	}
 
 	mutex_lock(&adev->enforce_isolation_mutex);
-
 	for (i = 0; i < num_partitions; i++) {
-		if (adev->enforce_isolation[i] && !partition_values[i]) {
+		if (adev->enforce_isolation[i] && !partition_values[i])
 			/* Going from enabled to disabled */
 			amdgpu_vmid_free_reserved(adev, AMDGPU_GFXHUB(i));
-			if (adev->enable_mes && adev->gfx.enable_cleaner_shader)
-				amdgpu_mes_set_enforce_isolation(adev, i, false);
-		} else if (!adev->enforce_isolation[i] && partition_values[i]) {
+		else if (!adev->enforce_isolation[i] && partition_values[i])
 			/* Going from disabled to enabled */
 			amdgpu_vmid_alloc_reserved(adev, AMDGPU_GFXHUB(i));
-			if (adev->enable_mes && adev->gfx.enable_cleaner_shader)
-				amdgpu_mes_set_enforce_isolation(adev, i, true);
-		}
 		adev->enforce_isolation[i] = partition_values[i];
 	}
-
 	mutex_unlock(&adev->enforce_isolation_mutex);
 
+	amdgpu_mes_update_enforce_isolation(adev);
+
 	return count;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +19 -1
index cee38bb6cfaf2..ca076306adba4 100644
@@ -1508,7 +1508,8 @@ bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev)
 }
 
 /* Fix me -- node_id is used to identify the correct MES instances in the future */
-int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_id, bool enable)
+static int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev,
+					    uint32_t node_id, bool enable)
 {
 	struct mes_misc_op_input op_input = {0};
 	int r;
@@ -1530,6 +1531,23 @@ int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_i
 	return r;
 }
 
+int amdgpu_mes_update_enforce_isolation(struct amdgpu_device *adev)
+{
+	int i, r = 0;
+
+	if (adev->enable_mes && adev->gfx.enable_cleaner_shader) {
+		mutex_lock(&adev->enforce_isolation_mutex);
+		for (i = 0; i < (adev->xcp_mgr ? adev->xcp_mgr->num_xcps : 1); i++) {
+			if (adev->enforce_isolation[i])
+				r |= amdgpu_mes_set_enforce_isolation(adev, i, true);
+			else
+				r |= amdgpu_mes_set_enforce_isolation(adev, i, false);
+		}
+		mutex_unlock(&adev->enforce_isolation_mutex);
+	}
+	return r;
+}
+
 #if defined(CONFIG_DEBUG_FS)
 
 static int amdgpu_debugfs_mes_event_log_show(struct seq_file *m, void *unused)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +1 -1
index 6a792ffc81e33..3a65c3788956d 100644
@@ -532,6 +532,6 @@ static inline void amdgpu_mes_unlock(struct amdgpu_mes *mes)
 
 bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev);
 
-int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_id, bool enable);
+int amdgpu_mes_update_enforce_isolation(struct amdgpu_device *adev);
 
 #endif /* __AMDGPU_MES_H__ */
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +4 -0
index 530371e6a7aee..fc7b17463cb4d 100644
@@ -1660,6 +1660,10 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block)
 		goto failure;
 	}
 
+	r = amdgpu_mes_update_enforce_isolation(adev);
+	if (r)
+		goto failure;
+
 out:
 	/*
 	 * Disable KIQ ring usage from the driver once MES is enabled.
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +4 -0
index 6db88584dd529..ec91c78468f30 100644
@@ -1773,6 +1773,10 @@ static int mes_v12_0_hw_init(struct amdgpu_ip_block *ip_block)
 		goto failure;
 	}
 
+	r = amdgpu_mes_update_enforce_isolation(adev);
+	if (r)
+		goto failure;
+
 out:
 	/*
 	 * Disable KIQ ring usage from the driver once MES is enabled.
Signature · 1 line
2.48.1
#1 lore raw
Quoted 103 lines · Alex Deucher

Re-send the mes message on resume to make sure the mes state is up to date.

Fixes 8521e3c5f058 ("drm/amd/amdgpu: limit single process inside MES")
Cc Shaoyun Liu<[email protected]>
Cc Srinivasan Shanmugam<[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 13 ++++---------
  drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 20 +++++++++++++++++++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h |  2 +-
  drivers/gpu/drm/amd/amdgpu/mes_v11_0.c  |  4 ++++
  drivers/gpu/drm/amd/amdgpu/mes_v12_0.c  |  4 ++++
  5 files changed, 32 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +4 -9
index b9bd6654f3172..a194bf3347cbc 100644
@@ -1665,24 +1665,19 @@ static ssize_t amdgpu_gfx_set_enforce_isolation(struct device *dev,
  	}
 
  	mutex_lock(&adev->enforce_isolation_mutex);
-
  	for (i = 0; i < num_partitions; i++) {
-		if (adev->enforce_isolation[i] && !partition_values[i]) {
+		if (adev->enforce_isolation[i] && !partition_values[i])
  			/* Going from enabled to disabled */
  			amdgpu_vmid_free_reserved(adev, AMDGPU_GFXHUB(i));
-			if (adev->enable_mes && adev->gfx.enable_cleaner_shader)
-				amdgpu_mes_set_enforce_isolation(adev, i, false);
-		} else if (!adev->enforce_isolation[i] && partition_values[i]) {
+		else if (!adev->enforce_isolation[i] && partition_values[i])
  			/* Going from disabled to enabled */
  			amdgpu_vmid_alloc_reserved(adev, AMDGPU_GFXHUB(i));
-			if (adev->enable_mes && adev->gfx.enable_cleaner_shader)
-				amdgpu_mes_set_enforce_isolation(adev, i, true);
-		}
  		adev->enforce_isolation[i] = partition_values[i];
  	}
-
  	mutex_unlock(&adev->enforce_isolation_mutex);
 
+	amdgpu_mes_update_enforce_isolation(adev);
+
  	return count;
  }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +19 -1
index cee38bb6cfaf2..ca076306adba4 100644
@@ -1508,7 +1508,8 @@ bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev)
  }
 
  /* Fix me -- node_id is used to identify the correct MES instances in the future */
-int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_id, bool enable)
+static int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev,
+					    uint32_t node_id, bool enable)
  {
  	struct mes_misc_op_input op_input = {0};
  	int r;
@@ -1530,6 +1531,23 @@ int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_i
  	return r;
  }
 
+int amdgpu_mes_update_enforce_isolation(struct amdgpu_device *adev)
+{
+	int i, r = 0;
+
+	if (adev->enable_mes && adev->gfx.enable_cleaner_shader) {
+		mutex_lock(&adev->enforce_isolation_mutex);
+		for (i = 0; i < (adev->xcp_mgr ? adev->xcp_mgr->num_xcps : 1); i++) {
+			if (adev->enforce_isolation[i])
+				r |= amdgpu_mes_set_enforce_isolation(adev, i, true);
+			else
+				r |= amdgpu_mes_set_enforce_isolation(adev, i, false);
+		}
+		mutex_unlock(&adev->enforce_isolation_mutex);
+	}
+	return r;
+}
+
  #if defined(CONFIG_DEBUG_FS)
 
  static int amdgpu_debugfs_mes_event_log_show(struct seq_file *m, void *unused)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +1 -1
index 6a792ffc81e33..3a65c3788956d 100644
@@ -532,6 +532,6 @@ static inline void amdgpu_mes_unlock(struct amdgpu_mes *mes)
 
  bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev);
 
-int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_id, bool enable);
+int amdgpu_mes_update_enforce_isolation(struct amdgpu_device *adev);
 
  #endif /* __AMDGPU_MES_H__ */
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +0 -0
index 530371e6a7aee..fc7b17463cb4d 100644

drivers/gpu/drm/amd/amdgpu/mes_v11_0.c static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block) · line 1666

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +4 -0
@@ -1660,6 +1660,10 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block)
  		goto failure;
  	}
 
+	r = amdgpu_mes_update_enforce_isolation(adev);
+	if (r)
+		goto failure;
+

Hi Alex,

Should this also be moved to mes_v11_0_hw_init. Please let me know your thoughts?

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +0 -0
  out:
  	/*
  	 * Disable KIQ ring usage from the driver once MES is enabled.
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +0 -0
index 6db88584dd529..ec91c78468f30 100644

drivers/gpu/drm/amd/amdgpu/mes_v12_0.c static int mes_v12_0_hw_init(struct amdgpu_ip_block *ip_block) · line 1779

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +4 -0
@@ -1773,6 +1773,10 @@ static int mes_v12_0_hw_init(struct amdgpu_ip_block *ip_block)
  		goto failure;
  	}
 
+	r = amdgpu_mes_update_enforce_isolation(adev);
+	if (r)
+		goto failure;
+

And Similarly here also?

Thanks!

Srini

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +0 -0
  out:
  	/*
  	 * Disable KIQ ring usage from the driver once MES is enabled.
#2 lore raw
Quoted 117 lines · SRINIVASAN SHANMUGAM

On 2/14/2025 11:05 PM, Alex Deucher wrote:

Re-send the mes message on resume to make sure the mes state is up to date.

Fixes 8521e3c5f058 ("drm/amd/amdgpu: limit single process inside MES")
Cc Shaoyun Liu <[email protected]>
Cc Srinivasan Shanmugam <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 13 ++++---------
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 20 +++++++++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h |  2 +-
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c  |  4 ++++
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c  |  4 ++++
 5 files changed, 32 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +4 -9
index b9bd6654f3172..a194bf3347cbc 100644
@@ -1665,24 +1665,19 @@ static ssize_t amdgpu_gfx_set_enforce_isolation(struct device *dev,
  }
 
  mutex_lock(&adev->enforce_isolation_mutex);
-
  for (i = 0; i < num_partitions; i++) {
- if (adev->enforce_isolation[i] && !partition_values[i]) {
+ if (adev->enforce_isolation[i] && !partition_values[i])
  /* Going from enabled to disabled */
  amdgpu_vmid_free_reserved(adev, AMDGPU_GFXHUB(i));
- if (adev->enable_mes && adev->gfx.enable_cleaner_shader)
- amdgpu_mes_set_enforce_isolation(adev, i, false);
- } else if (!adev->enforce_isolation[i] && partition_values[i]) {
+ else if (!adev->enforce_isolation[i] && partition_values[i])
  /* Going from disabled to enabled */
  amdgpu_vmid_alloc_reserved(adev, AMDGPU_GFXHUB(i));
- if (adev->enable_mes && adev->gfx.enable_cleaner_shader)
- amdgpu_mes_set_enforce_isolation(adev, i, true);
- }
  adev->enforce_isolation[i] = partition_values[i];
  }
-
  mutex_unlock(&adev->enforce_isolation_mutex);
 
+ amdgpu_mes_update_enforce_isolation(adev);
+
  return count;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +19 -1
index cee38bb6cfaf2..ca076306adba4 100644
@@ -1508,7 +1508,8 @@ bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev)
 }
 
 /* Fix me -- node_id is used to identify the correct MES instances in the future */
-int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_id, bool enable)
+static int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev,
+    uint32_t node_id, bool enable)
 {
  struct mes_misc_op_input op_input = {0};
  int r;
@@ -1530,6 +1531,23 @@ int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_i
  return r;
 }
 
+int amdgpu_mes_update_enforce_isolation(struct amdgpu_device *adev)
+{
+ int i, r = 0;
+
+ if (adev->enable_mes && adev->gfx.enable_cleaner_shader) {
+ mutex_lock(&adev->enforce_isolation_mutex);
+ for (i = 0; i < (adev->xcp_mgr ? adev->xcp_mgr->num_xcps : 1); i++) {
+ if (adev->enforce_isolation[i])
+ r |= amdgpu_mes_set_enforce_isolation(adev, i, true);
+ else
+ r |= amdgpu_mes_set_enforce_isolation(adev, i, false);
+ }
+ mutex_unlock(&adev->enforce_isolation_mutex);
+ }
+ return r;
+}
+
 #if defined(CONFIG_DEBUG_FS)
 
 static int amdgpu_debugfs_mes_event_log_show(struct seq_file *m, void *unused)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +1 -1
index 6a792ffc81e33..3a65c3788956d 100644
@@ -532,6 +532,6 @@ static inline void amdgpu_mes_unlock(struct amdgpu_mes *mes)
 
 bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev);
 
-int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_id, bool enable);
+int amdgpu_mes_update_enforce_isolation(struct amdgpu_device *adev);
 
 #endif /* __AMDGPU_MES_H__ */
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +4 -0
index 530371e6a7aee..fc7b17463cb4d 100644
@@ -1660,6 +1660,10 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block)
  goto failure;
  }
 
+ r = amdgpu_mes_update_enforce_isolation(adev);
+ if (r)
+ goto failure;
+
 
 Hi Alex,
 
Quoted 1 line

Should this also be moved to mes_v11_0_hw_init. Please let me know your thoughts?

I'm not sure I follow. This is in hw_init.

Alex

Quoted 26 lines

out:
/*
* Disable KIQ ring usage from the driver once MES is enabled.

drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +4 -0
index 6db88584dd529..ec91c78468f30 100644
@@ -1773,6 +1773,10 @@ static int mes_v12_0_hw_init(struct amdgpu_ip_block *ip_block)
  goto failure;
  }
 
+ r = amdgpu_mes_update_enforce_isolation(adev);
+ if (r)
+ goto failure;
+
 

And Similarly here also?

Thanks!

Srini

out:
/*
* Disable KIQ ring usage from the driver once MES is enabled.

#3 lore raw
Quoted 116 lines · Alex Deucher
Quoted 114 lines · SRINIVASAN SHANMUGAM

On 2/14/2025 11:05 PM, Alex Deucher wrote:

Re-send the mes message on resume to make sure the mes state is up to date.

Fixes 8521e3c5f058 ("drm/amd/amdgpu: limit single process inside MES")
Cc Shaoyun Liu <[email protected]>
Cc Srinivasan Shanmugam <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 13 ++++---------
  drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 20 +++++++++++++++++++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h |  2 +-
  drivers/gpu/drm/amd/amdgpu/mes_v11_0.c  |  4 ++++
  drivers/gpu/drm/amd/amdgpu/mes_v12_0.c  |  4 ++++
  5 files changed, 32 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +4 -9
index b9bd6654f3172..a194bf3347cbc 100644
@@ -1665,24 +1665,19 @@ static ssize_t amdgpu_gfx_set_enforce_isolation(struct device *dev,
   }
 
   mutex_lock(&adev->enforce_isolation_mutex);
-
   for (i = 0; i < num_partitions; i++) {
- if (adev->enforce_isolation[i] && !partition_values[i]) {
+ if (adev->enforce_isolation[i] && !partition_values[i])
   /* Going from enabled to disabled */
   amdgpu_vmid_free_reserved(adev, AMDGPU_GFXHUB(i));
- if (adev->enable_mes && adev->gfx.enable_cleaner_shader)
- amdgpu_mes_set_enforce_isolation(adev, i, false);
- } else if (!adev->enforce_isolation[i] && partition_values[i]) {
+ else if (!adev->enforce_isolation[i] && partition_values[i])
   /* Going from disabled to enabled */
   amdgpu_vmid_alloc_reserved(adev, AMDGPU_GFXHUB(i));
- if (adev->enable_mes && adev->gfx.enable_cleaner_shader)
- amdgpu_mes_set_enforce_isolation(adev, i, true);
- }
   adev->enforce_isolation[i] = partition_values[i];
   }
-
   mutex_unlock(&adev->enforce_isolation_mutex);
 
+ amdgpu_mes_update_enforce_isolation(adev);
+
   return count;
  }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +19 -1
index cee38bb6cfaf2..ca076306adba4 100644
@@ -1508,7 +1508,8 @@ bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev)
  }
 
  /* Fix me -- node_id is used to identify the correct MES instances in the future */
-int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_id, bool enable)
+static int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev,
+    uint32_t node_id, bool enable)
  {
   struct mes_misc_op_input op_input = {0};
   int r;
@@ -1530,6 +1531,23 @@ int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_i
   return r;
  }
 
+int amdgpu_mes_update_enforce_isolation(struct amdgpu_device *adev)
+{
+ int i, r = 0;
+
+ if (adev->enable_mes && adev->gfx.enable_cleaner_shader) {
+ mutex_lock(&adev->enforce_isolation_mutex);
+ for (i = 0; i < (adev->xcp_mgr ? adev->xcp_mgr->num_xcps : 1); i++) {
+ if (adev->enforce_isolation[i])
+ r |= amdgpu_mes_set_enforce_isolation(adev, i, true);
+ else
+ r |= amdgpu_mes_set_enforce_isolation(adev, i, false);
+ }
+ mutex_unlock(&adev->enforce_isolation_mutex);
+ }
+ return r;
+}
+
  #if defined(CONFIG_DEBUG_FS)
 
  static int amdgpu_debugfs_mes_event_log_show(struct seq_file *m, void *unused)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +1 -1
index 6a792ffc81e33..3a65c3788956d 100644
@@ -532,6 +532,6 @@ static inline void amdgpu_mes_unlock(struct amdgpu_mes *mes)
 
  bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev);
 
-int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_id, bool enable);
+int amdgpu_mes_update_enforce_isolation(struct amdgpu_device *adev);
 
  #endif /* __AMDGPU_MES_H__ */
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +4 -0
index 530371e6a7aee..fc7b17463cb4d 100644
@@ -1660,6 +1660,10 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block)
   goto failure;
   }
 
+ r = amdgpu_mes_update_enforce_isolation(adev);
+ if (r)
+ goto failure;
+
 
Quoted 6 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +0 -0
 Hi Alex,
 

Should this also be moved to mes_v11_0_hw_init. Please let me know your thoughts?

I'm not sure I follow. This is in hw_init.

Alex

Sorry, my mistake mes_v11_0_sw_init pls?

Thanks!

Srini

Quoted 25 lines
Quoted 25 lines

out:
/*
* Disable KIQ ring usage from the driver once MES is enabled.

drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +4 -0
index 6db88584dd529..ec91c78468f30 100644
@@ -1773,6 +1773,10 @@ static int mes_v12_0_hw_init(struct amdgpu_ip_block *ip_block)
   goto failure;
   }
 
+ r = amdgpu_mes_update_enforce_isolation(adev);
+ if (r)
+ goto failure;
+
 

And Similarly here also?

Thanks!

Srini

out:
/*
* Disable KIQ ring usage from the driver once MES is enabled.

#4 lore raw
Quoted 119 lines · SRINIVASAN SHANMUGAM
Quoted 116 lines · Alex Deucher
Quoted 114 lines · SRINIVASAN SHANMUGAM

On 2/14/2025 11:05 PM, Alex Deucher wrote:

Re-send the mes message on resume to make sure the mes state is up to date.

Fixes 8521e3c5f058 ("drm/amd/amdgpu: limit single process inside MES")
Cc Shaoyun Liu <[email protected]>
Cc Srinivasan Shanmugam <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 13 ++++---------
  drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 20 +++++++++++++++++++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h |  2 +-
  drivers/gpu/drm/amd/amdgpu/mes_v11_0.c  |  4 ++++
  drivers/gpu/drm/amd/amdgpu/mes_v12_0.c  |  4 ++++
  5 files changed, 32 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +4 -9
index b9bd6654f3172..a194bf3347cbc 100644
@@ -1665,24 +1665,19 @@ static ssize_t amdgpu_gfx_set_enforce_isolation(struct device *dev,
   }
 
   mutex_lock(&adev->enforce_isolation_mutex);
-
   for (i = 0; i < num_partitions; i++) {
- if (adev->enforce_isolation[i] && !partition_values[i]) {
+ if (adev->enforce_isolation[i] && !partition_values[i])
   /* Going from enabled to disabled */
   amdgpu_vmid_free_reserved(adev, AMDGPU_GFXHUB(i));
- if (adev->enable_mes && adev->gfx.enable_cleaner_shader)
- amdgpu_mes_set_enforce_isolation(adev, i, false);
- } else if (!adev->enforce_isolation[i] && partition_values[i]) {
+ else if (!adev->enforce_isolation[i] && partition_values[i])
   /* Going from disabled to enabled */
   amdgpu_vmid_alloc_reserved(adev, AMDGPU_GFXHUB(i));
- if (adev->enable_mes && adev->gfx.enable_cleaner_shader)
- amdgpu_mes_set_enforce_isolation(adev, i, true);
- }
   adev->enforce_isolation[i] = partition_values[i];
   }
-
   mutex_unlock(&adev->enforce_isolation_mutex);
 
+ amdgpu_mes_update_enforce_isolation(adev);
+
   return count;
  }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +19 -1
index cee38bb6cfaf2..ca076306adba4 100644
@@ -1508,7 +1508,8 @@ bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev)
  }
 
  /* Fix me -- node_id is used to identify the correct MES instances in the future */
-int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_id, bool enable)
+static int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev,
+    uint32_t node_id, bool enable)
  {
   struct mes_misc_op_input op_input = {0};
   int r;
@@ -1530,6 +1531,23 @@ int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_i
   return r;
  }
 
+int amdgpu_mes_update_enforce_isolation(struct amdgpu_device *adev)
+{
+ int i, r = 0;
+
+ if (adev->enable_mes && adev->gfx.enable_cleaner_shader) {
+ mutex_lock(&adev->enforce_isolation_mutex);
+ for (i = 0; i < (adev->xcp_mgr ? adev->xcp_mgr->num_xcps : 1); i++) {
+ if (adev->enforce_isolation[i])
+ r |= amdgpu_mes_set_enforce_isolation(adev, i, true);
+ else
+ r |= amdgpu_mes_set_enforce_isolation(adev, i, false);
+ }
+ mutex_unlock(&adev->enforce_isolation_mutex);
+ }
+ return r;
+}
+
  #if defined(CONFIG_DEBUG_FS)
 
  static int amdgpu_debugfs_mes_event_log_show(struct seq_file *m, void *unused)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +1 -1
index 6a792ffc81e33..3a65c3788956d 100644
@@ -532,6 +532,6 @@ static inline void amdgpu_mes_unlock(struct amdgpu_mes *mes)
 
  bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev);
 
-int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_id, bool enable);
+int amdgpu_mes_update_enforce_isolation(struct amdgpu_device *adev);
 
  #endif /* __AMDGPU_MES_H__ */
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +4 -0
index 530371e6a7aee..fc7b17463cb4d 100644
@@ -1660,6 +1660,10 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block)
   goto failure;
   }
 
+ r = amdgpu_mes_update_enforce_isolation(adev);
+ if (r)
+ goto failure;
+
 
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +0 -0
 Hi Alex,
 

Should this also be moved to mes_v11_0_hw_init. Please let me know your thoughts?

I'm not sure I follow. This is in hw_init.

Alex

Sorry, my mistake mes_v11_0_sw_init pls?

There's no need to call it in sw_init, plus the hw is not set up in sw_init so you can't call it there anyway. The whole point of this is to update the firmware with the current sw state after a suspend or reset.

Alex

Quoted 30 lines

Thanks!

Srini

Quoted 25 lines
Quoted 25 lines

out:
/*
* Disable KIQ ring usage from the driver once MES is enabled.

drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +4 -0
index 6db88584dd529..ec91c78468f30 100644
@@ -1773,6 +1773,10 @@ static int mes_v12_0_hw_init(struct amdgpu_ip_block *ip_block)
   goto failure;
   }
 
+ r = amdgpu_mes_update_enforce_isolation(adev);
+ if (r)
+ goto failure;
+
 

And Similarly here also?

Thanks!

Srini

out:
/*
* Disable KIQ ring usage from the driver once MES is enabled.

#5 lore raw
Quoted 124 lines · Alex Deucher
Quoted 122 lines · SRINIVASAN SHANMUGAM
Quoted 120 lines · Alex Deucher
Quoted 115 lines · SRINIVASAN SHANMUGAM

On 2/14/2025 11:05 PM, Alex Deucher wrote:

Re-send the mes message on resume to make sure the mes state is up to date.

Fixes 8521e3c5f058 ("drm/amd/amdgpu: limit single process inside MES")
Cc Shaoyun Liu<[email protected]>
Cc Srinivasan Shanmugam<[email protected]>
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 13 ++++---------
   drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 20 +++++++++++++++++++-
   drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h |  2 +-
   drivers/gpu/drm/amd/amdgpu/mes_v11_0.c  |  4 ++++
   drivers/gpu/drm/amd/amdgpu/mes_v12_0.c  |  4 ++++
   5 files changed, 32 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +4 -9
index b9bd6654f3172..a194bf3347cbc 100644
@@ -1665,24 +1665,19 @@ static ssize_t amdgpu_gfx_set_enforce_isolation(struct device *dev,
    }
 
    mutex_lock(&adev->enforce_isolation_mutex);
-
    for (i = 0; i < num_partitions; i++) {
- if (adev->enforce_isolation[i] && !partition_values[i]) {
+ if (adev->enforce_isolation[i] && !partition_values[i])
    /* Going from enabled to disabled */
    amdgpu_vmid_free_reserved(adev, AMDGPU_GFXHUB(i));
- if (adev->enable_mes && adev->gfx.enable_cleaner_shader)
- amdgpu_mes_set_enforce_isolation(adev, i, false);
- } else if (!adev->enforce_isolation[i] && partition_values[i]) {
+ else if (!adev->enforce_isolation[i] && partition_values[i])
    /* Going from disabled to enabled */
    amdgpu_vmid_alloc_reserved(adev, AMDGPU_GFXHUB(i));
- if (adev->enable_mes && adev->gfx.enable_cleaner_shader)
- amdgpu_mes_set_enforce_isolation(adev, i, true);
- }
    adev->enforce_isolation[i] = partition_values[i];
    }
-
    mutex_unlock(&adev->enforce_isolation_mutex);
 
+ amdgpu_mes_update_enforce_isolation(adev);
+
    return count;
   }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +19 -1
index cee38bb6cfaf2..ca076306adba4 100644
@@ -1508,7 +1508,8 @@ bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev)
   }
 
   /* Fix me -- node_id is used to identify the correct MES instances in the future */
-int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_id, bool enable)
+static int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev,
+    uint32_t node_id, bool enable)
   {
    struct mes_misc_op_input op_input = {0};
    int r;
@@ -1530,6 +1531,23 @@ int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_i
    return r;
   }
 
+int amdgpu_mes_update_enforce_isolation(struct amdgpu_device *adev)
+{
+ int i, r = 0;
+
+ if (adev->enable_mes && adev->gfx.enable_cleaner_shader) {
+ mutex_lock(&adev->enforce_isolation_mutex);
+ for (i = 0; i < (adev->xcp_mgr ? adev->xcp_mgr->num_xcps : 1); i++) {
+ if (adev->enforce_isolation[i])
+ r |= amdgpu_mes_set_enforce_isolation(adev, i, true);
+ else
+ r |= amdgpu_mes_set_enforce_isolation(adev, i, false);
+ }
+ mutex_unlock(&adev->enforce_isolation_mutex);
+ }
+ return r;
+}
+
   #if defined(CONFIG_DEBUG_FS)
 
   static int amdgpu_debugfs_mes_event_log_show(struct seq_file *m, void *unused)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +1 -1
index 6a792ffc81e33..3a65c3788956d 100644
@@ -532,6 +532,6 @@ static inline void amdgpu_mes_unlock(struct amdgpu_mes *mes)
 
   bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev);
 
-int amdgpu_mes_set_enforce_isolation(struct amdgpu_device *adev, uint32_t node_id, bool enable);
+int amdgpu_mes_update_enforce_isolation(struct amdgpu_device *adev);
 
   #endif /* __AMDGPU_MES_H__ */
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +4 -0
index 530371e6a7aee..fc7b17463cb4d 100644
@@ -1660,6 +1660,10 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block)
    goto failure;
    }
 
+ r = amdgpu_mes_update_enforce_isolation(adev);
+ if (r)
+ goto failure;
+
 
 Hi Alex,
 
Quoted 1 line

Should this also be moved to mes_v11_0_hw_init. Please let me know your thoughts?

I'm not sure I follow. This is in hw_init.

Quoted 6 lines
Quoted 2 lines
Quoted 1 line

Alex

Sorry, my mistake mes_v11_0_sw_init pls?

There's no need to call it in sw_init, plus the hw is not set up in sw_init so you can't call it there anyway. The whole point of this is to update the firmware with the current sw state after a suspend or reset.

Based on this understanding, at resume time - it is just the message that is needed to be sent only to MES, to make sure we re-enable enforce_isolation workaround after suspend.

Quoted 31 lines

Alex

Quoted 29 lines

Thanks!

Srini

Quoted 25 lines
Quoted 25 lines

out:
/*
* Disable KIQ ring usage from the driver once MES is enabled.

drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +4 -0
index 6db88584dd529..ec91c78468f30 100644
@@ -1773,6 +1773,10 @@ static int mes_v12_0_hw_init(struct amdgpu_ip_block *ip_block)
    goto failure;
    }
 
+ r = amdgpu_mes_update_enforce_isolation(adev);
+ if (r)
+ goto failure;
+
 

And Similarly here also?

Thanks!

Srini

out:
/*
* Disable KIQ ring usage from the driver once MES is enabled.