Skip to contentSkip to conversation

drm/virtio: Defer the host dumb buffer creation

PATCH In review Jocelyn Falempe 3 participants 8 messages Sep 3, 2024 – Sep 17, 2024

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

PATCH v2 1/2 drm/virtio: Defer the host dumb buffer creation

The host dumb buffer command needs a format, but the DRM_IOCTL_MODE_CREATE_DUMB only provides a buffer size.
So wait for the DRM_IOCTL_MODE_ADDFB(2), to get the format, and create the host resources at this time.

This will allow virtio-gpu to support multiple pixel formats.

This problem was noticed in commit 42fd9e6c29b39 ("drm/virtio: fix DRM_FORMAT_* handling")

---

v2:
* Move virtio_gpu_object deferred field to its own block (Geerd Hoffmann)
* Check that the size of the dumb buffer can hold the framebuffer (Geerd Hoffmann)

 drivers/gpu/drm/virtio/virtgpu_display.c | 33 ++++++++++++++++++++++++
 drivers/gpu/drm/virtio/virtgpu_drv.h     |  5 ++++
 drivers/gpu/drm/virtio/virtgpu_gem.c     |  1 -
 drivers/gpu/drm/virtio/virtgpu_object.c  | 13 +++++++---
 4 files changed, 47 insertions(+), 5 deletions(-)
drivers/gpu/drm/virtio/virtgpu_display.c +33 -0
index 64baf2f22d9f0..5e8ca742c6d00 100644
@@ -290,6 +290,30 @@ static int vgdev_output_init(struct virtio_gpu_device *vgdev, int index)
 	return 0;
 }
 
