aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu
diff options
context:
space:
mode:
authorHorace Chen <horace.chen@amd.com>2017-11-01 07:32:11 -0400
committerAlex Deucher <alexander.deucher@amd.com>2017-12-04 16:41:42 -0500
commit3c7388936a76affe656d7ba682a33740a99b4a19 (patch)
tree039fa61bf66bdd70288339cf7b4a910d5a96735a /drivers/gpu
parent5ffa61c1bdc35895f60ef7b553b43266d3fda469 (diff)
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. Signed-off-by: Horace Chen <horace.chen@amd.com> Reviewed-by: monk liu <monk.liu@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_device.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 69e724c96442..83dbd02004b0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -680,8 +680,12 @@ void amdgpu_fw_reserve_vram_fini(struct amdgpu_device *adev)
680int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev) 680int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev)
681{ 681{
682 int r = 0; 682 int r = 0;
683 int i;
683 u64 gpu_addr; 684 u64 gpu_addr;
684 u64 vram_size = adev->mc.visible_vram_size; 685 u64 vram_size = adev->mc.visible_vram_size;
686 u64 offset = adev->fw_vram_usage.start_offset;
687 u64 size = adev->fw_vram_usage.size;
688 struct amdgpu_bo *bo;
685 689
686 adev->fw_vram_usage.va = NULL; 690 adev->fw_vram_usage.va = NULL;
687 adev->fw_vram_usage.reserved_bo = NULL; 691 adev->fw_vram_usage.reserved_bo = NULL;
@@ -690,7 +694,7 @@ int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev)
690 adev->fw_vram_usage.size <= vram_size) { 694 adev->fw_vram_usage.size <= vram_size) {
691 695
692 r = amdgpu_bo_create(adev, adev->fw_vram_usage.size, 696 r = amdgpu_bo_create(adev, adev->fw_vram_usage.size,
693 PAGE_SIZE, true, 0, 697 PAGE_SIZE, true, AMDGPU_GEM_DOMAIN_VRAM,
694 AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED | 698 AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
695 AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS, NULL, NULL, 0, 699 AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS, NULL, NULL, 0,
696 &adev->fw_vram_usage.reserved_bo); 700 &adev->fw_vram_usage.reserved_bo);
@@ -700,6 +704,23 @@ int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev)
700 r = amdgpu_bo_reserve(adev->fw_vram_usage.reserved_bo, false); 704 r = amdgpu_bo_reserve(adev->fw_vram_usage.reserved_bo, false);
701 if (r) 705 if (r)
702 goto error_reserve; 706 goto error_reserve;
707
708 /* remove the original mem node and create a new one at the
709 * request position
710 */
711 bo = adev->fw_vram_usage.reserved_bo;
712 offset = ALIGN(offset, PAGE_SIZE);
713 for (i = 0; i < bo->placement.num_placement; ++i) {
714 bo->placements[i].fpfn = offset >> PAGE_SHIFT;
715 bo->placements[i].lpfn = (offset + size) >> PAGE_SHIFT;
716 }
717
718 ttm_bo_mem_put(&bo->tbo, &bo->tbo.mem);
719 r = ttm_bo_mem_space(&bo->tbo, &bo->placement, &bo->tbo.mem,
720 false, false);
721 if (r)
722 goto error_pin;
723
703 r = amdgpu_bo_pin_restricted(adev->fw_vram_usage.reserved_bo, 724 r = amdgpu_bo_pin_restricted(adev->fw_vram_usage.reserved_bo,
704 AMDGPU_GEM_DOMAIN_VRAM, 725 AMDGPU_GEM_DOMAIN_VRAM,
705 adev->fw_vram_usage.start_offset, 726 adev->fw_vram_usage.start_offset,