Skip to contentSkip to conversation

drm/amdkfd: Guard m->cp_hqd_eop_control setting by q->eop_ring_buffer_size

PATCH In review Xiaogang.Chen 2 participants 3 messages Jun 16 – Jun 19

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/amdkfd: Guard m->cp_hqd_eop_control setting by q->eop_ring_buffer_size

From: Xiaogang Chen <[email protected]>

To prevent getting incorrect m->cp_hqd_eop_control value.

---
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c   | 4 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c   | 4 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12.c   | 4 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c | 4 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c    | 4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c +2 -2
index 82f194ea2a21..5f8bf87f475e 100644
@@ -203,8 +203,8 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,
 	 * more than (EOP entry count - 1) so a queue size of 0x800 dwords
 	 * is safe, giving a maximum field value of 0xA.
 	 */
-	m->cp_hqd_eop_control = min(0xA,
-		ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1);
+	m->cp_hqd_eop_control = q->eop_ring_buffer_size ? min(0xA,
+		ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1) : 0;
 	m->cp_hqd_eop_base_addr_lo =
 			lower_32_bits(q->eop_ring_buffer_address >> 8);
 	m->cp_hqd_eop_base_addr_hi =
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c +2 -2
index dff016c9c65c..7506a1410385 100644
@@ -241,8 +241,8 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,
 	 * more than (EOP entry count - 1) so a queue size of 0x800 dwords
 	 * is safe, giving a maximum field value of 0xA.
 	 */
-	m->cp_hqd_eop_control = min(0xA,
-		ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1);
+	m->cp_hqd_eop_control = q->eop_ring_buffer_size ? min(0xA,
+		ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1) : 0;
 	m->cp_hqd_eop_base_addr_lo =
 			lower_32_bits(q->eop_ring_buffer_address >> 8);
 	m->cp_hqd_eop_base_addr_hi =
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12.c +2 -2
index 51dde2c86eb3..f1f923eb0ea5 100644
@@ -216,8 +216,8 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,
 	 * more than (EOP entry count - 1) so a queue size of 0x800 dwords
 	 * is safe, giving a maximum field value of 0xA.
 	 */
-	m->cp_hqd_eop_control = min(0xA,
-		ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1);
+	m->cp_hqd_eop_control = q->eop_ring_buffer_size ? min(0xA,
+		ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1) : 0;
 	m->cp_hqd_eop_base_addr_lo =
 			lower_32_bits(q->eop_ring_buffer_address >> 8);
 	m->cp_hqd_eop_base_addr_hi =
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c +2 -2
index 9014912ed82c..a6fff8032dce 100644
@@ -294,8 +294,8 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,
 	 * more than (EOP entry count - 1) so a queue size of 0x800 dwords
 	 * is safe, giving a maximum field value of 0xA.
 	 */
