Skip to contentSkip to conversation

drm/amdgpu: Refuse to create a KMS FB for non-P2P exported dma-bufs

PATCH In review Michel Dänzer 2 participants 16 messages Feb 22, 2024 – Feb 26, 2024

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

PATCH 1/3 drm/amdgpu: Refuse to create a KMS FB for non-P2P exported dma-bufs

From: Michel Dänzer <[email protected]>

Pinning the BO storage to VRAM for scanout would make it inaccessible to non-P2P dma-buf importers.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 38 ++++++++++++++++++---
 1 file changed, 33 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +33 -5
index b8fbe97efe1d3..514a5b2159815 100644
@@ -1255,13 +1255,41 @@ amdgpu_display_user_framebuffer_create(struct drm_device *dev,
 		return ERR_PTR(-ENOENT);
 	}
 
-	/* Handle is imported dma-buf, so cannot be migrated to VRAM for scanout */
 	bo = gem_to_amdgpu_bo(obj);
 	domains = amdgpu_display_supported_domains(drm_to_adev(dev), bo->flags);
-	if (obj->import_attach && !(domains & AMDGPU_GEM_DOMAIN_GTT)) {
-		drm_dbg_kms(dev, "Cannot create framebuffer from imported dma_buf\n");
-		drm_gem_object_put(obj);
-		return ERR_PTR(-EINVAL);
+	if (!(domains & AMDGPU_GEM_DOMAIN_GTT)) {
+		bool can_pin = true;
+
+		mutex_lock(&file_priv->prime.lock);
+
+		/* Handle is imported dma-buf, so cannot be migrated to VRAM for scanout */
+		if (obj->import_attach) {
+			drm_dbg_kms(dev, "Cannot create framebuffer from imported dma_buf\n");
+			can_pin = false;
+		} else if (obj->dma_buf) {
+			struct dma_buf *dmabuf = obj->dma_buf;
+			struct dma_buf_attachment *attachment;
+
+			dma_resv_lock(dmabuf->resv, NULL);
+
+			list_for_each_entry(attachment, &dmabuf->attachments, node) {
+				if (IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY) && attachment->peer2peer)
+					continue;
+
+				drm_dbg_kms(dev, "Cannot create framebuffer from non-P2P exported dma_buf\n");
+				can_pin = false;
+				break;
+			}
+
+			dma_resv_unlock(dmabuf->resv);
+		}
+
+		mutex_unlock(&file_priv->prime.lock);
+
+		if (!can_pin) {
+			drm_gem_object_put(obj);
+			return ERR_PTR(-EINVAL);
+		}
 	}
 
 	amdgpu_fb = kzalloc(sizeof(*amdgpu_fb), GFP_KERNEL);
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/3 drm/amdgpu: Keep track of the number of KMS FBs using an amdgpu_bo

From: Michel Dänzer <[email protected]>

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 14 ++++++++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h  |  3 +++
 2 files changed, 15 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +12 -2
index 514a5b2159815..89bda2a2baf58 100644
@@ -531,6 +531,15 @@ bool amdgpu_display_ddc_probe(struct amdgpu_connector *amdgpu_connector,
 	return true;
 }
 
+static void
+amdgpu_fb_destroy(struct drm_framebuffer *fb)
+{
+	struct amdgpu_bo *bo = gem_to_amdgpu_bo(fb->obj[0]);
+
+	atomic_dec(&bo->num_fbs);
+	drm_gem_fb_destroy(fb);
+}
+
 static int amdgpu_dirtyfb(struct drm_framebuffer *fb, struct drm_file *file,
 			  unsigned int flags, unsigned int color,
 			  struct drm_clip_rect *clips, unsigned int num_clips)
@@ -544,12 +553,12 @@ static int amdgpu_dirtyfb(struct drm_framebuffer *fb, struct drm_file *file,
 }
 
 static const struct drm_framebuffer_funcs amdgpu_fb_funcs = {
-	.destroy = drm_gem_fb_destroy,
+	.destroy = amdgpu_fb_destroy,
 	.create_handle = drm_gem_fb_create_handle,
 };
 
 static const struct drm_framebuffer_funcs amdgpu_fb_funcs_atomic = {
-	.destroy = drm_gem_fb_destroy,
+	.destroy = amdgpu_fb_destroy,
 	.create_handle = drm_gem_fb_create_handle,
 	.dirty = amdgpu_dirtyfb
 };
