drm/amdgpu: Fix map/unmap queue logic
Subsystems (3)
PATCH v2 1/2 drm/amdgpu: Fix map/unmap queue logic
In current logic, it calls ring_alloc followed by a ring_test. ring_test in turn will call another ring_alloc. This is illegal usage as a ring_alloc is expected to be closed properly with a ring_commit. Change to commit the map/unmap queue packet first followed by a ring_test. Add a comment about the usage of ring_test.
Also, reorder the current pre-condition checks of job hang or kiq ring scheduler not ready. Without them being met, it is not useful to attempt ring or memory allocations.
Fixes tag refers to the original patch which introduced this issue which then got carried over into newer code.
---
v2: Add same changes to map queue also (Le Ma)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 13 ++++- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 63 +++++++++++++++------- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 7 +++ 3 files changed, 63 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +11 -2
@@ -844,6 +844,9 @@ int amdgpu_amdkfd_unmap_hiq(struct amdgpu_device *adev, u32 doorbell_off,if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; +if (!kiq_ring->sched.ready || adev->job_hang) +return 0 ; + ring_funcs =kzalloc (sizeof (*ring_funcs),GFP_KERNEL );if (!ring_funcs)return -ENOMEM ;
@@ -868,8 +871,14 @@ int amdgpu_amdkfd_unmap_hiq(struct amdgpu_device *adev, u32 doorbell_off, kiq->pmf->kiq_unmap_queues (kiq_ring, ring,RESET_QUEUES ,0 ,0 ); -if (kiq_ring->sched.ready && !adev->job_hang) - r =amdgpu_ring_test_helper (kiq_ring); +/* Submit unmap queue packet */ +amdgpu_ring_commit (kiq_ring); +/* +* Ring test will do a basic scratch register change check. Just run +* this to ensure that unmap queues that is submitted before got +* processed successfully before returning. +*/ + r =amdgpu_ring_test_helper (kiq_ring);spin_unlock (&kiq->ring_lock);
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +45 -18
104 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +7 -0
@@ -4823,6 +4823,13 @@ static int gfx_v8_0_kcq_disable(struct amdgpu_device *adev)amdgpu_ring_write (kiq_ring,0 );amdgpu_ring_write (kiq_ring,0 ); } +/* Submit unmap queue packet */ +amdgpu_ring_commit (kiq_ring); +/* +* Ring test will do a basic scratch register change check. Just run +* this to ensure that unmap queues that is submitted before got +* processed successfully before returning. +*/ r =amdgpu_ring_test_helper (kiq_ring);if (r)DRM_ERROR ("KCQ disable failed\n" );
Signature · 1 line
2.25.1
PATCH v2 2/2 drm/amdgpu: Avoid kcq disable during reset
Reset sequence indicates that hardware already ran into a bad state. Avoid sending unmap queue request to reset KCQ. This will also cover RAS error scenarios which need a reset to recover, hence remove the check.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1 -9
@@ -515,15 +515,7 @@ int amdgpu_gfx_disable_kcq(struct amdgpu_device *adev, int xcc_id)if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; -if (!kiq_ring->sched.ready || adev->job_hang) -return 0 ; -/** -* This is workaround: only skip kiq_ring test -* during ras recovery in suspend stage for gfx9.4.3 -*/ -if ((amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,3 ) || -amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,4 )) && -amdgpu_ras_in_recovery (adev)) +if (!kiq_ring->sched.ready || adev->job_hang ||amdgpu_in_reset (adev))return 0 ;spin_lock (&kiq->ring_lock);
Signature · 1 line
2.25.1
RE: [PATCH v2 2/2] drm/amdgpu: Avoid kcq disable during reset
[AMD Official Use Only - AMD Internal Distribution Only]
Series is Reviewed-by: Le Ma <[email protected]>
Quoted 43 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, November 5, 2024 3:08 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Ma, Le <[email protected]>
Subject: [PATCH v2 2/2] drm/amdgpu: Avoid kcq disable during resetReset sequence indicates that hardware already ran into a bad state. Avoid sending unmap queue request to reset KCQ. This will also cover RAS error scenarios which need a reset to recover, hence remove the check.
Signed-off-by Lijo Lazar <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1
-9@@ -515,15 +515,7 @@ int amdgpu_gfx_disable_kcq(struct amdgpu_device *adev, int xcc_id)if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; -if (!kiq_ring->sched.ready || adev->job_hang) -return 0 ; -/** -* This is workaround: only skip kiq_ring test -* during ras recovery in suspend stage for gfx9.4.3 -*/ -if ((amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,3 ) || -amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,4 )) && -amdgpu_ras_in_recovery (adev)) +if (!kiq_ring->sched.ready || adev->job_hang ||amdgpu_in_reset (adev))return 0 ;spin_lock(&kiq->ring_lock);--
2.25.1