drm/amdgpu: Add flag to wipe VRAM on release
Subsystems (5)
Kuehling, Felix
maintainerPATCH 1/4 drm/amdgpu: Add flag to wipe VRAM on release
This memory allocation flag will be used to indicate BOs containing sensitive data that should not be leaked to other processes.
--- include/uapi/drm/amdgpu_drm.h | 4 ++++ 1 file changed, 4 insertions(+)
include/uapi/drm/amdgpu_drm.h +4 -0
@@ -131,6 +131,10 @@ extern "C" {* for the second page onward should be set to NC. */ #define AMDGPU_GEM_CREATE_MQD_GFX9 (1 << 8) +/* Flag that BO may contain sensitive data that must be wiped before +* releasing the memory +*/ +#define AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE (1 << 9)struct drm_amdgpu_gem_create_in {/** the requested memory size */
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
A message that is not in the archive (sent off-list or not yet received): 20190719220140.18968-1-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org
PATCH 2/4 drm/amdgpu: Mark KFD VRAM allocations for wipe on release
Memory used by KFD applications can contain sensitive information that should not be leaked to other processes. The current approach to prevent leaks is to clear VRAM at allocation time. This is not effective because memory can be reused in other ways without being cleared. Synchronously clearing memory on the allocation path also carries a significant performance penalty.
Stop clearing memory at allocation time. Instead mark the memory for wipe on release.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -1
@@ -1089,7 +1089,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(*/ if (flags &ALLOC_MEM_FLAGS_VRAM ) { domain = alloc_domain =AMDGPU_GEM_DOMAIN_VRAM ; - alloc_flags =AMDGPU_GEM_CREATE_VRAM_CLEARED ; + alloc_flags =AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE ; alloc_flags |= (flags &ALLOC_MEM_FLAGS_PUBLIC ) ?AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED :AMDGPU_GEM_CREATE_NO_CPU_ACCESS ;
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/4 drm/amdgpu: Implement VRAM wipe on release
In reply to a message not in the archiveWipe VRAM memory containing sensitive data when moving or releasing BOs. Clearing the memory is pipelined to minimize any impact on subsequent memory allocation latency. Use of a poison value should help debug future use-after-free bugs.
When moving BOs, the existing ttm_bo_pipelined_move ensures that the memory won't be reused before being wiped.
When releasing BOs, the BO is fenced with the memory fill operation, which results in queuing the BO for a delayed delete.
v2: Move amdgpu_amdkfd_unreserve_memory_limit into amdgpu_bo_release_notify so that KFD can use memory that's still being cleared in the background
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 39 ++++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 17 ++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 2 ++ 4 files changed, 56 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +36 -3
@@ -80,9 +80,6 @@ static void amdgpu_bo_destroy(struct ttm_buffer_object *tbo)if (bo->pin_count >0 )amdgpu_bo_subtract_pin_size (bo); -if (bo->kfd_bo) -amdgpu_amdkfd_unreserve_memory_limit (bo); -amdgpu_bo_kunmap (bo);if (bo->gem_base.import_attach)
@@ -1211,6 +1208,42 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo,trace_amdgpu_bo_move (abo, new_mem->mem_type, old_mem->mem_type); } +/** +* amdgpu_bo_move_notify - notification about a BO being released +* @bo: pointer to a buffer object +* +* Wipes VRAM buffers whose contents should not be leaked before the +* memory is released. +*/ +void amdgpu_bo_release_notify (struct ttm_buffer_object *bo) +{ +struct dma_fence *fence =NULL ; +struct amdgpu_bo *abo; +int r; + +if (!amdgpu_bo_is_amdgpu_bo (bo)) +return ; + + abo =ttm_to_amdgpu_bo (bo); + +if (abo->kfd_bo) +amdgpu_amdkfd_unreserve_memory_limit (abo); + +if (bo->mem.mem_type !=TTM_PL_VRAM || !bo->mem.mm_node || + !(abo->flags &AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE )) +return ; + +reservation_object_lock (bo->resv,NULL ); + + r =amdgpu_fill_buffer (abo,AMDGPU_POISON , bo->resv, &fence); +if (!WARN_ON (r)) { +amdgpu_bo_fence (abo, fence, false); +dma_fence_put (fence); + } + +reservation_object_unlock (bo->resv); +} +/** * amdgpu_bo_fault_reserve_notify - notification about a memory fault * @bo: pointer to a buffer object
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
@@ -265,6 +265,7 @@ int amdgpu_bo_get_metadata(struct amdgpu_bo *bo, void *buffer,void amdgpu_bo_move_notify (struct ttm_buffer_object *bo,bool evict,struct ttm_mem_reg *new_mem); +void amdgpu_bo_release_notify (struct ttm_buffer_object *bo);int amdgpu_bo_fault_reserve_notify (struct ttm_buffer_object *bo);void amdgpu_bo_fence (struct amdgpu_bo *bo,struct dma_fence *fence,bool shared);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +17 -0
@@ -439,6 +439,22 @@ static int amdgpu_move_blit(struct ttm_buffer_object *bo,if (r) goto error; +/* clear the space being freed */ +if (old_mem->mem_type ==TTM_PL_VRAM && + (ttm_to_amdgpu_bo (bo)->flags & +AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE )) { +struct dma_fence *wipe_fence =NULL ; + + r =amdgpu_fill_buffer (ttm_to_amdgpu_bo (bo),AMDGPU_POISON , +NULL , &wipe_fence); +if (r) { + goto error; + }else if (wipe_fence) { +dma_fence_put (fence); + fence = wipe_fence; + } + } +/* Always block for VM page tables before committing the new location */ if (bo->type == ttm_bo_type_kernel) r =ttm_bo_move_accel_cleanup (bo, fence, true, new_mem);
@@ -1594,6 +1610,7 @@ static struct ttm_bo_driver amdgpu_bo_driver = { .move = &amdgpu_bo_move, .verify_access = &amdgpu_verify_access, .move_notify = &amdgpu_bo_move_notify, + .release_notify = &amdgpu_bo_release_notify, .fault_reserve_notify = &amdgpu_bo_fault_reserve_notify, .io_mem_reserve = &amdgpu_ttm_io_mem_reserve, .io_mem_free = &amdgpu_ttm_io_mem_free,
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +2 -0
@@ -38,6 +38,8 @@#define AMDGPU_GTT_MAX_TRANSFER_SIZE 512#define AMDGPU_GTT_NUM_TRANSFER_WINDOWS 2 +#define AMDGPU_POISON 0xd0bed0be +struct amdgpu_mman {struct ttm_bo_device bdev;bool mem_global_referenced;
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 20.07.19 um 00:02 schrieb Kuehling, Felix:
Quoted 2 lines
This memory allocation flag will be used to indicate BOs containing sensitive data that should not be leaked to other processes.
Just a nit pick, but I would reorder the series and make patch #3 the first and #2 the last one.
Just to have a clean order between adding the callback to the TTM code, implementing the new flag and using it as last step.
Apart from that the series is Reviewed-by: Christian König <[email protected]>.
Regards,
Christian.
Quoted 11 lines
Signed-off-by Felix Kuehling <[email protected]>--- include/uapi/drm/amdgpu_drm.h | 4 ++++ 1 file changed, 4 insertions(+)include/uapi/drm/amdgpu_drm.h +0
-0
include/uapi/drm/amdgpu_drm.h extern "C" { · line 140
Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +4
-0@@ -131,6 +131,10 @@ extern "C" {* for the second page onward should be set to NC. */ #define AMDGPU_GEM_CREATE_MQD_GFX9 (1 << 8) +/* Flag that BO may contain sensitive data that must be wiped before +* releasing the memory +*/ +#define AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE (1 << 9)struct drm_amdgpu_gem_create_in {/** the requested memory size */
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Kuehling, Felix
maintainerPATCH 3/4 drm/ttm: Add release_notify callback to ttm_bo_driver
In reply to Kuehling, FelixThis notifies the driver that a BO is about to be released.
Releasing a BO also invokes the move_notify callback from ttm_bo_cleanup_memtype_use, but that happens too late for anything that would add fences to the BO and require a delayed delete.
--- drivers/gpu/drm/ttm/ttm_bo.c | 3 +++ include/drm/ttm/ttm_bo_driver.h | 10 ++++++++++ 2 files changed, 13 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +3 -0
@@ -671,6 +671,9 @@ static void ttm_bo_release(struct kref *kref)struct ttm_bo_device *bdev = bo->bdev;struct ttm_mem_type_manager *man = &bdev->man[bo->mem.mem_type]; +if (bo->bdev->driver->release_notify) + bo->bdev->driver->release_notify (bo); +drm_vma_offset_remove (&bdev->vma_manager, &bo->vma_node);ttm_mem_io_lock (man, false);ttm_mem_io_free_vm (bo);
include/drm/ttm/ttm_bo_driver.h +10 -0
@@ -390,6 +390,16 @@ struct ttm_bo_driver {* notify driver that a BO was deleted from LRU. */ void (*del_from_lru_notify)(struct ttm_buffer_object *bo); + +/** +* Notify the driver that we're about to release a BO +* +* @bo: BO that is about to be released +* +* Gives the driver a chance to do any cleanup, including +* adding fences that may force a delayed delete +*/ +void (*release_notify)(struct ttm_buffer_object *bo); };/**
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel