drm/amd/amdgpu: change the timeout for user queue fence waiting
Subsystems (2)
PATCH 1/3 drm/amd/amdgpu: change the timeout for user queue fence waiting
In certain error scenarios (e.g., malformed commands), a fence may never become signaled, causing the kernel to hang indefinitely when waiting with MAX_SCHEDULE_TIMEOUT. To prevent such hangs and ensure system responsiveness, replace the indefinite timeout with a reasonable 2-second limit.
This ensures that even if a fence never signals, the wait will time out and appropriate error handling can take place, rather than stalling the driver indefinitely.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1 -1
@@ -371,7 +371,7 @@ static int amdgpu_userq_wait_for_last_fence(struct amdgpu_usermode_queue *queue)int ret =0 ;if (f && !dma_fence_is_signaled (f)) { - ret =dma_fence_wait_timeout (f, true,MAX_SCHEDULE_TIMEOUT ); + ret =dma_fence_wait_timeout (f, true,msecs_to_jiffies (2000 ));if (ret <=0 ) {drm_file_err (uq_mgr->file,"Timed out waiting for fence=%llu:%llu\n" , f->context, f->seqno);
Signature · 1 line
2.49.0
PATCH 2/3 drm/amd/amdgpu: Schedule user queue reset on GPU privilege fault for gfx11
When a privilege fault occurs in a user queue context, the GPU may be left in a hang state. To handle this gracefully and recover the GPU, schedule a user queue reset via amdgpu_reset_domain_schedule.
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5 -0
@@ -50,6 +50,7 @@#include "mes_v11_0.h" #include "mes_userqueue.h" #include "amdgpu_userq_fence.h" +#include "amdgpu_reset.h" #define GFX11_NUM_GFX_RINGS 1#define GFX11_MEC_HPD_SIZE 2048
@@ -6653,6 +6654,10 @@ static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,BUG ();break ; } + }else { +/*TODO: schedule a user queue reset work */ +amdgpu_reset_domain_schedule (adev->reset_domain, + &adev->userq_reset_work); } }
Signature · 1 line
2.49.0
PATCH 3/3 drm/amd/amdgpu: Schedule user queue reset on GPU privilege fault for gfx12
In reply to Jesse.ZhangWhen a privilege fault occurs in a user queue context, the GPU may be left in a hang state. To handle this gracefully and recover the GPU, schedule a user queue reset via amdgpu_reset_domain_schedule.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +5 -0
@@ -46,6 +46,7 @@#include "mes_v12_0.h" #include "mes_userqueue.h" #include "amdgpu_userq_fence.h" +#include "amdgpu_reset.h" #define GFX12_NUM_GFX_RINGS 1#define GFX12_MEC_HPD_SIZE 2048
@@ -5030,6 +5031,10 @@ static void gfx_v12_0_handle_priv_fault(struct amdgpu_device *adev,BUG ();break ; } + }else { +/*TODO: schedule a user queue reset work */ +amdgpu_reset_domain_schedule (adev->reset_domain, + &adev->userq_reset_work); } }
Signature · 1 line
2.49.0
Quoted 17 lines · Jesse.Zhang
In certain error scenarios (e.g., malformed commands), a fence may never become signaled, causing the kernel to hang indefinitely when waiting with
MAX_SCHEDULE_TIMEOUT. To prevent such hangs and ensure system responsiveness, replace the indefinite timeout with a reasonable 2-second limit.This ensures that even if a fence never signals, the wait will time out and appropriate error handling can take place, rather than stalling the driver indefinitely.
Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_wait_for_last_fence(struct amdgpu_usermode_queue *queue) · line 374
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-1@@ -371,7 +371,7 @@ static int amdgpu_userq_wait_for_last_fence(struct amdgpu_usermode_queue *queue)int ret =0 ;if (f && !dma_fence_is_signaled (f)) { - ret =dma_fence_wait_timeout (f, true,MAX_SCHEDULE_TIMEOUT ); + ret =dma_fence_wait_timeout (f, true,msecs_to_jiffies (2000 ));
use adev->gfx_timeout to be consistent with kernel queues. You could even make it per queue type (adev->gfx_timeout vs adev->compute_timeout vs adev->sdma_timeout).
Alex
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-1if (ret <=0 ) {drm_file_err (uq_mgr->file,"Timed out waiting for fence=%llu:%llu\n" , f->context, f->seqno); --2.49.0
Christian König
maintainerQuoted 16 lines · Jesse.Zhang
In certain error scenarios (e.g., malformed commands), a fence may never become signaled, causing the kernel to hang indefinitely when waiting with
MAX_SCHEDULE_TIMEOUT. To prevent such hangs and ensure system responsiveness, replace the indefinite timeout with a reasonable 2-second limit.This ensures that even if a fence never signals, the wait will time out and appropriate error handling can take place, rather than stalling the driver indefinitely.
Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_wait_for_last_fence(struct amdgpu_usermode_queue *queue) · line 374
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-1@@ -371,7 +371,7 @@ static int amdgpu_userq_wait_for_last_fence(struct amdgpu_usermode_queue *queue)int ret =0 ;if (f && !dma_fence_is_signaled (f)) { - ret =dma_fence_wait_timeout (f, true,MAX_SCHEDULE_TIMEOUT ); + ret =dma_fence_wait_timeout (f, true,msecs_to_jiffies (2000 ));
That is clearly a no-go.
That we hang infidelity and never return is a must have behavior or otherwise we might run into data-corruption.
Regards,
Christian.
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0if (ret <=0 ) {drm_file_err (uq_mgr->file,"Timed out waiting for fence=%llu:%llu\n" , f->context, f->seqno);