Skip to contentSkip to conversation

drm/amdgpu: Update MQD initialization to accept separate sizes for GFX and compute queues

PATCH New Yifan Zha 1 participant 1 message Dec 23, 2025

Subsystems (2)
lore
Share & tools
lore

Yifan Zha

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Update MQD initialization to accept separate sizes for GFX and compute queues

[Why]
Enable separate sizes for GFX and compute MQD,
preventing memory corruption issues when different rings share contiguous memory.

[How]
Update MQD initialization to accept separate sizes for GFX and compute queues.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 25 ++++++++++++++++---------
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h |  4 +++-
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c  |  5 ++++-
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c  |  5 ++++-
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c  |  5 ++++-
 drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c  |  5 ++++-
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c   |  5 ++++-
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c   |  5 ++++-
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c |  4 +++-
 9 files changed, 46 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +16 -9
index 6abe5103a78d..14bd75dfd8c0 100644
@@ -379,13 +379,18 @@ int amdgpu_gfx_kiq_init(struct amdgpu_device *adev,
 
 /* create MQD for each compute/gfx queue */
 int amdgpu_gfx_mqd_sw_init(struct amdgpu_device *adev,
-			   unsigned int mqd_size, int xcc_id)
+			   unsigned int gfx_mqd_size,
+			   unsigned int compute_mqd_size,
+			   int xcc_id)
 {
 	int r, i, j;
 	struct amdgpu_kiq *kiq = &adev->gfx.kiq[xcc_id];
 	struct amdgpu_ring *ring = &kiq->ring;
 	u32 domain = AMDGPU_GEM_DOMAIN_GTT;
 
+	if (!gfx_mqd_size || !compute_mqd_size)
+		return -EINVAL;
+
 #if !defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
 	/* Only enable on gfx10 and 11 for now to avoid changing behavior on older chips */
 	if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(10, 0, 0))