-	m->cp_hqd_eop_control = min(0xA,
-		ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1);
+	m->cp_hqd_eop_control = q->eop_ring_buffer_size ? min(0xA,
+		ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1) : 0;
 	m->cp_hqd_eop_base_addr_lo =
 			lower_32_bits(q->eop_ring_buffer_address >> 8);
 	m->cp_hqd_eop_base_addr_hi =
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c +2 -2
index b3c3833b6874..14b4240de6f0 100644
@@ -214,8 +214,8 @@ static void __update_mqd(struct mqd_manager *mm, void *mqd,
 	 * more than (EOP entry count - 1) so a queue size of 0x800 dwords
 	 * is safe, giving a maximum field value of 0xA.
 	 */
-	m->cp_hqd_eop_control |= min(0xA,
-		order_base_2(q->eop_ring_buffer_size / 4) - 1);
+	m->cp_hqd_eop_control |= q->eop_ring_buffer_size ? min(0xA,
+		order_base_2(q->eop_ring_buffer_size / 4) - 1) : 0;
 	m->cp_hqd_eop_base_addr_lo =
 			lower_32_bits(q->eop_ring_buffer_address >> 8);
 	m->cp_hqd_eop_base_addr_hi =
Signature · 1 line
2.34.1
#1 lore raw

AMD General

ping

-----Original Message-----
From: Xiaogang.Chen <[email protected]>
Sent: Tuesday, June 16, 2026 5:23 PM
To: [email protected]
Cc: Chen, Xiaogang <[email protected]>
Subject: [PATCH v2] drm/amdkfd: Guard m->cp_hqd_eop_control setting by q->eop_ring_buffer_size

From: Xiaogang Chen <[email protected]>

To prevent getting incorrect m->cp_hqd_eop_control value.

---
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c   | 4 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c   | 4 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12.c   | 4 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c | 4 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c    | 4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c +2 -2
index 82f194ea2a21..5f8bf87f475e 100644
@@ -203,8 +203,8 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,
         * more than (EOP entry count - 1) so a queue size of 0x800 dwords
         * is safe, giving a maximum field value of 0xA.
         */
-       m->cp_hqd_eop_control = min(0xA,
-               ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1);
+       m->cp_hqd_eop_control = q->eop_ring_buffer_size ? min(0xA,
+               ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1) : 0;
        m->cp_hqd_eop_base_addr_lo =
                        lower_32_bits(q->eop_ring_buffer_address >> 8);
        m->cp_hqd_eop_base_addr_hi =
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c +2 -2
index dff016c9c65c..7506a1410385 100644
@@ -241,8 +241,8 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,
         * more than (EOP entry count - 1) so a queue size of 0x800 dwords
         * is safe, giving a maximum field value of 0xA.
         */
-       m->cp_hqd_eop_control = min(0xA,
-               ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1);
+       m->cp_hqd_eop_control = q->eop_ring_buffer_size ? min(0xA,
+               ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1) : 0;
        m->cp_hqd_eop_base_addr_lo =
                        lower_32_bits(q->eop_ring_buffer_address >> 8);
        m->cp_hqd_eop_base_addr_hi =
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12.c +2 -2
index 51dde2c86eb3..f1f923eb0ea5 100644
@@ -216,8 +216,8 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,
         * more than (EOP entry count - 1) so a queue size of 0x800 dwords
         * is safe, giving a maximum field value of 0xA.
         */
-       m->cp_hqd_eop_control = min(0xA,
-               ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1);
+       m->cp_hqd_eop_control = q->eop_ring_buffer_size ? min(0xA,
+               ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1) : 0;
        m->cp_hqd_eop_base_addr_lo =
                        lower_32_bits(q->eop_ring_buffer_address >> 8);
        m->cp_hqd_eop_base_addr_hi =
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c +2 -2
index 9014912ed82c..a6fff8032dce 100644
@@ -294,8 +294,8 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,
         * more than (EOP entry count - 1) so a queue size of 0x800 dwords
         * is safe, giving a maximum field value of 0xA.
         */
-       m->cp_hqd_eop_control = min(0xA,
-               ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1);
+       m->cp_hqd_eop_control = q->eop_ring_buffer_size ? min(0xA,
+               ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1) : 0;
        m->cp_hqd_eop_base_addr_lo =
                        lower_32_bits(q->eop_ring_buffer_address >> 8);
        m->cp_hqd_eop_base_addr_hi =
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c +2 -2
index b3c3833b6874..14b4240de6f0 100644
@@ -214,8 +214,8 @@ static void __update_mqd(struct mqd_manager *mm, void *mqd,
         * more than (EOP entry count - 1) so a queue size of 0x800 dwords
         * is safe, giving a maximum field value of 0xA.
         */
-       m->cp_hqd_eop_control |= min(0xA,
-               order_base_2(q->eop_ring_buffer_size / 4) - 1);
+       m->cp_hqd_eop_control |= q->eop_ring_buffer_size ? min(0xA,
+               order_base_2(q->eop_ring_buffer_size / 4) - 1) : 0;
        m->cp_hqd_eop_base_addr_lo =
                        lower_32_bits(q->eop_ring_buffer_address >> 8);
        m->cp_hqd_eop_base_addr_hi =

--
2.34.1

Reviewed-by on v2 1/1
#2 lore raw
In reply to Xiaogang.Chen
Quoted 4 lines · Xiaogang.Chen

From: Xiaogang Chen <[email protected]>

To prevent getting incorrect m->cp_hqd_eop_control value.

Would be clearer to say avoid wraparound if the value is 0. Either way:

Quoted 88 lines
---
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c   | 4 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c   | 4 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12.c   | 4 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c | 4 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c    | 4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c +2 -2
index 82f194ea2a21..5f8bf87f475e 100644
@@ -203,8 +203,8 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,
         * more than (EOP entry count - 1) so a queue size of 0x800 dwords
         * is safe, giving a maximum field value of 0xA.
         */
-       m->cp_hqd_eop_control = min(0xA,
-               ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1);
+       m->cp_hqd_eop_control = q->eop_ring_buffer_size ? min(0xA,
+               ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1) : 0;
        m->cp_hqd_eop_base_addr_lo =
                        lower_32_bits(q->eop_ring_buffer_address >> 8);
        m->cp_hqd_eop_base_addr_hi =
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c +2 -2
index dff016c9c65c..7506a1410385 100644
@@ -241,8 +241,8 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,
         * more than (EOP entry count - 1) so a queue size of 0x800 dwords
         * is safe, giving a maximum field value of 0xA.
         */
-       m->cp_hqd_eop_control = min(0xA,
-               ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1);
+       m->cp_hqd_eop_control = q->eop_ring_buffer_size ? min(0xA,
+               ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1) : 0;
        m->cp_hqd_eop_base_addr_lo =
                        lower_32_bits(q->eop_ring_buffer_address >> 8);
        m->cp_hqd_eop_base_addr_hi =
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12.c +2 -2
index 51dde2c86eb3..f1f923eb0ea5 100644
@@ -216,8 +216,8 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,
         * more than (EOP entry count - 1) so a queue size of 0x800 dwords
         * is safe, giving a maximum field value of 0xA.
         */
-       m->cp_hqd_eop_control = min(0xA,
-               ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1);
+       m->cp_hqd_eop_control = q->eop_ring_buffer_size ? min(0xA,
+               ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1) : 0;
        m->cp_hqd_eop_base_addr_lo =
                        lower_32_bits(q->eop_ring_buffer_address >> 8);
        m->cp_hqd_eop_base_addr_hi =
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c +2 -2
index 9014912ed82c..a6fff8032dce 100644
@@ -294,8 +294,8 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,
         * more than (EOP entry count - 1) so a queue size of 0x800 dwords
         * is safe, giving a maximum field value of 0xA.
         */
-       m->cp_hqd_eop_control = min(0xA,
-               ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1);
+       m->cp_hqd_eop_control = q->eop_ring_buffer_size ? min(0xA,
+               ffs(q->eop_ring_buffer_size / sizeof(unsigned int)) - 1 - 1) : 0;
        m->cp_hqd_eop_base_addr_lo =
                        lower_32_bits(q->eop_ring_buffer_address >> 8);
        m->cp_hqd_eop_base_addr_hi =
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c +2 -3
index b3c3833b6874..14b4240de6f0 100644
@@ -214,8 +214,8 @@ static void __update_mqd(struct mqd_manager *mm, void *mqd,
         * more than (EOP entry count - 1) so a queue size of 0x800 dwords
         * is safe, giving a maximum field value of 0xA.
         */
-       m->cp_hqd_eop_control |= min(0xA,
-               order_base_2(q->eop_ring_buffer_size / 4) - 1);
+       m->cp_hqd_eop_control |= q->eop_ring_buffer_size ? min(0xA,
+               order_base_2(q->eop_ring_buffer_size / 4) - 1) : 0;
        m->cp_hqd_eop_base_addr_lo =
                        lower_32_bits(q->eop_ring_buffer_address >> 8);
        m->cp_hqd_eop_base_addr_hi =
--

2.34.1