Skip to contentSkip to conversation

drm/amdgpu: validate shadow before restoring from it

PATCH In review Roger.He 3 participants 4 messages Apr 25, 2017 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Roger.He

author
#0 lore raw

PATCH 1/1 drm/amdgpu: validate shadow before restoring from it

Change-Id Id925f4e241c4192127880d2017fbf2979aa09fc7
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 33 ++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +33 -0
index f74149c..cebd546 100644
@@ -2468,6 +2468,27 @@ bool amdgpu_need_backup(struct amdgpu_device *adev)
 	return amdgpu_lockup_timeout > 0 ? true : false;
 }
 
+static int amdgpu_bo_validate(struct amdgpu_bo *bo)
+{
+	uint32_t domain;
+	int r;
+
+	if (bo->pin_count)
+		return 0;
+
+	domain = bo->prefered_domains;
+
+retry:
+	amdgpu_ttm_placement_from_domain(bo, domain);
+	r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
+	if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) {
+		domain = bo->allowed_domains;
+		goto retry;
+	}
+
+	return r;
+}
+
 static int amdgpu_recover_vram_from_shadow(struct amdgpu_device *adev,
 					   struct amdgpu_ring *ring,
 					   struct amdgpu_bo *bo,
@@ -2485,6 +2506,18 @@ static int amdgpu_recover_vram_from_shadow(struct amdgpu_device *adev,
 	domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
 	/* if bo has been evicted, then no need to recover */
 	if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
+		r = amdgpu_bo_validate(bo->shadow);
+		if (r) {
+			DRM_ERROR("bo validate failed!\n");
+			goto err;
+		}
+
+		r = amdgpu_ttm_bind(&bo->shadow->tbo, &bo->shadow->tbo.mem);
+		if (r) {
+			DRM_ERROR("%p bind failed\n", bo->shadow);
+			goto err;
+		}
+
 		r = amdgpu_bo_restore_from_shadow(adev, ring, bo,
 						 NULL, fence, true);
 		if (r) {
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): 1493090078-29023-1-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org

#2 lore raw
Quoted 24 lines · Roger.He
Change-Id Id925f4e241c4192127880d2017fbf2979aa09fc7
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 33 ++++++++++++++++++++++++++++++
  1 file changed, 33 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
index f74149c..cebd546 100644
@@ -2468,6 +2468,27 @@ bool amdgpu_need_backup(struct amdgpu_device *adev)
  	return amdgpu_lockup_timeout > 0 ? true : false;
  }
 
+static int amdgpu_bo_validate(struct amdgpu_bo *bo)
+{
+	uint32_t domain;
+	int r;
+
+	if (bo->pin_count)
+		return 0;
+
+	domain = bo->prefered_domains;
+

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c bool amdgpu_need_backup(struct amdgpu_device *adev) · line 2490

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
+retry:
+	amdgpu_ttm_placement_from_domain(bo, domain);
+	r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
+	if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) {
+		domain = bo->allowed_domains;
+		goto retry;
+	}
+
+	return r;
+}