@@ -1306,6 +1315,7 @@ amdgpu_display_user_framebuffer_create(struct drm_device *dev,
 		return ERR_PTR(ret);
 	}
 
+	atomic_inc(&bo->num_fbs);
 	drm_gem_object_put(obj);
 	return &amdgpu_fb->base;
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +3 -0
index a3ea8a82db23a..47579a6eb2ae8 100644
@@ -117,6 +117,9 @@ struct amdgpu_bo {
 	 * for memory accounting.
 	 */
 	int8_t				xcp_id;
+
+	/* Number of KMS FBs using this BO */
+	atomic_t			num_fbs;
 };
 
 struct amdgpu_bo_user {
Signature · 1 line
2.43.0
#2 lore raw

PATCH 3/3 drm/amdgpu: Refuse non-P2P dma-buf attachments for BOs with KMS FBs

In reply to Michel Dänzer

From: Michel Dänzer <[email protected]>

Pinning the BO storage to VRAM for scanout would make it inaccessible to non-P2P dma-buf importers.

Also keep file_priv->prime.lock locked until after bumping bo->num_fbs in amdgpu_display_user_framebuffer_create, so that the checks there and in amdgpu_dma_buf_attach are always consistent with each other.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 20 ++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 11 +++++++++++
 2 files changed, 23 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +12 -8
index 89bda2a2baf58..2afe5558ba895 100644
@@ -1251,6 +1251,7 @@ amdgpu_display_user_framebuffer_create(struct drm_device *dev,
 {
 	struct amdgpu_framebuffer *amdgpu_fb;
 	struct drm_gem_object *obj;
+	bool prime_locked = false;
 	struct amdgpu_bo *bo;
 	uint32_t domains;
 	int ret;
@@ -1270,6 +1271,7 @@ amdgpu_display_user_framebuffer_create(struct drm_device *dev,
 		bool can_pin = true;
 
 		mutex_lock(&file_priv->prime.lock);
+		prime_locked = true;
 
 		/* Handle is imported dma-buf, so cannot be migrated to VRAM for scanout */
 		if (obj->import_attach) {
@@ -1293,29 +1295,31 @@ amdgpu_display_user_framebuffer_create(struct drm_device *dev,
 			dma_resv_unlock(dmabuf->resv);
 		}
 
-		mutex_unlock(&file_priv->prime.lock);
-
 		if (!can_pin) {
-			drm_gem_object_put(obj);
-			return ERR_PTR(-EINVAL);
+			amdgpu_fb = ERR_PTR(-EINVAL);
+			goto out;
 		}
 	}
 
 	amdgpu_fb = kzalloc(sizeof(*amdgpu_fb), GFP_KERNEL);
 	if (amdgpu_fb == NULL) {
-		drm_gem_object_put(obj);
-		return ERR_PTR(-ENOMEM);
+		amdgpu_fb = ERR_PTR(-ENOMEM);
+		goto out;
 	}
 
 	ret = amdgpu_display_gem_fb_verify_and_init(dev, amdgpu_fb, file_priv,
 						    mode_cmd, obj);
 	if (ret) {
 		kfree(amdgpu_fb);
-		drm_gem_object_put(obj);
-		return ERR_PTR(ret);
+		amdgpu_fb = ERR_PTR(ret);
+		goto out;
 	}
 
 	atomic_inc(&bo->num_fbs);
+
+out:
+	if (prime_locked)
+		mutex_unlock(&file_priv->prime.lock);
 	drm_gem_object_put(obj);
 	return &amdgpu_fb->base;
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +11 -0
index decbbe3d4f06e..275d34898284d 100644
@@ -63,6 +63,17 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf,
 	if (pci_p2pdma_distance(adev->pdev, attach->dev, false) < 0)
 		attach->peer2peer = false;
 
+	if ((!IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY) || !attach->peer2peer) &&
+	    atomic_read(&bo->num_fbs) > 0) {
+		uint32_t domains = amdgpu_display_supported_domains(adev, bo->flags);
+
+		if (!(domains & AMDGPU_GEM_DOMAIN_GTT)) {
+			drm_dbg_prime(adev_to_drm(adev),
+				      "Cannot attach to BO with KMS FBs without P2P\n");
+			return -EINVAL;
+		}
+	}
+
 	r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
 	trace_amdgpu_runpm_reference_dumps(1, __func__);
 	if (r < 0)
Signature · 1 line
2.43.0
maintainer
#3 lore raw
In reply to Michel Dänzer

Am 22.02.24 um 18:28 schrieb Michel Dänzer:

Quoted 4 lines

From: Michel Dänzer <[email protected]>

Pinning the BO storage to VRAM for scanout would make it inaccessible to non-P2P dma-buf importers.

Thinking more about it I don't think we can do this.

Using the BO in a ping/pong fashion for scanout and DMA-buf is actually valid, you just can't do both at the same time.

And if I'm not completely mistaken we actually have use cases for this at the moment, only as fallback but it would still break existing userspace and that is a no-go.

So rejecting things during CS and atomic commit is the best thing we can do.

Regards,
Christian.

Quoted 58 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 38 ++++++++++++++++++---
  1 file changed, 33 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +33 -5
index b8fbe97efe1d3..514a5b2159815 100644
@@ -1255,13 +1255,41 @@ amdgpu_display_user_framebuffer_create(struct drm_device *dev,
  		return ERR_PTR(-ENOENT);
  	}
 
-	/* Handle is imported dma-buf, so cannot be migrated to VRAM for scanout */
  	bo = gem_to_amdgpu_bo(obj);
  	domains = amdgpu_display_supported_domains(drm_to_adev(dev), bo->flags);
-	if (obj->import_attach && !(domains & AMDGPU_GEM_DOMAIN_GTT)) {
-		drm_dbg_kms(dev, "Cannot create framebuffer from imported dma_buf\n");
-		drm_gem_object_put(obj);
-		return ERR_PTR(-EINVAL);
+	if (!(domains & AMDGPU_GEM_DOMAIN_GTT)) {
+		bool can_pin = true;
+
+		mutex_lock(&file_priv->prime.lock);
+
+		/* Handle is imported dma-buf, so cannot be migrated to VRAM for scanout */
+		if (obj->import_attach) {
+			drm_dbg_kms(dev, "Cannot create framebuffer from imported dma_buf\n");
+			can_pin = false;
+		} else if (obj->dma_buf) {
+			struct dma_buf *dmabuf = obj->dma_buf;
+			struct dma_buf_attachment *attachment;
+
+			dma_resv_lock(dmabuf->resv, NULL);
+
+			list_for_each_entry(attachment, &dmabuf->attachments, node) {
+				if (IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY) && attachment->peer2peer)
+					continue;
+
+				drm_dbg_kms(dev, "Cannot create framebuffer from non-P2P exported dma_buf\n");
+				can_pin = false;
+				break;
+			}
+
+			dma_resv_unlock(dmabuf->resv);
+		}
+
+		mutex_unlock(&file_priv->prime.lock);
+
+		if (!can_pin) {
+			drm_gem_object_put(obj);
+			return ERR_PTR(-EINVAL);
+		}
  	}
 
  	amdgpu_fb = kzalloc(sizeof(*amdgpu_fb), GFP_KERNEL);
#4 lore raw
Quoted 11 lines · Christian König

Am 22.02.24 um 18:28 schrieb Michel Dänzer:

Quoted 4 lines

From: Michel Dänzer <[email protected]>

Pinning the BO storage to VRAM for scanout would make it inaccessible to non-P2P dma-buf importers.

Thinking more about it I don't think we can do this.

Using the BO in a ping/pong fashion for scanout and DMA-buf is actually valid, you just can't do both at the same time.

And if I'm not completely mistaken we actually have use cases for this at the moment,

Those use cases don't have P2P & CONFIG_DMABUF_MOVE_NOTIFY?

(As discussed on the GitLab issue, AFAICT P2P could be made to work even without CONFIG_DMABUF_MOVE_NOTIFY, by pinning to VRAM instead of GTT for dma-buf sharing)

Quoted 1 line

only as fallback but it would still break existing userspace and that is a no-go.

I'm obviously aware of this general rule. There are exceptions though, and this might be one.

Quoted 1 line

So rejecting things during CS and atomic commit is the best thing we can do.

It's problematic for a Wayland compositor:

The CS ioctl failing is awkward. With GL, I'm pretty sure it means the compositor would have to destroy the context and create a new one. Not sure about Vulkan, but I suspect it's painful there as well.

Similarly for the KMS atomic commit ioctl. The compositor can't know why exactly it failed, all it gets is an error code.

And there's no other way for the compositor to detect when both things can actually work concurrently.

Together, this means the compositor always has to assume the worst case, and do workarounds such as using the scanout GPU to copy from the scanout buffer to another buffer for access from another GPU. Even when direct access from the other GPU would actually work fine.

Signature · 2 lines
Earthling Michel Dänzer            |                  https://redhat.com
Libre software enthusiast          |         Mesa and Xwayland developer
#5 lore raw
Quoted 6 lines · Michel Dänzer
Quoted 2 lines · Christian König

So rejecting things during CS and atomic commit is the best thing we can do.

It's problematic for a Wayland compositor:

Quoted 7 lines

The CS ioctl failing is awkward. With GL, I'm pretty sure it means the compositor would have to destroy the context and create a new one. Not sure about Vulkan, but I suspect it's painful there as well.

Similarly for the KMS atomic commit ioctl. The compositor can't know why exactly it failed, all it gets is an error code.

And there's no other way for the compositor to detect when both things can actually work concurrently.

Together, this means the compositor always has to assume the worst case, and do workarounds such as using the scanout GPU to copy from the scanout buffer to another buffer for access from another GPU. Even when direct access from the other GPU would actually work fine.

It's worse for Xwayland:

It can't know if/when the Wayland compositor uses a buffer for scanout. It would have to assume the worst case whenever a buffer is owned by the compositor.

Except Xwayland can't know which GPU a buffer is originally from. So it can't know when the workaround is actually needed, or which GPU it has to use for the workaround.

Signature · 2 lines
Earthling Michel Dänzer            |                  https://redhat.com
Libre software enthusiast          |         Mesa and Xwayland developer
maintainer
#6 lore raw
In reply to Michel Dänzer

Am 23.02.24 um 09:11 schrieb Michel Dänzer:

Quoted 12 lines · Christian König
Quoted 10 lines

Am 22.02.24 um 18:28 schrieb Michel Dänzer:

Quoted 4 lines

From: Michel Dänzer <[email protected]>

Pinning the BO storage to VRAM for scanout would make it inaccessible to non-P2P dma-buf importers.

Thinking more about it I don't think we can do this.

Using the BO in a ping/pong fashion for scanout and DMA-buf is actually valid, you just can't do both at the same time.

And if I'm not completely mistaken we actually have use cases for this at the moment,

Those use cases don't have P2P & CONFIG_DMABUF_MOVE_NOTIFY?

Nope, we are basically talking about unit tests and examples for inter device operations.

Those render into a shared buffer and then display it to check if the content was rendered/transferred correctly.

I'm not sure if we still do those test cases, the last time I looked into it was before P2P was even supported, but I also can't rule it out.

Quoted 1 line

(As discussed on the GitLab issue, AFAICT P2P could be made to work even without CONFIG_DMABUF_MOVE_NOTIFY, by pinning to VRAM instead of GTT for dma-buf sharing)

Longer story but that is something intentionally not done.

Quoted 10 lines
Quoted 1 line

only as fallback but it would still break existing userspace and that is a no-go.

I'm obviously aware of this general rule. There are exceptions though, and this might be one.

Quoted 1 line

So rejecting things during CS and atomic commit is the best thing we can do.

It's problematic for a Wayland compositor:

The CS ioctl failing is awkward. With GL, I'm pretty sure it means the compositor would have to destroy the context and create a new one. Not sure about Vulkan, but I suspect it's painful there as well.

Similarly for the KMS atomic commit ioctl. The compositor can't know why exactly it failed, all it gets is an error code.

Yeah, but that is not because the kernel is doing anything wrong.

Sharing, rendering and then doing an atomic commit is a perfectly valid use case.

You just can't do scanout and sharing at the same time.

Quoted 1 line

And there's no other way for the compositor to detect when both things can actually work concurrently.

That I totally agree with. And IIRC we already have at least a query for the buffer placement. E.g. you can already check if the BO is in GTT or VRAM and shared.

What's missing is exposing if the device can scanout from GTT or not.

It's just that blocking a valid use case because a special combination doesn't work is not going to fly I think.

Quoted 1 line

Together, this means the compositor always has to assume the worst case, and do workarounds such as using the scanout GPU to copy from the scanout buffer to another buffer for access from another GPU. Even when direct access from the other GPU would actually work fine.

Yeah, I think we can avoid that. I'm just not sure how to do it in a driver agnostic way.

Regards,
Christian.

#7 lore raw
Quoted 7 lines · Christian König

Am 23.02.24 um 09:11 schrieb Michel Dänzer:

Quoted 6 lines · Christian König
Quoted 5 lines

Am 22.02.24 um 18:28 schrieb Michel Dänzer:

Quoted 4 lines

From: Michel Dänzer <[email protected]>

Pinning the BO storage to VRAM for scanout would make it inaccessible to non-P2P dma-buf importers.

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

Thinking more about it I don't think we can do this.

Using the BO in a ping/pong fashion for scanout and DMA-buf is actually valid, you just can't do both at the same time.

And if I'm not completely mistaken we actually have use cases for this at the moment,

Those use cases don't have P2P & CONFIG_DMABUF_MOVE_NOTIFY?

Nope, we are basically talking about unit tests and examples for inter device operations.

Sounds like the "no user-space regressions" rule might not apply then.

Quoted 1 line

Those render into a shared buffer and then display it to check if the content was rendered/transferred correctly.

That can be fixed by dropping the dma-buf attachments from other GPUs before creating the KMS FB.

Conversely, tests / examples which do scanout first can be fixed by destroying KMS FBs before sharing the BO with another GPU.

Quoted 1 line

I'm not sure if we still do those test cases, the last time I looked into it was before P2P was even supported, but I also can't rule it out.

Sounds too vague to block this series.

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

So rejecting things during CS and atomic commit is the best thing we can do.

It's problematic for a Wayland compositor:

The CS ioctl failing is awkward. With GL, I'm pretty sure it means the compositor would have to destroy the context and create a new one. Not sure about Vulkan, but I suspect it's painful there as well.

Quoted 7 lines
Quoted 1 line

Similarly for the KMS atomic commit ioctl. The compositor can't know why exactly it failed, all it gets is an error code.

Yeah, but that is not because the kernel is doing anything wrong.

Sharing, rendering and then doing an atomic commit is a perfectly valid use case.

You just can't do scanout and sharing at the same time.

Per my later follow-up, Xwayland can't really avoid it.

Quoted 5 lines
Quoted 1 line

And there's no other way for the compositor to detect when both things can actually work concurrently.

That I totally agree with. And IIRC we already have at least a query for the buffer placement. E.g. you can already check if the BO is in GTT or VRAM and shared.

What's missing is exposing if the device can scanout from GTT or not.

Requiring Wayland compositors to have driver-specific knowledge like that baked in isn't great either.

Signature · 2 lines
Earthling Michel Dänzer            |                  https://redhat.com
Libre software enthusiast          |         Mesa and Xwayland developer
#8 lore raw
Quoted 10 lines · Michel Dänzer
Quoted 9 lines · Christian König

Am 23.02.24 um 09:11 schrieb Michel Dänzer:

Quoted 8 lines · Christian König
Quoted 7 lines

Am 22.02.24 um 18:28 schrieb Michel Dänzer:

Quoted 4 lines

From: Michel Dänzer <[email protected]>

Pinning the BO storage to VRAM for scanout would make it inaccessible to non-P2P dma-buf importers.

Thinking more about it I don't think we can do this.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

Using the BO in a ping/pong fashion for scanout and DMA-buf is actually valid, you just can't do both at the same time.

And if I'm not completely mistaken we actually have use cases for this at the moment,

Those use cases don't have P2P & CONFIG_DMABUF_MOVE_NOTIFY?

Nope, we are basically talking about unit tests and examples for inter device operations.

Sounds like the "no user-space regressions" rule might not apply then.

To clarify what I mean by that:

"We can't fix this issue, because it would break some unit tests and examples" is similar to saying "We can't fix this KMS bug, because there are IGT tests expecting the buggy behaviour". In practice, the latter do get fixed, along with the IGT tests.

Signature · 2 lines
Earthling Michel Dänzer            |                  https://redhat.com
Libre software enthusiast          |         Mesa and Xwayland developer
maintainer
#9 lore raw

Am 23.02.24 um 17:43 schrieb Michel Dänzer:

Quoted 13 lines · Michel Dänzer
Quoted 12 lines · Christian König
Quoted 11 lines

Am 23.02.24 um 09:11 schrieb Michel Dänzer:

Quoted 10 lines · Christian König
Quoted 9 lines

Am 22.02.24 um 18:28 schrieb Michel Dänzer:

Quoted 4 lines

From: Michel Dänzer <[email protected]>

Pinning the BO storage to VRAM for scanout would make it inaccessible to non-P2P dma-buf importers.

Thinking more about it I don't think we can do this.

Using the BO in a ping/pong fashion for scanout and DMA-buf is actually valid, you just can't do both at the same time.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

And if I'm not completely mistaken we actually have use cases for this at the moment,

Those use cases don't have P2P & CONFIG_DMABUF_MOVE_NOTIFY?

Nope, we are basically talking about unit tests and examples for inter device operations.

Sounds like the "no user-space regressions" rule might not apply then.

To clarify what I mean by that:

"We can't fix this issue, because it would break some unit tests and examples" is similar to saying "We can't fix this KMS bug, because there are IGT tests expecting the buggy behaviour". In practice, the latter do get fixed, along with the IGT tests.

The problem here is that this is not a bug, but intentional behavior. Exporting BOs and using them in scanout in a ping/pong fashion is perfectly valid.

We have use cases which depend on this behavior and I'm not going to break those to fix your use case.

So as far as I can see this approach here is a no-go.

Regards,
Christian.

#10 lore raw
Quoted 15 lines · Christian König

Am 23.02.24 um 17:43 schrieb Michel Dänzer:

Quoted 14 lines · Michel Dänzer
Quoted 13 lines · Christian König
Quoted 12 lines

Am 23.02.24 um 09:11 schrieb Michel Dänzer:

Quoted 11 lines · Christian König
Quoted 10 lines

Am 22.02.24 um 18:28 schrieb Michel Dänzer:

Quoted 4 lines

From: Michel Dänzer <[email protected]>

Pinning the BO storage to VRAM for scanout would make it inaccessible to non-P2P dma-buf importers.

Thinking more about it I don't think we can do this.

Using the BO in a ping/pong fashion for scanout and DMA-buf is actually valid, you just can't do both at the same time.

And if I'm not completely mistaken we actually have use cases for this at the moment,

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

Those use cases don't have P2P & CONFIG_DMABUF_MOVE_NOTIFY?

Nope, we are basically talking about unit tests and examples for inter device operations.

Sounds like the "no user-space regressions" rule might not apply then.

To clarify what I mean by that:

"We can't fix this issue, because it would break some unit tests and examples" is similar to saying "We can't fix this KMS bug, because there are IGT tests expecting the buggy behaviour". In practice, the latter do get fixed, along with the IGT tests.

The problem here is that this is not a bug, but intentional behavior. Exporting BOs and using them in scanout in a ping/pong fashion is perfectly valid.

The problem with the status quo is that it requires amdgpu-specific knowledge and worst-case pessimization in user space.

Quoted 1 line

We have use cases which depend on this behavior and I'm not going to break those to fix your use case.

It's not "my" use case, it's a Wayland compositor trying to make use of BO sharing and scanout without always pessimizing for the worst case.

That's surely more of a real-world use case than unit tests and examples.

Signature · 2 lines
Earthling Michel Dänzer            |                  https://redhat.com
Libre software enthusiast          |         Mesa and Xwayland developer
maintainer
#11 lore raw

Am 26.02.24 um 17:27 schrieb Michel Dänzer:

Quoted 16 lines · Christian König
Quoted 15 lines

Am 23.02.24 um 17:43 schrieb Michel Dänzer:

Quoted 14 lines · Michel Dänzer
Quoted 13 lines · Christian König
Quoted 12 lines

Am 23.02.24 um 09:11 schrieb Michel Dänzer:

Quoted 11 lines · Christian König
Quoted 10 lines

Am 22.02.24 um 18:28 schrieb Michel Dänzer:

Quoted 4 lines

From: Michel Dänzer<[email protected]>

Pinning the BO storage to VRAM for scanout would make it inaccessible to non-P2P dma-buf importers.

Thinking more about it I don't think we can do this.

Using the BO in a ping/pong fashion for scanout and DMA-buf is actually valid, you just can't do both at the same time.

And if I'm not completely mistaken we actually have use cases for this at the moment,

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

Those use cases don't have P2P & CONFIG_DMABUF_MOVE_NOTIFY?

Nope, we are basically talking about unit tests and examples for inter device operations.

Sounds like the "no user-space regressions" rule might not apply then.

To clarify what I mean by that:

"We can't fix this issue, because it would break some unit tests and examples" is similar to saying "We can't fix this KMS bug, because there are IGT tests expecting the buggy behaviour". In practice, the latter do get fixed, along with the IGT tests.

The problem here is that this is not a bug, but intentional behavior. Exporting BOs and using them in scanout in a ping/pong fashion is perfectly valid.

The problem with the status quo is that it requires amdgpu-specific knowledge and worst-case pessimization in user space.

Yeah, I'm perfectly aware of that. But that approach here really doesn't seems to be valid.

Quoted 4 lines
Quoted 1 line

We have use cases which depend on this behavior and I'm not going to break those to fix your use case.

It's not "my" use case, it's a Wayland compositor trying to make use of BO sharing and scanout without always pessimizing for the worst case.

That's surely more of a real-world use case than unit tests and examples.

I've looked a bit deeper into this and we have told customers for the last ~10 years or so that this is how it is supposed to work and that they can use this approach.

So this is much more than unit tests and examples, we are changing existing behavior which is clearly not a bug but intentional and have a very high chance to break valid use cases.

My question is why has it worked so far? I mean we are not doing this since yesterday and the problem only shows up now?

While I see the use case something is still missing in that picture.

Christian.

#12 lore raw
Quoted 19 lines · Christian König

Am 26.02.24 um 17:27 schrieb Michel Dänzer:

Quoted 18 lines · Christian König
Quoted 17 lines

Am 23.02.24 um 17:43 schrieb Michel Dänzer:

Quoted 16 lines · Michel Dänzer
Quoted 15 lines · Christian König
Quoted 14 lines

Am 23.02.24 um 09:11 schrieb Michel Dänzer:

Quoted 12 lines · Christian König
Quoted 10 lines

Am 22.02.24 um 18:28 schrieb Michel Dänzer:

Quoted 4 lines

From: Michel Dänzer <[email protected]>

Pinning the BO storage to VRAM for scanout would make it inaccessible to non-P2P dma-buf importers.

Thinking more about it I don't think we can do this.

Using the BO in a ping/pong fashion for scanout and DMA-buf is actually valid, you just can't do both at the same time.

And if I'm not completely mistaken we actually have use cases for this at the moment,

Those use cases don't have P2P & CONFIG_DMABUF_MOVE_NOTIFY?

Nope, we are basically talking about unit tests and examples for inter device operations.

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

Sounds like the "no user-space regressions" rule might not apply then.

To clarify what I mean by that:

"We can't fix this issue, because it would break some unit tests and examples" is similar to saying "We can't fix this KMS bug, because there are IGT tests expecting the buggy behaviour". In practice, the latter do get fixed, along with the IGT tests.

The problem here is that this is not a bug, but intentional behavior. Exporting BOs and using them in scanout in a ping/pong fashion is perfectly valid.

The problem with the status quo is that it requires amdgpu-specific knowledge and worst-case pessimization in user space.

Yeah, I'm perfectly aware of that. But that approach here really doesn't seems to be valid.

It's the only known sane approach at this point. There's no other proposal which allows using both BO sharing and scanout without pessimizing or hitting seemingly random CS ioctl failures.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

We have use cases which depend on this behavior and I'm not going to break those to fix your use case.

It's not "my" use case, it's a Wayland compositor trying to make use of BO sharing and scanout without always pessimizing for the worst case.

That's surely more of a real-world use case than unit tests and examples.

I've looked a bit deeper into this and we have told customers for the last ~10 years or so that this is how it is supposed to work and that they can use this approach.

So this is much more than unit tests and examples, we are changing existing behavior which is clearly not a bug but intentional and have a very high chance to break valid use cases.

"Very high chance" sounds like you still don't know of any actual real-world use case relying on it though?

Quoted 1 line

My question is why has it worked so far? I mean we are not doing this since yesterday and the problem only shows up now?

Yes, Wayland compositors are only starting to try and make use of this now.

Signature · 2 lines
Earthling Michel Dänzer            |                  https://redhat.com
Libre software enthusiast          |         Mesa and Xwayland developer
#13 lore raw
Quoted 5 lines · Michel Dänzer
Quoted 1 line · Christian König

My question is why has it worked so far? I mean we are not doing this since yesterday and the problem only shows up now?

Yes, Wayland compositors are only starting to try and make use of this now.

To expand on this, mutter will want to do something like this as well sooner or later. I suspect it's the same for others like kwin, sway etc.

Signature · 2 lines
Earthling Michel Dänzer            |                  https://redhat.com
Libre software enthusiast          |         Mesa and Xwayland developer
maintainer
#14 lore raw

Am 26.02.24 um 17:50 schrieb Michel Dänzer:

Quoted 6 lines · Michel Dänzer
Quoted 4 lines · Christian König
Quoted 2 lines

My question is why has it worked so far? I mean we are not doing this since yesterday and the problem only shows up now?

Yes, Wayland compositors are only starting to try and make use of this now.

To expand on this, mutter will want to do something like this as well sooner or later. I suspect it's the same for others like kwin, sway etc.

Yeah, but we have done similar things with X decades before. E.g. basically the client sends a BO to the server for displaying it.

Why we suddenly have to juggle with the fact that it is DMA-buf shared with another device? This has worked for at least a decade before.

Regards,
Christian.

#15 lore raw
Quoted 9 lines · Christian König

Am 26.02.24 um 17:50 schrieb Michel Dänzer:

Quoted 6 lines · Michel Dänzer
Quoted 4 lines · Christian König
Quoted 2 lines

My question is why has it worked so far? I mean we are not doing this since yesterday and the problem only shows up now?

Yes, Wayland compositors are only starting to try and make use of this now.

To expand on this, mutter will want to do something like this as well sooner or later. I suspect it's the same for others like kwin, sway etc.

Yeah, but we have done similar things with X decades before. E.g. basically the client sends a BO to the server for displaying it.

The scenario in https://gitlab.freedesktop.org/mesa/mesa/-/issues/10635 is direct scanout of a client buffer on a secondary dGPU, while the compositor uses the APU as the primary compositing GPU.

AFAIR Xorg has never supported direct scanout of client buffers in this scenario. Secondary GPU scanout is always done from a separate local buffer allocated by Xorg / the driver.

This is Wayland compositors pushing the envelope.

Quoted 1 line

Why we suddenly have to juggle with the fact that it is DMA-buf shared with another device?

The problematic case is if the Wayland compositor has to produce a composited frame (e.g. due to a notification or other window popping up over the fullscreen window), but the client hasn't attached a new buffer to the fullscreen surface, so the compositor has to use the contents of the same client buffer which is still being scanned out by the dGPU for compositing with the APU.

Signature · 2 lines
Earthling Michel Dänzer            |                  https://redhat.com
Libre software enthusiast          |         Mesa and Xwayland developer