Skip to contentSkip to conversation

Fixes for interaction of imported dma-bufs and scanout

PATCH New [email protected] 10 participants 29 messages Mar 29, 2017 – Apr 4, 2017 13 messages not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fixes for interaction of imported dma-bufs and scanout

For nouveau, radeon, and amdgpu attempting to scanout of a bo will cause the driver to migrate it to VRAM.

When the bo in question is an imported dma-buf, this results in a buffer that appears to be shared but is actually device-private.

Consensus on #dri-devel seemed to be that it would be appropriate for addfb to fail when attempted on an imported dma-buf.

It *might* also be appropriate to fail addfb on an exported dma-buf (as that is likewise pinned to GTT), but #dri-devel thought it possible the buffer could be unshared between addfb and actually trying to scanout. An imported dma-buf doesn't have the same problem.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#1 lore raw

PATCH 1/6 drm/nouveau: Fail fb creation from imported dma-bufs.

From: Christopher James Halse Rogers <[email protected]>

Any use of the framebuffer will migrate it to VRAM, which is not sensible for an imported dma-buf.

---
 drivers/gpu/drm/nouveau/nouveau_display.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/nouveau/nouveau_display.c +4 -0
index 72fdba1a1c5d..e8e6bc7b6d51 100644
@@ -286,6 +286,10 @@ nouveau_user_framebuffer_create(struct drm_device *dev,
 		return ERR_PTR(-ENOENT);
 	nvbo = nouveau_gem_object(gem);
 
+	/* Handle is an imported dma-buf, so cannot be migrated to VRAM */
+	if (gem->import_attach)
+		return ERR_PTR(-EINVAL);
+
 	ret = nouveau_framebuffer_new(dev, mode_cmd, nvbo, &fb);
 	if (ret == 0)
 		return &fb->base;
Signature · 6 lines
2.11.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer Acked-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] drm/nouveau: Fail fb creation from imported dma-bufs.

Op 29-03-17 om 02:27 schreef [email protected]:

Quoted 16 lines

From: Christopher James Halse Rogers <[email protected]>

Any use of the framebuffer will migrate it to VRAM, which is not sensible for an imported dma-buf.

---
 drivers/gpu/drm/nouveau/nouveau_display.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/nouveau/nouveau_display.c +0 -0
index 72fdba1a1c5d..e8e6bc7b6d51 100644

drivers/gpu/drm/nouveau/nouveau_display.c nouveau_user_framebuffer_create(struct drm_device *dev, · line 295

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_display.c +4 -0
@@ -286,6 +286,10 @@ nouveau_user_framebuffer_create(struct drm_device *dev,
 		return ERR_PTR(-ENOENT);
 	nvbo = nouveau_gem_object(gem);
 
+	/* Handle is an imported dma-buf, so cannot be migrated to VRAM */
+	if (gem->import_attach)
+		return ERR_PTR(-EINVAL);
+
 	ret = nouveau_framebuffer_new(dev, mode_cmd, nvbo, &fb);
 	if (ret == 0)
 		return &fb->base;

I don't know if there's really a hard requirement for nouveau to scan out from GART on nv50+, but it might be a bigger problem on earlier platforms.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

PATCH 2/6 drm/nouveau: Pin bos from imported dma-bufs to GTT.

In reply to [email protected]

From: Christopher James Halse Rogers <[email protected]>

Attempting to migrate the bo will break the sharing of the buffer.

---
 drivers/gpu/drm/nouveau/nouveau_prime.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/nouveau/nouveau_prime.c +2 -0
index 1fefc93af1d7..5f474ebb4d6d 100644
@@ -76,6 +76,8 @@ struct drm_gem_object *nouveau_gem_prime_import_sg_table(struct drm_device *dev,
 		return ERR_PTR(ret);
 
 	nvbo->valid_domains = NOUVEAU_GEM_DOMAIN_GART;
+	/* pin imported buffer to GTT */
+	nouveau_bo_pin(nvbo, TTM_PL_FLAG_TT, false);
 
 	/* Initialize the embedded gem-object. We return a single gem-reference
 	 * to the caller, instead of a normal nouveau_bo ttm reference. */
Signature · 6 lines
2.11.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

Re: [PATCH 2/6] drm/nouveau: Pin bos from imported dma-bufs to GTT.

Op 29-03-17 om 02:27 schreef [email protected]:

Quoted 15 lines

From: Christopher James Halse Rogers <[email protected]>

Attempting to migrate the bo will break the sharing of the buffer.

---
 drivers/gpu/drm/nouveau/nouveau_prime.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/nouveau/nouveau_prime.c +0 -0
index 1fefc93af1d7..5f474ebb4d6d 100644

drivers/gpu/drm/nouveau/nouveau_prime.c struct drm_gem_object *nouveau_gem_prime_import_sg_table(struct drm_device *dev, · line 83

Quoted 8 lines
drivers/gpu/drm/nouveau/nouveau_prime.c +2 -0
@@ -76,6 +76,8 @@ struct drm_gem_object *nouveau_gem_prime_import_sg_table(struct drm_device *dev,
 		return ERR_PTR(ret);
 
 	nvbo->valid_domains = NOUVEAU_GEM_DOMAIN_GART;
+	/* pin imported buffer to GTT */
+	nouveau_bo_pin(nvbo, TTM_PL_FLAG_TT, false);
 
 	/* Initialize the embedded gem-object. We return a single gem-reference
 	 * to the caller, instead of a normal nouveau_bo ttm reference. */

Missing error handling here?

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw

PATCH v2 2/6 drm/nouveau: Pin bos from imported dma-bufs to GTT. (v2)

In reply to [email protected]

From: Christopher James Halse Rogers <[email protected]>

Attempting to migrate the bo will break the sharing of the buffer.

v2: Error-check the nouveau_bo_pin call; it can fail.

---
 drivers/gpu/drm/nouveau/nouveau_prime.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/nouveau/nouveau_prime.c +6 -0
index 1fefc93af1d7..ad5eaf70c8e2 100644
@@ -76,6 +76,12 @@ struct drm_gem_object *nouveau_gem_prime_import_sg_table(struct drm_device *dev,
 		return ERR_PTR(ret);
 
 	nvbo->valid_domains = NOUVEAU_GEM_DOMAIN_GART;
+	/* pin imported buffer to GTT */
+	ret = nouveau_bo_pin(nvbo, TTM_PL_FLAG_TT, false);
+	if (ret) {
+		nouveau_bo_ref(NULL, &nvbo);
+		return ERR_PTR(ret);
+	}
 
 	/* Initialize the embedded gem-object. We return a single gem-reference
 	 * to the caller, instead of a normal nouveau_bo ttm reference. */
Signature · 6 lines
2.11.0

_______________________________________________
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): 20170329002720.11445-1-raof-GeWIH/[email protected]

#7 lore raw

PATCH 3/6 drm/amdgpu: Fail fb creation from imported dma-bufs.

From: Christopher James Halse Rogers <[email protected]>

Any use of the framebuffer will migrate it to VRAM, which is not sensible for an imported dma-buf.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +6 -0
index 39fc388f222a..e7c3cc5b7d62 100644
@@ -612,6 +612,12 @@ amdgpu_user_framebuffer_create(struct drm_device *dev,
 		return ERR_PTR(-ENOENT);
 	}
 
+	/* Handle is imported dma-buf, so cannot be migrated to VRAM for scanout */
+	if (obj->import_attach) {
+		dev_err(&dev->pdev->dev, "Cannot create framebuffer from imported dma_buf\n");
+		return ERR_PTR(-EINVAL);
+	}
+
 	amdgpu_fb = kzalloc(sizeof(*amdgpu_fb), GFP_KERNEL);
 	if (amdgpu_fb == NULL) {
 		drm_gem_object_unreference_unlocked(obj);
Signature · 6 lines
2.11.0

_______________________________________________
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): 20170329002720.11445-4-raof-GeWIH/[email protected]

#9 lore raw

Re: [PATCH 3/6] drm/amdgpu: Fail fb creation from imported dma-bufs.

Quoted 16 lines · On 29/03/17 09:27 AM, [email protected] wrote:

From: Christopher James Halse Rogers <[email protected]>

Any use of the framebuffer will migrate it to VRAM, which is not sensible for an imported dma-buf.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
index 39fc388f222a..e7c3cc5b7d62 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c amdgpu_user_framebuffer_create(struct drm_device *dev, · line 615

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +1 -0
@@ -612,6 +612,12 @@ amdgpu_user_framebuffer_create(struct drm_device *dev,
 		return ERR_PTR(-ENOENT);
 	}
 
+	/* Handle is imported dma-buf, so cannot be migrated to VRAM for scanout */

Newer APUs support scanout from GTT, though they still impose some restrictions which will probably not be satisfied in general by BOs imported from other drivers. So this is probably okay for now.

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c amdgpu_user_framebuffer_create(struct drm_device *dev, · line 617

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -0
+	if (obj->import_attach) {
+		dev_err(&dev->pdev->dev, "Cannot create framebuffer from imported dma_buf\n");

This should probably be something like DRM_DEBUG, so userspace can't spam dmesg by default. Same for patch 5.

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +3 -0
+		return ERR_PTR(-EINVAL);
+	}
+
 	amdgpu_fb = kzalloc(sizeof(*amdgpu_fb), GFP_KERNEL);
 	if (amdgpu_fb == NULL) {
 		drm_gem_object_unreference_unlocked(obj);
Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
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): 4a950f45-3ad5-2d63-c434-0474e8cfda37-otUistvHUpPR7s880joybQ@public.gmane.org

#11 lore raw

Re: [PATCH 3/6] drm/amdgpu: Fail fb creation from imported dma-bufs.

Quoted 25 lines · On Wed, 29 Mar 2017 at 13:04 Michel Dänzer…
Quoted 1 line · On 29/03/17 09:27 AM, raof-GeWIH/[email protected] wrote:

From: Christopher James Halse Rogers <

[email protected]>

Quoted 2 lines

Any use of the framebuffer will migrate it to VRAM, which is not

sensible for

Quoted 3 lines

an imported dma-buf.

Signed-off-by Christopher James Halse Rogers <

[email protected]>

Review

Quoted 6 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 6 ++++++
 1 file changed, 6 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c amdgpu_user_framebuffer_create(struct drm_device

Quoted 4 lines

index 39fc388f222a..e7c3cc5b7d62 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
@@ -612,6 +612,12 @@ amdgpu_user_framebuffer_create(struct drm_device

*dev,

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
              return ERR_PTR(-ENOENT);
      }
 
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c amdgpu_user_framebuffer_create(struct drm_device · line 615

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +1 -0
+     /* Handle is imported dma-buf, so cannot be migrated to VRAM for

scanout */

Newer APUs support scanout from GTT, though they still impose some restrictions which will probably not be satisfied in general by BOs imported from other drivers. So this is probably okay for now.

As far as I can tell amdgpu unconditionally migrates to VRAM when trying to scanout at the moment. When that changes, so can this check :).

Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c amdgpu_user_framebuffer_create(struct drm_device · line 617

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -0
+     if (obj->import_attach) {
+             dev_err(&dev->pdev->dev, "Cannot create framebuffer from

imported dma_buf\n");

This should probably be something like DRM_DEBUG, so userspace can't spam dmesg by default. Same for patch 5.

Ta. v2 incoming.

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#12 lore raw

PATCH v2 1/1 drm/amdgpu: Fail fb creation from imported dma-bufs. (v2)

In reply to a message not in the archive

From: Christopher James Halse Rogers <[email protected]>

Any use of the framebuffer will migrate it to VRAM, which is not sensible for an imported dma-buf.

v2: Use DRM_DEBUG_KMS to prevent userspace accidentally spamming dmesg.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +6 -0
index 39fc388f222a..2f2e9b5c8a6a 100644
@@ -612,6 +612,12 @@ amdgpu_user_framebuffer_create(struct drm_device *dev,
 		return ERR_PTR(-ENOENT);
 	}
 
+	/* Handle is imported dma-buf, so cannot be migrated to VRAM for scanout */
+	if (obj->import_attach) {
+		DRM_DEBUG_KMS("Cannot create framebuffer from imported dma_buf\n");
+		return ERR_PTR(-EINVAL);
+	}
+
 	amdgpu_fb = kzalloc(sizeof(*amdgpu_fb), GFP_KERNEL);
 	if (amdgpu_fb == NULL) {
 		drm_gem_object_unreference_unlocked(obj);
Signature · 6 lines
2.11.0

_______________________________________________
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): 20170329040211.18844-1-raof-GeWIH/[email protected]

Reviewed-by
#14 lore raw

Re: [PATCH v2] drm/amdgpu: Fail fb creation from imported dma-bufs. (v2)

Quoted 21 lines · On 29/03/17 01:02 PM, [email protected] wrote:

From: Christopher James Halse Rogers <[email protected]>

Any use of the framebuffer will migrate it to VRAM, which is not sensible for an imported dma-buf.

v2: Use DRM_DEBUG_KMS to prevent userspace accidentally spamming dmesg.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
index 39fc388f222a..2f2e9b5c8a6a 100644
@@ -612,6 +612,12 @@ amdgpu_user_framebuffer_create(struct drm_device *dev,
 		return ERR_PTR(-ENOENT);
 	}

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c amdgpu_user_framebuffer_create(struct drm_device *dev, · line 623

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +6 -0
 
+	/* Handle is imported dma-buf, so cannot be migrated to VRAM for scanout */
+	if (obj->import_attach) {
+		DRM_DEBUG_KMS("Cannot create framebuffer from imported dma_buf\n");
+		return ERR_PTR(-EINVAL);
+	}
+
 	amdgpu_fb = kzalloc(sizeof(*amdgpu_fb), GFP_KERNEL);
 	if (amdgpu_fb == NULL) {
 		drm_gem_object_unreference_unlocked(obj);

This patch and v2 of patch 5 are

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
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): 2b175dd8-abeb-b3e7-d783-355607a48fda-otUistvHUpPR7s880joybQ@public.gmane.org

Applied
#16 lore raw

Re: [PATCH v2] drm/amdgpu: Fail fb creation from imported dma-bufs. (v2)

Quoted 35 lines · Michel Dänzer
Quoted 21 lines · On 29/03/17 01:02 PM, [email protected] wrote:

From: Christopher James Halse Rogers <[email protected]>

Any use of the framebuffer will migrate it to VRAM, which is not sensible for an imported dma-buf.

v2: Use DRM_DEBUG_KMS to prevent userspace accidentally spamming dmesg.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
index 39fc388f222a..2f2e9b5c8a6a 100644
@@ -612,6 +612,12 @@ amdgpu_user_framebuffer_create(struct drm_device *dev,
              return ERR_PTR(-ENOENT);
      }

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c amdgpu_user_framebuffer_create(struct drm_device *dev, · line 623

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +6 -0
 
+     /* Handle is imported dma-buf, so cannot be migrated to VRAM for scanout */
+     if (obj->import_attach) {
+             DRM_DEBUG_KMS("Cannot create framebuffer from imported dma_buf\n");
+             return ERR_PTR(-EINVAL);
+     }
+
      amdgpu_fb = kzalloc(sizeof(*amdgpu_fb), GFP_KERNEL);
      if (amdgpu_fb == NULL) {
              drm_gem_object_unreference_unlocked(obj);

This patch and v2 of patch 5 are

Quoted 1 line

Applied these two. Thanks!

Alex

Quoted 9 lines

--
Earthling Michel Dänzer | http://www.amd.com
Libre software enthusiast | Mesa and X developer
_______________________________________________
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

#17 lore raw

PATCH 4/6 drm/amd/amdgpu: Pin bos from imported dma-bufs to GTT.

In reply to a message not in the archive

From: Christopher James Halse Rogers <[email protected]>

Attempting to migrate the bo will break the sharing of the buffer.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +11 -0
index 3826d5aea0a6..3c84ec5c6ac8 100644
@@ -74,6 +74,17 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
 	if (ret)
 		return ERR_PTR(ret);
 
+	/* Imported bo must be pinned to GTT, as moving it breaks sharing */
+	ret = amdgpu_bo_reserve(bo, false);
+	if (ret)
+		return ERR_PTR(ret);
+
+	ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT, NULL);
+	if (ret)
+		return ERR_PTR(ret);
+
+	amdgpu_bo_unreserve(bo);
+
 	bo->prime_shared_count = 1;
 	return &bo->gem_base;
 }
Signature · 6 lines
2.11.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by on v1 4/6
#18 lore raw

Re: [PATCH 4/6] drm/amd/amdgpu: Pin bos from imported dma-bufs to GTT.

Quoted 23 lines · On 29/03/17 09:27 AM, [email protected] wrote:

From: Christopher James Halse Rogers <[email protected]>

Attempting to migrate the bo will break the sharing of the buffer.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4 -0
index 3826d5aea0a6..3c84ec5c6ac8 100644
@@ -74,6 +74,17 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
 	if (ret)
 		return ERR_PTR(ret);
 
+	/* Imported bo must be pinned to GTT, as moving it breaks sharing */
+	ret = amdgpu_bo_reserve(bo, false);
+	if (ret)
+		return ERR_PTR(ret);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c amdgpu_gem_prime_import_sg_table(struct drm_device *dev, · line 90

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7 -0
+
+	ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT, NULL);
+	if (ret)
+		return ERR_PTR(ret);
+
+	amdgpu_bo_unreserve(bo);
+
 	bo->prime_shared_count = 1;
 	return &bo->gem_base;
 }

Thanks for beating me to this! :) This patch and patch 6 are

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#19 lore raw

Re: [PATCH 4/6] drm/amd/amdgpu: Pin bos from imported dma-bufs to GTT.

In reply to raof-GeWIH/[email protected]

Am 29.03.2017 um 02:27 schrieb [email protected]:

Quoted 6 lines

From: Christopher James Halse Rogers <[email protected]>

Attempting to migrate the bo will break the sharing of the buffer.

NAK on this one and the radeon version.

We can't migrate the buffers to VRAM, but we shouldn't pin it either cause that will lock down the GTT space used for it.

Instead you should modify amdgpu_bo_pin() and fail if anybody tries to migrate a BO which has prime_shared_count != 0 to VRAM (you migth need to add this for radeon).

Regards,
Christian.

Quoted 16 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4 -0
index 3826d5aea0a6..3c84ec5c6ac8 100644
@@ -74,6 +74,17 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
  	if (ret)
  		return ERR_PTR(ret);
 
+	/* Imported bo must be pinned to GTT, as moving it breaks sharing */
+	ret = amdgpu_bo_reserve(bo, false);
+	if (ret)
+		return ERR_PTR(ret);

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c amdgpu_gem_prime_import_sg_table(struct drm_device *dev, · line 90

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7 -0
+
+	ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT, NULL);
+	if (ret)
+		return ERR_PTR(ret);
+
+	amdgpu_bo_unreserve(bo);
+
  	bo->prime_shared_count = 1;
  	return &bo->gem_base;
  }

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#20 lore raw

Re: [PATCH 4/6] drm/amd/amdgpu: Pin bos from imported dma-bufs to GTT.

Quoted 6 lines · Christian König

Am 29.03.2017 um 02:27 schrieb [email protected]:

Quoted 5 lines

From: Christopher James Halse Rogers
<[email protected]>

Attempting to migrate the bo will break the sharing of the buffer.

Quoted 8 lines
Quoted 3 lines

Signed-off-by: Christopher James Halse Rogers
<[email protected]>
CC: [email protected]

NAK on this one and the radeon version.

We can't migrate the buffers to VRAM, but we shouldn't pin it either cause that will lock down the GTT space used for it.

Ah, good point, didn't think of that.

Quoted 3 lines

Instead you should modify amdgpu_bo_pin() and fail if anybody tries to migrate a BO which has prime_shared_count != 0 to VRAM (you migth need to add this for radeon).

This would also need to be checked in the AMDGPU_GEM_OP_SET_PLACEMENT case of amdgpu_gem_op_ioctl, otherwise userspace can change prefered_domains to AMDGPU_GEM_DOMAIN_VRAM, and using the BO for GPU operations may move it to VRAM.

Or maybe there's a central place which can catch both of these cases (and any others).

Signature · 7 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#21 lore raw

Re: [PATCH 4/6] drm/amd/amdgpu: Pin bos from imported dma-bufs to GTT.

Am 29.03.2017 um 11:07 schrieb Michel Dänzer:

Quoted 17 lines · Christian König
Quoted 6 lines

Am 29.03.2017 um 02:27 schrieb [email protected]:

Quoted 5 lines

From: Christopher James Halse Rogers
<[email protected]>

Attempting to migrate the bo will break the sharing of the buffer.

Quoted 7 lines
Quoted 3 lines

Signed-off-by: Christopher James Halse Rogers
<[email protected]>
CC: [email protected]

NAK on this one and the radeon version.

We can't migrate the buffers to VRAM, but we shouldn't pin it either cause that will lock down the GTT space used for it.

Ah, good point, didn't think of that.

Quoted 7 lines
Quoted 3 lines

Instead you should modify amdgpu_bo_pin() and fail if anybody tries to migrate a BO which has prime_shared_count != 0 to VRAM (you migth need to add this for radeon).

This would also need to be checked in the AMDGPU_GEM_OP_SET_PLACEMENT case of amdgpu_gem_op_ioctl, otherwise userspace can change prefered_domains to AMDGPU_GEM_DOMAIN_VRAM, and using the BO for GPU operations may move it to VRAM.

Good point as well, that indeed also needs to be forbidden.

Quoted 2 lines

Or maybe there's a central place which can catch both of these cases (and any others).

At least of hand I can't think of any. But catching those two cases should be sufficient as far as I can see.

Christian.

_______________________________________________
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): 20170329002720.11445-5-raof-GeWIH/[email protected]

#23 lore raw

PATCH 4/6 drm/amdgpu: Refuse to pin or change acceptable domains of prime BOs to VRAM. (v2)

From: Christopher James Halse Rogers <[email protected]>

Migration to VRAM will break the sharing, resulting in rendering on the exporting GPU never becoming visible on the importing GPU.

v2: Don't pin BOs to GTT. Instead, refuse to migrate them out of GTT.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c    | 5 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 ++++
 2 files changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +5 -0
index 106cf83c2e6b..bc5356d0a13d 100644
@@ -679,6 +679,11 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
 		break;
 	}
 	case AMDGPU_GEM_OP_SET_PLACEMENT:
+		if (robj->prime_shared_count && (args->value & AMDGPU_GEM_DOMAIN_VRAM)) {
+			r = -EINVAL;
+			amdgpu_bo_unreserve(robj);
+			break;
+		}
 		if (amdgpu_ttm_tt_get_usermm(robj->tbo.ttm)) {
 			r = -EPERM;
 			amdgpu_bo_unreserve(robj);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4 -0
index be80a4a68d7b..323580740a74 100644
@@ -665,6 +665,10 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
 	if (WARN_ON_ONCE(min_offset > max_offset))
 		return -EINVAL;
 
+	/* A shared bo cannot be migrated to VRAM */
+	if (bo->prime_shared_count && (domain == AMDGPU_GEM_DOMAIN_VRAM))
+		return -EINVAL;
+
 	if (bo->pin_count) {
 		uint32_t mem_type = bo->tbo.mem.mem_type;
 
Signature · 6 lines
2.11.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#24 lore raw

PATCH 5/6 drm/radeon: Fail fb creation from imported dma-bufs.

In reply to a message not in the archive

From: Christopher James Halse Rogers <[email protected]>

Any use of the framebuffer will migrate it to VRAM, which is not sensible for an imported dma-buf.

---
 drivers/gpu/drm/radeon/radeon_display.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/radeon/radeon_display.c +6 -0
index aea8b62835a4..289c9cbbe7d5 100644
@@ -1352,6 +1352,12 @@ radeon_user_framebuffer_create(struct drm_device *dev,
 		return ERR_PTR(-ENOENT);
 	}
 
+	/* Handle is imported dma-buf, so cannot be migrated to VRAM for scanout */
+	if (obj->import_attach) {
+		dev_err(&dev->pdev->dev, "Cannot create framebuffer from imported dma_buf\n");
+		return ERR_PTR(-EINVAL);
+	}
+
 	radeon_fb = kzalloc(sizeof(*radeon_fb), GFP_KERNEL);
 	if (radeon_fb == NULL) {
 		drm_gem_object_unreference_unlocked(obj);
Signature · 6 lines
2.11.0

_______________________________________________
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): 20170329002720.11445-6-raof-GeWIH/[email protected]

#26 lore raw

PATCH v2 1/1 drm/radeon: Fail fb creation from imported dma-bufs.

From: Christopher James Halse Rogers <[email protected]>

Any use of the framebuffer will migrate it to VRAM, which is not sensible for an imported dma-buf.

v2: Use DRM_DEBUG_KMS to prevent userspace accidentally spamming dmesg.

---
 drivers/gpu/drm/radeon/radeon_display.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/radeon/radeon_display.c +6 -0
index aea8b62835a4..f85e9c1eaa47 100644
@@ -1352,6 +1352,12 @@ radeon_user_framebuffer_create(struct drm_device *dev,
 		return ERR_PTR(-ENOENT);
 	}
 
+	/* Handle is imported dma-buf, so cannot be migrated to VRAM for scanout */
+	if (obj->import_attach) {
+		DRM_DEBUG_KMS("Cannot create framebuffer from imported dma_buf\n");
+		return ERR_PTR(-EINVAL);
+	}
+
 	radeon_fb = kzalloc(sizeof(*radeon_fb), GFP_KERNEL);
 	if (radeon_fb == NULL) {
 		drm_gem_object_unreference_unlocked(obj);
Signature · 6 lines
2.11.0

_______________________________________________
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): 20170329040054.18587-1-raof-GeWIH/[email protected]

#28 lore raw

Re: [PATCH v2] drm/radeon: Fail fb creation from imported dma-bufs.

Am 29.03.2017 um 06:00 schrieb [email protected]:

Quoted 9 lines

From: Christopher James Halse Rogers <[email protected]>

Any use of the framebuffer will migrate it to VRAM, which is not sensible for an imported dma-buf.

v2: Use DRM_DEBUG_KMS to prevent userspace accidentally spamming dmesg.

For this one and the amdgpu variant: Reviewed-by: Christian König <[email protected]>.

Quoted 11 lines
---
  drivers/gpu/drm/radeon/radeon_display.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/gpu/drm/radeon/radeon_display.c +0 -0
index aea8b62835a4..f85e9c1eaa47 100644
@@ -1352,6 +1352,12 @@ radeon_user_framebuffer_create(struct drm_device *dev,
  		return ERR_PTR(-ENOENT);
  	}

drivers/gpu/drm/radeon/radeon_display.c radeon_user_framebuffer_create(struct drm_device *dev, · line 1363

Quoted 10 lines
drivers/gpu/drm/radeon/radeon_display.c +6 -0
 
+	/* Handle is imported dma-buf, so cannot be migrated to VRAM for scanout */
+	if (obj->import_attach) {
+		DRM_DEBUG_KMS("Cannot create framebuffer from imported dma_buf\n");
+		return ERR_PTR(-EINVAL);
+	}
+
  	radeon_fb = kzalloc(sizeof(*radeon_fb), GFP_KERNEL);
  	if (radeon_fb == NULL) {
  		drm_gem_object_unreference_unlocked(obj);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#29 lore raw

PATCH 6/6 drm/radeon: Pin bos from imported dma-bufs to GTT.

In reply to [email protected]

From: Christopher James Halse Rogers <[email protected]>

Attempting to migrate the bo will break the sharing of the buffer.

---
 drivers/gpu/drm/radeon/radeon_prime.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpu/drm/radeon/radeon_prime.c +10 -0
index f3609c97496b..2dbbb4bd47b1 100644
@@ -73,6 +73,16 @@ struct drm_gem_object *radeon_gem_prime_import_sg_table(struct drm_device *dev,
 	if (ret)
 		return ERR_PTR(ret);
 
+	ret = radeon_bo_reserve(bo, false);
+	if (ret)
+		return ERR_PTR(ret);
+
+	ret = radeon_bo_pin(bo, RADEON_GEM_DOMAIN_GTT, NULL);
+	radeon_bo_unreserve(bo);
+
+	if (ret)
+		return ERR_PTR(ret);
+
 	mutex_lock(&rdev->gem.mutex);
 	list_add_tail(&bo->list, &rdev->gem.objects);
 	mutex_unlock(&rdev->gem.mutex);
Signature · 6 lines
2.11.0

_______________________________________________
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): 20170329002720.11445-7-raof-GeWIH/[email protected]

#31 lore raw

PATCH 6/7 drm/radeon: Maintain prime import/export refcount for BOs

From: Christopher James Halse Rogers <[email protected]>

---
 drivers/gpu/drm/radeon/radeon.h       | 1 +
 drivers/gpu/drm/radeon/radeon_prime.c | 6 ++++++
 2 files changed, 7 insertions(+)
drivers/gpu/drm/radeon/radeon.h +1 -0
index 44e0c5ed6418..1094325c1877 100644
@@ -499,6 +499,7 @@ struct radeon_bo {
 	u32				tiling_flags;
 	u32				pitch;
 	int				surface_reg;
+	unsigned			prime_shared_count;
 	/* list of all virtual address to which this bo
 	 * is associated to
 	 */
drivers/gpu/drm/radeon/radeon_prime.c +6 -0
index f3609c97496b..7110d403322c 100644
@@ -77,6 +77,7 @@ struct drm_gem_object *radeon_gem_prime_import_sg_table(struct drm_device *dev,
 	list_add_tail(&bo->list, &rdev->gem.objects);
 	mutex_unlock(&rdev->gem.mutex);
 
+	bo->prime_shared_count = 1;
 	return &bo->gem_base;
 }
 
@@ -91,6 +92,9 @@ int radeon_gem_prime_pin(struct drm_gem_object *obj)
 
 	/* pin buffer into GTT */
 	ret = radeon_bo_pin(bo, RADEON_GEM_DOMAIN_GTT, NULL);
+	if (likely(ret == 0))
+		bo->prime_shared_count++;
+
 	radeon_bo_unreserve(bo);
 	return ret;
 }
@@ -105,6 +109,8 @@ void radeon_gem_prime_unpin(struct drm_gem_object *obj)
 		return;
 
 	radeon_bo_unpin(bo);
+	if (bo->prime_shared_count)
+		bo->prime_shared_count--;
 	radeon_bo_unreserve(bo);
 }
 
Signature · 6 lines
2.11.0

_______________________________________________
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): 20170403033523.22639-1-raof-GeWIH/[email protected]

#33 lore raw

PATCH v2 7/7 drm/radeon: Refuse to migrate a prime BO to VRAM. (v2)

From: Christopher James Halse Rogers <[email protected]>

BOs shared via dma-buf, either imported or exported, cannot sensibly be migrated to VRAM without breaking the dma-buf sharing. Refuse userspace requests to migrate to VRAM, ensure such BOs are not migrated during command submission, and refuse to pin them to VRAM.

v2: Don't pin BOs in GTT. Instead, refuse to migrate BOs to VRAM.

---
 drivers/gpu/drm/radeon/radeon_cs.c     | 10 ++++++++++
 drivers/gpu/drm/radeon/radeon_gem.c    |  4 ++++
 drivers/gpu/drm/radeon/radeon_object.c |  5 +++++
 3 files changed, 19 insertions(+)
drivers/gpu/drm/radeon/radeon_cs.c +10 -0
index a8442f7196d6..df6b58c08544 100644
@@ -164,6 +164,16 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
 			p->relocs[i].allowed_domains = domain;
 		}
 
+		/* Objects shared as dma-bufs cannot be moved to VRAM */
+		if (p->relocs[i].robj->prime_shared_count) {
+			p->relocs[i].allowed_domains &= ~RADEON_GEM_DOMAIN_VRAM;
+			if (!p->relocs[i].allowed_domains) {
+				DRM_ERROR("BO associated with dma-buf cannot "
+					  "be moved to VRAM\n");
+				return -EINVAL;
+			}
+		}
+
 		p->relocs[i].tv.bo = &p->relocs[i].robj->tbo;
 		p->relocs[i].tv.shared = !r->write_domain;
 
drivers/gpu/drm/radeon/radeon_gem.c +4 -0
index 96683f5b2b1b..067ea7d7658a 100644
@@ -120,6 +120,10 @@ static int radeon_gem_set_domain(struct drm_gem_object *gobj,
 			return r;
 		}
 	}
+	if (domain == RADEON_GEM_DOMAIN_VRAM && robj->prime_shared_count) {
+		/* A BO that is associated with a dma-buf cannot be sensibly migrated to VRAM */
+		return -EINVAL;
+	}
 	return 0;
 }
 
drivers/gpu/drm/radeon/radeon_object.c +5 -0
index 74b276060c20..bec2ec056de4 100644
@@ -352,6 +352,11 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
 
 		return 0;
 	}
+	if (bo->prime_shared_count && domain == RADEON_GEM_DOMAIN_VRAM) {
+		/* A BO shared as a dma-buf cannot be sensibly migrated to VRAM */
+		return -EINVAL;
+	}
+
 	radeon_ttm_placement_from_domain(bo, domain);
 	for (i = 0; i < bo->placement.num_placement; i++) {
 		/* force to pin into visible video ram */
Signature · 6 lines
2.11.0

_______________________________________________
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): 20170403033523.22639-2-raof-GeWIH/[email protected]

#35 lore raw

Re: [PATCH 7/7 v2] drm/radeon: Refuse to migrate a prime BO to VRAM. (v2)

Am 03.04.2017 um 05:35 schrieb [email protected]:

Quoted 10 lines

From: Christopher James Halse Rogers <[email protected]>

BOs shared via dma-buf, either imported or exported, cannot sensibly be migrated to VRAM without breaking the dma-buf sharing. Refuse userspace requests to migrate to VRAM, ensure such BOs are not migrated during command submission, and refuse to pin them to VRAM.

v2: Don't pin BOs in GTT. Instead, refuse to migrate BOs to VRAM.

Patches #4, #6 and this one (#7) are Reviewed-by: Christian König <[email protected]>.

Quoted 48 lines
---
  drivers/gpu/drm/radeon/radeon_cs.c     | 10 ++++++++++
  drivers/gpu/drm/radeon/radeon_gem.c    |  4 ++++
  drivers/gpu/drm/radeon/radeon_object.c |  5 +++++
  3 files changed, 19 insertions(+)
drivers/gpu/drm/radeon/radeon_cs.c +10 -0
index a8442f7196d6..df6b58c08544 100644
@@ -164,6 +164,16 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
  			p->relocs[i].allowed_domains = domain;
  		}
 
+		/* Objects shared as dma-bufs cannot be moved to VRAM */
+		if (p->relocs[i].robj->prime_shared_count) {
+			p->relocs[i].allowed_domains &= ~RADEON_GEM_DOMAIN_VRAM;
+			if (!p->relocs[i].allowed_domains) {
+				DRM_ERROR("BO associated with dma-buf cannot "
+					  "be moved to VRAM\n");
+				return -EINVAL;
+			}
+		}
+
  		p->relocs[i].tv.bo = &p->relocs[i].robj->tbo;
  		p->relocs[i].tv.shared = !r->write_domain;
 
drivers/gpu/drm/radeon/radeon_gem.c +4 -0
index 96683f5b2b1b..067ea7d7658a 100644
@@ -120,6 +120,10 @@ static int radeon_gem_set_domain(struct drm_gem_object *gobj,
  			return r;
  		}
  	}
+	if (domain == RADEON_GEM_DOMAIN_VRAM && robj->prime_shared_count) {
+		/* A BO that is associated with a dma-buf cannot be sensibly migrated to VRAM */
+		return -EINVAL;
+	}
  	return 0;
  }
 
drivers/gpu/drm/radeon/radeon_object.c +0 -0
index 74b276060c20..bec2ec056de4 100644
@@ -352,6 +352,11 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
 

drivers/gpu/drm/radeon/radeon_object.c int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset, · line 362

Quoted 10 lines
drivers/gpu/drm/radeon/radeon_object.c +5 -0
  		return 0;
  	}
+	if (bo->prime_shared_count && domain == RADEON_GEM_DOMAIN_VRAM) {
+		/* A BO shared as a dma-buf cannot be sensibly migrated to VRAM */
+		return -EINVAL;
+	}
+
  	radeon_ttm_placement_from_domain(bo, domain);
  	for (i = 0; i < bo->placement.num_placement; i++) {
  		/* force to pin into visible video ram */

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#36 lore raw

Re: [PATCH 7/7 v2] drm/radeon: Refuse to migrate a prime BO to VRAM. (v2)

Quoted 13 lines · Christian König

Am 03.04.2017 um 05:35 schrieb [email protected]:

Quoted 12 lines

From: Christopher James Halse Rogers
<[email protected]>

BOs shared via dma-buf, either imported or exported, cannot sensibly be migrated to VRAM
without breaking the dma-buf sharing. Refuse userspace requests to migrate to VRAM,
ensure such BOs are not migrated during command submission, and refuse to pin them
to VRAM.

Quoted 8 lines
Quoted 4 lines

v2: Don't pin BOs in GTT. Instead, refuse to migrate BOs to VRAM.

Signed-off-by: Christopher James Halse Rogers
<[email protected]>

Patches #4, #6 and this one (#7) are Reviewed-by: Christian König <[email protected]>.

Will this cause any issues with self sharing? E.g., the standard use case with a single GPU and DRI3?

Alex

Quoted 66 lines
Quoted 66 lines

---
  drivers/gpu/drm/radeon/radeon_cs.c     | 10 ++++++++++
  drivers/gpu/drm/radeon/radeon_gem.c    |  4 ++++
  drivers/gpu/drm/radeon/radeon_object.c |  5 +++++
  3 files changed, 19 insertions(+)
drivers/gpu/drm/radeon/radeon_cs.c +4 -0
index a8442f7196d6..df6b58c08544 100644
@@ -164,6 +164,16 @@ static int radeon_cs_parser_relocs(struct
 radeon_cs_parser *p)
                        p->relocs[i].allowed_domains = domain;
                }
  +             /* Objects shared as dma-bufs cannot be moved to VRAM */
+               if (p->relocs[i].robj->prime_shared_count) {
+                       p->relocs[i].allowed_domains &=
 ~RADEON_GEM_DOMAIN_VRAM;
+                       if (!p->relocs[i].allowed_domains) {
+                               DRM_ERROR("BO associated with dma-buf

cannot "

drivers/gpu/drm/radeon/radeon_cs.c +5 -0
+                                         "be moved to VRAM\n");
+                               return -EINVAL;
+                       }
+               }
+
                p->relocs[i].tv.bo = &p->relocs[i].robj->tbo;
                p->relocs[i].tv.shared = !r->write_domain;
  diff --git a/drivers/gpu/drm/radeon/radeon_gem.c

b/drivers/gpu/drm/radeon/radeon_gem.c
index 96683f5b2b1b..067ea7d7658a 100644

drivers/gpu/drm/radeon/radeon_gem.c +2 -0
@@ -120,6 +120,10 @@ static int radeon_gem_set_domain(struct
 drm_gem_object *gobj,
                        return r;
                }
        }
