drm/amdgpu/sdma: fix engine reset handling
Subsystems (3)
Alex Deucher
maintainerPATCH 1/2 drm/amdgpu/sdma: fix engine reset handling
Move the kfd suspend/resume code into the caller. That is where the KFD is likely to detect a reset so on the KFD side there is no need to call them. Also add a mutex to lock the actual reset sequence.
v2: make the locking per instance
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 15 +++------------ drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 3 ++- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 9 ++++++++- .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3 -12
@@ -524,7 +524,6 @@ void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct* amdgpu_sdma_reset_engine - Reset a specific SDMA engine * @adev: Pointer to the AMDGPU device * @instance_id: ID of the SDMA engine instance to reset -* @suspend_user_queues: check if suspend user queue. * * This function performs the following steps: * 1. Calls all registered pre_reset callbacks to allow KFD and AMDGPU to save their state.
@@ -533,7 +532,7 @@ void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct* * Returns: 0 on success, or a negative error code on failure. */ -int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id,bool suspend_user_queues) +int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id) {struct sdma_on_reset_funcs *funcs;int ret =0 ;
@@ -542,13 +541,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, bstruct amdgpu_ring *page_ring = &sdma_instance->page;bool gfx_sched_stopped = false, page_sched_stopped = false; -/* Suspend KFD if suspend_user_queues is true. -* prevent the destruction of in-flight healthy user queue packets and -* avoid race conditions between KFD and KGD during the reset process. -*/ -if (suspend_user_queues) -amdgpu_amdkfd_suspend (adev, false); - +mutex_lock (&sdma_instance->engine_reset_mutex);/* Stop the scheduler's work queue for the GFX and page rings if they are running. * This ensures that no new tasks are submitted to the queues while * the reset is in progress.
@@ -609,9 +602,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, bdrm_sched_wqueue_start (&page_ring->sched); } } - -if (suspend_user_queues) -amdgpu_amdkfd_resume (adev, false); +mutex_unlock (&sdma_instance->engine_reset_mutex);return ret; }
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +2 -1
@@ -64,6 +64,7 @@ struct amdgpu_sdma_instance {struct amdgpu_bo *sdma_fw_obj;uint64_t sdma_fw_gpu_addr;uint32_t *sdma_fw_ptr; +struct mutex engine_reset_mutex; };enum amdgpu_sdma_ras_memory_id {
@@ -169,7 +170,7 @@ struct amdgpu_buffer_funcs { };void amdgpu_sdma_register_on_reset_callbacks (struct amdgpu_device *adev,struct sdma_on_reset_funcs *funcs); -int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id,bool suspend_user_queues); +int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id);#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t))#define amdgpu_emit_fill_buffer (adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +8 -1
@@ -1445,6 +1445,7 @@ static int sdma_v4_4_2_sw_init(struct amdgpu_ip_block *ip_block) }for (i =0 ; i < adev->sdma.num_instances; i++) { +mutex_init (&adev->sdma.instance[i].engine_reset_mutex); ring = &adev->sdma.instance[i].ring; ring->ring_obj =NULL ; ring->use_doorbell = true;
@@ -1666,7 +1667,13 @@ static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid) {struct amdgpu_device *adev = ring->adev;u32 id =GET_INST (SDMA0 , ring->me); -return amdgpu_sdma_reset_engine (adev, id, true); +int r; + +amdgpu_amdkfd_suspend (adev, false); + r =amdgpu_sdma_reset_engine (adev, id); +amdgpu_amdkfd_resume (adev, false); + +return r; }static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev,uint32_t instance_id)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -1
@@ -2310,7 +2310,7 @@ static int reset_hung_queues_sdma(struct device_queue_manager *dqm)continue ;/* Reset engine and check. */ -if (amdgpu_sdma_reset_engine (dqm->dev->adev, i, false) || +if (amdgpu_sdma_reset_engine (dqm->dev->adev, i) || dqm->dev->kfd2kgd->hqd_sdma_get_doorbell (dqm->dev->adev, i, j) || !set_sdma_queue_as_reset (dqm, doorbell_off)) { r = -ENOTRECOVERABLE ;
Signature · 1 line
2.48.1
Alex Deucher
maintainerPATCH 2/2 drm/amdgpu/sdma: guilty tracking is per instance
The gfx and page queues are per instance, so track them per instance.
v2: drop extra paramter (Lijo)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 7 +++--- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 27 ++++++++++++------------ 2 files changed, 18 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +4 -3
@@ -65,6 +65,10 @@ struct amdgpu_sdma_instance {uint64_t sdma_fw_gpu_addr;uint32_t *sdma_fw_ptr;struct mutex engine_reset_mutex; +/* track guilty state of GFX and PAGE queues */ +bool gfx_guilty; +bool page_guilty; + };enum amdgpu_sdma_ras_memory_id {
@@ -127,9 +131,6 @@ struct amdgpu_sdma {uint32_t *ip_dump;uint32_t supported_reset;struct list_head reset_callback_list; -/* track guilty state of GFX and PAGE queues */ -bool gfx_guilty; -bool page_guilty; };/*
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +14 -13
@@ -672,12 +672,11 @@ static uint32_t sdma_v4_4_2_rb_cntl(struct amdgpu_ring *ring, uint32_t rb_cntl)* @adev: amdgpu_device pointer * @i: instance to resume * @restore: used to restore wptr when restart -* @guilty: boolean indicating whether this queue is the guilty one (caused the timeout/error) * * Set up the gfx DMA ring buffers and enable them. * Returns 0 for success, error for failure. */ -static void sdma_v4_4_2_gfx_resume (struct amdgpu_device *adev,unsigned int i,bool restore,bool guilty) +static void sdma_v4_4_2_gfx_resume (struct amdgpu_device *adev,unsigned int i,bool restore) {struct amdgpu_ring *ring = &adev->sdma.instance[i].ring;u32 rb_cntl, ib_cntl, wptr_poll_cntl;
@@ -714,7 +713,7 @@ static void sdma_v4_4_2_gfx_resume(struct amdgpu_device *adev, unsigned int i, b/* For the guilty queue, set RPTR to the current wptr to skip bad commands, * It is not a guilty queue, restore cache_rptr and continue execution. */ -if (guilty) +if (adev->sdma.instance[i].gfx_guilty) rwptr = ring->wptr;else rwptr = ring->cached_rptr;
@@ -779,12 +778,11 @@ static void sdma_v4_4_2_gfx_resume(struct amdgpu_device *adev, unsigned int i, b* @adev: amdgpu_device pointer * @i: instance to resume * @restore: boolean to say restore needed or not -* @guilty: boolean indicating whether this queue is the guilty one (caused the timeout/error) * * Set up the page DMA ring buffers and enable them. * Returns 0 for success, error for failure. */ -static void sdma_v4_4_2_page_resume (struct amdgpu_device *adev,unsigned int i,bool restore,bool guilty) +static void sdma_v4_4_2_page_resume (struct amdgpu_device *adev,unsigned int i,bool restore) {struct amdgpu_ring *ring = &adev->sdma.instance[i].page;u32 rb_cntl, ib_cntl, wptr_poll_cntl;
@@ -803,7 +801,7 @@ static void sdma_v4_4_2_page_resume(struct amdgpu_device *adev, unsigned int i,/* For the guilty queue, set RPTR to the current wptr to skip bad commands, * It is not a guilty queue, restore cache_rptr and continue execution. */ -if (guilty) +if (adev->sdma.instance[i].page_guilty) rwptr = ring->wptr;else rwptr = ring->cached_rptr;
@@ -989,9 +987,9 @@ static int sdma_v4_4_2_inst_start(struct amdgpu_device *adev,uint32_t temp;WREG32_SDMA (i, regSDMA_SEM_WAIT_FAIL_TIMER_CNTL,0 ); -sdma_v4_4_2_gfx_resume (adev, i, restore, adev->sdma.gfx_guilty); +sdma_v4_4_2_gfx_resume (adev, i, restore);if (adev->sdma.has_page_queue) -sdma_v4_4_2_page_resume (adev, i, restore, adev->sdma.page_guilty); +sdma_v4_4_2_page_resume (adev, i, restore);/* set utc l1 enable flag always to 1 */ temp =RREG32_SDMA (i, regSDMA_CNTL);
@@ -1446,6 +1444,10 @@ static int sdma_v4_4_2_sw_init(struct amdgpu_ip_block *ip_block)for (i =0 ; i < adev->sdma.num_instances; i++) {mutex_init (&adev->sdma.instance[i].engine_reset_mutex); +/* Initialize guilty flags for GFX and PAGE queues */ + adev->sdma.instance[i].gfx_guilty = false; + adev->sdma.instance[i].page_guilty = false; + ring = &adev->sdma.instance[i].ring; ring->ring_obj =NULL ; ring->use_doorbell = true;
@@ -1507,9 +1509,6 @@ static int sdma_v4_4_2_sw_init(struct amdgpu_ip_block *ip_block) r =amdgpu_sdma_sysfs_reset_mask_init (adev);if (r)return r; -/* Initialize guilty flags for GFX and PAGE queues */ - adev->sdma.gfx_guilty = false; - adev->sdma.page_guilty = false;return r; }
@@ -1686,9 +1685,11 @@ static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev, uint32_t instance_return -EINVAL ;/* Check if this queue is the guilty one */ - adev->sdma.gfx_guilty =sdma_v4_4_2_is_queue_selected (adev, instance_id, false); + adev->sdma.instance[instance_id].gfx_guilty = +sdma_v4_4_2_is_queue_selected (adev, instance_id, false);if (adev->sdma.has_page_queue) - adev->sdma.page_guilty =sdma_v4_4_2_is_queue_selected (adev, instance_id, true); + adev->sdma.instance[instance_id].page_guilty = +sdma_v4_4_2_is_queue_selected (adev, instance_id, true);/* Cache the rptr before reset, after the reset, * all of the registers will be reset to 0
Signature · 1 line
2.48.1
Re: [PATCH 2/2] drm/amdgpu/sdma: guilty tracking is per instance
Quoted 7 lines · Alex Deucher
The gfx and page queues are per instance, so track them per instance.
v2: drop extra paramter (Lijo)
Fixes fdbfaaaae06b ("drm/amdgpu: Improve SDMA reset logic with guilty queue tracking")Signed-off-by Alex Deucher <[email protected]>
Thanks,
Lijo
Quoted 127 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 7 +++--- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 27 ++++++++++++------------ 2 files changed, 18 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +4
-3@@ -65,6 +65,10 @@ struct amdgpu_sdma_instance {uint64_t sdma_fw_gpu_addr;uint32_t *sdma_fw_ptr;struct mutex engine_reset_mutex; +/* track guilty state of GFX and PAGE queues */ +bool gfx_guilty; +bool page_guilty; + };enum amdgpu_sdma_ras_memory_id {@@ -127,9 +131,6 @@ struct amdgpu_sdma {uint32_t *ip_dump;uint32_t supported_reset;struct list_head reset_callback_list; -/* track guilty state of GFX and PAGE queues */ -bool gfx_guilty; -bool page_guilty; };/* drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +14
-13@@ -672,12 +672,11 @@ static uint32_t sdma_v4_4_2_rb_cntl(struct amdgpu_ring *ring, uint32_t rb_cntl)* @adev: amdgpu_device pointer * @i: instance to resume * @restore: used to restore wptr when restart -* @guilty: boolean indicating whether this queue is the guilty one (caused the timeout/error) * * Set up the gfx DMA ring buffers and enable them. * Returns 0 for success, error for failure. */ -static void sdma_v4_4_2_gfx_resume (struct amdgpu_device *adev,unsigned int i,bool restore,bool guilty) +static void sdma_v4_4_2_gfx_resume (struct amdgpu_device *adev,unsigned int i,bool restore) {struct amdgpu_ring *ring = &adev->sdma.instance[i].ring;u32 rb_cntl, ib_cntl, wptr_poll_cntl;@@ -714,7 +713,7 @@ static void sdma_v4_4_2_gfx_resume(struct amdgpu_device *adev, unsigned int i, b/* For the guilty queue, set RPTR to the current wptr to skip bad commands, * It is not a guilty queue, restore cache_rptr and continue execution. */ -if (guilty) +if (adev->sdma.instance[i].gfx_guilty) rwptr = ring->wptr;else rwptr = ring->cached_rptr;@@ -779,12 +778,11 @@ static void sdma_v4_4_2_gfx_resume(struct amdgpu_device *adev, unsigned int i, b* @adev: amdgpu_device pointer * @i: instance to resume * @restore: boolean to say restore needed or not -* @guilty: boolean indicating whether this queue is the guilty one (caused the timeout/error) * * Set up the page DMA ring buffers and enable them. * Returns 0 for success, error for failure. */ -static void sdma_v4_4_2_page_resume (struct amdgpu_device *adev,unsigned int i,bool restore,bool guilty) +static void sdma_v4_4_2_page_resume (struct amdgpu_device *adev,unsigned int i,bool restore) {struct amdgpu_ring *ring = &adev->sdma.instance[i].page;u32 rb_cntl, ib_cntl, wptr_poll_cntl;@@ -803,7 +801,7 @@ static void sdma_v4_4_2_page_resume(struct amdgpu_device *adev, unsigned int i,/* For the guilty queue, set RPTR to the current wptr to skip bad commands, * It is not a guilty queue, restore cache_rptr and continue execution. */ -if (guilty) +if (adev->sdma.instance[i].page_guilty) rwptr = ring->wptr;else rwptr = ring->cached_rptr;@@ -989,9 +987,9 @@ static int sdma_v4_4_2_inst_start(struct amdgpu_device *adev,uint32_t temp;WREG32_SDMA (i, regSDMA_SEM_WAIT_FAIL_TIMER_CNTL,0 ); -sdma_v4_4_2_gfx_resume (adev, i, restore, adev->sdma.gfx_guilty); +sdma_v4_4_2_gfx_resume (adev, i, restore);if (adev->sdma.has_page_queue) -sdma_v4_4_2_page_resume (adev, i, restore, adev->sdma.page_guilty); +sdma_v4_4_2_page_resume (adev, i, restore);/* set utc l1 enable flag always to 1 */ temp =RREG32_SDMA (i, regSDMA_CNTL);@@ -1446,6 +1444,10 @@ static int sdma_v4_4_2_sw_init(struct amdgpu_ip_block *ip_block)for (i =0 ; i < adev->sdma.num_instances; i++) {mutex_init (&adev->sdma.instance[i].engine_reset_mutex); +/* Initialize guilty flags for GFX and PAGE queues */ + adev->sdma.instance[i].gfx_guilty = false; + adev->sdma.instance[i].page_guilty = false; + ring = &adev->sdma.instance[i].ring; ring->ring_obj =NULL ; ring->use_doorbell = true;@@ -1507,9 +1509,6 @@ static int sdma_v4_4_2_sw_init(struct amdgpu_ip_block *ip_block) r =amdgpu_sdma_sysfs_reset_mask_init (adev);if (r)return r; -/* Initialize guilty flags for GFX and PAGE queues */ - adev->sdma.gfx_guilty = false; - adev->sdma.page_guilty = false;return r; }@@ -1686,9 +1685,11 @@ static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev, uint32_t instance_return -EINVAL ;/* Check if this queue is the guilty one */ - adev->sdma.gfx_guilty =sdma_v4_4_2_is_queue_selected (adev, instance_id, false); + adev->sdma.instance[instance_id].gfx_guilty = +sdma_v4_4_2_is_queue_selected (adev, instance_id, false);if (adev->sdma.has_page_queue) - adev->sdma.page_guilty =sdma_v4_4_2_is_queue_selected (adev, instance_id, true); + adev->sdma.instance[instance_id].page_guilty = +sdma_v4_4_2_is_queue_selected (adev, instance_id, true);/* Cache the rptr before reset, after the reset, * all of the registers will be reset to 0
Ping?
Quoted 128 lines · Alex Deucher
Move the kfd suspend/resume code into the caller. That is where the KFD is likely to detect a reset so on the KFD side there is no need to call them. Also add a mutex to lock the actual reset sequence.
v2: make the locking per instance
Fixes bac38ca8c475 ("drm/amdkfd: implement per queue sdma reset for gfx 9.4+")Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 15 +++------------ drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 3 ++- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 9 ++++++++- .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3
-12@@ -524,7 +524,6 @@ void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct* amdgpu_sdma_reset_engine - Reset a specific SDMA engine * @adev: Pointer to the AMDGPU device * @instance_id: ID of the SDMA engine instance to reset -* @suspend_user_queues: check if suspend user queue. * * This function performs the following steps: * 1. Calls all registered pre_reset callbacks to allow KFD and AMDGPU to save their state. @@ -533,7 +532,7 @@ void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct* * Returns: 0 on success, or a negative error code on failure. */ -int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id,bool suspend_user_queues) +int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id) {struct sdma_on_reset_funcs *funcs;int ret =0 ;@@ -542,13 +541,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, bstruct amdgpu_ring *page_ring = &sdma_instance->page;bool gfx_sched_stopped = false, page_sched_stopped = false; -/* Suspend KFD if suspend_user_queues is true. -* prevent the destruction of in-flight healthy user queue packets and -* avoid race conditions between KFD and KGD during the reset process. -*/ -if (suspend_user_queues) -amdgpu_amdkfd_suspend (adev, false); - +mutex_lock (&sdma_instance->engine_reset_mutex);/* Stop the scheduler's work queue for the GFX and page rings if they are running. * This ensures that no new tasks are submitted to the queues while * the reset is in progress. @@ -609,9 +602,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, bdrm_sched_wqueue_start (&page_ring->sched); } } - -if (suspend_user_queues) -amdgpu_amdkfd_resume (adev, false); +mutex_unlock (&sdma_instance->engine_reset_mutex);return ret; }drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +2
-1@@ -64,6 +64,7 @@ struct amdgpu_sdma_instance {struct amdgpu_bo *sdma_fw_obj;uint64_t sdma_fw_gpu_addr;uint32_t *sdma_fw_ptr; +struct mutex engine_reset_mutex; };enum amdgpu_sdma_ras_memory_id {@@ -169,7 +170,7 @@ struct amdgpu_buffer_funcs { };void amdgpu_sdma_register_on_reset_callbacks (struct amdgpu_device *adev,struct sdma_on_reset_funcs *funcs); -int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id,bool suspend_user_queues); +int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id);#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t))#define amdgpu_emit_fill_buffer (adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +8
-1@@ -1445,6 +1445,7 @@ static int sdma_v4_4_2_sw_init(struct amdgpu_ip_block *ip_block) }for (i =0 ; i < adev->sdma.num_instances; i++) { +mutex_init (&adev->sdma.instance[i].engine_reset_mutex); ring = &adev->sdma.instance[i].ring; ring->ring_obj =NULL ; ring->use_doorbell = true;@@ -1666,7 +1667,13 @@ static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid) {struct amdgpu_device *adev = ring->adev;u32 id =GET_INST (SDMA0 , ring->me); -return amdgpu_sdma_reset_engine (adev, id, true); +int r; + +amdgpu_amdkfd_suspend (adev, false); + r =amdgpu_sdma_reset_engine (adev, id); +amdgpu_amdkfd_resume (adev, false); + +return r; }static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev,uint32_t instance_id)drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1
-2@@ -2310,7 +2310,7 @@ static int reset_hung_queues_sdma(struct device_queue_manager *dqm)continue ;/* Reset engine and check. */ -if (amdgpu_sdma_reset_engine (dqm->dev->adev, i, false) || +if (amdgpu_sdma_reset_engine (dqm->dev->adev, i) || dqm->dev->kfd2kgd->hqd_sdma_get_doorbell (dqm->dev->adev, i, j) || !set_sdma_queue_as_reset (dqm, doorbell_off)) { r = -ENOTRECOVERABLE ; --2.48.1
[AMD Official Use Only - AMD Internal Distribution Only]
This patch is Reviewed-by: Jesse Zhang <[email protected]>
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Tuesday, March 18, 2025 9:11 PM
To: Deucher, Alexander <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 1/2] drm/amdgpu/sdma: fix engine reset handling
Ping?
Quoted 141 lines · Alex Deucher
Move the kfd suspend/resume code into the caller. That is where the KFD is likely to detect a reset so on the KFD side there is no need to call them. Also add a mutex to lock the actual reset sequence.
v2: make the locking per instance
Fixes bac38ca8c475 ("drm/amdkfd: implement per queue sdma reset forgfx 9.4+")
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 15 +++------------ drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 3 ++- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 9 ++++++++- .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +4
-12@@ -524,7 +524,6 @@ void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct* amdgpu_sdma_reset_engine - Reset a specific SDMA engine * @adev: Pointer to the AMDGPU device * @instance_id: ID of the SDMA engine instance to reset -* @suspend_user_queues: check if suspend user queue. * * This function performs the following steps: * 1. Calls all registered pre_reset callbacks to allow KFD and AMDGPU to save their state. @@ -533,7 +532,7 @@ void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct* * Returns: 0 on success, or a negative error code on failure. */ -int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id, bool suspend_user_queues) +int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t +instance_id) {struct sdma_on_reset_funcs *funcs;int ret =0 ;@@ -542,13 +541,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, bstruct amdgpu_ring *page_ring = &sdma_instance->page;bool gfx_sched_stopped = false, page_sched_stopped = false; -/* Suspend KFD if suspend_user_queues is true. -* prevent the destruction of in-flight healthy user queue packets and -* avoid race conditions between KFD and KGD during the reset process. -*/ -if (suspend_user_queues) -amdgpu_amdkfd_suspend (adev, false); - +mutex_lock (&sdma_instance->engine_reset_mutex);/* Stop the scheduler's work queue for the GFX and page rings if they are running. * This ensures that no new tasks are submitted to the queues while * the reset is in progress. @@ -609,9 +602,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, bdrm_sched_wqueue_start (&page_ring->sched); } } - -if (suspend_user_queues) -amdgpu_amdkfd_resume (adev, false); +mutex_unlock (&sdma_instance->engine_reset_mutex);return ret; }drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1
-0@@ -64,6 +64,7 @@ struct amdgpu_sdma_instance {struct amdgpu_bo *sdma_fw_obj;uint64_t sdma_fw_gpu_addr;uint32_t *sdma_fw_ptr; +struct mutex engine_reset_mutex; };enum amdgpu_sdma_ras_memory_id {@@ -169,7 +170,7 @@ struct amdgpu_buffer_funcs { };void amdgpu_sdma_register_on_reset_callbacks (struct amdgpu_device *adev,struct sdma_on_reset_funcs *funcs); -int
amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, bool suspend_user_queues);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +2
-0+int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t +instance_id);#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t)(adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t)) #define
amdgpu_emit_fill_buffer(adev, ib, s, d, b)(adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b)) diff --gita/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.cb/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
indexfd34dc1380811..927db7a080f0a100644drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0@@ -1445,6 +1445,7 @@ static int sdma_v4_4_2_sw_init(struct amdgpu_ip_block *ip_block) }for (i =0 ; i < adev->sdma.num_instances; i++) { + +mutex_init (&adev->sdma.instance[i].engine_reset_mutex); ring = &adev->sdma.instance[i].ring; ring->ring_obj =NULL ; ring->use_doorbell = true; @@ -1666,7 +1667,13 @@static int sdma_v4_4_2_reset_queue(struct
amdgpu_ring*ring, unsignedint vmid) { struct amdgpu_device *adev = ring->adev; u32 id = GET_INST(SDMA0, ring->me);drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +7
-1-return amdgpu_sdma_reset_engine (adev, id, true); +int r; + +amdgpu_amdkfd_suspend (adev, false); + r =amdgpu_sdma_reset_engine (adev, id); +amdgpu_amdkfd_resume (adev, false); + +return r; } static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev,
uint32_tinstance_id) diff --gita/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.cb/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.cindex2ed003d3ff0e0..c610e172a2b83100644drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +2
-2@@ -2310,7 +2310,7 @@ static int reset_hung_queues_sdma(struct device_queue_manager *dqm)continue ;/* Reset engine and check. */ -if (amdgpu_sdma_reset_engine (dqm->dev->adev, i, false) || +if (amdgpu_sdma_reset_engine (dqm->dev->adev, + i) || dqm->dev->kfd2kgd->hqd_sdma_get_doorbell (dqm->dev->adev, i, j) || !set_sdma_queue_as_reset (dqm, doorbell_off)) { r = -ENOTRECOVERABLE ; --2.48.1