drm/amdgpu: refine SR-IOV firmware VRAM reservation to protect data
Subsystems (2)
PATCH 1/1 drm/amdgpu: refine SR-IOV firmware VRAM reservation to protect data
The previous solution will create a zero buffer on the system domain and then move the zeroes to the VRAM. This will break the original data on the VRAM.
Refine the code to create bo on VRAM domain directly and then remove and re-create mem node to the exact position before bo_pin. This can avoid breaking the data and will not cause eviction.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +22 -1
@@ -680,8 +680,12 @@ void amdgpu_fw_reserve_vram_fini(struct amdgpu_device *adev)int amdgpu_fw_reserve_vram_init (struct amdgpu_device *adev) {int r =0 ; +int i;u64 gpu_addr;u64 vram_size = adev->mc.visible_vram_size; +u64 offset = adev->fw_vram_usage.start_offset; +u64 size = adev->fw_vram_usage.size; +struct amdgpu_bo *bo; adev->fw_vram_usage.va =NULL ; adev->fw_vram_usage.reserved_bo =NULL ;
@@ -690,7 +694,7 @@ int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev) adev->fw_vram_usage.size <= vram_size) { r =amdgpu_bo_create (adev, adev->fw_vram_usage.size, -PAGE_SIZE , true,0 , +PAGE_SIZE , true,AMDGPU_GEM_DOMAIN_VRAM ,AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS ,NULL ,NULL ,0 , &adev->fw_vram_usage.reserved_bo);
@@ -700,6 +704,23 @@ int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev) r =amdgpu_bo_reserve (adev->fw_vram_usage.reserved_bo, false);if (r) goto error_reserve; + +/* remove the original mem node and create a new one at the +* request position +*/ + bo = adev->fw_vram_usage.reserved_bo; + offset =ALIGN (offset,PAGE_SIZE ); +for (i =0 ; i < bo->placement.num_placement; ++i) { + bo->placements[i].fpfn = offset >>PAGE_SHIFT ; + bo->placements[i].lpfn = (offset + size) >>PAGE_SHIFT ; + } + +ttm_bo_mem_put (&bo->tbo, &bo->tbo.mem); + r =ttm_bo_mem_space (&bo->tbo, &bo->placement, &bo->tbo.mem, + false, false); +if (r) + goto error_pin; + r = amdgpu_bo_pin_restricted(adev->fw_vram_usage.reserved_bo, AMDGPU_GEM_DOMAIN_VRAM, adev->fw_vram_usage.start_offset,
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1509537715-27266-1-git-send-email-horace.chen-5C7GfCeVMHo@public.gmane.org
-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Horace Chen
Sent: 2017年11月1日 20:02
To: [email protected]
Cc: Chen, Horace <[email protected]>
Subject: [PATCH] drm/amdgpu: refine SR-IOV firmware VRAM reservation to protect data
The previous solution will create a zero buffer on the system domain and then move the zeroes to the VRAM. This will break the original data on the VRAM.
Refine the code to create bo on VRAM domain directly and then remove and re-create mem node to the exact position before bo_pin. This can avoid breaking the data and will not cause eviction.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
@@ -680,8 +680,12 @@ void amdgpu_fw_reserve_vram_fini(struct amdgpu_device *adev) int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev) {int r =0 ; +int i;u64 gpu_addr;u64 vram_size = adev->mc.visible_vram_size; +u64 offset = adev->fw_vram_usage.start_offset; +u64 size = adev->fw_vram_usage.size; +struct amdgpu_bo *bo; adev->fw_vram_usage.va =NULL ; adev->fw_vram_usage.reserved_bo = NULL; @@ -690,7 +694,7 @@ int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev) adev->fw_vram_usage.size <= vram_size) {
r = amdgpu_bo_create(adev, adev->fw_vram_usage.size,
- PAGE_SIZE, true, 0,
+ PAGE_SIZE, true, AMDGPU_GEM_DOMAIN_VRAM,
AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED | AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS, NULL, NULL, 0, &adev->fw_vram_usage.reserved_bo);
@@ -700,6 +704,23 @@ int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev)
r = amdgpu_bo_reserve(adev->fw_vram_usage.reserved_bo, false); if (r)
goto error_reserve;
+
+ /* remove the original mem node and create a new one at the
+ * request position
+ */
+ bo = adev->fw_vram_usage.reserved_bo;
+ offset = ALIGN(offset, PAGE_SIZE);
+ for (i = 0; i < bo->placement.num_placement; ++i) {
+ bo->placements[i].fpfn = offset >> PAGE_SHIFT;
+ bo->placements[i].lpfn = (offset + size) >> PAGE_SHIFT;
+ }
+
+ ttm_bo_mem_put(&bo->tbo, &bo->tbo.mem);
+ r = ttm_bo_mem_space(&bo->tbo, &bo->placement, &bo->tbo.mem,
+ false, false);
+ if (r)
+ goto error_pin;
+
r = amdgpu_bo_pin_restricted(adev->fw_vram_usage.reserved_bo,
AMDGPU_GEM_DOMAIN_VRAM, adev->fw_vram_usage.start_offset,
--
2.7.4
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx