Skip to contentSkip to conversation

drm/amdgpu: skip vm inv for kiq ring

PATCH In review Frank Min 3 participants 25 messages Dec 4

Subsystems (3)
lore
Share & tools
lore

Frank Min

author
#0 lore raw

PATCH 1/9 drm/amdgpu: skip vm inv for kiq ring

skip vm inv for kiq ring

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2 -1
index 23354bf366880..75c3ded068db5 100644
@@ -675,7 +675,8 @@ int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev)
 		if (ring == &adev->mes.ring[0] ||
 		    ring == &adev->mes.ring[1] ||
 		    ring == &adev->umsch_mm.ring ||
-		    ring == &adev->cper.ring_buf)
+		    ring == &adev->cper.ring_buf ||
+		    ring == &adev->gfx.kiq[0].ring)
 			continue;
 
 		/* Skip if the ring is a shared ring */
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 2/9 drm/amdgpu: disable gfx 13 pipe 1 ring

Disable gfx13 pipe 1 ring usage from the driver.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 3 ++-
 drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c  | 9 +++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2 -1
index 75c3ded068db5..1a1d176357b30 100644
@@ -676,7 +676,8 @@ int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev)
 		    ring == &adev->mes.ring[1] ||
 		    ring == &adev->umsch_mm.ring ||
 		    ring == &adev->cper.ring_buf ||
-		    ring == &adev->gfx.kiq[0].ring)
+		    ring == &adev->gfx.kiq[0].ring ||
+		    ring == &adev->gfx.gfx_ring[1])
 			continue;
 
 		/* Skip if the ring is a shared ring */
drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c +7 -2
index c06fa6b9b2991..f0ac919a43480 100644
@@ -990,10 +990,13 @@ static int gfx_v13_0_gfx_ring_init(struct amdgpu_device *adev, int ring_id,
 	ring->ring_obj = NULL;
 	ring->use_doorbell = true;
 
-	if (!ring_id)
+	if (!ring_id) {
 		ring->doorbell_index = adev->doorbell_index.gfx_ring0 << 1;
-	else
+	} else {
 		ring->doorbell_index = adev->doorbell_index.gfx_ring1 << 1;
+		ring->no_scheduler = true;
+	}
+
 	ring->vm_hub = AMDGPU_GFXHUB(0);
 	sprintf(ring->name, "gfx_%d.%d.%d", ring->me, ring->pipe, ring->queue);
 
@@ -3658,6 +3661,8 @@ static int gfx_v13_0_hw_init(struct amdgpu_ip_block *ip_block)
 	if (r)
 		return r;
 
+	adev->gfx.gfx_ring[1].sched.ready = false;
+
 	return r;
 }
 
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 2/9] drm/amdgpu: disable gfx 13 pipe 1 ring

Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] drm/amdgpu: amdgpu_gmc_allocate_vm_inv_eng() breaks gfx_ring[1] on GFX10/11 - [Medium] drm/amdgpu…

Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] drm/amdgpu: amdgpu_gmc_allocate_vm_inv_eng() breaks gfx_ring[1] on GFX10/11
- [Medium] drm/amdgpu: gfx_v13_0_gfx_ring_init() leaves gfx_ring[1] re-enableable
- [Medium] drm/amdgpu: gfx_v13_0_hw_init() clears gfx_ring[1].sched.ready too late
- [Low] drm/amdgpu: commit message lacks rationale for disabling gfx13 pipe 1
--

commit 99b1a1cd968d2f39334b32d40212198583f21ae0
Author: Frank Min <[email protected]>

Quoted 6 lines

drm/amdgpu: disable gfx 13 pipe 1 ring

Disable gfx13 pipe 1 ring usage from the driver.

[Severity: Low]
Could the commit message explain why gfx13 pipe 1 ring needs to be disabled? It currently only restates the subject, without saying why gfx_ring[1] remains initialized and ring-tested in hardware or why the shared amdgpu_gmc_allocate_vm_inv_eng() path is changed.

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev) · line 675

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2 -1
index 12165f20a2c73..c7d7467730998 100644
@@ -670,7 +670,8 @@ int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev)
 		    ring == &adev->mes.ring[1] ||
 		    ring == &adev->umsch_mm.ring ||
 		    ring == &adev->cper.ring_buf ||
-		    ring == &adev->gfx.kiq[0].ring)
+		    ring == &adev->gfx.kiq[0].ring ||
+		    ring == &adev->gfx.gfx_ring[1])
 			continue;

[Severity: High]
Does unconditionally skipping gfx_ring[1] here break active pipe 1 rings on GFX 10.3 and GFX 11?

amdgpu_gmc_allocate_vm_inv_eng() is shared across GMC generations. On GFX 10.3 (and GFX 11 with kernel queues enabled and RS64/TMZ disabled), gfx_ring[1] is still an active scheduled ring on AMDGPU_GFXHUB(0). Skipping it leaves gfx_ring[1].vm_inv_eng at 0, aliasing gfx_ring[0].

Because AMDGPU_GFXHUB(0) flushes in gmc_v10_0_emit_flush_gpu_tlb() and gmc_v11_0_emit_flush_gpu_tlb() do not use hardware semaphores, concurrent submissions on gfx_ring[0] and gfx_ring[1] will race on engine 0, risking stale GPU TLB entries or wait timeouts and GPU hangs.

Checking ring->no_scheduler (or scoping the skip to GFX 13) would preserve dedicated invalidation engines on earlier ASICs.

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c +0 -0
index c06fa6b9b2991..f0ac919a43480 100644
@@ -990,10 +990,13 @@ static int gfx_v13_0_gfx_ring_init(struct amdgpu_device *adev, int ring_id,
 	ring->ring_obj = NULL;

drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c static int gfx_v13_0_gfx_ring_init(struct amdgpu_device *adev, int ring_id, · line 998

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c +4 -2
 	ring->use_doorbell = true;
 
-	if (!ring_id)
+	if (!ring_id) {
 		ring->doorbell_index = adev->doorbell_index.gfx_ring0 << 1;
-	else
+	} else {
 		ring->doorbell_index = adev->doorbell_index.gfx_ring1 << 1;
+		ring->no_scheduler = true;
+	}

[Severity: Medium]
Can debugfs still re-enable gfx_ring[1] when only no_scheduler is set?

With adev->gfx.num_gfx_rings still at 2, amdgpu_debugfs_gfx_sched_mask_set() flips ring->sched.ready back to true without checking ring->no_scheduler. Because ring->no_user_submission is still false, amdgpu_hw_ip_info() then counts gfx_ring[1] as a usable user ring and amdgpu_ib_ring_tests() tests it.

Keeping num_gfx_rings at 2 also still allocates, maps, and ring-tests pipe 1 in gfx_v13_0_cp_resume(), so a pipe 1 test failure still aborts hw_init.

Setting ring->no_user_submission = true and checking ring->no_scheduler in amdgpu_debugfs_gfx_sched_mask_set() (or setting num_gfx_rings to 1 if firmware does not require pipe 1 to be mapped) would avoid this.

[ ... ]

drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c static int gfx_v13_0_hw_init(struct amdgpu_ip_block *ip_block) · line 3667

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c +2 -0
@@ -3658,6 +3661,8 @@ static int gfx_v13_0_hw_init(struct amdgpu_ip_block *ip_block)
 	if (r)
 		return r;
 
+	adev->gfx.gfx_ring[1].sched.ready = false;
+
 	return r;
 }

[Severity: Medium]
Will an error in gfx_v13_0_cp_resume() leave gfx_ring[1].sched.ready set to true?

gfx_v13_0_cp_resume() calls amdgpu_ring_test_helper() on gfx_ring[1], which sets ring->sched.ready = true before testing the compute rings. If a compute ring test fails, gfx_v13_0_hw_init() returns early before clearing sched.ready, leaving the unscheduled ring marked ready.

Even when all ring tests succeed during resume or GPU reset, sched.ready is transiently true while the compute ring tests run. Using amdgpu_ring_test_ring() instead of amdgpu_ring_test_helper() when ring->no_scheduler is set would avoid publishing sched.ready at all.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#3 lore raw

Re: [PATCH 2/9] drm/amdgpu: disable gfx 13 pipe 1 ring

In reply to Frank Min
Quoted 15 lines · Frank Min

Disable gfx13 pipe 1 ring usage from the driver.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 3 ++-
 drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c  | 9 +++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
index 75c3ded068db5..1a1d176357b30 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev) · line 680

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2 -1
@@ -676,7 +676,8 @@ int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev)
                    ring == &adev->mes.ring[1] ||
                    ring == &adev->umsch_mm.ring ||
                    ring == &adev->cper.ring_buf ||
-                   ring == &adev->gfx.kiq[0].ring)
+                   ring == &adev->gfx.kiq[0].ring ||
+                   ring == &adev->gfx.gfx_ring[1])

Won't this break other parts which use gfx ring 1? I think this patch should be dropped.

Alex

Quoted 35 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
                        continue;
 
                /* Skip if the ring is a shared ring */
drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c +7 -3
index c06fa6b9b2991..f0ac919a43480 100644
@@ -990,10 +990,13 @@ static int gfx_v13_0_gfx_ring_init(struct amdgpu_device *adev, int ring_id,
        ring->ring_obj = NULL;
        ring->use_doorbell = true;
 
-       if (!ring_id)
+       if (!ring_id) {
                ring->doorbell_index = adev->doorbell_index.gfx_ring0 << 1;
-       else
+       } else {
                ring->doorbell_index = adev->doorbell_index.gfx_ring1 << 1;
+               ring->no_scheduler = true;
+       }
+
        ring->vm_hub = AMDGPU_GFXHUB(0);
        sprintf(ring->name, "gfx_%d.%d.%d", ring->me, ring->pipe, ring->queue);
 
@@ -3658,6 +3661,8 @@ static int gfx_v13_0_hw_init(struct amdgpu_ip_block *ip_block)
        if (r)
                return r;
 
+       adev->gfx.gfx_ring[1].sched.ready = false;
+
        return r;
 }
 
--

2.43.0

author
#4 lore raw

PATCH 3/9 drm/amdgpu: update table info retrieval from discovery binary

In reply to Frank Min

Update table info retrieval from discovery binary to align with discovery table update.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 47 +++++++++++++------
 1 file changed, 33 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +33 -14
index 6fba2560a2abe..50b0112825c42 100644
@@ -609,18 +609,36 @@ amdgpu_discovery_get_table_info_from_bin(uint8_t *discovery_bin,
 					 uint16_t table_id)
 {
 	struct binary_header *bhdr = (struct binary_header *)discovery_bin;
-	struct binary_header_v2 *bhdrv2;
-
-	switch (bhdr->version_major) {
-	case 2:
-		bhdrv2 = (struct binary_header_v2 *)discovery_bin;
-		return &bhdrv2->table_list[table_id];
-	case 1:
+	struct binary_header_v2 *bhdrv2 = (struct binary_header_v2 *)discovery_bin;
+	uint16_t version = le16_to_cpu(bhdr->version_major);
+	uint16_t binary_size = le16_to_cpu(bhdr->binary_size);
+	struct table_info *table_list;
+	uint16_t num_tables, i;
+	size_t table_offset;
+
+	switch (version) {
 	case 0:
-		return &bhdr->table_list[table_id];
+	case 1:
+		table_list = bhdr->table_list;
+		num_tables = ARRAY_SIZE(bhdr->table_list);
+		break;
+	case 2:
+		table_list = bhdrv2->table_list;
+		num_tables = le16_to_cpu(bhdrv2->num_tables);
+		break;
 	default:
 		return NULL;
 	}
+
+	table_offset = (uint8_t *)table_list - discovery_bin;
+	if (table_offset + num_tables * sizeof(*table_list) > binary_size)
+		return NULL;
+
+	for (i = 0; i < num_tables; i++)
+		if (le16_to_cpu(table_list[i].table_id) == table_id)
+			return &table_list[i];
+
+	return NULL;
 }
 
 static int amdgpu_discovery_get_table_info(struct amdgpu_device *adev,
@@ -633,8 +651,8 @@ static int amdgpu_discovery_get_table_info(struct amdgpu_device *adev,
 	*info = amdgpu_discovery_get_table_info_from_bin(adev->discovery.bin,
 							 table_id);
 	if (!*info) {
-		dev_err(adev->dev, "Invalid ip discovery table version %d\n",
-			bhdr->version_major);
+		dev_err(adev->dev, "Not found table for header version %d table id %d\n",
+			bhdr->version_major, table_id);
 		return -EINVAL;
 	}
 
@@ -645,15 +663,16 @@ static int amdgpu_discovery_table_check(struct amdgpu_device *adev,
 					uint8_t *discovery_bin,
 					uint16_t table_id)
 {
-	int r, act_val, exp_val, table_size;
+	int act_val, exp_val, table_size;
 	uint16_t offset, checksum;
 	struct table_info *info;
 	bool check_table = true;
 	char *table_name;
 
-	r = amdgpu_discovery_get_table_info(adev, &info, table_id);
-	if (r)
-		return r;
+	info = amdgpu_discovery_get_table_info_from_bin(discovery_bin, table_id);
+	if (!info)
+		return 0;
+
 	offset = le16_to_cpu(info->offset);
 	checksum = le16_to_cpu(info->checksum);
 
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH 3/9] drm/amdgpu: update table info retrieval from discovery binary

Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] drm/amdgpu: v0/v1 discovery lookup broken by table_id scan - [Medium] drm/amdgpu…

Thank you for your contribution! Sashiko AI review found 6 potential issues to consider:
- [High] drm/amdgpu: v0/v1 discovery lookup broken by table_id scan
- [Medium] drm/amdgpu: amdgpu_discovery_table_check() ignores invalid headers
- [Medium] drm/amdgpu: amdgpu_discovery_refresh_nps_info() misses v2 table_id lookup
- [Medium] drm/amdgpu: OOB read in amdgpu_discovery_get_table_info_from_bin()
- [Low] drm/amdgpu: commit message omits discovery table format and lookup rationale
- [Low] drm/amdgpu: spurious dev_err() in amdgpu_discovery_get_table_info()
--

commit 2a203845aec3dbcd54cbcfc1a749319c4ba689f3
Author: Frank Min <[email protected]>

Quoted 7 lines

drm/amdgpu: update table info retrieval from discovery binary

Update table info retrieval from discovery binary to align with discovery table update.

[Severity: Low]
Can the commit message explain what changed in the discovery table format and why the lookup and error handling changed? It does not mention that v2 binaries populate table_info.table_id and may omit unused entries, why v0 and v1 are also changed, or why amdgpu_discovery_table_check() returns 0.

Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +13 -8
index c52b0d9ac00b7..5997946fb1171 100644
@@ -609,18 +609,36 @@ amdgpu_discovery_get_table_info_from_bin(uint8_t *discovery_bin,
 					 uint16_t table_id)
 {
 	struct binary_header *bhdr = (struct binary_header *)discovery_bin;
-	struct binary_header_v2 *bhdrv2;
-
-	switch (bhdr->version_major) {
-	case 2:
-		bhdrv2 = (struct binary_header_v2 *)discovery_bin;
-		return &bhdrv2->table_list[table_id];
-	case 1:
+	struct binary_header_v2 *bhdrv2 = (struct binary_header_v2 *)discovery_bin;
+	uint16_t version = le16_to_cpu(bhdr->version_major);
+	uint16_t binary_size = le16_to_cpu(bhdr->binary_size);
+	struct table_info *table_list;
+	uint16_t num_tables, i;
+	size_t table_offset;
+
+	switch (version) {
 	case 0:
-		return &bhdr->table_list[table_id];
+	case 1:
+		table_list = bhdr->table_list;
+		num_tables = ARRAY_SIZE(bhdr->table_list);
+		break;
+	case 2:

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c amdgpu_discovery_get_table_info_from_bin(uint8_t *discovery_bin, · line 635

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +7 -0
+		table_list = bhdrv2->table_list;
+		num_tables = le16_to_cpu(bhdrv2->num_tables);
+		break;
 	default:
 		return NULL;
 	}
+
+	table_offset = (uint8_t *)table_list - discovery_bin;
+	if (table_offset + num_tables * sizeof(*table_list) > binary_size)
+		return NULL;

[Severity: Medium]
Can this bounds check still read past the end of discovery_bin? It compares against bhdr->binary_size from the binary itself (up to 65535 bytes) rather than the allocated buffer size.

adev->discovery.bin defaults to DISCOVERY_TMR_SIZE (10 KiB), and amdgpu_discovery_sysfs_early_init() always copies DISCOVERY_TMR_SIZE bytes into ip_top->discovery_bin. A v2 header with a larger binary_size and num_tables passes this check and reads out of bounds during the scan.

In addition, case 2 reads bhdrv2->num_tables before checking that the buffer is at least sizeof(*bhdrv2) bytes, while amdgpu_discovery_read_binary_from_file() only enforces a 12-byte minimum. Passing the allocated buffer size into this helper and checking both binary_size and sizeof(*bhdrv2) against it would close both over-reads.

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c amdgpu_discovery_get_table_info_from_bin(uint8_t *discovery_bin, · line 642

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +6 -0
+
+	for (i = 0; i < num_tables; i++)
+		if (le16_to_cpu(table_list[i].table_id) == table_id)
+			return &table_list[i];
+
+	return NULL;
 }

[Severity: High]
Does routing v0 and v1 headers through this table_id scan break table lookups on every GPU with a v0 or v1 discovery binary?

In drivers/gpu/drm/amd/include/discovery.h, table_info.table_id is padding for v1 (and v0) headers and is zero-filled, while bhdr->table_list is indexed directly by enum table.

Every non-zero table_id (GC, HARVEST_INFO, VCN_INFO, MALL_INFO, NPS_INFO) will therefore return NULL, leaving harvest masks and GFX/MALL/VCN configuration unpopulated during probe because amdgpu_discovery_set_ip_blocks() ignores those lookup failures.

Scanning all 8 entries of bhdr->table_list on older 6-slot v0/v1 binaries also reads 16 bytes past table_list into adjacent table data. Versions 0 and 1 should keep direct indexing (&bhdr->table_list[table_id]) with bounds checks, reserving the table_id scan for v2.

[Severity: Medium]
Should amdgpu_discovery_refresh_nps_info() also be updated for the v2 table_id lookup?

It reads the discovery header directly from VRAM and still indexes bhdrv2.table_list[NPS_INFO] by fixed position under case 2, which will read the wrong entry or fail checksum verification during NPS refresh after reset on v2 binaries with sparse or reordered tables. It also switches on bhdr.version_major without le16_to_cpu() and omits case 0.

[ ... ]

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c static int amdgpu_discovery_get_table_info(struct amdgpu_device *adev, · line 657

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +2 -2
@@ -633,8 +651,8 @@ static int amdgpu_discovery_get_table_info(struct amdgpu_device *adev,
 	*info = amdgpu_discovery_get_table_info_from_bin(adev->discovery.bin,
 							 table_id);
 	if (!*info) {
-		dev_err(adev->dev, "Invalid ip discovery table version %d\n",
-			bhdr->version_major);
+		dev_err(adev->dev, "Not found table for header version %d table id %d\n",
+			bhdr->version_major, table_id);
 		return -EINVAL;
 	}

[Severity: Low]
Will this emit spurious dev_err() messages during normal probe on v2 binaries that omit optional tables?

Previously dev_err() only fired on unsupported header versions. Now amdgpu_discovery_init() probes the optional MEM_RESERVED_INFO table (whose caller logs absence at dev_dbg()) and amdgpu_discovery_set_ip_blocks() probes MALL_INFO and VCN_INFO, logging errors whenever they are absent.

[ ... ]

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +1 -1
@@ -645,15 +663,16 @@ static int amdgpu_discovery_table_check(struct amdgpu_device *adev,
 					uint8_t *discovery_bin,
 					uint16_t table_id)
 {
-	int r, act_val, exp_val, table_size;
+	int act_val, exp_val, table_size;
 	uint16_t offset, checksum;

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c static int amdgpu_discovery_table_check(struct amdgpu_device *adev, · line 674

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +3 -3
 	struct table_info *info;
 	bool check_table = true;
 	char *table_name;
 
-	r = amdgpu_discovery_get_table_info(adev, &info, table_id);
-	if (r)
-		return r;
+	info = amdgpu_discovery_get_table_info_from_bin(discovery_bin, table_id);
+	if (!info)
+		return 0;

[Severity: Medium]
Does returning 0 on NULL bypass header validation and mandatory IP_DISCOVERY checks in amdgpu_discovery_init()?

amdgpu_discovery_get_table_info_from_bin() returns NULL for an unsupported version_major, an out-of-bounds num_tables, and a missing IP_DISCOVERY table, not just absent optional tables.

Because amdgpu_discovery_init() has no other check on version_major or num_tables, it will return 0 on an invalid binary instead of freeing adev->discovery.bin and calling amdgpu_ras_query_boot_status().

That lets amdgpu_discovery_sysfs_early_init() copy the invalid binary in amdgpu_discovery_reg_base_init(), and on legacy ASICs leaves adev->discovery.bin non-NULL so amdgpu_discovery_sysfs_init() leaks ip_top and die_kset when amdgpu_discovery_sysfs_recurse() fails.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#6 lore raw

Re: [PATCH 3/9] drm/amdgpu: update table info retrieval from discovery binary

In reply to Frank Min
Quoted 6 lines · Frank Min

Update table info retrieval from discovery binary to align with discovery table update.

Please double check Sashiko's comments. Note that this patch caused regressions in CI for IP discovery parsing when I checked it. I didn't check to see if you changed anything from the original patch.

Alex

Quoted 88 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 47 +++++++++++++------
 1 file changed, 33 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +33 -15
index 6fba2560a2abe..50b0112825c42 100644
@@ -609,18 +609,36 @@ amdgpu_discovery_get_table_info_from_bin(uint8_t *discovery_bin,
                                         uint16_t table_id)
 {
        struct binary_header *bhdr = (struct binary_header *)discovery_bin;
-       struct binary_header_v2 *bhdrv2;
-
-       switch (bhdr->version_major) {
-       case 2:
-               bhdrv2 = (struct binary_header_v2 *)discovery_bin;
-               return &bhdrv2->table_list[table_id];
-       case 1:
+       struct binary_header_v2 *bhdrv2 = (struct binary_header_v2 *)discovery_bin;
+       uint16_t version = le16_to_cpu(bhdr->version_major);
+       uint16_t binary_size = le16_to_cpu(bhdr->binary_size);
+       struct table_info *table_list;
+       uint16_t num_tables, i;
+       size_t table_offset;
+
+       switch (version) {
        case 0:
-               return &bhdr->table_list[table_id];
+       case 1:
+               table_list = bhdr->table_list;
+               num_tables = ARRAY_SIZE(bhdr->table_list);
+               break;
+       case 2:
+               table_list = bhdrv2->table_list;
+               num_tables = le16_to_cpu(bhdrv2->num_tables);
+               break;
        default:
                return NULL;
        }
+
+       table_offset = (uint8_t *)table_list - discovery_bin;
+       if (table_offset + num_tables * sizeof(*table_list) > binary_size)
+               return NULL;
+
+       for (i = 0; i < num_tables; i++)
+               if (le16_to_cpu(table_list[i].table_id) == table_id)
+                       return &table_list[i];
+
+       return NULL;
 }
 
 static int amdgpu_discovery_get_table_info(struct amdgpu_device *adev,
@@ -633,8 +651,8 @@ static int amdgpu_discovery_get_table_info(struct amdgpu_device *adev,
        *info = amdgpu_discovery_get_table_info_from_bin(adev->discovery.bin,
                                                         table_id);
        if (!*info) {
-               dev_err(adev->dev, "Invalid ip discovery table version %d\n",
-                       bhdr->version_major);
+               dev_err(adev->dev, "Not found table for header version %d table id %d\n",
+                       bhdr->version_major, table_id);
                return -EINVAL;
        }
 
@@ -645,15 +663,16 @@ static int amdgpu_discovery_table_check(struct amdgpu_device *adev,
                                        uint8_t *discovery_bin,
                                        uint16_t table_id)
 {
-       int r, act_val, exp_val, table_size;
+       int act_val, exp_val, table_size;
        uint16_t offset, checksum;
        struct table_info *info;
        bool check_table = true;
        char *table_name;
 
-       r = amdgpu_discovery_get_table_info(adev, &info, table_id);
-       if (r)
-               return r;
+       info = amdgpu_discovery_get_table_info_from_bin(discovery_bin, table_id);
+       if (!info)
+               return 0;
+
        offset = le16_to_cpu(info->offset);
        checksum = le16_to_cpu(info->checksum);
 
--

2.43.0

author
#7 lore raw

PATCH 4/9 drm/amdgpu: add lsdma v8 fw query interface

In reply to Frank Min

Add lsdma v8 fw query interface.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 14 ++++++++++++++
 include/uapi/drm/amdgpu_drm.h           |  2 ++
 2 files changed, 16 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +14 -0
index 75fc49fb4b319..e6872352e0035 100644
@@ -332,6 +332,10 @@ static int amdgpu_firmware_info(struct drm_amdgpu_info_firmware *fw_info,
 		fw_info->ver = adev->sdma.instance[query_fw->index].fw_version;
 		fw_info->feature = adev->sdma.instance[query_fw->index].feature_version;
 		break;
+	case AMDGPU_INFO_FW_LSDMA:
+		fw_info->ver = adev->lsdma.fw_version;
+		fw_info->feature = adev->lsdma.feature_version;
+		break;
 	case AMDGPU_INFO_FW_SOS:
 		fw_info->ver = adev->psp.sos.fw_version;
 		fw_info->feature = adev->psp.sos.feature_version;
@@ -2028,6 +2032,16 @@ static int amdgpu_debugfs_firmware_info_show(struct seq_file *m, void *unused)
 			   i, fw_info.feature, fw_info.ver);
 	}
 
+	/* LSDMA */
+	if (adev->lsdma.fw) {
+		query_fw.fw_type = AMDGPU_INFO_FW_LSDMA;
+		ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
+		if (ret)
+			return ret;
+		seq_printf(m, "LSDMA feature version: %u, firmware version: 0x%08x\n",
+			   fw_info.feature, fw_info.ver);
+	}
+
 	/* VCN */
 	query_fw.fw_type = AMDGPU_INFO_FW_VCN;
 	ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
include/uapi/drm/amdgpu_drm.h +2 -0
index a9aa08c8d3095..37eeef7f43145 100644
@@ -1228,6 +1228,8 @@ struct drm_amdgpu_cs_chunk_cp_gfx_shadow {
 	#define AMDGPU_INFO_FW_VPE		0x1c
 	/* Subquery id: Query MP5 firmware version */
 	#define AMDGPU_INFO_FW_MP5		0x1d
+	/* Subquery id: Query LSDMA firmware version */
+	#define AMDGPU_INFO_FW_LSDMA		0x1e
 
 /* number of bytes moved for TTM migration */
 #define AMDGPU_INFO_NUM_BYTES_MOVED		0x0f
Signature · 1 line
2.43.0
#8 lore raw

Re: [PATCH 4/9] drm/amdgpu: add lsdma v8 fw query interface

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] drm/amdgpu: build failure in amdgpu_kms.c from missing amdgpu_lsdma fields --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] drm/amdgpu: build failure in amdgpu_kms.c from missing amdgpu_lsdma fields
--

commit a926f15d698b8e97f1a0c23946c2b960f6427223
Author: Frank Min <[email protected]>

drm/amdgpu: add lsdma v8 fw query interface

This commit adds the AMDGPU_INFO_FW_LSDMA firmware query subquery and exposes LSDMA firmware and feature versions through amdgpu_firmware_info() and debugfs.

Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +7 -0
index 21ca29ff9eb78..a8d2acfabbd0e 100644
@@ -335,6 +335,10 @@ static int amdgpu_firmware_info(struct drm_amdgpu_info_firmware *fw_info,
 		fw_info->ver = adev->sdma.instance[query_fw->index].fw_version;
 		fw_info->feature = adev->sdma.instance[query_fw->index].feature_version;
 		break;
+	case AMDGPU_INFO_FW_LSDMA:
+		fw_info->ver = adev->lsdma.fw_version;
+		fw_info->feature = adev->lsdma.feature_version;
+		break;
 	case AMDGPU_INFO_FW_SOS:
 		fw_info->ver = adev->psp.sos.fw_version;
 		fw_info->feature = adev->psp.sos.feature_version;
@@ -2022,6 +2026,16 @@ static int amdgpu_debugfs_firmware_info_show(struct seq_file *m, void *unused)
 			   i, fw_info.feature, fw_info.ver);
 	}
 
+	/* LSDMA */
+	if (adev->lsdma.fw) {
+		query_fw.fw_type = AMDGPU_INFO_FW_LSDMA;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c static int amdgpu_debugfs_firmware_info_show(struct seq_file *m, void *unused) · line 2041

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +7 -0
+		ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
+		if (ret)
+			return ret;
+		seq_printf(m, "LSDMA feature version: %u, firmware version: 0x%08x\n",
+			   fw_info.feature, fw_info.ver);
+	}
+
 	/* VCN */
 	query_fw.fw_type = AMDGPU_INFO_FW_VCN;
 	ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);

[Severity: High]
Does this fail to build because struct amdgpu_lsdma does not yet define fw_version, feature_version, or fw?

In drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.h, struct amdgpu_lsdma only has lock, funcs, and inst_mask here, so building amdgpu_kms.c fails and breaks git bisect.

Those fields are added in the next commit "drm/amdgpu: add lsdma v8 fw loading support", so moving that patch before this one would keep the series bisectable.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Reviewed-by on v1 4/9
#9 lore raw

Re: [PATCH 4/9] drm/amdgpu: add lsdma v8 fw query interface

In reply to Frank Min
Quoted 5 lines · Frank Min

Add lsdma v8 fw query interface.

This should come after patch 5 to avoid breaking the build. WIth that fixed:

Quoted 53 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 14 ++++++++++++++
 include/uapi/drm/amdgpu_drm.h           |  2 ++
 2 files changed, 16 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +14 -0
index 75fc49fb4b319..e6872352e0035 100644
@@ -332,6 +332,10 @@ static int amdgpu_firmware_info(struct drm_amdgpu_info_firmware *fw_info,
                fw_info->ver = adev->sdma.instance[query_fw->index].fw_version;
                fw_info->feature = adev->sdma.instance[query_fw->index].feature_version;
                break;
+       case AMDGPU_INFO_FW_LSDMA:
+               fw_info->ver = adev->lsdma.fw_version;
+               fw_info->feature = adev->lsdma.feature_version;
+               break;
        case AMDGPU_INFO_FW_SOS:
                fw_info->ver = adev->psp.sos.fw_version;
                fw_info->feature = adev->psp.sos.feature_version;
@@ -2028,6 +2032,16 @@ static int amdgpu_debugfs_firmware_info_show(struct seq_file *m, void *unused)
                           i, fw_info.feature, fw_info.ver);
        }
 
+       /* LSDMA */
+       if (adev->lsdma.fw) {
+               query_fw.fw_type = AMDGPU_INFO_FW_LSDMA;
+               ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
+               if (ret)
+                       return ret;
+               seq_printf(m, "LSDMA feature version: %u, firmware version: 0x%08x\n",
+                          fw_info.feature, fw_info.ver);
+       }
+
        /* VCN */
        query_fw.fw_type = AMDGPU_INFO_FW_VCN;
        ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
include/uapi/drm/amdgpu_drm.h +2 -1
index a9aa08c8d3095..37eeef7f43145 100644
@@ -1228,6 +1228,8 @@ struct drm_amdgpu_cs_chunk_cp_gfx_shadow {
        #define AMDGPU_INFO_FW_VPE              0x1c
        /* Subquery id: Query MP5 firmware version */
        #define AMDGPU_INFO_FW_MP5              0x1d
+       /* Subquery id: Query LSDMA firmware version */
+       #define AMDGPU_INFO_FW_LSDMA            0x1e
 
 /* number of bytes moved for TTM migration */
 #define AMDGPU_INFO_NUM_BYTES_MOVED            0x0f
--

2.43.0

author
#10 lore raw

PATCH 5/9 drm/amdgpu: add lsdma v8 fw loading support

In reply to Frank Min

Add lsdma v8 fw loading support.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.c | 51 +++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.h |  5 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c   |  3 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c | 12 ++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.h | 10 +++++
 drivers/gpu/drm/amd/amdgpu/lsdma_v8_0.c   |  2 +
 drivers/gpu/drm/amd/amdgpu/psp_v15_0_3.c  |  3 ++
 drivers/gpu/drm/amd/amdgpu/sdma_v8_0.c    |  7 ++++
 8 files changed, 93 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.c +51 -0
index 1f83d9b69135b..5d093e25cac6d 100644
@@ -21,6 +21,7 @@
  *
  */
 
+#include <linux/firmware.h>
 #include "amdgpu.h"
 #include "amdgpu_lsdma.h"
 
@@ -146,3 +147,53 @@ int amdgpu_lsdma_selftest(struct amdgpu_device *adev)
 
 	return r;
 }
+
+void amdgpu_lsdma_fini_microcode(struct amdgpu_device *adev)
+{
+	amdgpu_ucode_release(&adev->lsdma.fw);
+	adev->lsdma.fw_version = 0;
+	adev->lsdma.feature_version = 0;
+}
+
+int amdgpu_lsdma_init_microcode(struct amdgpu_device *adev)
+{
+	const struct lsdma_firmware_header_v1_0 *hdr;
+	struct amdgpu_firmware_info *info;
+	char ucode_prefix[30];
+	int err;
+
+	/* LSDMA before v8 has no firmware */
+	if (amdgpu_ip_version(adev, LSDMA_HWIP, 0) < IP_VERSION(8, 0, 0))
+		return 0;
+
+	amdgpu_ucode_ip_version_decode(adev, LSDMA_HWIP, ucode_prefix, sizeof(ucode_prefix));
+	err = amdgpu_ucode_request(adev, &adev->lsdma.fw, AMDGPU_UCODE_REQUIRED,
+				   "amdgpu/%s.bin", ucode_prefix);
+	if (err)
+		goto out;
+
+	hdr = (const struct lsdma_firmware_header_v1_0 *)adev->lsdma.fw->data;
+	switch (le16_to_cpu(hdr->header.header_version_major)) {
+	case 1:
+		break;
+	default:
+		err = -EINVAL;
+		goto out;
+	}
+
+	adev->lsdma.fw_version = le32_to_cpu(hdr->header.ucode_version);
+	adev->lsdma.feature_version = le32_to_cpu(hdr->ucode_feature_version);
+
+	if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
+		info = &adev->firmware.ucode[AMDGPU_UCODE_ID_LSDMA];
+		info->ucode_id = AMDGPU_UCODE_ID_LSDMA;
+		info->fw = adev->lsdma.fw;
+		adev->firmware.fw_size +=
+			ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE);
+	}
+
+out:
+	if (err)
+		amdgpu_lsdma_fini_microcode(adev);
+	return err;
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.h +5 -0
index f0a5eeb3529fb..79ac16e352d71 100644
@@ -30,6 +30,9 @@ struct amdgpu_lsdma {
 	struct mutex lock;
 	const struct amdgpu_lsdma_funcs      *funcs;
 	uint32_t inst_mask;
+	const struct firmware *fw;
+	uint32_t fw_version;
+	uint32_t feature_version;
 };
 
 struct amdgpu_lsdma_funcs {
@@ -47,5 +50,7 @@ int amdgpu_lsdma_fill_mem(struct amdgpu_device *adev, uint64_t dst_addr,
 int amdgpu_lsdma_wait_for(struct amdgpu_device *adev, uint32_t reg_index,
 			  uint32_t reg_val, uint32_t mask);
 int amdgpu_lsdma_selftest(struct amdgpu_device *adev);
+int amdgpu_lsdma_init_microcode(struct amdgpu_device *adev);
+void amdgpu_lsdma_fini_microcode(struct amdgpu_device *adev);
 
 #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +3 -0
index da4672707755c..9624b3dc95bfe 100644
@@ -3759,6 +3759,9 @@ int amdgpu_psp_get_fw_type(struct amdgpu_firmware_info *ucode,
 	case AMDGPU_UCODE_ID_SDMA_UCODE_TH1:
 		*type = GFX_FW_TYPE_SDMA_UCODE_TH1;
 		break;
+	case AMDGPU_UCODE_ID_LSDMA:
+		*type = GFX_FW_TYPE_LSDMA;
+		break;
 	case AMDGPU_UCODE_ID_IMU_I:
 		*type = GFX_FW_TYPE_IMU_I;
 		break;
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c +12 -0
index d2ce526dd95cc..c6b9078570456 100644
@@ -729,6 +729,8 @@ const char *amdgpu_ucode_name(enum AMDGPU_UCODE_ID ucode_id)
 		return "JPEG";
 	case AMDGPU_UCODE_ID_SDMA_RS64:
 		return "RS64_SDMA";
+	case AMDGPU_UCODE_ID_LSDMA:
+		return "LSDMA";
 	case AMDGPU_UCODE_ID_CP_RS64_PFP:
 		return "RS64_PFP";
 	case AMDGPU_UCODE_ID_CP_RS64_ME:
@@ -878,6 +880,7 @@ static int amdgpu_ucode_init_single_fw(struct amdgpu_device *adev,
 	const struct mes_firmware_header_v1_0 *mes_hdr = NULL;
 	const struct sdma_firmware_header_v2_0 *sdma_hdr = NULL;
 	const struct sdma_firmware_header_v3_0 *sdmav3_hdr = NULL;
+	const struct lsdma_firmware_header_v1_0 *lsdma_hdr = NULL;
 	const struct imu_firmware_header_v1_0 *imu_hdr = NULL;
 	const struct vpe_firmware_header_v1_0 *vpe_hdr = NULL;
 	const struct umsch_mm_firmware_header_v1_0 *umsch_mm_hdr = NULL;
@@ -900,6 +903,7 @@ static int amdgpu_ucode_init_single_fw(struct amdgpu_device *adev,
 	mes_hdr = (const struct mes_firmware_header_v1_0 *)ucode->fw->data;
 	sdma_hdr = (const struct sdma_firmware_header_v2_0 *)ucode->fw->data;
 	sdmav3_hdr = (const struct sdma_firmware_header_v3_0 *)ucode->fw->data;
+	lsdma_hdr = (const struct lsdma_firmware_header_v1_0 *)ucode->fw->data;
 	imu_hdr = (const struct imu_firmware_header_v1_0 *)ucode->fw->data;
 	vpe_hdr = (const struct vpe_firmware_header_v1_0 *)ucode->fw->data;
 	umsch_mm_hdr = (const struct umsch_mm_firmware_header_v1_0 *)ucode->fw->data;
@@ -921,6 +925,11 @@ static int amdgpu_ucode_init_single_fw(struct amdgpu_device *adev,
 			ucode_addr = (u8 *)ucode->fw->data +
 				le32_to_cpu(sdmav3_hdr->header.ucode_array_offset_bytes);
 			break;
+		case AMDGPU_UCODE_ID_LSDMA:
+			ucode->ucode_size = le32_to_cpu(lsdma_hdr->ucode_size_bytes);
+			ucode_addr = (u8 *)ucode->fw->data +
+				le32_to_cpu(lsdma_hdr->header.ucode_array_offset_bytes);
+			break;
 		case AMDGPU_UCODE_ID_CP_MEC1:
 		case AMDGPU_UCODE_ID_CP_MEC2:
 			ucode->ucode_size = le32_to_cpu(header->ucode_size_bytes) -
@@ -1500,6 +1509,9 @@ void amdgpu_ucode_ip_version_decode(struct amdgpu_device *adev, int block_type,
 	case SDMA0_HWIP:
 		ip_name = "sdma";
 		break;
+	case LSDMA_HWIP:
+		ip_name = "lsdma";
+		break;
 	case MP0_HWIP:
 		ip_name = "psp";
 		break;
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.h +10 -0
index 7c809692807fc..f8a57ff454c58 100644
@@ -375,6 +375,14 @@ struct sdma_firmware_header_v3_0 {
     uint32_t ucode_size_bytes;
 };
 
+/* version_major=1, version_minor=0 */
+struct lsdma_firmware_header_v1_0 {
+	struct common_firmware_header header;
+	uint32_t ucode_feature_version;
+	uint32_t ucode_offset_bytes;
+	uint32_t ucode_size_bytes;
+};
+
 /* gpu info payload */
 struct gpu_info_firmware_v1_0 {
 	uint32_t gc_num_se;
@@ -463,6 +471,7 @@ union amdgpu_firmware_header {
 	struct sdma_firmware_header_v1_1 sdma_v1_1;
 	struct sdma_firmware_header_v2_0 sdma_v2_0;
 	struct sdma_firmware_header_v3_0 sdma_v3_0;
+	struct lsdma_firmware_header_v1_0 lsdma;
 	struct gpu_info_firmware_header_v1_0 gpu_info;
 	struct dmcu_firmware_header_v1_0 dmcu;
 	struct dmcub_firmware_header_v1_0 dmcub;
@@ -489,6 +498,7 @@ enum AMDGPU_UCODE_ID {
 	AMDGPU_UCODE_ID_SDMA_UCODE_TH0,
 	AMDGPU_UCODE_ID_SDMA_UCODE_TH1,
 	AMDGPU_UCODE_ID_SDMA_RS64,
+	AMDGPU_UCODE_ID_LSDMA,
 	AMDGPU_UCODE_ID_CP_CE,
 	AMDGPU_UCODE_ID_CP_PFP,
 	AMDGPU_UCODE_ID_CP_ME,
drivers/gpu/drm/amd/amdgpu/lsdma_v8_0.c +2 -0
index d19d7f8add50e..722c85b2ccf3b 100644
@@ -29,6 +29,8 @@
 #include "lsdma/lsdma_8_0_1_offset.h"
 #include "lsdma/lsdma_8_0_1_sh_mask.h"
 
+MODULE_FIRMWARE("amdgpu/lsdma_8_0_1.bin");
+
 static int lsdma_v8_0_wait_pio_status(struct amdgpu_device *adev)
 {
 	u32 error_mask;
drivers/gpu/drm/amd/amdgpu/psp_v15_0_3.c +3 -0
index a7c7dcb74d989..3c77db281068d 100644
@@ -684,6 +684,9 @@ static int psp_v15_0_3_get_fw_type(struct amdgpu_firmware_info *ucode,
 	case AMDGPU_UCODE_ID_SDMA_RS64:
 		*type = GFX_FW_TYPE_SDMA0;
 		break;
+	case AMDGPU_UCODE_ID_LSDMA:
+		*type = GFX_FW_TYPE_LSDMA;
+		break;
 	case AMDGPU_UCODE_ID_CP_MES:
 		*type = GFX_FW_TYPE_CP_MES;
 		break;
drivers/gpu/drm/amd/amdgpu/sdma_v8_0.c +7 -0
index 58b85fbba2ca3..e39a005b0faf4 100644
@@ -1293,6 +1293,12 @@ static int sdma_v8_0_early_init(struct amdgpu_ip_block *ip_block)
 		return r;
 	}
 
+	r = amdgpu_lsdma_init_microcode(adev);
+	if (r) {
+		DRM_ERROR("Failed to init lsdma firmware!\n");
+		return r;
+	}
+
 	sdma_v8_0_set_ring_funcs(adev);
 	amdgpu_sdma_set_vm_pte_scheds(adev, &sdma_v8_0_vm_pte_funcs);
 	sdma_v8_0_set_irq_funcs(adev);
@@ -1377,6 +1383,7 @@ static int sdma_v8_0_sw_fini(struct amdgpu_ip_block *ip_block)
 
 	amdgpu_sdma_sysfs_reset_mask_fini(adev);
 	amdgpu_sdma_destroy_inst_ctx(adev, true);
+	amdgpu_lsdma_fini_microcode(adev);
 
 	if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT)
 		sdma_v8_0_0_free_ucode_buffer(adev);
Signature · 1 line
2.43.0
#11 lore raw

Re: [PATCH 5/9] drm/amdgpu: add lsdma v8 fw loading support

Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] drm/amdgpu: struct amdgpu_lsdma fields added after parent commit uses them - [Medium] drm/amdgpu…

Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] drm/amdgpu: struct amdgpu_lsdma fields added after parent commit uses them
- [Medium] drm/amdgpu: missing LSDMA firmware header, payload, and ALIGN bounds checks
- [Medium] drm/amdgpu: sdma_v8_0_early_init() leaks SDMA fw on LSDMA init failure
- [Medium] drm/amdgpu: leak LSDMA firmware on probe failure before sdma_v8_0_sw_init()
--

commit 8d33406c65061fd80329c2978329e7275ecae49b
Author: Frank Min <[email protected]>

drm/amdgpu: add lsdma v8 fw loading support

This commit adds LSDMA v8 firmware loading support, including the v1.0 firmware header definition, microcode initialization and teardown helpers, and PSP/SDMA v8.0 integration.

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.c +0 -0
index 1f83d9b69135b..5d093e25cac6d 100644

[ ... ]

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.c +9 -0
+	hdr = (const struct lsdma_firmware_header_v1_0 *)adev->lsdma.fw->data;
+	switch (le16_to_cpu(hdr->header.header_version_major)) {
+	case 1:
+		break;
+	default:
+		err = -EINVAL;
+		goto out;
+	}
+

drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.c int amdgpu_lsdma_selftest(struct amdgpu_device *adev) · line 193

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.c +10 -0
+	adev->lsdma.fw_version = le32_to_cpu(hdr->header.ucode_version);
+	adev->lsdma.feature_version = le32_to_cpu(hdr->ucode_feature_version);
+
+	if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
+		info = &adev->firmware.ucode[AMDGPU_UCODE_ID_LSDMA];
+		info->ucode_id = AMDGPU_UCODE_ID_LSDMA;
+		info->fw = adev->lsdma.fw;
+		adev->firmware.fw_size +=
+			ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE);
+	}

[Severity: Medium]
Can a truncated or malformed LSDMA firmware image cause an out-of-bounds read from fw->data or an out-of-bounds write into fw_buf here?

amdgpu_ucode_validate() only checks fw->size == le32_to_cpu(hdr->size_bytes), so fw->data may be smaller than sizeof(*hdr), and neither this function nor amdgpu_ucode_init_single_fw() checks that ucode_array_offset_bytes + ucode_size_bytes fits within fw->size before memcpy(). In addition, ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE) and the addition into 32-bit adev->firmware.fw_size can wrap around, causing amdgpu_ucode_create_bo() to allocate an undersized firmware BO.

[ ... ]

drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.h struct amdgpu_lsdma { · line 36

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.h +3 -0
index f0a5eeb3529fb..79ac16e352d71 100644
@@ -30,6 +30,9 @@ struct amdgpu_lsdma {
 	struct mutex lock;
 	const struct amdgpu_lsdma_funcs      *funcs;
 	uint32_t inst_mask;
+	const struct firmware *fw;
+	uint32_t fw_version;
+	uint32_t feature_version;
 };

[Severity: High]
Does adding fw, fw_version, and feature_version here break git bisect with the preceding commit "drm/amdgpu: add lsdma v8 fw query interface"?

That earlier commit already references adev->lsdma.fw_version and adev->lsdma.feature_version in amdgpu_firmware_info() and adev->lsdma.fw in amdgpu_debugfs_firmware_info_show(), so the tree fails to build at that commit. These struct fields (or this whole commit) should be ordered before the query interface patch.

[ ... ]

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/sdma_v8_0.c +0 -0
index 58b85fbba2ca3..e39a005b0faf4 100644
@@ -1293,6 +1293,12 @@ static int sdma_v8_0_early_init(struct amdgpu_ip_block *ip_block)
 		return r;
 	}

drivers/gpu/drm/amd/amdgpu/sdma_v8_0.c static int sdma_v8_0_early_init(struct amdgpu_ip_block *ip_block) · line 1304

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/sdma_v8_0.c +6 -0
 
+	r = amdgpu_lsdma_init_microcode(adev);
+	if (r) {
+		DRM_ERROR("Failed to init lsdma firmware!\n");
+		return r;
+	}
+
 	sdma_v8_0_set_ring_funcs(adev);
 	amdgpu_sdma_set_vm_pte_scheds(adev, &sdma_v8_0_vm_pte_funcs);
 	sdma_v8_0_set_irq_funcs(adev);

[Severity: Medium]
Does returning here leak the SDMA firmware loaded just above by amdgpu_sdma_init_microcode()?

When sdma_v8_0_early_init() fails, status.sw stays false and amdgpu_device_ip_fini() skips sdma_v8_0_sw_fini(), so amdgpu_sdma_destroy_inst_ctx(adev, true) never runs to release adev->sdma.instance[0].fw.

drivers/gpu/drm/amd/amdgpu/sdma_v8_0.c static int sdma_v8_0_sw_fini(struct amdgpu_ip_block *ip_block) · line 1389

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/sdma_v8_0.c +1 -0
@@ -1377,6 +1383,7 @@ static int sdma_v8_0_sw_fini(struct amdgpu_ip_block *ip_block)
 
 	amdgpu_sdma_sysfs_reset_mask_fini(adev);
 	amdgpu_sdma_destroy_inst_ctx(adev, true);
+	amdgpu_lsdma_fini_microcode(adev);
 
 	if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT)
 		sdma_v8_0_0_free_ucode_buffer(adev);

[Severity: Medium]
Can adev->lsdma.fw be leaked if device probe fails after sdma_v8_0_early_init() succeeds but before sdma_v8_0_sw_init() completes?

amdgpu_device_ip_init() only sets status.sw after sw_init() returns 0, and sdma_v8_0_ip_funcs has no early_fini callback, so amdgpu_device_ip_fini() skips sdma_v8_0_sw_fini() on an earlier probe failure (such as another IP block's early_init() or an error inside sdma_v8_0_sw_init()). Moving the microcode init into sw_init() or providing an early_fini callback would ensure adev->lsdma.fw is released.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
author
#12 lore raw

PATCH 6/9 drm/amdgpu: Fix system aperture size for gfx13

In reply to Frank Min

Gfx13 vram layout introduced vram offset, but aperture space should not be affected. So fix system aperture size to align with it.

---
 drivers/gpu/drm/amd/amdgpu/gmc_v13_0.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/gmc_v13_0.c +9 -3
index 49fee18eb5253..b548b748d670e 100644
@@ -618,10 +618,14 @@ static int gmc_v13_0_late_init(struct amdgpu_ip_block *ip_block)
 	return amdgpu_irq_get(adev, &adev->gmc.vm_fault, 0);
 }
 
-static void gmc_v13_0_vram_gtt_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc, u64 base, u64 offset)
+static void gmc_v13_0_vram_gtt_location(struct amdgpu_device *adev,
+					struct amdgpu_gmc *mc, u64 base)
 {
 	amdgpu_gmc_set_agp_default(adev, mc);
 	amdgpu_gmc_vram_location(adev, mc, base);
+
+	if (!amdgpu_sriov_vf(adev))
+		mc->fb_start = adev->mmhub.funcs->get_fb_location(adev);
 	amdgpu_gmc_gart_location(adev, mc, AMDGPU_GART_PLACEMENT_LOW);
 	if (!amdgpu_sriov_vf(adev) && (amdgpu_agp == 1))
 		amdgpu_gmc_agp_location(adev, mc);
@@ -630,7 +634,9 @@ static void gmc_v13_0_vram_gtt_location(struct amdgpu_device *adev, struct amdgp
 	if (amdgpu_sriov_vf(adev))
 		adev->vm_manager.vram_base_offset = 0;
 	else
-		adev->vm_manager.vram_base_offset = adev->mmhub.funcs->get_mc_fb_offset(adev) + offset;
+		adev->vm_manager.vram_base_offset =
+			adev->mmhub.funcs->get_mc_fb_offset(adev) +
+			mc->vram_start - mc->fb_start;
 }
 
 /**
@@ -689,7 +695,7 @@ static int gmc_v13_0_mc_init(struct amdgpu_device *adev)
 	/* set the gart size */
 	amdgpu_gmc_set_gart_size(adev, SZ_512M);
 
-	gmc_v13_0_vram_gtt_location(adev, &adev->gmc, base, mc_vram_offset);
+	gmc_v13_0_vram_gtt_location(adev, &adev->gmc, base);
 
 	return 0;
 }
Signature · 1 line
2.43.0
#13 lore raw

Re: [PATCH 6/9] drm/amdgpu: Fix system aperture size for gfx13

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] drm/amdgpu: fb_start split in gmc_v13_0_vram_gtt_location() breaks DMUB - [Low] drm/amdgpu…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] drm/amdgpu: fb_start split in gmc_v13_0_vram_gtt_location() breaks DMUB
- [Low] drm/amdgpu: missing Fixes trailer for gmc_v13_0_vram_gtt_location() bug fix
--

commit 161a9a2ab1dbbfb524cfebbbafa5623789e83c80
Author: Frank Min <[email protected]>

Quoted 7 lines

drm/amdgpu: Fix system aperture size for gfx13

Gfx13 vram layout introduced vram offset, but aperture space should not be affected. So fix system aperture size to align with it.

[Severity: Low]
This looks like a bug fix for the GFX13 aperture setup. Should this include:

Fixes 41a7a8f5012e ("drm/amdgpu: Add gmc v13_0 support")
Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/gmc_v13_0.c +5 -1
index 49fee18eb5253..b548b748d670e 100644
@@ -618,10 +618,14 @@ static int gmc_v13_0_late_init(struct amdgpu_ip_block *ip_block)
 	return amdgpu_irq_get(adev, &adev->gmc.vm_fault, 0);
 }
 
-static void gmc_v13_0_vram_gtt_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc, u64 base, u64 offset)
+static void gmc_v13_0_vram_gtt_location(struct amdgpu_device *adev,
+					struct amdgpu_gmc *mc, u64 base)
 {
 	amdgpu_gmc_set_agp_default(adev, mc);
 	amdgpu_gmc_vram_location(adev, mc, base);
+
+	if (!amdgpu_sriov_vf(adev))
+		mc->fb_start = adev->mmhub.funcs->get_fb_location(adev);
 	amdgpu_gmc_gart_location(adev, mc, AMDGPU_GART_PLACEMENT_LOW);
 	if (!amdgpu_sriov_vf(adev) && (amdgpu_agp == 1))
 		amdgpu_gmc_agp_location(adev, mc);

drivers/gpu/drm/amd/amdgpu/gmc_v13_0.c static void gmc_v13_0_vram_gtt_location(struct amdgpu_device *adev, struct amdgp · line 640

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gmc_v13_0.c +3 -1
@@ -630,7 +634,9 @@ static void gmc_v13_0_vram_gtt_location(struct amdgpu_device *adev, struct amdgp
 	if (amdgpu_sriov_vf(adev))
 		adev->vm_manager.vram_base_offset = 0;
 	else
-		adev->vm_manager.vram_base_offset = adev->mmhub.funcs->get_mc_fb_offset(adev) + offset;
+		adev->vm_manager.vram_base_offset =
+			adev->mmhub.funcs->get_mc_fb_offset(adev) +
+			mc->vram_start - mc->fb_start;
 }

[Severity: Medium]
Does splitting mc->fb_start from mc->vram_start here break DMUB address translation during backdoor firmware loading?

dm_dmub_hw_init() pairs adev->gmc.fb_start with
adev->vm_manager.vram_base_offset:

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.c:dm_dmub_hw_init() {
	...
	hw_params.soc_fb_info.fb_base = adev->gmc.fb_start;
	hw_params.soc_fb_info.fb_offset = adev->vm_manager.vram_base_offset;
	...
}

On bare-metal GFX13 with a non-zero HDP VRAM offset, mc->fb_start is now the unshifted FB location while adev->vm_manager.vram_base_offset stays shifted by (mc->vram_start - mc->fb_start). When adev->firmware.load_type is not AMDGPU_FW_LOAD_PSP, dmub_dcn60_backdoor_load() translates CW0 and CW1 VRAM addresses via dmub_dcn60_translate_addr() (addr_in - fb_base + fb_offset), which double-counts that offset.

This shifts DMCUB_REGION3_CW0_OFFSET and DMCUB_REGION3_CW1_OFFSET outside the DMUB VRAM BO, causing backdoor boot to fail or stack DMA writes to corrupt VRAM. Should dm_dmub_hw_init() pair adev->gmc.vram_start with adev->vm_manager.vram_base_offset instead?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
author
#14 lore raw

PATCH 7/9 drm/amdgpu: remove the unused ring parameter in update_spm_vmid() for gfx13

In reply to Frank Min

remove the unused ring parameter in update_spm_vmid() for gfx13.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c +1 -11
index f0ac919a43480..9ef249b95f916 100644
@@ -2134,7 +2134,7 @@ static int gfx_v13_0_rlc_resume(struct amdgpu_device *adev)
 
 	/* init spm vmid with 0xf */
 	if (adev->gfx.rlc.funcs->update_spm_vmid)
-		adev->gfx.rlc.funcs->update_spm_vmid(adev, 0, NULL, adev->vm_manager.spm_vmid);
+		adev->gfx.rlc.funcs->update_spm_vmid(adev, 0, adev->vm_manager.spm_vmid);
 
 	return 0;
 }
@@ -3963,22 +3963,12 @@ static void gfx_v13_0_update_perf_clk(struct amdgpu_device *adev,
 
 static void gfx_v13_0_update_spm_vmid(struct amdgpu_device *adev,
 				      int xcc_id,
-				      struct amdgpu_ring *ring,
 				      unsigned vmid)
 {
 	u32 reg, data;
 
 	reg = SOC15_REG_OFFSET(GC, 0, regRLC_SPM_MC_CNTL);
 
-	if (ring) {
-		if ((ring->funcs->type == AMDGPU_RING_TYPE_GFX) ||
-		    (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE)) {
-			data = (vmid & RLC_SPM_MC_CNTL__RLC_SPM_VMID_MASK) << RLC_SPM_MC_CNTL__RLC_SPM_VMID__SHIFT;
-			amdgpu_ring_emit_wreg(ring, reg, data);
-		}
-		return;
-	}
-
 	amdgpu_gfx_off_ctrl(adev, false);
 	if (amdgpu_sriov_is_pp_one_vf(adev))
 		data = RREG32_NO_KIQ(reg);
Signature · 1 line
2.43.0
#15 lore raw

Re: [PATCH 7/9] drm/amdgpu: remove the unused ring parameter in update_spm_vmid() for gfx13

Quoted 4 lines · Frank Min

remove the unused ring parameter in update_spm_vmid() for gfx13.

What branch is this against? Ring is a valid parameter.

Alex

Quoted 43 lines
---
 drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c +1 -12
index f0ac919a43480..9ef249b95f916 100644
@@ -2134,7 +2134,7 @@ static int gfx_v13_0_rlc_resume(struct amdgpu_device *adev)
 
        /* init spm vmid with 0xf */
        if (adev->gfx.rlc.funcs->update_spm_vmid)
-               adev->gfx.rlc.funcs->update_spm_vmid(adev, 0, NULL, adev->vm_manager.spm_vmid);
+               adev->gfx.rlc.funcs->update_spm_vmid(adev, 0, adev->vm_manager.spm_vmid);
 
        return 0;
 }
@@ -3963,22 +3963,12 @@ static void gfx_v13_0_update_perf_clk(struct amdgpu_device *adev,
 
 static void gfx_v13_0_update_spm_vmid(struct amdgpu_device *adev,
                                      int xcc_id,
-                                     struct amdgpu_ring *ring,
                                      unsigned vmid)
 {
        u32 reg, data;
 
        reg = SOC15_REG_OFFSET(GC, 0, regRLC_SPM_MC_CNTL);
 
-       if (ring) {
-               if ((ring->funcs->type == AMDGPU_RING_TYPE_GFX) ||
-                   (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE)) {
-                       data = (vmid & RLC_SPM_MC_CNTL__RLC_SPM_VMID_MASK) << RLC_SPM_MC_CNTL__RLC_SPM_VMID__SHIFT;
-                       amdgpu_ring_emit_wreg(ring, reg, data);
-               }
-               return;
-       }
-
        amdgpu_gfx_off_ctrl(adev, false);
        if (amdgpu_sriov_is_pp_one_vf(adev))
                data = RREG32_NO_KIQ(reg);
--

2.43.0

#16 lore raw

Re: [PATCH 7/9] drm/amdgpu: remove the unused ring parameter in update_spm_vmid() for gfx13

In reply to Frank Min
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] drm/amdgpu: update_spm_vmid() signature mismatch breaks gfx_v13_0.c build - [High] drm/amdgpu…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] drm/amdgpu: update_spm_vmid() signature mismatch breaks gfx_v13_0.c build
- [High] drm/amdgpu: dropping ring path in gfx_v13_0_update_spm_vmid() breaks IB SPM
--

commit a118ecae2dc4a26b43bad4e4bf47f778ad08d52a
Author: Frank Min <[email protected]>

drm/amdgpu: remove the unused ring parameter in update_spm_vmid() for gfx13

This patch removes the ring parameter and its in-band ring write path from gfx_v13_0_update_spm_vmid(), and updates its call site in gfx_v13_0_rlc_resume() accordingly.

drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c static int gfx_v13_0_rlc_resume(struct amdgpu_device *adev) · line 2137

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c +1 -1
index f0ac919a43480..9ef249b95f916 100644
@@ -2134,7 +2134,7 @@ static int gfx_v13_0_rlc_resume(struct amdgpu_device *adev)
 
 	/* init spm vmid with 0xf */
 	if (adev->gfx.rlc.funcs->update_spm_vmid)
-		adev->gfx.rlc.funcs->update_spm_vmid(adev, 0, NULL, adev->vm_manager.spm_vmid);
+		adev->gfx.rlc.funcs->update_spm_vmid(adev, 0, adev->vm_manager.spm_vmid);

[Severity: High]
Does this break the build due to a signature mismatch with struct amdgpu_rlc_funcs?

struct amdgpu_rlc_funcs in drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.h still declares update_spm_vmid with four parameters, including struct amdgpu_ring *ring, as restored by e9ebb72a64b6 ("drm/amdgpu: bring back the ring parameter for update_spm_vmid()").

Calling update_spm_vmid() with three arguments here fails compilation, as does assigning the three-parameter gfx_v13_0_update_spm_vmid() to gfx_v13_0_rlc_funcs.update_spm_vmid.

[ ... ]

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c +0 -3
@@ -3963,22 +3963,12 @@ static void gfx_v13_0_update_perf_clk(struct amdgpu_device *adev,
 
 static void gfx_v13_0_update_spm_vmid(struct amdgpu_device *adev,
 				      int xcc_id,
-				      struct amdgpu_ring *ring,
 				      unsigned vmid)
 {
 	u32 reg, data;
 
 	reg = SOC15_REG_OFFSET(GC, 0, regRLC_SPM_MC_CNTL);
 
-	if (ring) {
-		if ((ring->funcs->type == AMDGPU_RING_TYPE_GFX) ||

drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c static void gfx_v13_0_update_perf_clk(struct amdgpu_device *adev, · line 3974

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c +0 -7
-		    (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE)) {
-			data = (vmid & RLC_SPM_MC_CNTL__RLC_SPM_VMID_MASK) << RLC_SPM_MC_CNTL__RLC_SPM_VMID__SHIFT;
-			amdgpu_ring_emit_wreg(ring, reg, data);
-		}
-		return;
-	}
-
 	amdgpu_gfx_off_ctrl(adev, false);
 	if (amdgpu_sriov_is_pp_one_vf(adev))
 		data = RREG32_NO_KIQ(reg);

[Severity: High]
Is the ring parameter actually unused, and does deleting this branch break in-band SPM updates during IB submission?

amdgpu_ib_schedule() still passes a non-NULL ring to update_spm_vmid() on every gfx and compute IB submission. Both gfx_v13_0_ring_funcs_gfx and gfx_v13_0_ring_funcs_compute also reserve 5 dwords in emit_frame_size for this write.

Even if the signature were reconciled, dropping the if (ring) path loses the ring-based regRLC_SPM_MC_CNTL update across gfxoff cycles and forces every IB submission through amdgpu_gfx_off_ctrl() (acquiring adev->gfx.gfx_off_mutex) and unlocked CPU register read-modify-writes.

Should this patch be dropped instead so gfx13 keeps the ring path?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
author
#17 lore raw

PATCH 8/9 drm/amdgpu: enable uni-mes for gfx13

In reply to Frank Min

Enable uni-mes for gfx13.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +3 -3
index 50b0112825c42..c8fe1cb45dd95 100644
@@ -3424,10 +3424,10 @@ static int amdgpu_discovery_set_mes_ip_blocks(struct amdgpu_device *adev)
 	case IP_VERSION(13, 0, 1):
 	case IP_VERSION(13, 0, 4):
 		amdgpu_device_ip_block_add(adev, &mes_v13_0_ip_block);
-		adev->enable_mes = false;
-		adev->enable_mes_kiq = false;
+		adev->enable_mes = true;
+		adev->enable_mes_kiq = true;
 		if (amdgpu_uni_mes)
-			adev->enable_uni_mes = false;
+			adev->enable_uni_mes = true;
 		break;
 	default:
 		break;
Signature · 1 line
2.43.0
#18 lore raw

Re: [PATCH 8/9] drm/amdgpu: enable uni-mes for gfx13

Thank you for your contribution! Sashiko AI review found 9 potential issues to consider: - [High] drm/amdgpu: GFX13 MES enabled with no-op suspend_gang/resume_gang stubs - [High] drm/amdgpu…

Thank you for your contribution! Sashiko AI review found 9 potential issues to consider:
- [High] drm/amdgpu: GFX13 MES enabled with no-op suspend_gang/resume_gang stubs
- [High] drm/amdgpu: mes_v13_0_submit_pkt_and_poll_completion() returns 0 on errors
- [High] drm/amdgpu: mes_v13_0_remove_hw_queue() omits queue_type and reset flag
- [Medium] drm/amdgpu: GFX13 uni-mes routes legacy KQs and resets to KIQ pipe
- [Medium] drm/amdgpu: amdgpu_mes_queue_reset_by_mes_supported() omits GC 13.x
- [Medium] drm/amdgpu: missing MODULE_FIRMWARE declarations for GC 13.0.4 MES firmware
- [Medium] drm/amdgpu: literal 0 write clears regCP_MQD_CONTROL in mes_v13_0_queue_init_register()
- [Medium] drm/amdgpu: mes_v13_0_set_hw_resources_1() gated on 0x4b and unchecked
- [Low] drm/amdgpu: commit message omits unconditional enable_mes and enable_mes_kiq
--

commit bfe01128f1efb4aa22fc5a9f7950763067c635fd
Author: Frank Min <[email protected]>

Quoted 5 lines

drm/amdgpu: enable uni-mes for gfx13

Enable uni-mes for gfx13.

[Severity: Low]
The subject and body only mention enabling uni-mes, but this patch also unconditionally enables adev->enable_mes and adev->enable_mes_kiq for both GC 13.0.1 and GC 13.0.4 even when amdgpu.uni_mes=0 is set. Could the commit message describe all three changes and explain why GFX13 is ready for MES enablement?

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c static int amdgpu_discovery_set_mes_ip_blocks(struct amdgpu_device *adev) · line 3410

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +1 -2
index 5997946fb1171..292245f167e07 100644
@@ -3407,10 +3407,10 @@ static int amdgpu_discovery_set_mes_ip_blocks(struct amdgpu_device *adev)
 	case IP_VERSION(13, 0, 1):
 	case IP_VERSION(13, 0, 4):
 		amdgpu_device_ip_block_add(adev, &mes_v13_0_ip_block);
-		adev->enable_mes = false;
-		adev->enable_mes_kiq = false;
+		adev->enable_mes = true;

[Severity: High]
Can GFX13 enable MES before mes_v13_0_suspend_gang() and mes_v13_0_resume_gang() are implemented?

Both callbacks in drivers/gpu/drm/amd/amdgpu/mes_v13_0.c are empty stubs returning 0 without submitting a packet or signaling the suspend fence. During user queue preemption (such as S0ix suspend or enforce_isolation switches), mes_userq_preempt() zeroes *fence_ptr, calls suspend_gang(), and busy-waits in a udelay(1) loop for 2.1 seconds per queue before failing with -ETIMEDOUT, marking healthy queues hung while leaving them active on hardware.

In addition, amdgpu_mes_suspend_resume_all_supported() returns true for GC 13.x, so amdgpu_gfx_reset_mes_compute() treats the stub 0 return from amdgpu_mes_suspend() as all gangs suspended and skips amdgpu_mes_detect_and_reset_hung_queues().

[Severity: High]
Does mes_v13_0_submit_pkt_and_poll_completion() silently return 0 on MES command failures?

Per MES_API_STATUS in drivers/gpu/drm/amd/include/mes_v13_api_def.h, MES v13 reports API rejections by writing 0 to the lower 32 bits and a non-zero error code to the upper 32 bits. Testing !*status_ptr across all 64 bits instead of !lower_32_bits(*status_ptr) treats rejected commands as success.

Similarly, when amdgpu_fence_wait_polling() times out waiting for ring space, it returns 0, and jumping to error_undo returns 0 without submitting the packet instead of -ETIMEDOUT. If mes_v13_0_remove_hw_queue() falsely succeeds on either error, amdgpu_userq_destroy() skips GPU reset and frees the queue BOs while the queue may still be active on hardware, risking DMA use-after-free.

[Severity: High]
Does mes_v13_0_remove_hw_queue() leave mes_remove_queue_pkt.queue_type at 0 (MES_QUEUE_TYPE_GFX) for compute and SDMA queues?

With adev->enable_mes enabled, KFD and userq tear down compute and SDMA queues through this function, but it only populates doorbell_offset and gang_context_addr. As seen in commit 89db46e455ab ("drm/amdgpu,amdkfd:
correct setting MES queue type"), sending REMOVE_QUEUE with the wrong queue type makes MES search the wrong queue class, causing unmap hangs or leaving the queue active after its memory is freed.

It also ignores input->remove_queue_after_reset, breaking post-reset cleanup in reset_queue_mes().

[Severity: Medium]
Should amdgpu_mes_queue_reset_by_mes_supported() in drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c also handle GC 13.x?

It currently only checks GC 11.x, 12.0, and 12.1, so it returns false on GFX13 even though gfx_v13_0 advertises per-queue compute reset. When a KFD compute queue hangs, reset_queues_mes() fails with -ENOTRECOVERABLE and escalates to a full GPU reset.

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c static int amdgpu_discovery_set_mes_ip_blocks(struct amdgpu_device *adev) · line 3428

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +1 -0
+		adev->enable_mes_kiq = true;

[Severity: Medium]
Now that adev->enable_mes_kiq is enabled, does mes_v13_0_queue_init_register() wipe regCP_MQD_CONTROL?

drivers/gpu/drm/amd/amdgpu/mes_v13_0.c:mes_v13_0_queue_init_register() {
    ...
	data = RREG32_SOC15(GC, 0, regCP_MQD_CONTROL);
	data = REG_SET_FIELD(data, CP_MQD_CONTROL, VMID, 0);
	WREG32_SOC15(GC, 0, regCP_MQD_CONTROL, 0);
    ...
}

Writing literal 0 instead of data clears PRIV_STATE and the other control fields during MES KIQ HQD setup on every init, resume, and reset.

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c static int amdgpu_discovery_set_mes_ip_blocks(struct amdgpu_device *adev) · line 3430

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +1 -1
 		if (amdgpu_uni_mes)
-			adev->enable_uni_mes = false;
+			adev->enable_uni_mes = true;

[Severity: Medium]
Should mes_v13_0_map_legacy_queue(), mes_v13_0_unmap_legacy_queue(), and mes_v13_0_reset_hw_queue() use AMDGPU_MES_SCHED_PIPE for non-MES legacy kernel queues when enable_uni_mes is set?

All three functions in drivers/gpu/drm/amd/amdgpu/mes_v13_0.c currently send legacy kernel queues and is_kq resets to AMDGPU_MES_KIQ_PIPE. As fixed for GFX12 in commit 5ec4cc917083 ("drm/amdgpu/mes_v12_0: use mes schedule pipe for legacy queues on unified MES"), pipe 0 MES only tracks queues on the schedule pipe, leaving legacy kernel queues (when booted with amdgpu.user_queue=0 or 1) inconsistent across suspend/resume and resets.

[Severity: Medium]
Are MODULE_FIRMWARE declarations missing for GC 13.0.4 MES firmware?

drivers/gpu/drm/amd/amdgpu/mes_v13_0.c only declares MODULE_FIRMWARE for gc_13_0_1, whereas enabling MES on IP_VERSION(13, 0, 4) makes amdgpu_mes_init_microcode() require amdgpu/gc_13_0_4_uni_mes.bin (or gc_13_0_4_mes.bin and gc_13_0_4_mes1.bin with amdgpu.uni_mes=0). Initramfs builders using modinfo will omit them, causing probe to fail with -ENODEV during early boot.

[Severity: Medium]
Should mes_v13_0_hw_init() call mes_v13_0_set_hw_resources_1() unconditionally and check its return value in both mes_v13_0_hw_init() and mes_v13_0_kiq_hw_init()?

On GFX13, mes_v13_0_set_hw_resources_1() is the only place sdma_hqd_mask is sent to MES, yet mes_v13_0_hw_init() gates it on sched_version >= 0x4b (a GFX12 check from commit 0180e0a5dd5c ("drm/amdgpu/mes: add compatibility checks for set_hw_resource_1")) while mes_v13_0_kiq_hw_init() calls it unconditionally. On GFX13 firmware with a version below 0x4b, this leaves sdma_hqd_mask zeroed and breaks MES SDMA user-queue scheduling.

Both callers also discard the int return value of mes_v13_0_set_hw_resources_1(), allowing MES initialization to succeed even if the packet submission or completion fails.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Reviewed-by on v1 8/9
#19 lore raw

Re: [PATCH 8/9] drm/amdgpu: enable uni-mes for gfx13

In reply to Frank Min
Quoted 4 lines · Frank Min

Enable uni-mes for gfx13.

We may want to get rid of the amdgpu_uni_mes parameter at some point? I don't think any of the chips that support uni-mes actually support non-uni-mes in production.

Alex

Quoted 25 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +3 -4
index 50b0112825c42..c8fe1cb45dd95 100644
@@ -3424,10 +3424,10 @@ static int amdgpu_discovery_set_mes_ip_blocks(struct amdgpu_device *adev)
        case IP_VERSION(13, 0, 1):
        case IP_VERSION(13, 0, 4):
                amdgpu_device_ip_block_add(adev, &mes_v13_0_ip_block);
-               adev->enable_mes = false;
-               adev->enable_mes_kiq = false;
+               adev->enable_mes = true;
+               adev->enable_mes_kiq = true;
                if (amdgpu_uni_mes)
-                       adev->enable_uni_mes = false;
+                       adev->enable_uni_mes = true;
                break;
        default:
                break;
--

2.43.0

author
#20 lore raw

PATCH 9/9 drm/amdgpu: fix mutex unlock position for ucode loading

In reply to Frank Min

Reset the GRBM selection before dropping srbm_mutex.

Fix gfx v11.0/v12.0/v12.1 and v13.0.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 4 ++--
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c | 3 ++-
 4 files changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2 -2
index ea74defe7fea0..13ff74ec3a540 100644
@@ -3030,8 +3030,8 @@ static int gfx_v11_0_config_mec_cache_rs64(struct amdgpu_device *adev, uint64_t
 		WREG32_SOC15(GC, 0, regCP_CPC_IC_BASE_HI,
 		     upper_32_bits(addr));
 	}
-	mutex_unlock(&adev->srbm_mutex);
 	soc21_grbm_select(adev, 0, 0, 0, 0);
+	mutex_unlock(&adev->srbm_mutex);
 
 	/* Trigger an invalidation of the L1 instruction caches */
 	tmp = RREG32_SOC15(GC, 0, regCP_MEC_DC_OP_CNTL);
@@ -3989,8 +3989,8 @@ static int gfx_v11_0_cp_compute_load_microcode_rs64(struct amdgpu_device *adev)
 		WREG32_SOC15(GC, 0, regCP_CPC_IC_BASE_HI,
 		     upper_32_bits(adev->gfx.mec.mec_fw_gpu_addr));
 	}
-	mutex_unlock(&adev->srbm_mutex);
 	soc21_grbm_select(adev, 0, 0, 0, 0);
+	mutex_unlock(&adev->srbm_mutex);
 
 	/* Trigger an invalidation of the L1 instruction caches */
 	tmp = RREG32_SOC15(GC, 0, regCP_MEC_DC_OP_CNTL);
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1 -1
index 8d6e74167d1c4..02894a2bb4bf3 100644
@@ -2860,8 +2860,8 @@ static int gfx_v12_0_cp_compute_load_microcode_rs64(struct amdgpu_device *adev)
 		WREG32_SOC15(GC, 0, regCP_CPC_IC_BASE_HI,
 			     upper_32_bits(adev->gfx.mec.mec_fw_gpu_addr));
 	}
-	mutex_unlock(&adev->srbm_mutex);
 	soc24_grbm_select(adev, 0, 0, 0, 0);
+	mutex_unlock(&adev->srbm_mutex);
 
 	/* Trigger an invalidation of the L1 instruction caches */
 	tmp = RREG32_SOC15(GC, 0, regCP_MEC_DC_OP_CNTL);
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +1 -1
index d393435e994b2..b200863bad906 100644
@@ -2183,8 +2183,8 @@ static int gfx_v12_1_xcc_cp_compute_load_microcode_rs64(struct amdgpu_device *ad
 		WREG32_SOC15(GC, GET_INST(GC, xcc_id), regCP_CPC_IC_BASE_HI,
 				upper_32_bits(adev->gfx.mec.mec_fw_gpu_addr));
 	}
-	mutex_unlock(&adev->srbm_mutex);
 	soc_v1_0_grbm_select(adev, 0, 0, 0, 0, GET_INST(GC, xcc_id));
+	mutex_unlock(&adev->srbm_mutex);
 
 	/* Trigger an invalidation of the L1 instruction caches */
 	tmp = RREG32_SOC15(GC, GET_INST(GC, xcc_id), regCP_MEC_DC_OP_CNTL);
drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c +2 -1
index 9ef249b95f916..439e51ded70ce 100644
@@ -2877,8 +2877,9 @@ static int gfx_v13_0_cp_compute_load_microcode_rs64(struct amdgpu_device *adev)
 				upper_32_bits(adev->gfx.mec.mec_fw_gpu_addr));
 		}
 	}
-	mutex_unlock(&adev->srbm_mutex);
 	soc_v2_0_grbm_select(adev, 0, 0, 0, 0);
+	mutex_unlock(&adev->srbm_mutex);
+
 	/* Trigger an invalidation of the L1 instruction caches */
 	tmp = RREG32_SOC15(GC, 0, regCP_CPC_IC_OP_NATIVE_CNTL);
 	tmp = REG_SET_FIELD(tmp, CP_CPC_IC_OP_NATIVE_CNTL, INVALIDATE_CACHE, 1);
Signature · 1 line
2.43.0
Reviewed-by on v1 9/9
#21 lore raw

Re: [PATCH 9/9] drm/amdgpu: fix mutex unlock position for ucode loading

Quoted 11 lines · Frank Min

Reset the GRBM selection before dropping srbm_mutex.

Fix gfx v11.0/v12.0/v12.1 and v13.0.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 4 ++--
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c | 3 ++-

Would be good to split this out per IP to make it easier to backport to stable. WIth that fixed,

Quoted 72 lines
 4 files changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2 -2
index ea74defe7fea0..13ff74ec3a540 100644
@@ -3030,8 +3030,8 @@ static int gfx_v11_0_config_mec_cache_rs64(struct amdgpu_device *adev, uint64_t
                WREG32_SOC15(GC, 0, regCP_CPC_IC_BASE_HI,
                     upper_32_bits(addr));
        }
-       mutex_unlock(&adev->srbm_mutex);
        soc21_grbm_select(adev, 0, 0, 0, 0);
+       mutex_unlock(&adev->srbm_mutex);
 
        /* Trigger an invalidation of the L1 instruction caches */
        tmp = RREG32_SOC15(GC, 0, regCP_MEC_DC_OP_CNTL);
@@ -3989,8 +3989,8 @@ static int gfx_v11_0_cp_compute_load_microcode_rs64(struct amdgpu_device *adev)
                WREG32_SOC15(GC, 0, regCP_CPC_IC_BASE_HI,
                     upper_32_bits(adev->gfx.mec.mec_fw_gpu_addr));
        }
-       mutex_unlock(&adev->srbm_mutex);
        soc21_grbm_select(adev, 0, 0, 0, 0);
+       mutex_unlock(&adev->srbm_mutex);
 
        /* Trigger an invalidation of the L1 instruction caches */
        tmp = RREG32_SOC15(GC, 0, regCP_MEC_DC_OP_CNTL);
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1 -1
index 8d6e74167d1c4..02894a2bb4bf3 100644
@@ -2860,8 +2860,8 @@ static int gfx_v12_0_cp_compute_load_microcode_rs64(struct amdgpu_device *adev)
                WREG32_SOC15(GC, 0, regCP_CPC_IC_BASE_HI,
                             upper_32_bits(adev->gfx.mec.mec_fw_gpu_addr));
        }
-       mutex_unlock(&adev->srbm_mutex);
        soc24_grbm_select(adev, 0, 0, 0, 0);
+       mutex_unlock(&adev->srbm_mutex);
 
        /* Trigger an invalidation of the L1 instruction caches */
        tmp = RREG32_SOC15(GC, 0, regCP_MEC_DC_OP_CNTL);
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +1 -1
index d393435e994b2..b200863bad906 100644
@@ -2183,8 +2183,8 @@ static int gfx_v12_1_xcc_cp_compute_load_microcode_rs64(struct amdgpu_device *ad
                WREG32_SOC15(GC, GET_INST(GC, xcc_id), regCP_CPC_IC_BASE_HI,
                                upper_32_bits(adev->gfx.mec.mec_fw_gpu_addr));
        }
-       mutex_unlock(&adev->srbm_mutex);
        soc_v1_0_grbm_select(adev, 0, 0, 0, 0, GET_INST(GC, xcc_id));
+       mutex_unlock(&adev->srbm_mutex);
 
        /* Trigger an invalidation of the L1 instruction caches */
        tmp = RREG32_SOC15(GC, GET_INST(GC, xcc_id), regCP_MEC_DC_OP_CNTL);
drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c +2 -2
index 9ef249b95f916..439e51ded70ce 100644
@@ -2877,8 +2877,9 @@ static int gfx_v13_0_cp_compute_load_microcode_rs64(struct amdgpu_device *adev)
                                upper_32_bits(adev->gfx.mec.mec_fw_gpu_addr));
                }
        }
-       mutex_unlock(&adev->srbm_mutex);
        soc_v2_0_grbm_select(adev, 0, 0, 0, 0);
+       mutex_unlock(&adev->srbm_mutex);
+
        /* Trigger an invalidation of the L1 instruction caches */
        tmp = RREG32_SOC15(GC, 0, regCP_CPC_IC_OP_NATIVE_CNTL);
        tmp = REG_SET_FIELD(tmp, CP_CPC_IC_OP_NATIVE_CNTL, INVALIDATE_CACHE, 1);
--

2.43.0

#22 lore raw

Re: [PATCH 9/9] drm/amdgpu: fix mutex unlock position for ucode loading

In reply to Frank Min
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] drm/amdgpu: missing Fixes trailers for srbm_mutex unlock ordering fix --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] drm/amdgpu: missing Fixes trailers for srbm_mutex unlock ordering fix
--

