From patchwork Fri Feb 16 15:12:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 10224911 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 779AF603EE for ; Fri, 16 Feb 2018 15:12:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6768E2823D for ; Fri, 16 Feb 2018 15:12:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B3AC27F8E; Fri, 16 Feb 2018 15:12:25 +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 F224F294C7 for ; Fri, 16 Feb 2018 15:12:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CACBC6E613; Fri, 16 Feb 2018 15:12:23 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk0-f193.google.com (mail-qk0-f193.google.com [209.85.220.193]) by gabe.freedesktop.org (Postfix) with ESMTPS id 723C96E096 for ; Fri, 16 Feb 2018 15:12:22 +0000 (UTC) Received: by mail-qk0-f193.google.com with SMTP id c4so4161118qkm.2 for ; Fri, 16 Feb 2018 07:12:22 -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=WMhxJ1il8qXHodcuXwu5txtVBpKsbuLqX59qtu0pL/8=; b=bZjSxwhtKrkHrTzgy4RRp41IZ1bT46dHo4/bO0IzL288eWB84Hv6UZLRAKWYy5pMmZ 8ajxXAiQgEeLt+xKmC6pr7Ltkg30SUVGL7hawT+FQdBCfwOwzmxG5H3ao2mKtiNlkMje zwAC5HOxA4sd5JAia5l9IbfHzPQHZuQTiQ7s4tjkhZFPL5UBMzy2gAq380OW03UcAvsR b4ACz9NX0eU/ZH/Bm75UOBygJ46KopJ+s5ZKEd6j8a08jFVtTMcSdAokD7tfE/L0f/x8 Io5UdpPitBIolpMCOe5wQsZna9pncnvYldti9Mdnwr0Y/vfoXN15mdeRjdX9rLrEtAFW igjQ== X-Gm-Message-State: APf1xPBRQsd7QzeRyBpwiiLbEXBDL9G9ahy/zOWVB2Lzr1emaNDavApz 9q3rgaZuOhFNZvvee2qBraUovVXo X-Google-Smtp-Source: AH8x224loU6oATiRBqRyNdJuzPg+5btoJVbnjZY9ssEbJ8WBX6Ljv3y64Qv6zhxhPzjRvK2P7PPTSA== X-Received: by 10.55.139.2 with SMTP id n2mr10104210qkd.209.1518793941373; Fri, 16 Feb 2018 07:12:21 -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.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 16 Feb 2018 07:12:20 -0800 (PST) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 3/5] drm/virtio: add in-fences support for explicit synchronization Date: Fri, 16 Feb 2018 13:12:05 -0200 Message-Id: <20180216151207.28912-4-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 When the execbuf call receives an in-fence it will get the dma_fence related to that fence fd. If that fence is from a foreign context we wait on it before submitting the draw call. v2: - incorporate fix for context check from Rob Herring Signed-off-by: Gustavo Padovan Signed-off-by: Rob Herring virtio-gpu: fix context check We may have a foreign context from sw_sync, so we need to wait in that case. If there's a match, returning an error doesn't seem right either. Signed-off-by: Rob Herring --- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 42 ++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index bd46b0d76754..f3d1ffbbd430 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "virtgpu_drv.h" @@ -113,6 +114,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; @@ -120,6 +123,22 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, if (vgdev->has_virgl_3d == false) return -ENOSYS; + if (exbuf->flags & VIRTGPU_EXECBUF_FENCE_FD_IN) { + in_fence = sync_file_get_fence(in_fence_fd); + if (!in_fence) + return -EINVAL; + + /* + * Wait if the fence is from a foreign context, or if the fence + * array contains any fence from a foreign context. + */ + if (!dma_fence_match_context(in_fence, vgdev->fence_drv.context)) { + ret = dma_fence_wait(in_fence, true); + if (ret) + return ret; + } + } + INIT_LIST_HEAD(&validate_list); if (exbuf->num_bo_handles) { @@ -129,26 +148,22 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, sizeof(struct ttm_validate_buffer), GFP_KERNEL | __GFP_ZERO); if (!bo_handles || !buflist) { - kvfree(bo_handles); - kvfree(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; - kvfree(bo_handles); - kvfree(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) { - kvfree(bo_handles); - kvfree(buflist); - return -ENOENT; + ret = -ENOENT; + goto out_in_fence; } qobj = gem_to_virtio_gpu_obj(gobj); @@ -157,6 +172,7 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, list_add(&buflist[i].head, &validate_list); } kvfree(bo_handles); + bo_handles = NULL; } ret = virtio_gpu_object_list_validate(&ticket, &validate_list); @@ -177,6 +193,11 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, goto out_unresv; } + if (in_fence) { + dma_fence_put(in_fence); + in_fence = NULL; + } + virtio_gpu_cmd_submit(vgdev, buf, exbuf->size, vfpriv->ctx_id, fence); @@ -191,7 +212,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: + kvfree(bo_handles); kvfree(buflist); + dma_fence_put(in_fence); return ret; }