From: Anthoine Bourgeois <anthoine.bourgeois@gmail.com>
To: Gurchetan Singh <gurchetansingh@chromium.org>
Cc: virtio-dev@lists.oasis-open.org, mst@redhat.com,
dri-devel@lists.freedesktop.org, sebastien.boeuf@intel.com,
kraxel@redhat.com, vgoyal@redhat.com
Subject: Re: [PATCH 23/24] drm/virtio: implement blob resources: resource create blob ioctl
Date: Mon, 17 Aug 2020 19:46:57 +0200 [thread overview]
Message-ID: <20200817174657.GA237811@gmail.com> (raw)
In-Reply-To: <20200814024000.2485-24-gurchetansingh@chromium.org>
On Thu, Aug 13, 2020 at 07:39:59PM -0700, Gurchetan Singh wrote:
>From: Gerd Hoffmann <kraxel@redhat.com>
>
>Implement resource create blob as specified.
>
>Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
>Co-developed-by: Gurchetan Singh <gurchetansingh@chromium.org>
>Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org>
>Acked-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
>---
> drivers/gpu/drm/virtio/virtgpu_drv.h | 4 +-
> drivers/gpu/drm/virtio/virtgpu_ioctl.c | 136 ++++++++++++++++++++++++
> drivers/gpu/drm/virtio/virtgpu_object.c | 5 +-
> drivers/gpu/drm/virtio/virtgpu_vram.c | 2 +
> 4 files changed, 144 insertions(+), 3 deletions(-)
>
>diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h
>index 444b65c8d4ee..3e9ec5b1fb63 100644
>--- a/drivers/gpu/drm/virtio/virtgpu_drv.h
>+++ b/drivers/gpu/drm/virtio/virtgpu_drv.h
>@@ -255,8 +255,8 @@ struct virtio_gpu_fpriv {
> struct mutex context_lock;
> };
>
>-/* virtgpu_ioctl.c */
>-#define DRM_VIRTIO_NUM_IOCTLS 10
>+/* virtio_ioctl.c */
>+#define DRM_VIRTIO_NUM_IOCTLS 11
> extern struct drm_ioctl_desc virtio_gpu_ioctls[DRM_VIRTIO_NUM_IOCTLS];
> void virtio_gpu_create_context(struct drm_device *dev, struct drm_file *file);
>
>diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
>index 7dbe24248a20..47ac32b7031a 100644
>--- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
>+++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
>@@ -34,6 +34,10 @@
>
> #include "virtgpu_drv.h"
>
>+#define VIRTGPU_BLOB_FLAG_USE_MASK (VIRTGPU_BLOB_FLAG_USE_MAPPABLE | \
>+ VIRTGPU_BLOB_FLAG_USE_SHAREABLE | \
>+ VIRTGPU_BLOB_FLAG_USE_CROSS_DEVICE)
>+
> void virtio_gpu_create_context(struct drm_device *dev, struct drm_file *file)
> {
> struct virtio_gpu_device *vgdev = dev->dev_private;
>@@ -520,6 +524,134 @@ static int virtio_gpu_get_caps_ioctl(struct drm_device *dev,
> return 0;
> }
>
>+static int verify_blob(struct virtio_gpu_device *vgdev,
>+ struct virtio_gpu_fpriv *vfpriv,
>+ struct virtio_gpu_object_params *params,
>+ struct drm_virtgpu_resource_create_blob *rc_blob,
>+ bool *guest_blob, bool *host3d_blob)
>+{
>+ if (!vgdev->has_resource_blob)
>+ return -EINVAL;
>+
>+ if ((rc_blob->blob_flags & ~VIRTGPU_BLOB_FLAG_USE_MASK) ||
>+ !rc_blob->blob_flags)
>+ return -EINVAL;
>+
>+ if (rc_blob->blob_flags & VIRTGPU_BLOB_FLAG_USE_CROSS_DEVICE) {
>+ if (!vgdev->has_resource_assign_uuid)
>+ return -EINVAL;
>+ }
>+
>+ switch (rc_blob->blob_mem) {
>+ case VIRTGPU_BLOB_MEM_GUEST:
>+ *guest_blob = true;
>+ break;
>+ case VIRTGPU_BLOB_MEM_HOST3D_GUEST:
>+ *guest_blob = true;
>+ fallthrough;
>+ case VIRTGPU_BLOB_MEM_HOST3D:
>+ *host3d_blob = true;
>+ break;
>+ default:
>+ return -EINVAL;
>+ }
>+
>+ if (*host3d_blob) {
>+ if (!vgdev->has_virgl_3d)
>+ return -EINVAL;
>+
>+ /* Must be dword aligned. */
>+ if ((rc_blob->cmd_size) % 4 != 0)
>+ return -EINVAL;
>+
>+ params->ctx_id = vfpriv->ctx_id;
>+ params->blob_id = rc_blob->blob_id;
>+ } else {
>+ if (rc_blob->blob_id != 0)
>+ return -EINVAL;
>+
>+ if (rc_blob->cmd_size != 0)
>+ return -EINVAL;
>+ }
>+
>+ params->blob_mem = rc_blob->blob_mem;
>+ params->size = rc_blob->size;
>+ params->blob = true;
>+ params->blob_flags = rc_blob->blob_flags;
>+ return 0;
>+}
>+
>+static int virtio_gpu_resource_create_blob(struct drm_device *dev,
>+ void *data, struct drm_file *file)
>+{
>+ int ret = 0;
>+ uint32_t handle = 0;
>+ struct drm_gem_object *obj;
>+ struct virtio_gpu_object *bo;
>+ bool host3d_blob, guest_blob;
>+ struct virtio_gpu_object_params params = { 0 };
>+ struct virtio_gpu_device *vgdev = dev->dev_private;
>+ struct virtio_gpu_fpriv *vfpriv = file->driver_priv;
>+ struct drm_virtgpu_resource_create_blob *rc_blob = data;
>+
>+ guest_blob = host3d_blob = false;
>+ if (verify_blob(vgdev, vfpriv, ¶ms, rc_blob,
>+ &guest_blob, &host3d_blob))
>+ return -EINVAL;
>+
>+ if (vgdev->has_virgl_3d)
>+ virtio_gpu_create_context(dev, file);
>+
>+ if (rc_blob->cmd_size) {
>+ void *buf;
>+
>+ buf = memdup_user(u64_to_user_ptr(rc_blob->cmd),
>+ rc_blob->cmd_size);
>+
>+ if (IS_ERR(buf))
>+ return PTR_ERR(buf);
>+
>+ virtio_gpu_cmd_submit(vgdev, buf, rc_blob->cmd_size,
>+ vfpriv->ctx_id, NULL, NULL);
>+ }
>+
>+ if (guest_blob)
>+ ret = virtio_gpu_object_create(vgdev, ¶ms, &bo, NULL);
>+ else if (!guest_blob && host3d_blob)
>+ ret = virtio_gpu_vram_create(vgdev, ¶ms, &bo);
>+ else
>+ return -EINVAL;
>+
>+ if (ret < 0)
>+ return ret;
>+
>+ bo->guest_blob = guest_blob;
>+ bo->host3d_blob = host3d_blob;
>+ bo->blob_mem = rc_blob->blob_mem;
>+ bo->blob_flags = rc_blob->blob_flags;
>+
>+ obj = &bo->base.base;
>+ if (params.blob_flags & VIRTGPU_BLOB_FLAG_USE_CROSS_DEVICE) {
>+ ret = virtio_gpu_resource_assign_uuid(vgdev, bo);
>+ if (ret) {
>+ drm_gem_object_release(obj);
>+ return ret;
>+ }
>+ }
>+
>+ ret = drm_gem_handle_create(file, obj, &handle);
>+ if (ret) {
>+ drm_gem_object_release(obj);
>+ return ret;
>+ }
>+ drm_gem_object_put(obj);
>+
>+ rc_blob->res_handle = bo->hw_res_handle;
>+ rc_blob->bo_handle = handle;
>+
>+ return 0;
>+}
>+
> struct drm_ioctl_desc virtio_gpu_ioctls[DRM_VIRTIO_NUM_IOCTLS] = {
> DRM_IOCTL_DEF_DRV(VIRTGPU_MAP, virtio_gpu_map_ioctl,
> DRM_RENDER_ALLOW),
>@@ -552,4 +684,8 @@ struct drm_ioctl_desc virtio_gpu_ioctls[DRM_VIRTIO_NUM_IOCTLS] = {
>
> DRM_IOCTL_DEF_DRV(VIRTGPU_GET_CAPS, virtio_gpu_get_caps_ioctl,
> DRM_RENDER_ALLOW),
>+
>+ DRM_IOCTL_DEF_DRV(VIRTGPU_RESOURCE_CREATE_BLOB,
>+ virtio_gpu_resource_create_blob,
Should the function be suffixed by _ioctl like the others?
Other than than, all the serie is:
Reviewed-by: Anthoine Bourgeois <anthoine.bourgeois@gmail.com>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2020-08-17 17:47 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-14 2:39 [PATCH 00/24] Blob prerequisites + blob resources Gurchetan Singh
2020-08-14 2:39 ` [PATCH 01/24] drm/virtio: Revert "drm/virtio: Call the right shmem helpers" Gurchetan Singh
2020-08-14 2:39 ` [PATCH 02/24] virtio: add dma-buf support for exported objects Gurchetan Singh
2020-08-14 2:39 ` [PATCH 03/24] virtio-gpu: add VIRTIO_GPU_F_RESOURCE_UUID feature Gurchetan Singh
2020-08-14 2:39 ` [PATCH 04/24] drm/virtio: Support virtgpu exported resources Gurchetan Singh
2020-08-14 2:39 ` [PATCH 05/24] virtio: Add get_shm_region method Gurchetan Singh
2020-08-14 2:39 ` [PATCH 06/24] virtio: Implement get_shm_region for PCI transport Gurchetan Singh
2020-08-14 2:39 ` [PATCH 07/24] virtio: Implement get_shm_region for MMIO transport Gurchetan Singh
2020-08-14 2:39 ` [PATCH 08/24] drm/virtio: blob prep: refactor getting pages and attaching backing Gurchetan Singh
2020-08-14 2:39 ` [PATCH 09/24] drm/virtio: blob prep: make CPU responses more generic Gurchetan Singh
2020-08-14 2:39 ` [PATCH 10/24] virtio-gpu api: blob resources Gurchetan Singh
2020-08-14 2:39 ` [PATCH 11/24] virtio-gpu api: host visible feature Gurchetan Singh
2020-08-14 2:39 ` [PATCH 12/24] virtio-gpu api: cross-device feature Gurchetan Singh
2020-08-14 2:39 ` [PATCH 13/24] drm/virtio: implement blob resources: probe for the feature Gurchetan Singh
2020-08-14 2:39 ` [PATCH 14/24] drm/virtio: implement blob resources: probe for host visible region Gurchetan Singh
2020-08-16 13:10 ` kernel test robot
2020-08-14 2:39 ` [PATCH 15/24] drm/virtio: implement blob resources: expose virtio_gpu_resource_id_get Gurchetan Singh
2020-08-14 2:39 ` [PATCH 16/24] drm/virtio: implement blob resources: add new fields to internal structs Gurchetan Singh
2020-08-14 2:39 ` [PATCH 17/24] drm/virtio: implement blob resources: implement vram object Gurchetan Singh
2020-08-14 5:39 ` kernel test robot
2020-08-14 2:39 ` [PATCH 18/24] drm/virtio: implement blob resources: hypercall interface Gurchetan Singh
2020-08-14 6:12 ` kernel test robot
2020-08-14 2:39 ` [PATCH 19/24] drm/virtio: implement blob resources: blob display integration Gurchetan Singh
2020-08-14 2:39 ` [PATCH 20/24] drm/virtio: implement blob resources: refactor UUID code somewhat Gurchetan Singh
2020-08-14 2:39 ` [PATCH 21/24] drm/virtio: implement blob resources: fix stride discrepancy Gurchetan Singh
2020-08-14 2:39 ` [PATCH 22/24] drm/virtio: implement blob resources: report blob mem to userspace Gurchetan Singh
2020-08-14 2:39 ` [PATCH 23/24] drm/virtio: implement blob resources: resource create blob ioctl Gurchetan Singh
2020-08-17 17:46 ` Anthoine Bourgeois [this message]
2020-08-14 2:40 ` [PATCH 24/24] drm/virtio: advertise features to userspace Gurchetan Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200817174657.GA237811@gmail.com \
--to=anthoine.bourgeois@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gurchetansingh@chromium.org \
--cc=kraxel@redhat.com \
--cc=mst@redhat.com \
--cc=sebastien.boeuf@intel.com \
--cc=vgoyal@redhat.com \
--cc=virtio-dev@lists.oasis-open.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox