]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amdkfd: Guard m->cp_hqd_eop_control setting by q->eop_ring_buffer_size
authorXiaogang Chen <xiaogang.chen@amd.com>
Tue, 16 Jun 2026 22:18:59 +0000 (17:18 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 1 Jul 2026 16:58:33 +0000 (12:58 -0400)
To avoid wraparound if the value is 0.

Signed-off-by: Xiaogang Chen <xiaogang.chen@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit c0cae35661868af207077a4306bc42c7c972947c)
Cc: stable@vger.kernel.org
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12.c
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c

index 8e8ec266ca46d670cd1c77cce67adc15f3e9a707..e034da638c07a3a6aa6d11beca652766e9d99118 100644 (file)
@@ -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 =
index fff137e00b5e307e3210bafe8aaf9eae43165f44..350fcbbba4b295e663e443d62a69fb6b014823d8 100644 (file)
@@ -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 =
index 8c815f129614c7ef13e528492f36c090623ab162..7c387fa900766a8b17b98bfc0311459e0b868365 100644 (file)
@@ -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 =
index 475589b924e90a2b92f0a5823aa79aa330be418a..431a940f91f3b9fcb650d9c179385a01f4836e84 100644 (file)
@@ -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 =
index c86779af323bb5e7895feb4128911538ca0eb3f9..60b87a5006983b09e3af07324fb73e045d36433c 100644 (file)
@@ -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 =