+       if (domain == RADEON_GEM_DOMAIN_VRAM && robj->prime_shared_count)
 {
+               /* A BO that is associated with a dma-buf cannot be

sensibly migrated to VRAM */

drivers/gpu/drm/radeon/radeon_gem.c +2 -0
+               return -EINVAL;
+       }
        return 0;
  }
  diff --git a/drivers/gpu/drm/radeon/radeon_object.c

b/drivers/gpu/drm/radeon/radeon_object.c
index 74b276060c20..bec2ec056de4 100644

drivers/gpu/drm/radeon/radeon_object.c +2 -0
@@ -352,6 +352,11 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo,
 u32 domain, u64 max_offset,
                return 0;
        }
+       if (bo->prime_shared_count && domain == RADEON_GEM_DOMAIN_VRAM) {
+               /* A BO shared as a dma-buf cannot be sensibly migrated to

VRAM */

drivers/gpu/drm/radeon/radeon_object.c +3 -0
+               return -EINVAL;
+       }
+
        radeon_ttm_placement_from_domain(bo, domain);
        for (i = 0; i < bo->placement.num_placement; i++) {
Quoted 8 lines
Quoted 1 line
                /* force to pin into visible video ram */

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#37 lore raw

Re: [PATCH 7/7 v2] drm/radeon: Refuse to migrate a prime BO to VRAM. (v2)

Am 03.04.2017 um 17:51 schrieb Alex Deucher:

Quoted 15 lines · Christian König
Quoted 14 lines

Am 03.04.2017 um 05:35 schrieb [email protected]:

Quoted 13 lines

From: Christopher James Halse Rogers
<[email protected]>

BOs shared via dma-buf, either imported or exported, cannot sensibly be migrated to VRAM
without breaking the dma-buf sharing. Refuse userspace requests to migrate to VRAM,
ensure such BOs are not migrated during command submission, and refuse to pin them
to VRAM.

v2: Don't pin BOs in GTT. Instead, refuse to migrate BOs to VRAM.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Signed-off-by: Christopher James Halse Rogers
<[email protected]>

Patches #4, #6 and this one (#7) are Reviewed-by: Christian König <[email protected]>.

Will this cause any issues with self sharing? E.g., the standard use case with a single GPU and DRI3?

No, the code from amdgpu to count the number of times we really shared a BO with somebody was ported over to radeon as far as I can see.

So that should work fine, but I haven't double checked or tested it.

Christian.

Quoted 75 lines

Alex

Quoted 64 lines
Quoted 64 lines
---
   drivers/gpu/drm/radeon/radeon_cs.c     | 10 ++++++++++
   drivers/gpu/drm/radeon/radeon_gem.c    |  4 ++++
   drivers/gpu/drm/radeon/radeon_object.c |  5 +++++
   3 files changed, 19 insertions(+)
drivers/gpu/drm/radeon/radeon_cs.c +4 -0
index a8442f7196d6..df6b58c08544 100644
@@ -164,6 +164,16 @@ static int radeon_cs_parser_relocs(struct
 radeon_cs_parser *p)
                         p->relocs[i].allowed_domains = domain;
                 }
   +             /* Objects shared as dma-bufs cannot be moved to VRAM */
