drm/amdgpu: undo the halted activities when the HW reset is skipped
Subsystems (2)
PATCH 1/4 drm/amdgpu: undo the halted activities when the HW reset is skipped
When the guilty job has already signaled, amdgpu_device_gpu_recover() jumps to skip_hw_reset after amdgpu_device_halt_activities(). The following parts of the halt are only undone in amdgpu_device_reinit_after_reset(), so they stay in effect after this "successful" recovery:
- amdgpu_userq_pre_reset() unmapped all user queues and marked them HUNG; they are never mapped again.
- drm_client_dev_suspend() suspended fbdev; the console stops updating.
- amdgpu_ras_suspend() disabled RAS on all IPs.
- amdgpu_unregister_gpu_instance() dropped the device from mgpu_info.
Seen on navi31 with ring and soft reset disabled and a GFX job that completes right after its timeout:
amdgpu: ring gfx_0.0.0 timeout, signaled seq=3, emitted seq=4
amdgpu: GPU reset begin!. Source: 1
amdgpu: Guilty job already signaled, skipping HW reset
where tracing shows userq_pre_reset, drm_client_dev_suspend, ras_suspend and unregister_gpu_instance without their counterparts.
Undo them on the skip path the same way the reinit path does.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +20 -0
@@ -5565,6 +5565,25 @@ static void amdgpu_device_halt_activities(struct amdgpu_device *adev, } } +/* +* Undo the parts of amdgpu_device_halt_activities() that are otherwise only +* undone by amdgpu_device_reinit_after_reset(), for a recovery that skips +* the HW reset. +*/ +static void amdgpu_device_resume_activities (struct amdgpu_device *adev, +struct list_head *device_list) +{ +struct amdgpu_device *tmp_adev =NULL ; + +list_for_each_entry (tmp_adev, device_list, reset_list) { +amdgpu_register_gpu_instance (tmp_adev); +amdgpu_userq_post_reset (tmp_adev, false); +drm_client_dev_resume (adev_to_drm (tmp_adev)); +if (!amdgpu_reset_in_dpc (adev)) +amdgpu_ras_resume (tmp_adev); + } +} +static int amdgpu_device_asic_reset (struct amdgpu_device *adev,struct list_head *device_list,struct amdgpu_reset_context *reset_context)
@@ -5806,6 +5825,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,if (job && (dma_fence_get_status (&job->hw_fence->base) >0 )) { job_signaled = true;dev_info (adev->dev,"Guilty job already signaled, skipping HW reset" ); +amdgpu_device_resume_activities (adev, &device_list); goto skip_hw_reset; }
Signature · 1 line
2.50.1
PATCH 2/4 drm/amdgpu: report the BO alignment in bytes in GEM_LIST_HANDLES
The uapi documents drm_amdgpu_gem_list_handles_entry.alignment as "physical start_addr alignment in bytes", and GEM_OP GET_GEM_CREATE_INFO returns the same value in bytes, but GEM_LIST_HANDLES returns tbo.page_alignment, which is in pages. For a BO created with a 64 KiB alignment on navi31:
GET_GEM_CREATE_INFO: alignment=65536
GEM_LIST_HANDLES: alignment=16
so a user such as CRIU that recreates BOs from this list uses the wrong alignment. Convert it to bytes.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -1
@@ -1281,7 +1281,7 @@ int amdgpu_gem_list_handles_ioctl(struct drm_device *dev, void *data, bo_entry->alloc_flags = bo->flags &AMDGPU_GEM_CREATE_SETTABLE_MASK ; bo_entry->preferred_domains = bo->preferred_domains; bo_entry->gem_handle = id; - bo_entry->alignment = bo->tbo.page_alignment; + bo_entry->alignment = (u64 )bo->tbo.page_alignment <<PAGE_SHIFT ;if (bo->tbo.base.import_attach) bo_entry->flags |=AMDGPU_GEM_LIST_HANDLES_FLAG_IS_IMPORT ;
Signature · 1 line
2.50.1
Re: [PATCH 2/4] drm/amdgpu: report the BO alignment in bytes in GEM_LIST_HANDLES
Quoted 6 lines · Jesse Zhang
The uapi documents drm_amdgpu_gem_list_handles_entry.alignment as "physical
start_addralignment in bytes", andGEM_OPGET_GEM_CREATE_INFOreturns the same value in bytes, butGEM_LIST_HANDLESreturns tbo.page_alignment, which is in pages. For a BO created with a 64 KiB alignment on navi31:
Quoted 8 lines
GET_GEM_CREATE_INFO: alignment=65536
GEM_LIST_HANDLES: alignment=16so a user such as CRIU that recreates BOs from this list uses the wrong alignment. Convert it to bytes.
Fixes f9db1fc52ceb ("drm/amdgpu: Add ioctl to get all gem handles for a process")Signed-off-by Jesse Zhang <[email protected]>
Quoted 17 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-1@@ -1281,7 +1281,7 @@ int amdgpu_gem_list_handles_ioctl(struct drm_device *dev, void *data, bo_entry->alloc_flags = bo->flags &AMDGPU_GEM_CREATE_SETTABLE_MASK ; bo_entry->preferred_domains = bo->preferred_domains; bo_entry->gem_handle = id; - bo_entry->alignment = bo->tbo.page_alignment; + bo_entry->alignment = (u64 )bo->tbo.page_alignment <<PAGE_SHIFT ;if (bo->tbo.base.import_attach) bo_entry->flags |=AMDGPU_GEM_LIST_HANDLES_FLAG_IS_IMPORT ;
PATCH 3/4 drm/amdgpu: keep the eviction fence until the last handle is closed
In reply to Jesse Zhangamdgpu_gem_object_close() detaches the user queue eviction fence from the BO before it checks bo_va->ref_count, so closing any handle of a BO removes the fence, even when the file still has another handle to the BO and the bo_va with its GPU mappings stays. The BO can then be evicted without suspending the user queues of the file, which keep accessing it through mappings that are only marked for update.
Seen on navi31 with a SDMA user queue: a BO opened twice in the same file (GEM_FLINK + GEM_OPEN) loses its eviction fence when the second handle is closed (traced attach/detach of the fence):
attach bo=ffff8c78a6c84c00
GEM_CLOSE handle=7
detach bo=ffff8c78a6c84c00
while handle 6 and the mapping are still in use.
Only detach the fence when the last reference to the bo_va goes away, matching amdgpu_gem_object_open(), which attaches it only when the bo_va is created. With this the fence stays until the file is closed.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +6 -3
@@ -351,11 +351,14 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj, goto out_unlock; } + bo_va =amdgpu_vm_bo_find (vm, bo); +/* the fence is attached once per bo_va, so keep it for other handles */ +if (bo_va && --bo_va->ref_count) + goto out_unlock; +if (!amdgpu_vm_is_bo_always_valid (vm, bo))amdgpu_evf_mgr_detach_fence (&fpriv->evf_mgr, bo); - - bo_va =amdgpu_vm_bo_find (vm, bo); -if (!bo_va || --bo_va->ref_count) +if (!bo_va) goto out_unlock;amdgpu_vm_bo_del (adev, bo_va);
Signature · 1 line
2.50.1
Re: [PATCH 3/4] drm/amdgpu: keep the eviction fence until the last handle is closed
Quoted 15 lines · Jesse Zhang
amdgpu_gem_object_close()detaches the user queue eviction fence from the BO before it checksbo_va->ref_count, so closing any handle of a BO removes the fence, even when the file still has another handle to the BO and thebo_vawith its GPU mappings stays. The BO can then be evicted without suspending the user queues of the file, which keep accessing it through mappings that are only marked for update.Seen on navi31 with a SDMA user queue: a BO opened twice in the same file (
GEM_FLINK+GEM_OPEN) loses its eviction fence when the second handle is closed (traced attach/detach of the fence):attach bo=ffff8c78a6c84c00
GEM_CLOSEhandle=7
detach bo=ffff8c78a6c84c00
Quoted 8 lines
while handle 6 and the mapping are still in use.
Only detach the fence when the last reference to the
bo_vagoes away, matchingamdgpu_gem_object_open(), which attaches it only when thebo_vais created. With this the fence stays until the file is closed.Fixes 31f7efcdca4d ("drm/amdgpu: enable eviction fence")Signed-off-by Jesse Zhang <[email protected]>
Quoted 26 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +6
-3@@ -351,11 +351,14 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj, goto out_unlock; } + bo_va =amdgpu_vm_bo_find (vm, bo); +/* the fence is attached once per bo_va, so keep it for other handles */ +if (bo_va && --bo_va->ref_count) + goto out_unlock; +if (!amdgpu_vm_is_bo_always_valid (vm, bo))amdgpu_evf_mgr_detach_fence (&fpriv->evf_mgr, bo); - - bo_va =amdgpu_vm_bo_find (vm, bo); -if (!bo_va || --bo_va->ref_count) +if (!bo_va) goto out_unlock;amdgpu_vm_bo_del (adev, bo_va);
PATCH 4/4 drm/amdgpu: reject unknown GEM_METADATA ops
In reply to Jesse Zhangamdgpu_gem_metadata_ioctl() handles AMDGPU_GEM_METADATA_OP_GET_METADATA and AMDGPU_GEM_METADATA_OP_SET_METADATA and returns r otherwise, which is 0 from the successful amdgpu_bo_reserve(). Any other op therefore succeeds without doing anything.
Return -EINVAL for unknown ops.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -0
@@ -780,6 +780,8 @@ int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data, r =amdgpu_bo_set_metadata (robj, args->data.data, args->data.data_size_bytes, args->data.flags); + }else { + r = -EINVAL ; } unreserve:
Signature · 1 line
2.50.1
Christian König
maintainerRe: [PATCH 4/4] drm/amdgpu: reject unknown GEM_METADATA ops
Quoted 18 lines · Jesse Zhang
amdgpu_gem_metadata_ioctl()handlesAMDGPU_GEM_METADATA_OP_GET_METADATAandAMDGPU_GEM_METADATA_OP_SET_METADATAand returns r otherwise, which is 0 from the successfulamdgpu_bo_reserve(). Any other op therefore succeeds without doing anything.Return
-EINVALfor unknown ops.Fixes d38ceaf99ed0 ("drm/amdgpu: add core driver (v4)")Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data, · line 785
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-0@@ -780,6 +780,8 @@ int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data, r =amdgpu_bo_set_metadata (robj, args->data.data, args->data.data_size_bytes, args->data.flags); + }else { + r = -EINVAL ; }
We should probably switch the if/else if/else into a switch case, but apart from that looks reasonable to me.
Regards,
Christian.
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0unreserve: