drm/amd/amdgpu: Add timeout for user queue fence waiting
Subsystems (2)
PATCH v2 1/3 drm/amd/amdgpu: Add 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.
v2: make timeout per queue type (adev->gfx_timeout vs adev->compute_timeout vs adev->sdma_timeout) to be consistent with kernel queues. (Alex)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +19 -1
@@ -367,11 +367,29 @@ static int amdgpu_userq_map_helper(struct amdgpu_usermode_queue *queue)static int amdgpu_userq_wait_for_last_fence (struct amdgpu_usermode_queue *queue) {struct amdgpu_userq_mgr *uq_mgr = queue->userq_mgr; +struct amdgpu_device *adev = uq_mgr->adev;struct dma_fence *f = queue->last_fence; +signed long timeout;int ret =0 ; +/* Determine timeout based on queue type */ +switch (queue->queue_type) { +case AMDGPU_RING_TYPE_GFX : + timeout = adev->gfx_timeout; +break ; +case AMDGPU_RING_TYPE_COMPUTE : + timeout = adev->compute_timeout; +break ; +case AMDGPU_RING_TYPE_SDMA : + timeout = adev->sdma_timeout; +break ; +default : + timeout = adev->gfx_timeout; +break ; + } +if (f && !dma_fence_is_signaled (f)) { - ret =dma_fence_wait_timeout (f, true,MAX_SCHEDULE_TIMEOUT ); + ret =dma_fence_wait_timeout (f, true, timeout);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 v2 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 an inconsistent 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 v2 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 an 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