@@ -399,7 +404,7 @@ int amdgpu_gfx_mqd_sw_init(struct amdgpu_device *adev,
 		 * deallocated and gart_unbind, to strict diverage we decide to use VRAM domain for
 		 * KIQ MQD no matter SRIOV or Bare-metal
 		 */
-		r = amdgpu_bo_create_kernel(adev, mqd_size, PAGE_SIZE,
+		r = amdgpu_bo_create_kernel(adev, compute_mqd_size, PAGE_SIZE,
 					    AMDGPU_GEM_DOMAIN_VRAM |
 					    AMDGPU_GEM_DOMAIN_GTT,
 					    &ring->mqd_obj,
@@ -411,12 +416,14 @@ int amdgpu_gfx_mqd_sw_init(struct amdgpu_device *adev,
 		}
 
 		/* prepare MQD backup */
-		kiq->mqd_backup = kzalloc(mqd_size, GFP_KERNEL);
+		kiq->mqd_backup = kzalloc(compute_mqd_size, GFP_KERNEL);
 		if (!kiq->mqd_backup) {
 			dev_warn(adev->dev,
 				 "no memory to create MQD backup for ring %s\n", ring->name);
 			return -ENOMEM;
 		}
+
+		ring->mqd_size = compute_mqd_size;
 	}
 
 	if (adev->asic_type >= CHIP_NAVI10 && amdgpu_async_gfx_ring) {
@@ -424,7 +431,7 @@ int amdgpu_gfx_mqd_sw_init(struct amdgpu_device *adev,
 		for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
 			ring = &adev->gfx.gfx_ring[i];
 			if (!ring->mqd_obj) {
-				r = amdgpu_bo_create_kernel(adev, mqd_size, PAGE_SIZE,
+				r = amdgpu_bo_create_kernel(adev, gfx_mqd_size, PAGE_SIZE,
 							    domain, &ring->mqd_obj,
 							    &ring->mqd_gpu_addr, &ring->mqd_ptr);
 				if (r) {
@@ -432,9 +439,9 @@ int amdgpu_gfx_mqd_sw_init(struct amdgpu_device *adev,
 					return r;
 				}
 
-				ring->mqd_size = mqd_size;
+				ring->mqd_size = gfx_mqd_size;
 				/* prepare MQD backup */
-				adev->gfx.me.mqd_backup[i] = kzalloc(mqd_size, GFP_KERNEL);
+				adev->gfx.me.mqd_backup[i] = kzalloc(gfx_mqd_size, GFP_KERNEL);
 				if (!adev->gfx.me.mqd_backup[i]) {
 					dev_warn(adev->dev, "no memory to create MQD backup for ring %s\n", ring->name);
 					return -ENOMEM;
@@ -448,7 +455,7 @@ int amdgpu_gfx_mqd_sw_init(struct amdgpu_device *adev,
 		j = i + xcc_id * adev->gfx.num_compute_rings;
 		ring = &adev->gfx.compute_ring[j];
 		if (!ring->mqd_obj) {
-			r = amdgpu_bo_create_kernel(adev, mqd_size, PAGE_SIZE,
+			r = amdgpu_bo_create_kernel(adev, compute_mqd_size, PAGE_SIZE,
 						    domain, &ring->mqd_obj,
 						    &ring->mqd_gpu_addr, &ring->mqd_ptr);
 			if (r) {
@@ -456,9 +463,9 @@ int amdgpu_gfx_mqd_sw_init(struct amdgpu_device *adev,
 				return r;
 			}
 
-			ring->mqd_size = mqd_size;
+			ring->mqd_size = compute_mqd_size;
 			/* prepare MQD backup */
-			adev->gfx.mec.mqd_backup[j] = kzalloc(mqd_size, GFP_KERNEL);
+			adev->gfx.mec.mqd_backup[j] = kzalloc(compute_mqd_size, GFP_KERNEL);
 			if (!adev->gfx.mec.mqd_backup[j]) {
 				dev_warn(adev->dev, "no memory to create MQD backup for ring %s\n", ring->name);
 				return -ENOMEM;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3 -1
index 585cc8e81bb2..c5970aafa49d 100644
@@ -581,7 +581,9 @@ int amdgpu_gfx_kiq_init(struct amdgpu_device *adev,
 			unsigned hpd_size, int xcc_id);
 
 int amdgpu_gfx_mqd_sw_init(struct amdgpu_device *adev,
-			   unsigned mqd_size, int xcc_id);
+			   unsigned int gfx_mqd_size,
+			   unsigned int compute_mqd_size,
+			   int xcc_id);
 void amdgpu_gfx_mqd_sw_fini(struct amdgpu_device *adev, int xcc_id);
 int amdgpu_gfx_disable_kcq(struct amdgpu_device *adev, int xcc_id);
 int amdgpu_gfx_enable_kcq(struct amdgpu_device *adev, int xcc_id);
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +4 -1
index 41bbedb8e157..4d4820adac4d 100644
@@ -4973,7 +4973,10 @@ static int gfx_v10_0_sw_init(struct amdgpu_ip_block *ip_block)
 	if (r)
 		return r;
 
-	r = amdgpu_gfx_mqd_sw_init(adev, sizeof(struct v10_compute_mqd), 0);
+	r = amdgpu_gfx_mqd_sw_init(adev,
+				   sizeof(struct v10_gfx_mqd),
+				   sizeof(struct v10_compute_mqd),
+				   0);
 	if (r)
 		return r;
 
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4 -1
index 3a4ca104b161..968098b20a02 100644
@@ -1860,7 +1860,10 @@ static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block)
 			return r;
 	}
 
-	r = amdgpu_gfx_mqd_sw_init(adev, sizeof(struct v11_compute_mqd), 0);
+	r = amdgpu_gfx_mqd_sw_init(adev,
+				   sizeof(struct v11_gfx_mqd),
+				   sizeof(struct v11_compute_mqd),
+				   0);
 	if (r)
 		return r;
 
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4 -1
index 6cd16f016c37..ecb04e387111 100644
@@ -1576,7 +1576,10 @@ static int gfx_v12_0_sw_init(struct amdgpu_ip_block *ip_block)
 			return r;
 	}
 
-	r = amdgpu_gfx_mqd_sw_init(adev, sizeof(struct v12_compute_mqd), 0);
+	r = amdgpu_gfx_mqd_sw_init(adev,
+				   sizeof(struct v12_gfx_mqd),
+				   sizeof(struct v12_compute_mqd),
+				   0);
 	if (r)
 		return r;
 
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +4 -1
index 86cc90a66296..db96fac75b95 100644
@@ -1229,7 +1229,10 @@ static int gfx_v12_1_sw_init(struct amdgpu_ip_block *ip_block)
 				return r;
 		}
 
-		r = amdgpu_gfx_mqd_sw_init(adev, sizeof(struct v12_1_compute_mqd), xcc_id);
+		r = amdgpu_gfx_mqd_sw_init(adev,
+					   sizeof(struct v12_1_compute_mqd),
+					   sizeof(struct v12_1_compute_mqd),
+					   xcc_id);
 		if (r)
 			return r;
 	}
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +4 -1
index a6b4c8f41dc1..c35bea99df5d 100644
@@ -2013,7 +2013,10 @@ static int gfx_v8_0_sw_init(struct amdgpu_ip_block *ip_block)
 		return r;
 
 	/* create MQD for all compute queues as well as KIQ for SRIOV case */
-	r = amdgpu_gfx_mqd_sw_init(adev, sizeof(struct vi_mqd_allocation), 0);
+	r = amdgpu_gfx_mqd_sw_init(adev,
+				   sizeof(struct vi_mqd_allocation),
+				   sizeof(struct vi_mqd_allocation),
+				   0);
 	if (r)
 		return r;
 
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +4 -1
index 7e9d753f4a80..10802e26f371 100644
@@ -2427,7 +2427,10 @@ static int gfx_v9_0_sw_init(struct amdgpu_ip_block *ip_block)
 		return r;
 
 	/* create MQD for all compute queues as wel as KIQ for SRIOV case */
-	r = amdgpu_gfx_mqd_sw_init(adev, sizeof(struct v9_mqd_allocation), 0);
+	r = amdgpu_gfx_mqd_sw_init(adev,
+				   sizeof(struct v9_mqd_allocation),
+				   sizeof(struct v9_mqd_allocation),
+				   0);
 	if (r)
 		return r;
 
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +3 -1
index ad4d442e7345..f76a0de617f4 100644
@@ -1139,7 +1139,9 @@ static int gfx_v9_4_3_sw_init(struct amdgpu_ip_block *ip_block)
 
 		/* create MQD for all compute queues as wel as KIQ for SRIOV case */
 		r = amdgpu_gfx_mqd_sw_init(adev,
-				sizeof(struct v9_mqd_allocation), xcc_id);
+					   sizeof(struct v9_mqd_allocation),
+					   sizeof(struct v9_mqd_allocation),
+					   xcc_id);
 		if (r)
 			return r;
 	}
Signature · 1 line
2.43.0