commit daa9e4b41815085d7ee15f7c8391275134b52ff7
Author: Frank Min <[email protected]>

Quoted 7 lines

drm/amdgpu: fix mutex unlock position for ucode loading

Reset the GRBM selection before dropping srbm_mutex.

Fix gfx v11.0/v12.0/v12.1 and v13.0.

[Severity: Low]
This fixes a locking bug across gfx v11.0, v12.0, v12.1, and v13.0 where adev->srbm_mutex was unlocked before resetting GRBM_GFX_CNTL. Should this include Fixes tags for the introducing commits?

Fixes 3d879e81f0f9 ("drm/amdgpu: add init support for GFX11 (v2)")
Fixes 52cb80c12e8a ("drm/amdgpu: Add gfx v12_0 ip block support (v6)")
Fixes ad5f1ee0a9b0 ("drm/amdgpu: Add initial support for gfx v12_1")
Fixes bffef1cc5b3d ("drm/amdgpu: Add gfx v13 ip block")
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
#23 lore raw
In reply to Frank Min
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] drm/amdgpu: amdgpu_gmc_allocate_vm_inv_eng() only skips kiq[0] ring - [Low] drm/amdgpu: commit…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] drm/amdgpu: amdgpu_gmc_allocate_vm_inv_eng() only skips kiq[0] ring
- [Low] drm/amdgpu: commit message repeats subject without rationale --