+               if (p->relocs[i].robj->prime_shared_count) {
+                       p->relocs[i].allowed_domains &=
 ~RADEON_GEM_DOMAIN_VRAM;
+                       if (!p->relocs[i].allowed_domains) {
+                               DRM_ERROR("BO associated with dma-buf

cannot "

drivers/gpu/drm/radeon/radeon_cs.c +5 -0
+                                         "be moved to VRAM\n");
+                               return -EINVAL;
+                       }
+               }
+
                 p->relocs[i].tv.bo = &p->relocs[i].robj->tbo;
                 p->relocs[i].tv.shared = !r->write_domain;
   diff --git a/drivers/gpu/drm/radeon/radeon_gem.c

b/drivers/gpu/drm/radeon/radeon_gem.c
index 96683f5b2b1b..067ea7d7658a 100644

drivers/gpu/drm/radeon/radeon_gem.c +2 -0
@@ -120,6 +120,10 @@ static int radeon_gem_set_domain(struct
 drm_gem_object *gobj,
                         return r;
                 }
         }
+       if (domain == RADEON_GEM_DOMAIN_VRAM && robj->prime_shared_count)
 {
+               /* A BO that is associated with a dma-buf cannot be

sensibly migrated to VRAM */

drivers/gpu/drm/radeon/radeon_gem.c +2 -0
+               return -EINVAL;
+       }
         return 0;
   }
   diff --git a/drivers/gpu/drm/radeon/radeon_object.c