+static int virtio_gpu_deferred_create(struct virtio_gpu_object *bo,
+				      struct virtio_gpu_device *vgdev,
+				      const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+	struct virtio_gpu_object_params params = { 0 };
+
+	params.format = virtio_gpu_translate_format(mode_cmd->pixel_format);
+	params.dumb = true;
+	params.width = mode_cmd->width;
+	params.height = mode_cmd->height;
+	params.size = params.height * params.width * 4;
+	params.size = ALIGN(params.size, PAGE_SIZE);
+
+	if (params.size > bo->base.base.size)
+		return -EINVAL;
+
+	virtio_gpu_cmd_create_resource(vgdev, bo, &params, NULL, NULL);
+	virtio_gpu_object_attach(vgdev, bo, bo->ents, bo->nents);
+
+	bo->deferred = false;
+	bo->ents = NULL;
+	return 0;
+}
+
 static struct drm_framebuffer *
 virtio_gpu_user_framebuffer_create(struct drm_device *dev,
 				   struct drm_file *file_priv,
@@ -297,6 +321,8 @@ virtio_gpu_user_framebuffer_create(struct drm_device *dev,
 {
 	struct drm_gem_object *obj = NULL;
 	struct virtio_gpu_framebuffer *virtio_gpu_fb;
+	struct virtio_gpu_device *vgdev = dev->dev_private;
+	struct virtio_gpu_object *bo;
 	int ret;
 
 	if (mode_cmd->pixel_format != DRM_FORMAT_HOST_XRGB8888 &&
@@ -308,6 +334,13 @@ virtio_gpu_user_framebuffer_create(struct drm_device *dev,
 	if (!obj)
 		return ERR_PTR(-EINVAL);
 
+	bo = gem_to_virtio_gpu_obj(obj);
+	if (bo->deferred) {
+		ret = virtio_gpu_deferred_create(bo, vgdev, mode_cmd);
+		if (ret)
+			return ERR_PTR(ret);
+	}
+
 	virtio_gpu_fb = kzalloc(sizeof(*virtio_gpu_fb), GFP_KERNEL);
 	if (virtio_gpu_fb == NULL) {
 		drm_gem_object_put(obj);
drivers/gpu/drm/virtio/virtgpu_drv.h +5 -0
index 64c236169db88..4302933e5067c 100644
@@ -95,6 +95,11 @@ struct virtio_gpu_object {
 	bool host3d_blob, guest_blob;
 	uint32_t blob_mem, blob_flags;
 
+	/* For deferred dumb buffer creation */
+	bool deferred;
+	struct virtio_gpu_mem_entry *ents;
+	unsigned int nents;
+
 	int uuid_state;
 	uuid_t uuid;
 };
drivers/gpu/drm/virtio/virtgpu_gem.c +0 -1
index 7db48d17ee3a8..33ad15fed30f6 100644
@@ -75,7 +75,6 @@ int virtio_gpu_mode_dumb_create(struct drm_file *file_priv,
 	args->size = pitch * args->height;
 	args->size = ALIGN(args->size, PAGE_SIZE);
 
-	params.format = virtio_gpu_translate_format(DRM_FORMAT_HOST_XRGB8888);
 	params.width = args->width;
 	params.height = args->height;
 	params.size = args->size;
drivers/gpu/drm/virtio/virtgpu_object.c +9 -4
index c7e74cf130221..b5a537a761294 100644
@@ -67,6 +67,8 @@ void virtio_gpu_cleanup_object(struct virtio_gpu_object *bo)
 
 	virtio_gpu_resource_id_put(vgdev, bo->hw_res_handle);
 	if (virtio_gpu_is_shmem(bo)) {
+		if (bo->deferred)
+			kvfree(bo->ents);
 		drm_gem_shmem_free(&bo->base);
 	} else if (virtio_gpu_is_vram(bo)) {
 		struct virtio_gpu_object_vram *vram = to_virtio_gpu_vram(bo);
@@ -228,10 +230,13 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
 		virtio_gpu_cmd_resource_create_3d(vgdev, bo, params,
 						  objs, fence);
 		virtio_gpu_object_attach(vgdev, bo, ents, nents);
-	} else {
-		virtio_gpu_cmd_create_resource(vgdev, bo, params,
-					       objs, fence);
-		virtio_gpu_object_attach(vgdev, bo, ents, nents);
+	} else if (params->dumb) {
+		/* Create the host resource in virtio_gpu_user_framebuffer_create()
+		 * because the pixel format is not specified yet
+		 */
+		bo->ents = ents;
+		bo->nents = nents;
+		bo->deferred = true;
 	}
 
 	*bo_ptr = bo;

base-commit: 9345e3aab7fef06b8908308634974ea32a29e276

Signature · 1 line
2.46.0
#1 lore raw

PATCH v2 2/2 drm/virtio: Add support for XRGB8888 and BGRX8888

On big endian machine, fbdev wants BGRX8888, but gnome/wayland wants XRGB8888, which wasn't possible because virtio-gpu could only support one format. Now that it's fixed, it can support both.

---
 drivers/gpu/drm/virtio/virtgpu_display.c | 6 ++++--
 drivers/gpu/drm/virtio/virtgpu_plane.c   | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/gpu/drm/virtio/virtgpu_display.c +4 -2
index 5e8ca742c6d00..b94d16134b8cf 100644
@@ -325,8 +325,10 @@ virtio_gpu_user_framebuffer_create(struct drm_device *dev,
 	struct virtio_gpu_object *bo;
 	int ret;
 
-	if (mode_cmd->pixel_format != DRM_FORMAT_HOST_XRGB8888 &&
-	    mode_cmd->pixel_format != DRM_FORMAT_HOST_ARGB8888)
+	if (mode_cmd->pixel_format != DRM_FORMAT_XRGB8888 &&
+	    mode_cmd->pixel_format != DRM_FORMAT_ARGB8888 &&
+	    mode_cmd->pixel_format != DRM_FORMAT_BGRX8888 &&
+	    mode_cmd->pixel_format != DRM_FORMAT_BGRA8888)
 		return ERR_PTR(-ENOENT);
 
 	/* lookup object associated with res handle */
drivers/gpu/drm/virtio/virtgpu_plane.c +4 -2
index a72a2dbda031c..32fbe30b45a46 100644
@@ -30,11 +30,13 @@
 #include "virtgpu_drv.h"
 
 static const uint32_t virtio_gpu_formats[] = {
-	DRM_FORMAT_HOST_XRGB8888,
+	DRM_FORMAT_XRGB8888,
+	DRM_FORMAT_BGRX8888,
 };
 
 static const uint32_t virtio_gpu_cursor_formats[] = {
-	DRM_FORMAT_HOST_ARGB8888,
+	DRM_FORMAT_ARGB8888,
+	DRM_FORMAT_BGRA8888,
 };
 
 uint32_t virtio_gpu_translate_format(uint32_t drm_fourcc)
Signature · 1 line
2.46.0
maintainer Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] drm/virtio: Add support for XRGB8888 and BGRX8888

Quoted 3 lines · Jocelyn Falempe

On big endian machine, fbdev wants BGRX8888, but gnome/wayland wants XRGB8888, which wasn't possible because virtio-gpu could only support one format. Now that it's fixed, it can support both.

take care,
Gerd

maintainer Reviewed-by on v2 1/2
#3 lore raw
In reply to Jocelyn Falempe

Hi,

drivers/gpu/drm/virtio/virtgpu_object.c int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, · line 240

Quoted 12 lines
drivers/gpu/drm/virtio/virtgpu_object.c +7 -4
-	} else {
-		virtio_gpu_cmd_create_resource(vgdev, bo, params,
-					       objs, fence);
-		virtio_gpu_object_attach(vgdev, bo, ents, nents);
+	} else if (params->dumb) {
+		/* Create the host resource in virtio_gpu_user_framebuffer_create()
+		 * because the pixel format is not specified yet
+		 */
+		bo->ents = ents;
+		bo->nents = nents;
+		bo->deferred = true;
 	}
else {
	return -EINVAL;
}

I think this should not happen, because non-dumb buffers are only created with virgl being active. Nevertheless we should catch this case and return an error, maybe even have a WARN_ONCE() there.

Otherwise looks good to me, so with that fixed:

take care,
Gerd

maintainer
#4 lore raw
In reply to Jocelyn Falempe
Quoted 103 lines · Jocelyn Falempe

The host dumb buffer command needs a format, but the DRM_IOCTL_MODE_CREATE_DUMB only provides a buffer size.
So wait for the DRM_IOCTL_MODE_ADDFB(2), to get the format, and create the host resources at this time.

This will allow virtio-gpu to support multiple pixel formats.

This problem was noticed in commit 42fd9e6c29b39 ("drm/virtio: fix DRM_FORMAT_* handling")

---

v2:
* Move virtio_gpu_object deferred field to its own block (Geerd Hoffmann)
* Check that the size of the dumb buffer can hold the framebuffer (Geerd Hoffmann)

 drivers/gpu/drm/virtio/virtgpu_display.c | 33 ++++++++++++++++++++++++
 drivers/gpu/drm/virtio/virtgpu_drv.h     |  5 ++++
 drivers/gpu/drm/virtio/virtgpu_gem.c     |  1 -
 drivers/gpu/drm/virtio/virtgpu_object.c  | 13 +++++++---
 4 files changed, 47 insertions(+), 5 deletions(-)
drivers/gpu/drm/virtio/virtgpu_display.c +33 -0
index 64baf2f22d9f0..5e8ca742c6d00 100644
@@ -290,6 +290,30 @@ static int vgdev_output_init(struct virtio_gpu_device *vgdev, int index)
 	return 0;
 }
 
+static int virtio_gpu_deferred_create(struct virtio_gpu_object *bo,
+				      struct virtio_gpu_device *vgdev,
+				      const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+	struct virtio_gpu_object_params params = { 0 };
+
+	params.format = virtio_gpu_translate_format(mode_cmd->pixel_format);
+	params.dumb = true;
+	params.width = mode_cmd->width;
+	params.height = mode_cmd->height;
+	params.size = params.height * params.width * 4;
+	params.size = ALIGN(params.size, PAGE_SIZE);
+
+	if (params.size > bo->base.base.size)
+		return -EINVAL;
+
+	virtio_gpu_cmd_create_resource(vgdev, bo, &params, NULL, NULL);
+	virtio_gpu_object_attach(vgdev, bo, bo->ents, bo->nents);
+
+	bo->deferred = false;
+	bo->ents = NULL;
+	return 0;
+}
+
 static struct drm_framebuffer *
 virtio_gpu_user_framebuffer_create(struct drm_device *dev,
 				   struct drm_file *file_priv,
@@ -297,6 +321,8 @@ virtio_gpu_user_framebuffer_create(struct drm_device *dev,
 {
 	struct drm_gem_object *obj = NULL;
 	struct virtio_gpu_framebuffer *virtio_gpu_fb;
+	struct virtio_gpu_device *vgdev = dev->dev_private;
+	struct virtio_gpu_object *bo;
 	int ret;
 
 	if (mode_cmd->pixel_format != DRM_FORMAT_HOST_XRGB8888 &&
@@ -308,6 +334,13 @@ virtio_gpu_user_framebuffer_create(struct drm_device *dev,
 	if (!obj)
 		return ERR_PTR(-EINVAL);
 
+	bo = gem_to_virtio_gpu_obj(obj);
+	if (bo->deferred) {
+		ret = virtio_gpu_deferred_create(bo, vgdev, mode_cmd);
+		if (ret)
+			return ERR_PTR(ret);
+	}
+
 	virtio_gpu_fb = kzalloc(sizeof(*virtio_gpu_fb), GFP_KERNEL);
 	if (virtio_gpu_fb == NULL) {
 		drm_gem_object_put(obj);
drivers/gpu/drm/virtio/virtgpu_drv.h +5 -0
index 64c236169db88..4302933e5067c 100644
@@ -95,6 +95,11 @@ struct virtio_gpu_object {
 	bool host3d_blob, guest_blob;
 	uint32_t blob_mem, blob_flags;
 
+	/* For deferred dumb buffer creation */
+	bool deferred;
+	struct virtio_gpu_mem_entry *ents;
+	unsigned int nents;
+
 	int uuid_state;
 	uuid_t uuid;
 };
drivers/gpu/drm/virtio/virtgpu_gem.c +0 -0
index 7db48d17ee3a8..33ad15fed30f6 100644

drivers/gpu/drm/virtio/virtgpu_gem.c int virtio_gpu_mode_dumb_create(struct drm_file *file_priv, · line 78

Quoted 4 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +0 -1
@@ -75,7 +75,6 @@ int virtio_gpu_mode_dumb_create(struct drm_file *file_priv,
 	args->size = pitch * args->height;
 	args->size = ALIGN(args->size, PAGE_SIZE);
 
-	params.format = virtio_gpu_translate_format(DRM_FORMAT_HOST_XRGB8888);

This will break the guest blob code path in virtio_gpu_object_create(), AFAICT.

Quoted 22 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +0 -0
 	params.width = args->width;
 	params.height = args->height;
 	params.size = args->size;
drivers/gpu/drm/virtio/virtgpu_object.c +2 -2
index c7e74cf130221..b5a537a761294 100644
@@ -67,6 +67,8 @@ void virtio_gpu_cleanup_object(struct virtio_gpu_object *bo)
 
 	virtio_gpu_resource_id_put(vgdev, bo->hw_res_handle);
 	if (virtio_gpu_is_shmem(bo)) {
+		if (bo->deferred)
+			kvfree(bo->ents);
 		drm_gem_shmem_free(&bo->base);
 	} else if (virtio_gpu_is_vram(bo)) {
 		struct virtio_gpu_object_vram *vram = to_virtio_gpu_vram(bo);
@@ -228,10 +230,13 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
 		virtio_gpu_cmd_resource_create_3d(vgdev, bo, params,
 						  objs, fence);
 		virtio_gpu_object_attach(vgdev, bo, ents, nents);
-	} else {
-		virtio_gpu_cmd_create_resource(vgdev, bo, params,

drivers/gpu/drm/virtio/virtgpu_object.c int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, · line 240

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_object.c +7 -2
-					       objs, fence);
-		virtio_gpu_object_attach(vgdev, bo, ents, nents);
+	} else if (params->dumb) {
+		/* Create the host resource in virtio_gpu_user_framebuffer_create()
+		 * because the pixel format is not specified yet
+		 */
+		bo->ents = ents;
+		bo->nents = nents;
+		bo->deferred = true;
 	}

AFAICS, the "params.dumb = true" should be set in virtio_gpu_mode_dumb_create() and not in virtio_gpu_deferred_create(). Was this patch tested?

Overall, this deferred resource creation doesn't look robust. Could be better to either add SET_SCANOUT2 with the format info or add cmd that overrides the res fmt.

#5 lore raw
Quoted 107 lines · Dmitry Osipenko
Quoted 106 lines · Jocelyn Falempe

The host dumb buffer command needs a format, but the DRM_IOCTL_MODE_CREATE_DUMB only provides a buffer size.
So wait for the DRM_IOCTL_MODE_ADDFB(2), to get the format, and create the host resources at this time.

This will allow virtio-gpu to support multiple pixel formats.

This problem was noticed in commit 42fd9e6c29b39 ("drm/virtio: fix DRM_FORMAT_* handling")

---

v2:
* Move virtio_gpu_object deferred field to its own block (Geerd Hoffmann)
* Check that the size of the dumb buffer can hold the framebuffer (Geerd Hoffmann)

  drivers/gpu/drm/virtio/virtgpu_display.c | 33 ++++++++++++++++++++++++
  drivers/gpu/drm/virtio/virtgpu_drv.h     |  5 ++++
  drivers/gpu/drm/virtio/virtgpu_gem.c     |  1 -
  drivers/gpu/drm/virtio/virtgpu_object.c  | 13 +++++++---
  4 files changed, 47 insertions(+), 5 deletions(-)
drivers/gpu/drm/virtio/virtgpu_display.c +33 -0
index 64baf2f22d9f0..5e8ca742c6d00 100644
@@ -290,6 +290,30 @@ static int vgdev_output_init(struct virtio_gpu_device *vgdev, int index)
  	return 0;
  }
 
+static int virtio_gpu_deferred_create(struct virtio_gpu_object *bo,
+				      struct virtio_gpu_device *vgdev,
+				      const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+	struct virtio_gpu_object_params params = { 0 };
+
+	params.format = virtio_gpu_translate_format(mode_cmd->pixel_format);
+	params.dumb = true;
+	params.width = mode_cmd->width;
+	params.height = mode_cmd->height;
+	params.size = params.height * params.width * 4;
+	params.size = ALIGN(params.size, PAGE_SIZE);
+
+	if (params.size > bo->base.base.size)
+		return -EINVAL;
+
+	virtio_gpu_cmd_create_resource(vgdev, bo, &params, NULL, NULL);
+	virtio_gpu_object_attach(vgdev, bo, bo->ents, bo->nents);
+
+	bo->deferred = false;
+	bo->ents = NULL;
+	return 0;
+}
+
  static struct drm_framebuffer *
  virtio_gpu_user_framebuffer_create(struct drm_device *dev,
  				   struct drm_file *file_priv,
@@ -297,6 +321,8 @@ virtio_gpu_user_framebuffer_create(struct drm_device *dev,
  {
  	struct drm_gem_object *obj = NULL;
  	struct virtio_gpu_framebuffer *virtio_gpu_fb;
+	struct virtio_gpu_device *vgdev = dev->dev_private;
+	struct virtio_gpu_object *bo;
  	int ret;
 
  	if (mode_cmd->pixel_format != DRM_FORMAT_HOST_XRGB8888 &&
@@ -308,6 +334,13 @@ virtio_gpu_user_framebuffer_create(struct drm_device *dev,
  	if (!obj)
  		return ERR_PTR(-EINVAL);
 
+	bo = gem_to_virtio_gpu_obj(obj);
+	if (bo->deferred) {
+		ret = virtio_gpu_deferred_create(bo, vgdev, mode_cmd);
+		if (ret)
+			return ERR_PTR(ret);
+	}
+
  	virtio_gpu_fb = kzalloc(sizeof(*virtio_gpu_fb), GFP_KERNEL);
  	if (virtio_gpu_fb == NULL) {
  		drm_gem_object_put(obj);
drivers/gpu/drm/virtio/virtgpu_drv.h +5 -0
index 64c236169db88..4302933e5067c 100644
@@ -95,6 +95,11 @@ struct virtio_gpu_object {
  	bool host3d_blob, guest_blob;
  	uint32_t blob_mem, blob_flags;
 
+	/* For deferred dumb buffer creation */
+	bool deferred;
+	struct virtio_gpu_mem_entry *ents;
+	unsigned int nents;
+
  	int uuid_state;
  	uuid_t uuid;
  };
drivers/gpu/drm/virtio/virtgpu_gem.c +0 -0
index 7db48d17ee3a8..33ad15fed30f6 100644
@@ -75,7 +75,6 @@ int virtio_gpu_mode_dumb_create(struct drm_file *file_priv,
  	args->size = pitch * args->height;
  	args->size = ALIGN(args->size, PAGE_SIZE);
 
Quoted 4 lines

drivers/gpu/drm/virtio/virtgpu_gem.c int virtio_gpu_mode_dumb_create(struct drm_file *file_priv, · line 78

Quoted 1 line
drivers/gpu/drm/virtio/virtgpu_gem.c +0 -1
-	params.format = virtio_gpu_translate_format(DRM_FORMAT_HOST_XRGB8888);

This will break the guest blob code path in virtio_gpu_object_create(), AFAICT.

The params.format is not used in virtio_gpu_cmd_resource_create_3d() nor in virtio_gpu_cmd_resource_create_blob(), it's only used for dumb buffer creation. So it shouldn't break the guest blob path.

Quoted 29 lines
Quoted 29 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +0 -0
  	params.width = args->width;
  	params.height = args->height;
  	params.size = args->size;
drivers/gpu/drm/virtio/virtgpu_object.c +6 -4
index c7e74cf130221..b5a537a761294 100644
@@ -67,6 +67,8 @@ void virtio_gpu_cleanup_object(struct virtio_gpu_object *bo)
 
  	virtio_gpu_resource_id_put(vgdev, bo->hw_res_handle);
  	if (virtio_gpu_is_shmem(bo)) {
+		if (bo->deferred)
+			kvfree(bo->ents);
  		drm_gem_shmem_free(&bo->base);
  	} else if (virtio_gpu_is_vram(bo)) {
  		struct virtio_gpu_object_vram *vram = to_virtio_gpu_vram(bo);
@@ -228,10 +230,13 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
  		virtio_gpu_cmd_resource_create_3d(vgdev, bo, params,
  						  objs, fence);
  		virtio_gpu_object_attach(vgdev, bo, ents, nents);
-	} else {
-		virtio_gpu_cmd_create_resource(vgdev, bo, params,
-					       objs, fence);
-		virtio_gpu_object_attach(vgdev, bo, ents, nents);
+	} else if (params->dumb) {
+		/* Create the host resource in virtio_gpu_user_framebuffer_create()
+		 * because the pixel format is not specified yet
+		 */
Quoted 8 lines

drivers/gpu/drm/virtio/virtgpu_object.c int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, · line 240

Quoted 4 lines
drivers/gpu/drm/virtio/virtgpu_object.c +3 -0
+		bo->ents = ents;
+		bo->nents = nents;
+		bo->deferred = true;
  	}

AFAICS, the "params.dumb = true" should be set in virtio_gpu_mode_dumb_create() and not in virtio_gpu_deferred_create(). Was this patch tested?

You're right that params.dumb is not used in virtio_gpu_cmd_create_resource() so it's useless to set it in virtio_gpu_deferred_create(). I can remove that line. But it's also set in virtio_gpu_mode_dumb_create() and I didn't change that with this patch.

I'm testing on a s390x machine, and it allows wayland compositor to work. (The colors are still a mess, but at least it starts with this patch).

Quoted 5 lines

Overall, this deferred resource creation doesn't look robust. Could be better to either add SET_SCANOUT2 with the format info or add cmd that overrides the res fmt.

This would also need modification in the qemu code, so it looks much more complex than this patch.

Best regards,

Signature · 1 line
Jocelyn
maintainer
#6 lore raw

On 9/11/24 11:04, Jocelyn Falempe wrote:
...

Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +0 -0
@@ -75,7 +75,6 @@ int virtio_gpu_mode_dumb_create(struct drm_file
 *file_priv,
       args->size = pitch * args->height;
       args->size = ALIGN(args->size, PAGE_SIZE);

  -    params.format = virtio_gpu_translate_format(DRM_FORMAT_HOST_XRGB8888);

This will break the guest blob code path in virtio_gpu_object_create(), AFAICT.

Quoted 3 lines

The params.format is not used in virtio_gpu_cmd_resource_create_3d() nor in virtio_gpu_cmd_resource_create_blob(), it's only used for dumb buffer creation. So it shouldn't break the guest blob path.

Indeed

Quoted 46 lines
Quoted 31 lines
Quoted 31 lines

      params.width = args->width;
      params.height = args->height;
      params.size = args->size;

drivers/gpu/drm/virtio/virtgpu_object.c +6 -4
index c7e74cf130221..b5a537a761294 100644
@@ -67,6 +67,8 @@ void virtio_gpu_cleanup_object(struct
 virtio_gpu_object *bo)
         virtio_gpu_resource_id_put(vgdev, bo->hw_res_handle);
       if (virtio_gpu_is_shmem(bo)) {
+        if (bo->deferred)
+            kvfree(bo->ents);
           drm_gem_shmem_free(&bo->base);
       } else if (virtio_gpu_is_vram(bo)) {
           struct virtio_gpu_object_vram *vram = to_virtio_gpu_vram(bo);
@@ -228,10 +230,13 @@ int virtio_gpu_object_create(struct
 virtio_gpu_device *vgdev,
           virtio_gpu_cmd_resource_create_3d(vgdev, bo, params,
                             objs, fence);
           virtio_gpu_object_attach(vgdev, bo, ents, nents);
-    } else {
-        virtio_gpu_cmd_create_resource(vgdev, bo, params,
-                           objs, fence);
-        virtio_gpu_object_attach(vgdev, bo, ents, nents);
+    } else if (params->dumb) {
+        /* Create the host resource in
 virtio_gpu_user_framebuffer_create()
+         * because the pixel format is not specified yet
+         */
Quoted 8 lines

drivers/gpu/drm/virtio/virtgpu_object.c int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, · line 240

Quoted 4 lines
drivers/gpu/drm/virtio/virtgpu_object.c +3 -0
+        bo->ents = ents;
+        bo->nents = nents;
+        bo->deferred = true;
       }

AFAICS, the "params.dumb = true" should be set in virtio_gpu_mode_dumb_create() and not in virtio_gpu_deferred_create(). Was this patch tested?

You're right that params.dumb is not used in virtio_gpu_cmd_create_resource() so it's useless to set it in virtio_gpu_deferred_create(). I can remove that line.
But it's also set in virtio_gpu_mode_dumb_create() and I didn't change that with this patch.

Quoted 3 lines

I'm testing on a s390x machine, and it allows wayland compositor to work. (The colors are still a mess, but at least it starts with this patch).

The commit message of patch #2 says that it's fbdev that doesn't work because it uses BGRX8888, i.e. wayland should work without this patch, isn't it?

Please try to find why colors are wrong, could become that we won't need this patch anymore once you'll figure out the root of the problem.

Signature · 2 lines
Best regards,
Dmitry
maintainer
#7 lore raw
In reply to Dmitry Osipenko

Hi,

Quoted 9 lines
Quoted 8 lines
(quoted diff) +8 -0
+static int virtio_gpu_deferred_create(struct virtio_gpu_object *bo,
+				      struct virtio_gpu_device *vgdev,
+				      const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+	struct virtio_gpu_object_params params = { 0 };
+
+	params.format = virtio_gpu_translate_format(mode_cmd->pixel_format);
+	params.dumb = true;
Quoted 4 lines

Review

Quoted 1 line
(quoted diff) +0 -1
-	params.format = virtio_gpu_translate_format(DRM_FORMAT_HOST_XRGB8888);

This will break the guest blob code path in virtio_gpu_object_create(), AFAICT.

Good point.

Quoted 4 lines
Quoted 4 lines
(quoted diff) +4 -0
+	} else if (params->dumb) {
+		/* Create the host resource in virtio_gpu_user_framebuffer_create()
+		 * because the pixel format is not specified yet
+		 */
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +3 -0
+		bo->ents = ents;
+		bo->nents = nents;
+		bo->deferred = true;
 	}

AFAICS, the "params.dumb = true" should be set in virtio_gpu_mode_dumb_create() and not in virtio_gpu_deferred_create(). Was this patch tested?

virtio_gpu_deferred_create re-creates params from scratch, so it must set "params.dumb = true" too. That looks fine to me.

Quoted 3 lines

Overall, this deferred resource creation doesn't look robust. Could be better to either add SET_SCANOUT2 with the format info or add cmd that overrides the res fmt.

If we can solve this issue with a guest-side fix I'd very much prefer that. When adding device features for that the driver will have to support both old + new devices, which I don't think will be better in the end.

take care,
Gerd

PS: Figured how using blob resources on s390x should work
(tested in emulation only).
----------------------- cut here -----------------------

fedora-s390x-gfx-blob.xml 2024-09-11 11:29:54.662935454 +0200 renamed from fedora-s390x-gfx.xml 2024-09-11 11:29:57.864900808 +0200 +6 -3
@@ -1,8 +1,11 @@
 <domain type='qemu'>
-  <name>fedora-s390x-gfx</name>
-  <uuid>00e1b01c-f220-4d95-9d25-cd52c4284238</uuid>
+  <name>fedora-s390x-gfx-blob</name>
+  <uuid>2dcfa930-019d-4c25-8636-65abeed741c0</uuid>
   <memory unit='KiB'>4194304</memory>
   <currentMemory unit='KiB'>4194304</currentMemory>
+  <memoryBacking>
+    <source type='memfd'/>
+  </memoryBacking>
   <vcpu placement='static'>2</vcpu>
   <os>
     <type arch='s390x' machine='s390-ccw-virtio-6.2'>hvm</type>
@@ -59,7 +62,7 @@
     </graphics>
     <audio id='1' type='none'/>
     <video>
-      <model type='virtio' heads='1' primary='yes'/>
+      <model type='virtio' heads='1' primary='yes' blob='on'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'>
         <zpci uid='0x0001' fid='0x00000000'/>
       </address>