From patchwork Mon Dec 12 20:48:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 9471281 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D71F4607D3 for ; Mon, 12 Dec 2016 20:48:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD18628518 for ; Mon, 12 Dec 2016 20:48:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C23942851B; Mon, 12 Dec 2016 20:48:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 75AA928518 for ; Mon, 12 Dec 2016 20:48:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2008C6E406; Mon, 12 Dec 2016 20:48:47 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ua0-f195.google.com (mail-ua0-f195.google.com [209.85.217.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id C567D6E3FE for ; Mon, 12 Dec 2016 20:48:43 +0000 (UTC) Received: by mail-ua0-f195.google.com with SMTP id b35so9802432uaa.1 for ; Mon, 12 Dec 2016 12:48:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7jixrsYM0MjGtTl4QvJRhGIlUsPSiBTkXVV1LcZ6s2I=; b=W+9pDV3x3PeJiNzVM5f9wyqjAbfSNDUUXQyyywilOFtqjbtN2e6YaV8tvlDTCGsSaM eNMjm0x42MfpDzZC0BO/IrhZ9FGksRJhyJEBxm4NW0kWN54m8KnRSw3z2K7kzC6XzYRg DLgudx/piDqCpgKJowYV1emuzMZEz5dAVfL9ayqPpQxp7rmL3auL9rBa3SmS9Oxp3a4g kZCzaPEVSyOBEdLeO5t5DhUT3004EJAR++w6jLpLf3qqASWnjSr51Dhniwvks/g4w75e F8pk+fuQ8ahYWiveejM4yAbiodJRdvC1vfxh2OAx/VEoP+FvF4psmivHx+zD4ME0LjUN YU4w== X-Gm-Message-State: AKaTC00YMY1+UcPuR53slh1OBs+DubFlMa3sTodf4LKBcB3y3LIDWYp9U46eKkPhtIfYVw== X-Received: by 10.159.55.142 with SMTP id q14mr78612589uaq.107.1481575722634; Mon, 12 Dec 2016 12:48:42 -0800 (PST) Received: from jade.localdomain ([187.64.235.185]) by smtp.gmail.com with ESMTPSA id y6sm12496436vkc.12.2016.12.12.12.48.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Dec 2016 12:48:42 -0800 (PST) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [RFC 3/5] drm/virtio: add in-fences support for explicit synchronization Date: Mon, 12 Dec 2016 18:48:27 -0200 Message-Id: <1481575710-12535-3-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1481575710-12535-1-git-send-email-gustavo@padovan.org> References: <1481575710-12535-1-git-send-email-gustavo@padovan.org> Cc: open list , "open list:VIRTIO GPU DRIVER" , Gerd Hoffmann , Gustavo Padovan X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Gustavo Padovan 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 --- 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 #include "ttm/ttm_execbuf_util.h" +#include 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; }