Various fixes to pass libdrm hotunplug tests
Subsystems (4)
cover Various fixes to pass libdrm hotunplug tests
Bunch of fixes to enable passing hotplug tests i previosly added here[1] with latest code.
Once accepted I will enable the tests on libdrm side.
[1] - https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/172
Andrey Grodzovsky (4):
drm/amdgpu: Move flush VCE idle_work during HW fini drm/ttm: Create pinned list
drm/amdgpu: drm/amdgpu: Handle IOMMU enabled case drm/amdgpu: Add a UAPI flag for hot plug/unplug
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 50 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 1 - drivers/gpu/drm/amd/amdgpu/vce_v2_0.c | 4 ++ drivers/gpu/drm/amd/amdgpu/vce_v3_0.c | 5 ++- drivers/gpu/drm/amd/amdgpu/vce_v4_0.c | 2 + drivers/gpu/drm/ttm/ttm_bo.c | 24 +++++++++-- drivers/gpu/drm/ttm/ttm_resource.c | 1 + include/drm/ttm/ttm_resource.h | 1 + 11 files changed, 88 insertions(+), 6 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/4 drm/amdgpu: Move flush VCE idle_work during HW fini
Attepmts to powergate after device is removed lead to crash.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 1 - drivers/gpu/drm/amd/amdgpu/vce_v2_0.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/vce_v3_0.c | 5 ++++- drivers/gpu/drm/amd/amdgpu/vce_v4_0.c | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +0 -1
@@ -218,7 +218,6 @@ int amdgpu_vce_sw_fini(struct amdgpu_device *adev)if (adev->vce.vcpu_bo ==NULL )return 0 ; -cancel_delayed_work_sync (&adev->vce.idle_work);drm_sched_entity_destroy (&adev->vce.entity); amdgpu_bo_free_kernel(&adev->vce.vcpu_bo, &adev->vce.gpu_addr,
drivers/gpu/drm/amd/amdgpu/vce_v2_0.c +4 -0
@@ -477,6 +477,10 @@ static int vce_v2_0_hw_init(void *handle)static int vce_v2_0_hw_fini (void *handle) { +struct amdgpu_device *adev = (struct amdgpu_device *)handle; + +cancel_delayed_work_sync (&adev->vce.idle_work); +return 0 ; }
drivers/gpu/drm/amd/amdgpu/vce_v3_0.c +4 -1
@@ -495,7 +495,10 @@ static int vce_v3_0_hw_fini(void *handle)return r;vce_v3_0_stop (adev); -return vce_v3_0_set_clockgating_state (adev,AMD_CG_STATE_GATE ); + r =vce_v3_0_set_clockgating_state (adev,AMD_CG_STATE_GATE ); +cancel_delayed_work_sync (&adev->vce.idle_work); + +return r; }static int vce_v3_0_suspend (void *handle)
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +2 -0
@@ -550,6 +550,8 @@ static int vce_v4_0_hw_fini(void *handle)DRM_DEBUG ("For SRIOV client, shouldn't do anything.\n" ); } +cancel_delayed_work_sync (&adev->vce.idle_work); +return 0 ; }
Signature · 1 line
2.25.1
RE: [PATCH 1/4] drm/amdgpu: Move flush VCE idle_work during HW fini
[AMD Official Use Only]
Hi Andrey,
I sent out a similar patch set to address S3 issue. And I believe it should be able to address the issue here too.
https://lists.freedesktop.org/archives/amd-gfx/2021-August/067972.html
https://lists.freedesktop.org/archives/amd-gfx/2021-August/067967.html
BR
Evan
Quoted 84 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Andrey Grodzovsky
Sent: Wednesday, August 25, 2021 5:01 AM
To: [email protected]; [email protected]
Cc: [email protected]; Grodzovsky, Andrey <[email protected]>
Subject: [PATCH 1/4] drm/amdgpu: Move flush VCEidle_workduring HW finiAttepmts to powergate after device is removed lead to crash.
Signed-off-by Andrey Grodzovsky <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 1 - drivers/gpu/drm/amd/amdgpu/vce_v2_0.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/vce_v3_0.c | 5 ++++- drivers/gpu/drm/amd/amdgpu/vce_v4_0.c | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +0
-1@@ -218,7 +218,6 @@ int amdgpu_vce_sw_fini(struct amdgpu_device *adev)if (adev->vce.vcpu_bo ==NULL )return 0 ; -cancel_delayed_work_sync (&adev->vce.idle_work);drm_sched_entity_destroy (&adev->vce.entity);amdgpu_bo_free_kernel(&adev->vce.vcpu_bo, &adev-
Quoted 1 line
vce.gpu_addr,
drivers/gpu/drm/amd/amdgpu/vce_v2_0.c +4
-0@@ -477,6 +477,10 @@ static int vce_v2_0_hw_init(void *handle)static int vce_v2_0_hw_fini (void *handle) { +struct amdgpu_device *adev = (struct amdgpu_device *)handle; + +cancel_delayed_work_sync (&adev->vce.idle_work); +return 0 ; }drivers/gpu/drm/amd/amdgpu/vce_v3_0.c +4
-1@@ -495,7 +495,10 @@ static int vce_v3_0_hw_fini(void *handle)return r;vce_v3_0_stop (adev); -return vce_v3_0_set_clockgating_state (adev, AMD_CG_STATE_GATE); + r =vce_v3_0_set_clockgating_state (adev,AMD_CG_STATE_GATE ); +cancel_delayed_work_sync (&adev->vce.idle_work); + +return r; }static int
vce_v3_0_suspend(void *handle)drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +2
-1@@ -550,6 +550,8 @@ static int vce_v4_0_hw_fini(void *handle)DRM_DEBUG ("For SRIOV client, shouldn't do anything.\n" ); } +cancel_delayed_work_sync (&adev->vce.idle_work); +return 0 ; } --2.25.1
Re: [PATCH 1/4] drm/amdgpu: Move flush VCE idle_work during HW fini
Right, they will cover my use case, when are they landing ? I rebased today and haven't seen them.
Andrey
Quoted 94 lines · Evan
[AMD Official Use Only]
Hi Andrey,
I sent out a similar patch set to address S3 issue. And I believe it should be able to address the issue here too.
https://lists.freedesktop.org/archives/amd-gfx/2021-August/067972.html
https://lists.freedesktop.org/archives/amd-gfx/2021-August/067967.htmlBR
EvanQuoted 84 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Andrey Grodzovsky
Sent: Wednesday, August 25, 2021 5:01 AM
To: [email protected]; [email protected]
Cc: [email protected]; Grodzovsky, Andrey <[email protected]>
Subject: [PATCH 1/4] drm/amdgpu: Move flush VCEidle_workduring HW finiAttepmts to powergate after device is removed lead to crash.
Signed-off-by Andrey Grodzovsky <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 1 - drivers/gpu/drm/amd/amdgpu/vce_v2_0.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/vce_v3_0.c | 5 ++++- drivers/gpu/drm/amd/amdgpu/vce_v4_0.c | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +0
-1@@ -218,7 +218,6 @@ int amdgpu_vce_sw_fini(struct amdgpu_device *adev)if (adev->vce.vcpu_bo ==NULL )return 0 ; -cancel_delayed_work_sync (&adev->vce.idle_work);drm_sched_entity_destroy (&adev->vce.entity);amdgpu_bo_free_kernel(&adev->vce.vcpu_bo, &adev-
Quoted 1 line
vce.gpu_addr,
drivers/gpu/drm/amd/amdgpu/vce_v2_0.c +4
-0@@ -477,6 +477,10 @@ static int vce_v2_0_hw_init(void *handle)static int vce_v2_0_hw_fini (void *handle) { +struct amdgpu_device *adev = (struct amdgpu_device *)handle; + +cancel_delayed_work_sync (&adev->vce.idle_work); +return 0 ; }drivers/gpu/drm/amd/amdgpu/vce_v3_0.c +4
-1@@ -495,7 +495,10 @@ static int vce_v3_0_hw_fini(void *handle)return r;vce_v3_0_stop (adev); -return vce_v3_0_set_clockgating_state (adev, AMD_CG_STATE_GATE); + r =vce_v3_0_set_clockgating_state (adev,AMD_CG_STATE_GATE ); +cancel_delayed_work_sync (&adev->vce.idle_work); + +return r; }static int
vce_v3_0_suspend(void *handle)drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +2
-1@@ -550,6 +550,8 @@ static int vce_v4_0_hw_fini(void *handle)DRM_DEBUG ("For SRIOV client, shouldn't do anything.\n" ); } +cancel_delayed_work_sync (&adev->vce.idle_work); +return 0 ; } --2.25.1
RE: [PATCH 1/4] drm/amdgpu: Move flush VCE idle_work during HW fini
[AMD Official Use Only]
Just landed.
Thanks,
Evan
Quoted 111 lines
-----Original Message-----
From: Grodzovsky, Andrey <[email protected]>
Sent: Wednesday, August 25, 2021 11:20 AM
To: Quan, Evan <[email protected]>; [email protected]; [email protected]
Cc: [email protected]
Subject: Re: [PATCH 1/4] drm/amdgpu: Move flush VCEidle_workduring HW finiRight, they will cover my use case, when are they landing ? I rebased today and haven't seen them.
Andrey
Quoted 5 lines · Evan
[AMD Official Use Only]
Hi Andrey,
I sent out a similar patch set to address S3 issue. And I believe it should be
able to address the issue here too.
Quoted 90 lines
https://lists.freedesktop.org/archives/amd-gfx/2021-August/067972.html
https://lists.freedesktop.org/archives/amd-gfx/2021-August/067967.htmlBR
EvanQuoted 85 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Andrey Grodzovsky
Sent: Wednesday, August 25, 2021 5:01 AM
To: [email protected]; [email protected]
Cc: [email protected]; Grodzovsky, Andrey <[email protected]>
Subject: [PATCH 1/4] drm/amdgpu: Move flush VCEidle_workduring HW finiAttepmts to powergate after device is removed lead to crash.
Signed-off-by Andrey Grodzovsky <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 1 - drivers/gpu/drm/amd/amdgpu/vce_v2_0.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/vce_v3_0.c | 5 ++++- drivers/gpu/drm/amd/amdgpu/vce_v4_0.c | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +0
-1@@ -218,7 +218,6 @@ int amdgpu_vce_sw_fini(struct amdgpu_device *adev)if (adev->vce.vcpu_bo ==NULL )return 0 ; -cancel_delayed_work_sync (&adev->vce.idle_work);drm_sched_entity_destroy (&adev->vce.entity);amdgpu_bo_free_kernel(&adev->vce.vcpu_bo, &adev-
Quoted 1 line
vce.gpu_addr,
drivers/gpu/drm/amd/amdgpu/vce_v2_0.c +4
-0@@ -477,6 +477,10 @@ static int vce_v2_0_hw_init(void *handle)static int vce_v2_0_hw_fini (void *handle) { +struct amdgpu_device *adev = (struct amdgpu_device *)handle; + +cancel_delayed_work_sync (&adev->vce.idle_work); +return 0 ; }drivers/gpu/drm/amd/amdgpu/vce_v3_0.c +4
-1@@ -495,7 +495,10 @@ static int vce_v3_0_hw_fini(void *handle)return r;vce_v3_0_stop (adev); -return vce_v3_0_set_clockgating_state (adev, AMD_CG_STATE_GATE); + r =vce_v3_0_set_clockgating_state (adev,AMD_CG_STATE_GATE ); +cancel_delayed_work_sync (&adev->vce.idle_work); + +return r; }static int
vce_v3_0_suspend(void *handle)diff --gita/drivers/gpu/drm/amd/amdgpu/vce_v4_0.cb/drivers/gpu/drm/amd/amdgpu/vce_v4_0.c
index90910d19db12..3297405fd32d100644drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +2
-1@@ -550,6 +550,8 @@ static int vce_v4_0_hw_fini(void *handle)DRM_DEBUG ("For SRIOV client, shouldn't do anything.\n" ); } +cancel_delayed_work_sync (&adev->vce.idle_work); +return 0 ; } --2.25.1
PATCH 2/4 drm/ttm: Create pinned list
In reply to Andrey GrodzovskyThis list will be used to capture all non VRAM BOs not on LRU so when device is hot unplugged we can iterate the list and unmap DMA mappings before device is removed.
--- drivers/gpu/drm/ttm/ttm_bo.c | 24 +++++++++++++++++++++--- drivers/gpu/drm/ttm/ttm_resource.c | 1 + include/drm/ttm/ttm_resource.h | 1 + 3 files changed, 23 insertions(+), 3 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +21 -3
@@ -69,16 +69,34 @@ static void ttm_bo_mem_space_debug(struct ttm_buffer_object *bo, } } -static void ttm_bo_del_from_lru (struct ttm_buffer_object *bo) +static void ttm_bo_del_from_lru_imp (struct ttm_buffer_object *bo,bool final) {struct ttm_device *bdev = bo->bdev; +struct ttm_resource_manager *man =NULL ; -list_del_init (&bo->lru); +if (bo->resource) + man =ttm_manager_type (bdev, bo->resource->mem_type); + + +if (!final && man && man->use_tt) +list_move_tail (&bo->lru, &man->pinned); +else +list_del_init (&bo->lru);if (bdev->funcs->del_from_lru_notify) bdev->funcs->del_from_lru_notify (bo); } +static inline void ttm_bo_del_from_lru_final (struct ttm_buffer_object *bo) +{ +ttm_bo_del_from_lru_imp (bo, true); +} + +static inline void ttm_bo_del_from_lru (struct ttm_buffer_object *bo) +{ +ttm_bo_del_from_lru_imp (bo, false); +} +static void ttm_bo_bulk_move_set_pos (struct ttm_lru_bulk_move_pos *pos,struct ttm_buffer_object *bo) {
@@ -453,7 +471,7 @@ static void ttm_bo_release(struct kref *kref) }spin_lock (&bo->bdev->lru_lock); -ttm_bo_del_from_lru (bo); +ttm_bo_del_from_lru_final (bo);list_del (&bo->ddestroy);spin_unlock (&bo->bdev->lru_lock);
drivers/gpu/drm/ttm/ttm_resource.c +1 -0
@@ -85,6 +85,7 @@ void ttm_resource_manager_init(struct ttm_resource_manager *man,for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i)INIT_LIST_HEAD (&man->lru[i]); +INIT_LIST_HEAD (&man->pinned); man->move =NULL ; }EXPORT_SYMBOL (ttm_resource_manager_init);
include/drm/ttm/ttm_resource.h +1 -0
@@ -130,6 +130,7 @@ struct ttm_resource_manager {*/ struct list_head lru[TTM_MAX_BO_PRIORITY ]; +struct list_head pinned;/* * Protected by @move_lock.
Signature · 1 line
2.25.1
Christian König
maintainerRe: [PATCH 2/4] drm/ttm: Create pinned list
Am 24.08.21 um 23:01 schrieb Andrey Grodzovsky:
Quoted 17 lines
This list will be used to capture all non VRAM BOs not on LRU so when device is hot unplugged we can iterate the list and unmap DMA mappings before device is removed.
Signed-off-by Andrey Grodzovsky <[email protected]>Suggested-by Christian König <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 24 +++++++++++++++++++++--- drivers/gpu/drm/ttm/ttm_resource.c | 1 + include/drm/ttm/ttm_resource.h | 1 + 3 files changed, 23 insertions(+), 3 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +0
-0
drivers/gpu/drm/ttm/ttm_bo.c static void ttm_bo_mem_space_debug(struct ttm_buffer_object *bo, · line 72
Quoted 5 lines
drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -69,16 +69,34 @@ static void ttm_bo_mem_space_debug(struct ttm_buffer_object *bo, } } -static void ttm_bo_del_from_lru (struct ttm_buffer_object *bo) +static void ttm_bo_del_from_lru_imp (struct ttm_buffer_object *bo,bool final)
I think we should rather inline the only user where we actually need to delete the BO from the LRU and then rename the function here to ttm_bo_move_to_pinned().
Apart from that looks good to me.
Regards,
Christian.
Quoted 64 lines
drivers/gpu/drm/ttm/ttm_bo.c +20
-2{struct ttm_device *bdev = bo->bdev; +struct ttm_resource_manager *man =NULL ; -list_del_init (&bo->lru); +if (bo->resource) + man =ttm_manager_type (bdev, bo->resource->mem_type); + + +if (!final && man && man->use_tt) +list_move_tail (&bo->lru, &man->pinned); +else +list_del_init (&bo->lru);if (bdev->funcs->del_from_lru_notify) bdev->funcs->del_from_lru_notify (bo); } +static inline void ttm_bo_del_from_lru_final (struct ttm_buffer_object *bo) +{ +ttm_bo_del_from_lru_imp (bo, true); +} + +static inline void ttm_bo_del_from_lru (struct ttm_buffer_object *bo) +{ +ttm_bo_del_from_lru_imp (bo, false); +} +static void ttm_bo_bulk_move_set_pos (struct ttm_lru_bulk_move_pos *pos,struct ttm_buffer_object *bo) {@@ -453,7 +471,7 @@ static void ttm_bo_release(struct kref *kref) }spin_lock (&bo->bdev->lru_lock); -ttm_bo_del_from_lru (bo); +ttm_bo_del_from_lru_final (bo);list_del (&bo->ddestroy);spin_unlock (&bo->bdev->lru_lock);drivers/gpu/drm/ttm/ttm_resource.c +1
-0@@ -85,6 +85,7 @@ void ttm_resource_manager_init(struct ttm_resource_manager *man,for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i)INIT_LIST_HEAD (&man->lru[i]); +INIT_LIST_HEAD (&man->pinned); man->move =NULL ; }EXPORT_SYMBOL (ttm_resource_manager_init);include/drm/ttm/ttm_resource.h +1
-0@@ -130,6 +130,7 @@ struct ttm_resource_manager {*/ struct list_head lru[TTM_MAX_BO_PRIORITY ]; +struct list_head pinned;/* * Protected by @move_lock.
PATCH 3/4 drm/amdgpu: drm/amdgpu: Handle IOMMU enabled case
In reply to Andrey GrodzovskyHandle all DMA IOMMU group related dependencies before the group is removed and we try to access it after free.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 50 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 + 3 files changed, 53 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -0
@@ -3860,6 +3860,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)amdgpu_device_ip_fini_early (adev); +amdgpu_ttm_clear_dma_mappings (adev); +amdgpu_gart_dummy_page_fini (adev);amdgpu_device_unmap_mmio (adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +50 -0
62 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +1 -0
@@ -190,6 +190,7 @@ bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);uint64_t amdgpu_ttm_tt_pde_flags (struct ttm_tt *ttm,struct ttm_resource *mem);uint64_t amdgpu_ttm_tt_pte_flags (struct amdgpu_device *adev,struct ttm_tt *ttm,struct ttm_resource *mem); +void amdgpu_ttm_clear_dma_mappings (struct amdgpu_device *adev);void amdgpu_ttm_debugfs_init (struct amdgpu_device *adev);
Signature · 1 line
2.25.1
Re: [PATCH 3/4] drm/amdgpu: drm/amdgpu: Handle IOMMU enabled case
Am 24.08.21 um 23:01 schrieb Andrey Grodzovsky:
Quoted 36 lines
Handle all DMA IOMMU group related dependencies before the group is removed and we try to access it after free.
Signed-off-by Andrey Grodzovsky <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 50 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 + 3 files changed, 53 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0@@ -3860,6 +3860,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)amdgpu_device_ip_fini_early (adev); +amdgpu_ttm_clear_dma_mappings (adev); +amdgpu_gart_dummy_page_fini (adev);amdgpu_device_unmap_mmio (adev);drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-0@@ -64,6 +64,7 @@static int amdgpu_ttm_backend_bind (struct ttm_device *bdev,struct ttm_tt *ttm,struct ttm_resource *bo_mem); +static void amdgpu_ttm_backend_unbind (struct ttm_device *bdev,struct ttm_tt *ttm);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static ssize_t amdgpu_iomem_write(struct file *f, const char __user *buf, · line 2297
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-0@@ -2293,6 +2294,55 @@ static ssize_t amdgpu_iomem_write(struct file *f, const char __user *buf,return result; } +void amdgpu_ttm_clear_dma_mappings (struct amdgpu_device *adev)
I strongly think that this function should be part of TTM. Something like ttm_device_force_unpopulate.
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +12
-0+{ +struct ttm_device *bdev = &adev->mman.bdev; +struct ttm_resource_manager *man; +struct ttm_buffer_object *bo; +unsigned int i, j; + +spin_lock (&bdev->lru_lock); +for (i =TTM_PL_SYSTEM ; i <TTM_NUM_MEM_TYPES ; ++i) { + man =ttm_manager_type (bdev, i); +if (!man || !man->use_tt) +continue ; +
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static ssize_t amdgpu_iomem_write(struct file *f, const char __user *buf, · line 2319
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +10
-0+while (!list_empty (&man->pinned)) { + bo = list_first_entry(&man->pinned, struct ttm_buffer_object, lru); +/* Take ref against racing releases once lru_lock is unlocked */ +ttm_bo_get (bo); +list_del_init (&bo->lru); +spin_unlock (&bdev->lru_lock); + +if (bo->ttm) { +amdgpu_ttm_backend_unbind (bo->bdev, bo->ttm); +ttm_tt_destroy_common (bo->bdev, bo->ttm);
Then you can also cleanly use ttm_tt_unpopulate here, cause this will result in incorrect statistics inside TTM atm.
Regards,
Christian.
Quoted 41 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +26
-0+ } + +ttm_bo_put (bo); +spin_lock (&bdev->lru_lock); + } + +for (j =0 ; j <TTM_MAX_BO_PRIORITY ; ++j) { +while (!list_empty (&man->lru[j])) { + bo = list_first_entry(&man->lru[j], struct ttm_buffer_object, lru); +ttm_bo_get (bo); +list_del_init (&bo->lru); +spin_unlock (&bdev->lru_lock); + +if (bo->ttm) { +amdgpu_ttm_backend_unbind (bo->bdev, bo->ttm); +ttm_tt_destroy_common (bo->bdev, bo->ttm); + } +ttm_bo_put (bo); +spin_lock (&bdev->lru_lock); + } + } + } +spin_unlock (&bdev->lru_lock); + +} +static const struct file_operations amdgpu_ttm_iomem_fops = { .owner =THIS_MODULE , .read = amdgpu_iomem_read,drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +1
-0@@ -190,6 +190,7 @@ bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);uint64_t amdgpu_ttm_tt_pde_flags (struct ttm_tt *ttm,struct ttm_resource *mem);uint64_t amdgpu_ttm_tt_pte_flags (struct amdgpu_device *adev,struct ttm_tt *ttm,struct ttm_resource *mem); +void amdgpu_ttm_clear_dma_mappings (struct amdgpu_device *adev);void amdgpu_ttm_debugfs_init (struct amdgpu_device *adev);
Re: [PATCH 3/4] drm/amdgpu: drm/amdgpu: Handle IOMMU enabled case
Quoted 33 lines · Christian König
Am 24.08.21 um 23:01 schrieb Andrey Grodzovsky:
Quoted 30 lines
Handle all DMA IOMMU group related dependencies before the group is removed and we try to access it after free.
Signed-off-by Andrey Grodzovsky <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 50 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 +3 files changed, 53 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0@@ -3860,6 +3860,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev) amdgpu_device_ip_fini_early(adev); + amdgpu_ttm_clear_dma_mappings(adev); + amdgpu_gart_dummy_page_fini(adev); amdgpu_device_unmap_mmio(adev);drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-0@@ -64,6 +64,7 @@ static int amdgpu_ttm_backend_bind(struct ttm_device *bdev, struct ttm_tt *ttm, struct ttm_resource *bo_mem); +
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0static void amdgpu_ttm_backend_unbind(struct ttm_device *bdev, struct ttm_tt *ttm); @@ -2293,6 +2294,55 @@ static ssize_t amdgpu_iomem_write(struct file *f, const char __user *buf,return result;
}
+voidamdgpu_ttm_clear_dma_mappings(struct amdgpu_device *adev)I strongly think that this function should be part of TTM. Something like
ttm_device_force_unpopulate.
Yes, this something I also wanted but see bellow
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +14
-0+{ + struct ttm_device *bdev = &adev->mman.bdev; + struct ttm_resource_manager *man; + struct ttm_buffer_object *bo; + unsigned int i, j; + + spin_lock(&bdev->lru_lock); + for (i = TTM_PL_SYSTEM; i < TTM_NUM_MEM_TYPES; ++i) { + man = ttm_manager_type(bdev, i); + if (!man || !man->use_tt) + continue; + + while (!list_empty(&man->pinned)) { + bo = list_first_entry(&man->pinned, struct
ttm_buffer_object, lru);
Quoted 8 lines
Quoted 8 lines
+ /* Take ref against racing releases once
lru_lockis unlocked */
+ttm_bo_get(bo);
+list_del_init(&bo->lru);
+spin_unlock(&bdev->lru_lock);
+
+ if (bo->ttm) {
+amdgpu_ttm_backend_unbind(bo->bdev, bo->ttm);
amdgpu_ttm_backend_unbind is needed to be called separately from ttm_tt_unpopulate to take care of code flows that do dma mapping though the gart bind and not through ttm_tt_populate, Since it's inside amdgpu i had to place the entire function in amdgpu. Any suggestions ?
Andrey
Quoted 48 lines
Quoted 1 line
+
ttm_tt_destroy_common(bo->bdev, bo->ttm);Then you can also cleanly use
ttm_tt_unpopulatehere, cause this will result in incorrect statistics inside TTM atm.Regards,
Christian.Quoted 40 lines
+ }
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +8
-0+ + ttm_bo_put(bo); + spin_lock(&bdev->lru_lock); + } + + for (j = 0; j < TTM_MAX_BO_PRIORITY; ++j) { + while (!list_empty(&man->lru[j])) { + bo = list_first_entry(&man->lru[j], struct
ttm_buffer_object, lru);
+ttm_bo_get(bo);
+list_del_init(&bo->lru);
+spin_unlock(&bdev->lru_lock);drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +14
-0+ + if (bo->ttm) { + amdgpu_ttm_backend_unbind(bo->bdev, bo->ttm); + ttm_tt_destroy_common(bo->bdev, bo->ttm); + } + ttm_bo_put(bo); + spin_lock(&bdev->lru_lock); + } + } + } + spin_unlock(&bdev->lru_lock); + +} +static const struct
file_operationsamdgpu_ttm_iomem_fops= { .owner =THIS_MODULE,
.read =amdgpu_iomem_read,drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +1
-0@@ -190,6 +190,7 @@ bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm); uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct ttm_resource *mem); uint64_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm, struct ttm_resource *mem); +void amdgpu_ttm_clear_dma_mappings (struct amdgpu_device *adev); void amdgpu_ttm_debugfs_init(struct amdgpu_device *adev);
Re: [PATCH 3/4] drm/amdgpu: drm/amdgpu: Handle IOMMU enabled case
Ping
Andrey
Quoted 130 lines · Andrey Grodzovsky
Quoted 34 lines · Christian König
Am 24.08.21 um 23:01 schrieb Andrey Grodzovsky:
Quoted 31 lines
Handle all DMA IOMMU group related dependencies before the group is removed and we try to access it after free.
Signed-off-by Andrey Grodzovsky <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 50
++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 +3 files changed, 53 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0@@ -3860,6 +3860,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev) amdgpu_device_ip_fini_early(adev); + amdgpu_ttm_clear_dma_mappings(adev); + amdgpu_gart_dummy_page_fini(adev); amdgpu_device_unmap_mmio(adev);drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-0@@ -64,6 +64,7 @@ static int amdgpu_ttm_backend_bind(struct ttm_device *bdev, struct ttm_tt *ttm, struct ttm_resource *bo_mem); +Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0static void amdgpu_ttm_backend_unbind(struct ttm_device *bdev, struct ttm_tt *ttm); @@ -2293,6 +2294,55 @@ static ssize_t amdgpu_iomem_write(struct file *f, const char __user *buf,return result;
}
+voidamdgpu_ttm_clear_dma_mappings(struct amdgpu_device *adev)I strongly think that this function should be part of TTM. Something like
ttm_device_force_unpopulate.Yes, this something I also wanted but see bellow
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +14
-0+{ + struct ttm_device *bdev = &adev->mman.bdev; + struct ttm_resource_manager *man; + struct ttm_buffer_object *bo; + unsigned int i, j; + + spin_lock(&bdev->lru_lock); + for (i = TTM_PL_SYSTEM; i < TTM_NUM_MEM_TYPES; ++i) { + man = ttm_manager_type(bdev, i); + if (!man || !man->use_tt) + continue; + + while (!list_empty(&man->pinned)) { + bo = list_first_entry(&man->pinned, struct
ttm_buffer_object, lru);Quoted 8 lines
Quoted 8 lines
+ /* Take ref against racing releases once
lru_lockis unlocked */
+ttm_bo_get(bo);
+list_del_init(&bo->lru);
+spin_unlock(&bdev->lru_lock);
+
+ if (bo->ttm) {
+amdgpu_ttm_backend_unbind(bo->bdev, bo->ttm);
amdgpu_ttm_backend_unbindis needed to be called separately fromttm_tt_unpopulateto take care of code flows that do dma mapping though the gart bind and not throughttm_tt_populate, Since it's inside amdgpu i had to place the entire function in amdgpu. Any suggestions ?Andrey
Quoted 48 lines
Quoted 1 line
+
ttm_tt_destroy_common(bo->bdev, bo->ttm);Then you can also cleanly use
ttm_tt_unpopulatehere, cause this will result in incorrect statistics inside TTM atm.Regards,
Christian.Quoted 40 lines
+ }
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +8
-0+ + ttm_bo_put(bo); + spin_lock(&bdev->lru_lock); + } + + for (j = 0; j < TTM_MAX_BO_PRIORITY; ++j) { + while (!list_empty(&man->lru[j])) { + bo = list_first_entry(&man->lru[j], struct
ttm_buffer_object, lru);
+ttm_bo_get(bo);
+list_del_init(&bo->lru);
+spin_unlock(&bdev->lru_lock);drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +14
-0+ + if (bo->ttm) { + amdgpu_ttm_backend_unbind(bo->bdev, bo->ttm); + ttm_tt_destroy_common(bo->bdev, bo->ttm); + } + ttm_bo_put(bo); + spin_lock(&bdev->lru_lock); + } + } + } + spin_unlock(&bdev->lru_lock); + +} +static const struct
file_operationsamdgpu_ttm_iomem_fops= { .owner =THIS_MODULE,
.read =amdgpu_iomem_read,drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +1
-0@@ -190,6 +190,7 @@ bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm); uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct ttm_resource *mem); uint64_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm, struct ttm_resource *mem); +void amdgpu_ttm_clear_dma_mappings (struct amdgpu_device *adev); void amdgpu_ttm_debugfs_init(struct amdgpu_device *adev);
Re: [PATCH 3/4] drm/amdgpu: drm/amdgpu: Handle IOMMU enabled case
Am 26.08.21 um 15:43 schrieb Andrey Grodzovsky:
Quoted 83 lines
Ping
Andrey
Quoted 78 lines · Andrey Grodzovsky
Quoted 34 lines · Christian König
Am 24.08.21 um 23:01 schrieb Andrey Grodzovsky:
Quoted 31 lines
Handle all DMA IOMMU group related dependencies before the group is removed and we try to access it after free.
Signed-off-by Andrey Grodzovsky <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 50
++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 +3 files changed, 53 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0@@ -3860,6 +3860,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev) amdgpu_device_ip_fini_early(adev); + amdgpu_ttm_clear_dma_mappings(adev); + amdgpu_gart_dummy_page_fini(adev); amdgpu_device_unmap_mmio(adev);drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-0@@ -64,6 +64,7 @@ static int amdgpu_ttm_backend_bind(struct ttm_device *bdev, struct ttm_tt *ttm, struct ttm_resource *bo_mem); +Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0static void amdgpu_ttm_backend_unbind(struct ttm_device *bdev, struct ttm_tt *ttm); @@ -2293,6 +2294,55 @@ static ssize_t amdgpu_iomem_write(struct file *f, const char __user *buf,return result;
}
+voidamdgpu_ttm_clear_dma_mappings(struct amdgpu_device *adev)I strongly think that this function should be part of TTM. Something like
ttm_device_force_unpopulate.Yes, this something I also wanted but see bellow
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +14
-0+{ + struct ttm_device *bdev = &adev->mman.bdev; + struct ttm_resource_manager *man; + struct ttm_buffer_object *bo; + unsigned int i, j; + + spin_lock(&bdev->lru_lock); + for (i = TTM_PL_SYSTEM; i < TTM_NUM_MEM_TYPES; ++i) { + man = ttm_manager_type(bdev, i); + if (!man || !man->use_tt) + continue; + + while (!list_empty(&man->pinned)) { + bo = list_first_entry(&man->pinned, struct
ttm_buffer_object, lru);Quoted 8 lines
Quoted 8 lines
+ /* Take ref against racing releases once
lru_lockis unlocked */
+ttm_bo_get(bo);
+list_del_init(&bo->lru);
+spin_unlock(&bdev->lru_lock);
+
+ if (bo->ttm) {
+amdgpu_ttm_backend_unbind(bo->bdev, bo->ttm);
amdgpu_ttm_backend_unbindis needed to be called separately fromttm_tt_unpopulateto take care of code flows that do dma mapping though the gart bind and not throughttm_tt_populate, Since it's inside amdgpu i had to place the entire function in amdgpu. Any suggestions ?
I think I've fixed exactly that just recently, see the patch here:
commit b7e8b086ffbc03b890ed22ae63ed5e5bd319d184
Author: Christian König <[email protected]> Date: Wed Jul 28 15:05:49 2021 +0200
drm/amdgpu: unbind in amdgpu_ttm_tt_unpopulate
Doing this in amdgpu_ttm_backend_destroy() is to late.
It turned out that this is not a good idea at all because it leaves pointers to freed up system memory pages in the GART tables of the drivers.
But that probably hasn't showed up in amd-staging-drm-next yet.
Christian.
Quoted 53 lines
Quoted 53 lines
Andrey
Quoted 49 lines
Quoted 1 line
+
ttm_tt_destroy_common(bo->bdev, bo->ttm);Then you can also cleanly use
ttm_tt_unpopulatehere, cause this will result in incorrect statistics inside TTM atm.Regards,
Christian.Quoted 41 lines
+ }
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +8
-0+ + ttm_bo_put(bo); + spin_lock(&bdev->lru_lock); + } + + for (j = 0; j < TTM_MAX_BO_PRIORITY; ++j) { + while (!list_empty(&man->lru[j])) { + bo = list_first_entry(&man->lru[j], struct
ttm_buffer_object, lru);
+ttm_bo_get(bo);
+list_del_init(&bo->lru);
+spin_unlock(&bdev->lru_lock);drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +14
-0+ + if (bo->ttm) { + amdgpu_ttm_backend_unbind(bo->bdev, bo->ttm); + ttm_tt_destroy_common(bo->bdev, bo->ttm); + } + ttm_bo_put(bo); + spin_lock(&bdev->lru_lock); + } + } + } + spin_unlock(&bdev->lru_lock); + +} +static const struct
file_operationsamdgpu_ttm_iomem_fops= { .owner =THIS_MODULE,
.read =amdgpu_iomem_read,drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +1
-0@@ -190,6 +190,7 @@ bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm); uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct ttm_resource *mem); uint64_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm, struct ttm_resource *mem); +void amdgpu_ttm_clear_dma_mappings (struct amdgpu_device *adev); void amdgpu_ttm_debugfs_init(struct amdgpu_device *adev);
PATCH 4/4 drm/amdgpu: Add a UAPI flag for hot plug/unplug
In reply to Andrey GrodzovskyTo support libdrm tests.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
@@ -96,9 +96,10 @@* - 3.40.0 - Add AMDGPU_IDS_FLAGS_TMZ * - 3.41.0 - Add video codec query * - 3.42.0 - Add 16bpc fixed point display support +* - 3.43.0 - Add device hot plug/unplug support */ #define KMS_DRIVER_MAJOR 3 -#define KMS_DRIVER_MINOR 42 +#define KMS_DRIVER_MINOR 43#define KMS_DRIVER_PATCHLEVEL 0int amdgpu_vram_limit;
Signature · 1 line
2.25.1