From: Gustavo Padovan <gustavo@padovan.org>
To: dri-devel@lists.freedesktop.org
Cc: robdclark@gmail.com,
Gustavo Padovan <gustavo.padovan@collabora.co.uk>,
David Airlie <airlied@linux.ie>,
Gerd Hoffmann <kraxel@redhat.com>,
virtualization@lists.linux-foundation.org (open list:VIRTIO GPU
DRIVER), linux-kernel@vger.kernel.org (open list)
Subject: [RFC 3/5] drm/virtio: add in-fences support for explicit synchronization
Date: Mon, 12 Dec 2016 18:48:27 -0200 [thread overview]
Message-ID: <1481575710-12535-3-git-send-email-gustavo@padovan.org> (raw)
In-Reply-To: <1481575710-12535-1-git-send-email-gustavo@padovan.org>
From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
When the execbuf call receives an in-fence it will get the dma_fence
related to that fence fd and wait on it before submitting the draw call.
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
drivers/gpu/drm/virtio/virtgpu_ioctl.c | 41 ++++++++++++++++++++++++++--------
1 file changed, 32 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
index d164b54..ac0b4b0 100644
--- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
+++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
@@ -29,6 +29,7 @@
#include "virtgpu_drv.h"
#include <drm/virtgpu_drm.h>
#include "ttm/ttm_execbuf_util.h"
+#include <linux/sync_file.h>
static void convert_to_hw_box(struct virtio_gpu_box *dst,
const struct drm_virtgpu_3d_box *src)
@@ -111,6 +112,8 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
struct ttm_validate_buffer *buflist = NULL;
int i;
struct ww_acquire_ctx ticket;
+ struct dma_fence *in_fence = NULL;
+ int in_fence_fd = exbuf->fence_fd;
void *buf;
exbuf->fence_fd = -1;
@@ -118,6 +121,19 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
if (vgdev->has_virgl_3d == false)
return -ENOSYS;
+ /* TODO: if the fence is a fence array we need to check
+ * the context of every single fence */
+ if (exbuf->flags & VIRTGPU_EXECBUF_FENCE_FD_IN) {
+ in_fence = sync_file_get_fence(in_fence_fd);
+ if (!in_fence)
+ return -EINVAL;
+
+ if (in_fence->context == vgdev->fence_drv.context) {
+ dma_fence_put(in_fence);
+ return -EINVAL;
+ }
+ }
+
INIT_LIST_HEAD(&validate_list);
if (exbuf->num_bo_handles) {
@@ -126,26 +142,22 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
buflist = drm_calloc_large(exbuf->num_bo_handles,
sizeof(struct ttm_validate_buffer));
if (!bo_handles || !buflist) {
- drm_free_large(bo_handles);
- drm_free_large(buflist);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto out_in_fence;
}
user_bo_handles = (void __user *)(uintptr_t)exbuf->bo_handles;
if (copy_from_user(bo_handles, user_bo_handles,
exbuf->num_bo_handles * sizeof(uint32_t))) {
ret = -EFAULT;
- drm_free_large(bo_handles);
- drm_free_large(buflist);
- return ret;
+ goto out_in_fence;
}
for (i = 0; i < exbuf->num_bo_handles; i++) {
gobj = drm_gem_object_lookup(drm_file, bo_handles[i]);
if (!gobj) {
- drm_free_large(bo_handles);
- drm_free_large(buflist);
- return -ENOENT;
+ ret = -ENOENT;
+ goto out_in_fence;
}
qobj = gem_to_virtio_gpu_obj(gobj);
@@ -154,6 +166,7 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
list_add(&buflist[i].head, &validate_list);
}
drm_free_large(bo_handles);
+ bo_handles = NULL;
}
ret = virtio_gpu_object_list_validate(&ticket, &validate_list);
@@ -173,6 +186,13 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
ret = -ENOMEM;
goto out_unresv;
}
+
+ if (in_fence) {
+ dma_fence_wait(in_fence, true);
+ dma_fence_put(in_fence);
+ in_fence = NULL;
+ }
+
virtio_gpu_cmd_submit(vgdev, buf, exbuf->size,
vfpriv->ctx_id, fence);
@@ -188,7 +208,10 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
ttm_eu_backoff_reservation(&ticket, &validate_list);
out_free:
virtio_gpu_unref_list(&validate_list);
+out_in_fence:
drm_free_large(buflist);
+ drm_free_large(bo_handles);
+ dma_fence_put(in_fence);
return ret;
}
--
2.5.5
next prev parent reply other threads:[~2016-12-12 20:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-12 20:48 [RFC 1/5] drm/virtio: add virtio_gpu_alloc_fence() Gustavo Padovan
2016-12-12 20:48 ` [RFC 2/5] drm/virtio: add uapi for in and out explicit fences Gustavo Padovan
2016-12-12 20:48 ` Gustavo Padovan [this message]
2016-12-12 20:48 ` [RFC 4/5] drm/virtio: add out-fences support for explicit synchronization Gustavo Padovan
2016-12-12 20:48 ` [RFC 5/5] drm/virtio: bump driver version after explicit synchronization addition Gustavo Padovan
2016-12-13 6:47 ` [RFC 1/5] drm/virtio: add virtio_gpu_alloc_fence() Gerd Hoffmann
2016-12-13 11:53 ` Gustavo Padovan
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=1481575710-12535-3-git-send-email-gustavo@padovan.org \
--to=gustavo@padovan.org \
--cc=airlied@linux.ie \
--cc=dri-devel@lists.freedesktop.org \
--cc=gustavo.padovan@collabora.co.uk \
--cc=kraxel@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=robdclark@gmail.com \
--cc=virtualization@lists.linux-foundation.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
all inboxes | Powered by JetHome®