b/drivers/gpu/drm/radeon/radeon_object.c
index 74b276060c20..bec2ec056de4 100644

drivers/gpu/drm/radeon/radeon_object.c +2 -0
@@ -352,6 +352,11 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo,
 u32 domain, u64 max_offset,
                 return 0;
         }
+       if (bo->prime_shared_count && domain == RADEON_GEM_DOMAIN_VRAM) {
+               /* A BO shared as a dma-buf cannot be sensibly migrated to

VRAM */

drivers/gpu/drm/radeon/radeon_object.c +3 -0
+               return -EINVAL;
+       }
+
         radeon_ttm_placement_from_domain(bo, domain);
Quoted 8 lines
Quoted 2 lines
         for (i = 0; i < bo->placement.num_placement; i++) {
                 /* force to pin into visible video ram */

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
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): c9417139-b930-040b-c186-e99b8ecc3474-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#39 lore raw

Re: [PATCH 7/7 v2] drm/radeon: Refuse to migrate a prime BO to VRAM. (v2)

I also haven't tested it on hardware (all my hardware seems to be supported by amdgpu), but the only times we touch prime_shared_count are:
1) It's set to 1 in radeon_gem_prime_import_sg_table. This shouldn't be called in the self-import case (and isn't, as far as I can tell), and
2) It's incremented in radeon_gem_prime_pin, right after the bo is pinned to GTT, so cannot be migrated to VRAM anyway (unless there's an unmatched radeon_bo_unpin call somewhere else?).