you can move this function to amdgpu_object.c, with that fix, it looks ok to me, Reviewed-by: Chunming Zhou <[email protected]>

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6 -0
+
  static int amdgpu_recover_vram_from_shadow(struct amdgpu_device *adev,
  					   struct amdgpu_ring *ring,
  					   struct amdgpu_bo *bo,
@@ -2485,6 +2506,18 @@ static int amdgpu_recover_vram_from_shadow(struct amdgpu_device *adev,
  	domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
  	/* if bo has been evicted, then no need to recover */
  	if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
+		r = amdgpu_bo_validate(bo->shadow);
+		if (r) {
+			DRM_ERROR("bo validate failed!\n");
+			goto err;
+		}

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_recover_vram_from_shadow(struct amdgpu_device *adev, · line 2523

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7 -0
+
+		r = amdgpu_ttm_bind(&bo->shadow->tbo, &bo->shadow->tbo.mem);
+		if (r) {
+			DRM_ERROR("%p bind failed\n", bo->shadow);
+			goto err;
+		}
+
  		r = amdgpu_bo_restore_from_shadow(adev, ring, bo,
  						 NULL, fence, true);
  		if (r) {

_______________________________________________
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): [email protected]

#4 lore raw

Am 25.04.2017 um 05:16 schrieb zhoucm1:

Quoted 31 lines · Roger.He
Quoted 28 lines
Change-Id Id925f4e241c4192127880d2017fbf2979aa09fc7
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 33 
++++++++++++++++++++++++++++++
  1 file changed, 33 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +12 -0
index f74149c..cebd546 100644
@@ -2468,6 +2468,27 @@ bool amdgpu_need_backup(struct amdgpu_device 
 *adev)
      return amdgpu_lockup_timeout > 0 ? true : false;
  }
  +static int amdgpu_bo_validate(struct amdgpu_bo *bo)
+{
+    uint32_t domain;
+    int r;
+
+    if (bo->pin_count)
+        return 0;
+
+    domain = bo->prefered_domains;
+
+retry:
+    amdgpu_ttm_placement_from_domain(bo, domain);
+    r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c bool amdgpu_need_backup(struct amdgpu_device *adev) · line 2490

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7 -0
+    if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) {
+        domain = bo->allowed_domains;
+        goto retry;
+    }
+
+    return r;
+}

you can move this function to amdgpu_object.c, with that fix, it looks ok to me, Reviewed-by: Chunming Zhou <[email protected]>

Yeah, agree. Might even be a good idea to use this helper in amdgpu_cs.c as well. IIRC we had something very similar in there as well.

But that should be a separate patch, with the function moved to amdgpu_object.c this patch is Reviewed-by: Christian König <[email protected]> as well.

Regards,
Christian.

Quoted 22 lines
Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +13 -0
+
  static int amdgpu_recover_vram_from_shadow(struct amdgpu_device *adev,
                         struct amdgpu_ring *ring,
                         struct amdgpu_bo *bo,
@@ -2485,6 +2506,18 @@ static int 
 amdgpu_recover_vram_from_shadow(struct amdgpu_device *adev,
      domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
      /* if bo has been evicted, then no need to recover */
      if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
+        r = amdgpu_bo_validate(bo->shadow);
+        if (r) {
+            DRM_ERROR("bo validate failed!\n");
+            goto err;
+        }
+
+        r = amdgpu_ttm_bind(&bo->shadow->tbo, &bo->shadow->tbo.mem);
+        if (r) {
+            DRM_ERROR("%p bind failed\n", bo->shadow);
+            goto err;
+        }
+
Quoted 8 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
          r = amdgpu_bo_restore_from_shadow(adev, ring, bo,
                           NULL, fence, true);
          if (r) {

_______________________________________________
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

A message that is not in the archive (sent off-list or not yet received): 21598379-3859-bf61-50b9-467cbd40ab74-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

author
#6 lore raw

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Tuesday, April 25, 2017 4:10 PM
To: Zhou, David(ChunMing); He, Hongbo; [email protected]
Subject: Re: [PATCH] drm/amdgpu: validate shadow before restoring from it

Am 25.04.2017 um 05:16 schrieb zhoucm1:

Quoted 33 lines · Roger.He
Quoted 30 lines
Change-Id Id925f4e241c4192127880d2017fbf2979aa09fc7
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 33
++++++++++++++++++++++++++++++
  1 file changed, 33 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +13 -0
index f74149c..cebd546 100644
@@ -2468,6 +2468,27 @@ bool amdgpu_need_backup(struct amdgpu_device
 *adev)
      return amdgpu_lockup_timeout > 0 ? true : false;
  }
  +static int amdgpu_bo_validate(struct amdgpu_bo *bo)
+{
+    uint32_t domain;
+    int r;
+
+    if (bo->pin_count)
+        return 0;
+
+    domain = bo->prefered_domains;
+
+retry:
+    amdgpu_ttm_placement_from_domain(bo, domain);
+    r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
+    if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) {
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c bool amdgpu_need_backup(struct amdgpu_device *adev) · line 2490

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6 -0
+        domain = bo->allowed_domains;
+        goto retry;
+    }
+
+    return r;
+}

you can move this function to amdgpu_object.c, with that fix, it looks ok to me, Reviewed-by: Chunming Zhou <[email protected]>

Yeah, agree. Might even be a good idea to use this helper in amdgpu_cs.c as well. IIRC we had something very similar in there as well.

Yes, I have noticed they have some similar logic code. Later if have time, I will try to do that. Thanks for your suggestion!

Thanks
Roger(Hongbo.He)

But that should be a separate patch, with the function moved to amdgpu_object.c this patch is Reviewed-by: Christian König <[email protected]> as well.

Regards,
Christian.

Quoted 22 lines
Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
+
  static int amdgpu_recover_vram_from_shadow(struct amdgpu_device *adev,
                         struct amdgpu_ring *ring,
                         struct amdgpu_bo *bo, @@ -2485,6 +2506,18 @@ 

static int amdgpu_recover_vram_from_shadow(struct amdgpu_device *adev,

      domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
      /* if bo has been evicted, then no need to recover */
      if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +12 -0
+        r = amdgpu_bo_validate(bo->shadow);
+        if (r) {
+            DRM_ERROR("bo validate failed!\n");
+            goto err;
+        }
+
+        r = amdgpu_ttm_bind(&bo->shadow->tbo, &bo->shadow->tbo.mem);
+        if (r) {
+            DRM_ERROR("%p bind failed\n", bo->shadow);
+            goto err;
+        }
+
Quoted 8 lines
Quoted 3 lines
          r = amdgpu_bo_restore_from_shadow(adev, ring, bo,
                           NULL, fence, true);
          if (r) {

_______________________________________________
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