From patchwork Fri Feb 16 15:12:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 10224919 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 A97D2603EE for ; Fri, 16 Feb 2018 15:12:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 993482823D for ; Fri, 16 Feb 2018 15:12:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E13F2851A; Fri, 16 Feb 2018 15:12:31 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 13FF62823D for ; Fri, 16 Feb 2018 15:12:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4BC386E651; Fri, 16 Feb 2018 15:12:30 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk0-f194.google.com (mail-qk0-f194.google.com [209.85.220.194]) by gabe.freedesktop.org (Postfix) with ESMTPS id BA9AD6E64D for ; Fri, 16 Feb 2018 15:12:24 +0000 (UTC) Received: by mail-qk0-f194.google.com with SMTP id f25so4160169qkm.0 for ; Fri, 16 Feb 2018 07:12:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ucPiCewbT8RyMGDDtJNrNHW6SVc2gWpWy/zSItKqlBw=; b=naEhcPBualKj1s7BVgTC5BsMFoBvrGCHH1h0zcKxZ9iVbcK03p4WeNZvKo6ZX6XBSP f3wotnca0H6rPCg3mC/isamvmWrJxAX7K8Tkr460lZ8rBKjy7Aq6d1Oaj+8djjB1KBEQ 5v6krW+j3H/z++MdFv2eQlR/+D9VwZKMLx4ZtWxegFP6klzaCndCfpda8sZTTMtkIy97 mfV+4cn2LwGXJfUyWdhBP+tgR24nQ9yQ1Qmyk8Oxa+ETETw5CgeUihhJU7lAakpowb68 JEhL9QstKgcZgI+axJ23E6TEXOYEBcVAMElavBq0hTapSxlxikHY8/oasnyMQZlzb0Kf QnzA== X-Gm-Message-State: APf1xPD+1yQripwJ2hCI5VKYTqiNbJQRXGMLnyNn0Wu1z2C2NwMjPClg bwhEEHH+MPJpkcr+VtBnPSfb3XaD X-Google-Smtp-Source: AH8x227qYjKJ1SWaoijrMYW64/ZR/2WInVwGRvuolngLDUpMcpNXBTASQ/mTxDmS/L4GpU0pZ9p+hA== X-Received: by 10.55.197.79 with SMTP id p76mr8688605qki.337.1518793943626; Fri, 16 Feb 2018 07:12:23 -0800 (PST) Received: from localhost.localdomain ([2804:14c:138:2ada:c36a:f21:635:771c]) by smtp.gmail.com with ESMTPSA id c42sm13326473qtc.42.2018.02.16.07.12.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 16 Feb 2018 07:12:23 -0800 (PST) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 4/5] drm/virtio: add out-fences support for explicit synchronization Date: Fri, 16 Feb 2018 13:12:06 -0200 Message-Id: <20180216151207.28912-5-gustavo@padovan.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180216151207.28912-1-gustavo@padovan.org> References: <20180216151207.28912-1-gustavo@padovan.org> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel@collabora.com, Gerd Hoffmann , Gustavo Padovan 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 | 49 ++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index f3d1ffbbd430..a015663d87d2 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -105,7 +105,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; @@ -115,7 +115,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; @@ -139,6 +141,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) { @@ -149,21 +159,21 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, GFP_KERNEL | __GFP_ZERO); 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); @@ -186,11 +196,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(&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) { @@ -199,22 +220,28 @@ 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); kvfree(buflist); 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: kvfree(bo_handles); kvfree(buflist); + + if (out_fence_fd >= 0) + put_unused_fd(out_fence_fd); +out_in_fence: dma_fence_put(in_fence); return ret; }