commit b1355b6a846065fc7eb680a37bdb10989818e156
Author: Frank Min <[email protected]>

Quoted 6 lines

drm/amdgpu: skip vm inv for kiq ring

skip vm inv for kiq ring

[Severity: Low]
The commit body repeats the subject line without explaining why this change is needed or why it is safe. Could it briefly note that skipping KIQ conserves limited per-GFXHUB VM invalidation engines and is safe because KIQ rings do not implement emit_vm_flush or use ring->vm_inv_eng?

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
index c3732a61f1c90..12165f20a2c73 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev) · line 676

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2 -1
@@ -669,7 +669,8 @@ int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev)
 		if (ring == &adev->mes.ring[0] ||
 		    ring == &adev->mes.ring[1] ||
 		    ring == &adev->umsch_mm.ring ||
-		    ring == &adev->cper.ring_buf)
+		    ring == &adev->cper.ring_buf ||
+		    ring == &adev->gfx.kiq[0].ring)
 			continue;
 
 		/* Skip if the ring is a shared ring */

[Severity: Medium]
Does checking &adev->gfx.kiq[0].ring miss KIQ rings on secondary XCCs?

On multi-XCC devices such as GC 9.4.3, gfx_v9_4_3_sw_init() registers a KIQ ring for every xcc_id via amdgpu_gfx_kiq_init_ring(). Only skipping index 0 leaves kiq[1..num_xcc-1].ring consuming a VM invalidation engine on their GFXHUB, risking -EINVAL during probe if per-GFXHUB engines run out.

Checking ring->funcs->type == AMDGPU_RING_TYPE_KIQ would skip KIQ rings across all XCC instances.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#24 lore raw
In reply to Frank Min
Quoted 13 lines · Frank Min

skip vm inv for kiq ring

---> drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
index 23354bf366880..75c3ded068db5 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev) · line 679

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2 -1
@@ -675,7 +675,8 @@ int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev)
                if (ring == &adev->mes.ring[0] ||
                    ring == &adev->mes.ring[1] ||
                    ring == &adev->umsch_mm.ring ||
-                   ring == &adev->cper.ring_buf)
+                   ring == &adev->cper.ring_buf ||
+                   ring == &adev->gfx.kiq[0].ring)

Per Sashiko's comments, I think this skip all KIQ rings.

Alex

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -1
                        continue;
 
                /* Skip if the ring is a shared ring */
--

2.43.0