Quoted 98 lines · On Tue, 4 Apr 2017 at 02:30 Christian König…

Am 03.04.2017 um 17:51 schrieb Alex Deucher:

Quoted 1 line

On Mon, Apr 3, 2017 at 4:24 AM, Christian König <[email protected]>

Quoted 7 lines · wrote:
Quoted 7 lines

Am 03.04.2017 um 05:35 schrieb raof-GeWIH/[email protected]:

Quoted 6 lines

From: Christopher James Halse Rogers <[email protected]>

BOs shared via dma-buf, either imported or exported, cannot sensibly be migrated to VRAM
without breaking the dma-buf sharing. Refuse userspace requests to

migrate

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

to VRAM,
ensure such BOs are not migrated during command submission, and refuse

to

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

pin them
to VRAM.

v2: Don't pin BOs in GTT. Instead, refuse to migrate BOs to VRAM.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Signed-off-by: Christopher James Halse Rogers <[email protected]>

Patches #4, #6 and this one (#7) are Reviewed-by: Christian König <[email protected]>.

Will this cause any issues with self sharing? E.g., the standard use case with a single GPU and DRI3?

No, the code from amdgpu to count the number of times we really shared a BO with somebody was ported over to radeon as far as I can see.

So that should work fine, but I haven't double checked or tested it.

