From patchwork Mon Dec 12 20:48:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 9471283 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 1ADD5607D3 for ; Mon, 12 Dec 2016 20:48:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10AB428518 for ; Mon, 12 Dec 2016 20:48:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0536B2851B; Mon, 12 Dec 2016 20:48:58 +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 7D55328518 for ; Mon, 12 Dec 2016 20:48:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F18176E411; Mon, 12 Dec 2016 20:48:51 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-vk0-f67.google.com (mail-vk0-f67.google.com [209.85.213.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id 76D476E405 for ; Mon, 12 Dec 2016 20:48:46 +0000 (UTC) Received: by mail-vk0-f67.google.com with SMTP id w194so5017067vkw.3 for ; Mon, 12 Dec 2016 12:48:46 -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=2oV2JbFNORp85tM2tobBiw7+mDB4g0hsAhZMnrPx6tk=; b=F1Y6Eaa/nR1OugbN6+zu9y92lQv/UGqtb1q6raC4PCc2XJvn0IErM9GbEyii8uWCU8 mjs2UOnD/zaLEX39hY1BGSBGWrXpeLaQcNxaWaT2z1njr9wrxobywhMkIBUx5C49y5cn TLVDV+vNB+fTrfOeVLryEK1SW/NOSSLomqvxhgUiY2YztkZJp0CzMmFLNuUU0SIzgXzN CBO/bmwUoaB4ot0iwONLI1IEKNQAzKwy9j6wlGFBC5u6UsHn7eGjiADNk7WCKbauXlFs SNdFaTk6P2pzqTSez/eGzaEoBdFvKxTToOPedwQjfcvQ89Fdcf3A4TTKR72W34Z1K67O sWrg== X-Gm-Message-State: AKaTC014nebzCKRKh1FB+132HohlTcDo9BpcI56eLI67qcRtUMYEviNg2GgLuaF/nh5HhQ== X-Received: by 10.31.170.208 with SMTP id t199mr32554074vke.6.1481575725383; Mon, 12 Dec 2016 12:48:45 -0800 (PST) Received: from jade.localdomain ([187.64.235.185]) by smtp.gmail.com with ESMTPSA id y6sm12496436vkc.12.2016.12.12.12.48.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Dec 2016 12:48:45 -0800 (PST) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [RFC 4/5] drm/virtio: add out-fences support for explicit synchronization Date: Mon, 12 Dec 2016 18:48:28 -0200 Message-Id: <1481575710-12535-4-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 On the out-fence side we get fence returned by the submitted draw call and attach it to a sync_file and send the sync_file fd to userspace. On error -1 is returned to userspace. Signed-off-by: Gustavo Padovan --- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 51 ++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index ac0b4b0..f441928 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -103,7 +103,7 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, struct virtio_gpu_device *vgdev = dev->dev_private; struct virtio_gpu_fpriv *vfpriv = drm_file->driver_priv; struct drm_gem_object *gobj; - struct virtio_gpu_fence *fence; + struct virtio_gpu_fence *out_fence; struct virtio_gpu_object *qobj; int ret; uint32_t *bo_handles = NULL; @@ -113,7 +113,9 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, int i; struct ww_acquire_ctx ticket; struct dma_fence *in_fence = NULL; + struct sync_file *sync_file; int in_fence_fd = exbuf->fence_fd; + int out_fence_fd = -1; void *buf; exbuf->fence_fd = -1; @@ -134,6 +136,14 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, } } + if (exbuf->flags & VIRTGPU_EXECBUF_FENCE_FD_OUT) { + out_fence_fd = get_unused_fd_flags(O_CLOEXEC); + if (out_fence_fd < 0) { + ret = out_fence_fd; + goto out_in_fence; + } + } + INIT_LIST_HEAD(&validate_list); if (exbuf->num_bo_handles) { @@ -143,21 +153,21 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, sizeof(struct ttm_validate_buffer)); if (!bo_handles || !buflist) { ret = -ENOMEM; - goto out_in_fence; + goto out_unused_fd; } 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; - goto out_in_fence; + goto out_unused_fd; } for (i = 0; i < exbuf->num_bo_handles; i++) { gobj = drm_gem_object_lookup(drm_file, bo_handles[i]); if (!gobj) { ret = -ENOENT; - goto out_in_fence; + goto out_unused_fd; } qobj = gem_to_virtio_gpu_obj(gobj); @@ -180,11 +190,22 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, goto out_unresv; } - fence = virtio_gpu_fence_alloc(vgdev); - if (!fence) { - kfree(buf); + out_fence = virtio_gpu_fence_alloc(vgdev); + if(!out_fence) { ret = -ENOMEM; - goto out_unresv; + goto out_memdup; + } + + if (out_fence_fd >= 0) { + sync_file = sync_file_create(dma_fence_get(&out_fence->f)); + if (!sync_file) { + dma_fence_put(&out_fence->f); + ret = -ENOMEM; + goto out_memdup; + } + + exbuf->fence_fd = out_fence_fd; + fd_install(out_fence_fd, sync_file->file); } if (in_fence) { @@ -194,23 +215,29 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, } virtio_gpu_cmd_submit(vgdev, buf, exbuf->size, - vfpriv->ctx_id, fence); + vfpriv->ctx_id, out_fence); - ttm_eu_fence_buffer_objects(&ticket, &validate_list, &fence->f); + ttm_eu_fence_buffer_objects(&ticket, &validate_list, &out_fence->f); /* fence the command bo */ virtio_gpu_unref_list(&validate_list); drm_free_large(buflist); - dma_fence_put(&fence->f); + dma_fence_put(&out_fence->f); return 0; +out_memdup: + kfree(buf); out_unresv: ttm_eu_backoff_reservation(&ticket, &validate_list); out_free: virtio_gpu_unref_list(&validate_list); -out_in_fence: +out_unused_fd: drm_free_large(buflist); drm_free_large(bo_handles); + + if (out_fence_fd >= 0) + put_unused_fd(out_fence_fd); +out_in_fence: dma_fence_put(in_fence); return ret; }