Christian.

Quoted 10 lines

Alex

Quoted 7 lines
Quoted 7 lines
---
   drivers/gpu/drm/radeon/radeon_cs.c     | 10 ++++++++++
   drivers/gpu/drm/radeon/radeon_gem.c    |  4 ++++
   drivers/gpu/drm/radeon/radeon_object.c |  5 +++++
   3 files changed, 19 insertions(+)
Quoted 10 lines
Quoted 10 lines

drivers/gpu/drm/radeon/radeon_cs.c static int radeon_cs_parser_relocs(struct · line 167

Quoted 10 lines
drivers/gpu/drm/radeon/radeon_cs.c +0 -0
index a8442f7196d6..df6b58c08544 100644
@@ -164,6 +164,16 @@ static int radeon_cs_parser_relocs(struct
 radeon_cs_parser *p)
                         p->relocs[i].allowed_domains = domain;
                 }
   +             /* Objects shared as dma-bufs cannot be moved to VRAM

*/

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/radeon/radeon_cs.c +4 -0
+               if (p->relocs[i].robj->prime_shared_count) {
+                       p->relocs[i].allowed_domains &=
 ~RADEON_GEM_DOMAIN_VRAM;
+                       if (!p->relocs[i].allowed_domains) {
+                               DRM_ERROR("BO associated with dma-buf

cannot "

drivers/gpu/drm/radeon/radeon_cs.c +5 -0
+                                         "be moved to VRAM\n");
+                               return -EINVAL;
+                       }
+               }
+
                 p->relocs[i].tv.bo = &p->relocs[i].robj->tbo;
                 p->relocs[i].tv.shared = !r->write_domain;
   diff --git a/drivers/gpu/drm/radeon/radeon_gem.c

b/drivers/gpu/drm/radeon/radeon_gem.c
index 96683f5b2b1b..067ea7d7658a 100644

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/radeon/radeon_gem.c static int radeon_gem_set_domain(struct · line 124

Quoted 8 lines
drivers/gpu/drm/radeon/radeon_gem.c +1 -0
@@ -120,6 +120,10 @@ static int radeon_gem_set_domain(struct
 drm_gem_object *gobj,
                         return r;
                 }
         }
+       if (domain == RADEON_GEM_DOMAIN_VRAM &&

robj->prime_shared_count)

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/radeon/radeon_gem.c +1 -0
 {
+               /* A BO that is associated with a dma-buf cannot be

sensibly migrated to VRAM */

drivers/gpu/drm/radeon/radeon_gem.c +2 -0
+               return -EINVAL;
+       }
         return 0;
   }
   diff --git a/drivers/gpu/drm/radeon/radeon_object.c

b/drivers/gpu/drm/radeon/radeon_object.c

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/radeon/radeon_object.c int radeon_bo_pin_restricted(struct radeon_bo *bo, · line 355

Quoted 8 lines

index 74b276060c20..bec2ec056de4 100644

drivers/gpu/drm/radeon/radeon_object.c +1 -0
@@ -352,6 +352,11 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo,
 u32 domain, u64 max_offset,
                 return 0;
         }
+       if (bo->prime_shared_count && domain ==

RADEON_GEM_DOMAIN_VRAM) {

Quoted 22 lines
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/radeon/radeon_object.c int radeon_bo_pin_restricted(struct radeon_bo *bo, · line 356

Quoted 1 line
drivers/gpu/drm/radeon/radeon_object.c +1 -0
+               /* A BO shared as a dma-buf cannot be sensibly

migrated to

Quoted 17 lines
Quoted 9 lines

drivers/gpu/drm/radeon/radeon_object.c int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset, · line 362

Quoted 7 lines

VRAM */

drivers/gpu/drm/radeon/radeon_object.c +3 -0
+               return -EINVAL;
+       }
+
         radeon_ttm_placement_from_domain(bo, domain);
         for (i = 0; i < bo->placement.num_placement; i++) {
                 /* force to pin into visible video ram */
Quoted 4 lines

_______________________________________________
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

_______________________________________________
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): 4fe38f82-c9d5-c212-fa05-08c2b4684c4e-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#41 lore raw

Re: [PATCH 7/7 v2] drm/radeon: Refuse to migrate a prime BO to VRAM. (v2)

Quoted 13 lines · Christian König

Am 03.04.2017 um 05:35 schrieb [email protected]:

Quoted 12 lines

From: Christopher James Halse Rogers
<[email protected]>

BOs shared via dma-buf, either imported or exported, cannot sensibly be migrated to VRAM
without breaking the dma-buf sharing. Refuse userspace requests to migrate to VRAM,
ensure such BOs are not migrated during command submission, and refuse to pin them
to VRAM.

Quoted 8 lines
Quoted 4 lines

v2: Don't pin BOs in GTT. Instead, refuse to migrate BOs to VRAM.

Signed-off-by: Christopher James Halse Rogers
<[email protected]>

Patches #4, #6 and this one (#7) are Reviewed-by: Christian König <[email protected]>.

Applied 4, 6, 7.

Thanks,

Alex

Quoted 66 lines
Quoted 66 lines

---
  drivers/gpu/drm/radeon/radeon_cs.c     | 10 ++++++++++
  drivers/gpu/drm/radeon/radeon_gem.c    |  4 ++++
  drivers/gpu/drm/radeon/radeon_object.c |  5 +++++
  3 files changed, 19 insertions(+)
drivers/gpu/drm/radeon/radeon_cs.c +4 -0
index a8442f7196d6..df6b58c08544 100644
@@ -164,6 +164,16 @@ static int radeon_cs_parser_relocs(struct
 radeon_cs_parser *p)
                        p->relocs[i].allowed_domains = domain;
                }
  +             /* Objects shared as dma-bufs cannot be moved to VRAM */
+               if (p->relocs[i].robj->prime_shared_count) {
+                       p->relocs[i].allowed_domains &=
 ~RADEON_GEM_DOMAIN_VRAM;
+                       if (!p->relocs[i].allowed_domains) {
+                               DRM_ERROR("BO associated with dma-buf

cannot "

drivers/gpu/drm/radeon/radeon_cs.c +5 -0
+                                         "be moved to VRAM\n");
+                               return -EINVAL;
+                       }
+               }
+
                p->relocs[i].tv.bo = &p->relocs[i].robj->tbo;
                p->relocs[i].tv.shared = !r->write_domain;
  diff --git a/drivers/gpu/drm/radeon/radeon_gem.c

b/drivers/gpu/drm/radeon/radeon_gem.c
index 96683f5b2b1b..067ea7d7658a 100644

drivers/gpu/drm/radeon/radeon_gem.c +2 -0
@@ -120,6 +120,10 @@ static int radeon_gem_set_domain(struct
 drm_gem_object *gobj,
                        return r;
                }
        }
+       if (domain == RADEON_GEM_DOMAIN_VRAM && robj->prime_shared_count)
 {
+               /* A BO that is associated with a dma-buf cannot be

sensibly migrated to VRAM */

drivers/gpu/drm/radeon/radeon_gem.c +2 -0
+               return -EINVAL;
+       }
        return 0;
  }
  diff --git a/drivers/gpu/drm/radeon/radeon_object.c

b/drivers/gpu/drm/radeon/radeon_object.c
index 74b276060c20..bec2ec056de4 100644

drivers/gpu/drm/radeon/radeon_object.c +2 -0
@@ -352,6 +352,11 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo,
 u32 domain, u64 max_offset,
                return 0;
        }
+       if (bo->prime_shared_count && domain == RADEON_GEM_DOMAIN_VRAM) {
+               /* A BO shared as a dma-buf cannot be sensibly migrated to

VRAM */

drivers/gpu/drm/radeon/radeon_object.c +3 -0
+               return -EINVAL;
+       }
+
        radeon_ttm_placement_from_domain(bo, domain);
        for (i = 0; i < bo->placement.num_placement; i++) {
Quoted 8 lines
Quoted 1 line
                /* force to pin into visible video ram */

_______________________________________________
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