From patchwork Wed Feb 5 18:19:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chia-I Wu X-Patchwork-Id: 11366881 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C4D3921 for ; Wed, 5 Feb 2020 18:20:13 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EEC93217F4 for ; Wed, 5 Feb 2020 18:20:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="B4urB/rL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EEC93217F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 975086F919; Wed, 5 Feb 2020 18:20:11 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by gabe.freedesktop.org (Postfix) with ESMTPS id E376E6F919 for ; Wed, 5 Feb 2020 18:20:10 +0000 (UTC) Received: by mail-pl1-x642.google.com with SMTP id t6so1215038plj.5 for ; Wed, 05 Feb 2020 10:20:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ESAWQGiTJHtVjz116jPsFkeJFDiAPiDLtVdAr+9t9t0=; b=B4urB/rLosYqlKVL9teR0DmGCgbMHzCcyXbYOyHLkgFwoGqgCxLXOPsGc2y2v/Y9Zm doWSdA7pmDvzMx+bV30WH9HhKH8v/YhcNsrVx9LOFISUjb1zr4pji4dPln+TejH4oT6L 3gS/w8/y3pdz3VhKuko/HdhP4Scm0LCh2H+88MX692Xi3eumEGuBTJt05UzNvGjkAlQ7 um4EcXMVgBtGyGRbhczLmyG21TBbRq0owGgVrTp5FOKR43A/XmXsCTexiIAdxOnEcd2L 4e9lNKw++bt/NZMzihetJUxam51wqJ1M2mky/B8uTZaswU8/UX2ZN0KSGZV3X9m3qba1 aGXg== 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:mime-version:content-transfer-encoding; bh=ESAWQGiTJHtVjz116jPsFkeJFDiAPiDLtVdAr+9t9t0=; b=P8ZLhK0d+agqrskgryTU+/Kdq3rqR2V4DNL9OF/wXPJFY8+rfElfe4U/ser+7dwUss qZWp4qqYdyNiz6JofPDK2ukLE1A4qcpjkryOonLBFZX+yaP9y6R5TrN8XmvXKYC2nFQD MF6h0Sg2WfiKol+kGhy2l1khzCdgVy5cL4OgbUGWfBnQcLSOiYqMoNS87VTTN7VMko94 XyjqINUzEqbaQvrFaYp1g0ocvTOa9stoiP3+nhaMtmoac5v9TZHR1v9Iz7Uh4JWfxGZU AegQQRXDb4Ad0sCPsKGIIjyDVYgt+fAJk8XMwtJ/oRkr9d+HEPHWSMYeDldIZNaaiRal 59xA== X-Gm-Message-State: APjAAAXkT3Vg7nTVudy3pjWOWPQwH4mz0O+zkNjj+lVOsF8kE6VCH6UW 33BVzxuBB4rzXcyRs4m/rHqpWWdV X-Google-Smtp-Source: APXvYqwlfuqoYpfV3dMgCW5yN+OosR8hmjs+KoViZQiSor4fP9CgWVtSAF/qSHVN8/892C4qgsyJ6A== X-Received: by 2002:a17:902:e789:: with SMTP id cp9mr36161399plb.85.1580926810236; Wed, 05 Feb 2020 10:20:10 -0800 (PST) Received: from olv0.mtv.corp.google.com ([2620:15c:202:201:9649:82d6:f889:b307]) by smtp.gmail.com with ESMTPSA id h10sm158201pfo.181.2020.02.05.10.20.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 10:20:09 -0800 (PST) From: Chia-I Wu To: dri-devel@lists.freedesktop.org Subject: [PATCH 01/11] drm/virtio: fix a wait_event condition Date: Wed, 5 Feb 2020 10:19:45 -0800 Message-Id: <20200205181955.202485-2-olvaffe@gmail.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200205181955.202485-1-olvaffe@gmail.com> References: <20200205181955.202485-1-olvaffe@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kraxel@redhat.com, gurchetansingh@chromium.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" outcnt may be greater than 1 since commit e1218b8c0cc1 (drm/virtio: Use vmalloc for command buffer allocations.). Signed-off-by: Chia-I Wu Cc: David Riley --- drivers/gpu/drm/virtio/virtgpu_vq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index 5914e79d3429f..5169e8dd9fd6c 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -391,7 +391,8 @@ static void virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, */ if (vq->num_free < 2 + outcnt) { spin_unlock(&vgdev->ctrlq.qlock); - wait_event(vgdev->ctrlq.ack_queue, vq->num_free >= 3); + wait_event(vgdev->ctrlq.ack_queue, + vq->num_free >= 2 + outcnt); goto again; } From patchwork Wed Feb 5 18:19:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chia-I Wu X-Patchwork-Id: 11366883 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2722C17E0 for ; Wed, 5 Feb 2020 18:20:16 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0592C217BA for ; Wed, 5 Feb 2020 18:20:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nfyIAhLz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0592C217BA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B7CE06F91B; Wed, 5 Feb 2020 18:20:13 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3178D6F91C for ; Wed, 5 Feb 2020 18:20:12 +0000 (UTC) Received: by mail-pl1-x642.google.com with SMTP id g6so1218108plt.2 for ; Wed, 05 Feb 2020 10:20:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Tg40qP+ShitFGj8IpEOqFMhiCtZwoJkfbIFcmVhDNiI=; b=nfyIAhLzQtHFVXiNYYVDzni4jQ3EbZb3tf/u7OxOPBbXlwmEZCuFz/LcZY5I39HaSP BcVj+7XvuLzzPZupoUWEy8hKx/lJ4lFw1TaaZbSIhXVx4CbHDmLpkkugrFXYSOZxfHwg n6+UH8utSNg91/fV7u/3589w+XFFnNFeIChnzQWXIaTz7RL21Qzke0xoeRux6QmGV1lV NVuTxupxowvWjvFwu2xjRA5Bc2sWXI8aa3a+nrE+1TIOKs8nXdL9lAHKyxsLJbre2Jse uAFRk7M3pl7sLVX0A4H2CxksFc2+ZN23cYdRihi1W/dRFoIZvK00ozpZU88wHNL9Zpj5 UJzQ== 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:mime-version:content-transfer-encoding; bh=Tg40qP+ShitFGj8IpEOqFMhiCtZwoJkfbIFcmVhDNiI=; b=pPFxNSPvR7Hbw+nzLHw5rtBy3Q3wvaUCYSo6OwH0WrctW0xP5N6OWTu9nbsog2RyUj L5coJZXojnQVaZRVNJkP6lzL+JTt+B219/6J9ULX65hMfYxqgxU9FkbQhgloiXT+CSIH JV2a0b/Yqnm8S9q/agWQU360t4WuohqtI2QlXSk9YmoUorMSN6Qw2DE/FKct18zBNIWi fZJKtnKzW/jbQdFLskI4vCx/MhsSpg5zInFrU66Is3xRTOiHlCem3ffG1IEVn4hWk6FI FLEXtJ3MQpBWeai0hKOFrArZb+a94QjXGdk4aBQC5GDq2MpMqywCncT61/GifdTvhjRK iifg== X-Gm-Message-State: APjAAAVi0D6Y+RSl9I4vNu1WhKR8VfTVhDPumPB6tAtesXeKR1njWE6Q 3Fo/IQRtpC5+c7Uw/wOUlmBk1RDl X-Google-Smtp-Source: APXvYqztm7Z12UxbDSOIxpfKJ4eMcBX9iQWyMkWkZWtKSMg/uTtK94KIGS323jgGbjaVbf1ieqOf/A== X-Received: by 2002:a17:902:7c95:: with SMTP id y21mr35789204pll.186.1580926811371; Wed, 05 Feb 2020 10:20:11 -0800 (PST) Received: from olv0.mtv.corp.google.com ([2620:15c:202:201:9649:82d6:f889:b307]) by smtp.gmail.com with ESMTPSA id h10sm158201pfo.181.2020.02.05.10.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 10:20:10 -0800 (PST) From: Chia-I Wu To: dri-devel@lists.freedesktop.org Subject: [PATCH 02/11] drm/virtio: remove incorrect ENOSPC check Date: Wed, 5 Feb 2020 10:19:46 -0800 Message-Id: <20200205181955.202485-3-olvaffe@gmail.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200205181955.202485-1-olvaffe@gmail.com> References: <20200205181955.202485-1-olvaffe@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kraxel@redhat.com, gurchetansingh@chromium.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The handling of virtqueue_add_sgs ENOSPC error is incorrect because it can result in out-of-order virtqueue_add_sgs and break fences. We never get ENOSPC anyway because the caller waits until there is enough space (the other caller that did not wait was removed in commit 32d6c2c5b522). Remove the incorrect and unnecessary error path. This also adds a WARN_ON(ret) until we properly handle errors. Signed-off-by: Chia-I Wu Cc: David Riley --- drivers/gpu/drm/virtio/virtgpu_vq.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index 5169e8dd9fd6c..63d2df7fb0c98 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -310,8 +310,6 @@ static struct sg_table *vmalloc_to_sgt(char *data, uint32_t size, int *sg_ents) static bool virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev, struct virtio_gpu_vbuffer *vbuf, struct scatterlist *vout) - __releases(&vgdev->ctrlq.qlock) - __acquires(&vgdev->ctrlq.qlock) { struct virtqueue *vq = vgdev->ctrlq.vq; struct scatterlist *sgs[3], vcmd, vresp; @@ -337,19 +335,14 @@ static bool virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev, incnt++; } -retry: ret = virtqueue_add_sgs(vq, sgs, outcnt, incnt, vbuf, GFP_ATOMIC); - if (ret == -ENOSPC) { - spin_unlock(&vgdev->ctrlq.qlock); - wait_event(vgdev->ctrlq.ack_queue, vq->num_free >= outcnt + incnt); - spin_lock(&vgdev->ctrlq.qlock); - goto retry; - } else { - trace_virtio_gpu_cmd_queue(vq, - (struct virtio_gpu_ctrl_hdr *)vbuf->buf); + WARN_ON(ret); + + trace_virtio_gpu_cmd_queue(vq, + (struct virtio_gpu_ctrl_hdr *)vbuf->buf); + + notify = virtqueue_kick_prepare(vq); - notify = virtqueue_kick_prepare(vq); - } return notify; } From patchwork Wed Feb 5 18:19:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chia-I Wu X-Patchwork-Id: 11366885 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1B31D17E0 for ; Wed, 5 Feb 2020 18:20:19 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ECE8322314 for ; Wed, 5 Feb 2020 18:20:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fiYk8LIi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ECE8322314 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 08D006F91C; Wed, 5 Feb 2020 18:20:14 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by gabe.freedesktop.org (Postfix) with ESMTPS id E22496F91B for ; Wed, 5 Feb 2020 18:20:12 +0000 (UTC) Received: by mail-pf1-x442.google.com with SMTP id p14so1630748pfn.4 for ; Wed, 05 Feb 2020 10:20:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nuDRUYblmVNgz6OAds6obhdyd2/H8B/Wptu9R/XCM90=; b=fiYk8LIizlKW0OuZpLkGKArjUW12ALV3fM/0XswaM9NclH5ZJmuCBdQ+JfecwV7NTC 0UrbSz+X128Aqd4SxdCf9PEmuaHalEqhoWLnL5MqmdGU+vYCqg5wlYxVnWVkt1oWLnvV Mp0zEnk58DTvG5XJkv8xhVsAAsT0fedxTUrSo7onWLW9ybkLGvcSUb51CS7X/f7qAMY2 8NtdofXXFqgScXyUTz5CsONTbQggy5nUKD8++6IvK1PIO55nXzzyih7oBkNbxL+H8TRm zEwvqkOPgOvYXtnutM3LAemLtAqB2Dlx3QrdMyplYZ4N+jvJklGK4PXMvPE9IrXj8HIV NuVQ== 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:mime-version:content-transfer-encoding; bh=nuDRUYblmVNgz6OAds6obhdyd2/H8B/Wptu9R/XCM90=; b=J7HYR+cXv36aItqFG4kPfYvmIDj61dd0qspUMNF/hqouxwqSBEIg17JimQl9c3TA9o 2/f/9pITVPzA5OWewHZgUkG9uadm0Acdc2/b9I6YBArCkpkUkKWk5PDv0lvz59CDU4lQ 8573ZEI+wN4RsjTc7xTyZ07zAY/2B46mI1G5ohDHYHj80meXzUVQoxBesqvm5pZ6GWvy xLyBSIIBPPHWBi8lfvSaPSlsPgvHwhwk9NWTsagYSb/4YdZ8DfFlR34bwgw/QY0w3fgq WoEiFDEv3z0gOVztf3aSWEpfY5S06gPmETzrwQSOg6r1+7EZWJT6VBCzC3GTSDlotz72 43hw== X-Gm-Message-State: APjAAAURGJESkexuiECabzUyvO00dxSQfGygZL51h7MbZWm+PjYuYLl4 8ZttJF2MmfXXZQdXxddsI+3aYsow X-Google-Smtp-Source: APXvYqwZGkc+1TAIQT2uWZ7JOYju33UboZ5hvnCyU5wBUoU7uJbdKULZURFawwSndZmHTJb8/1b2cg== X-Received: by 2002:a63:e007:: with SMTP id e7mr6778394pgh.414.1580926812023; Wed, 05 Feb 2020 10:20:12 -0800 (PST) Received: from olv0.mtv.corp.google.com ([2620:15c:202:201:9649:82d6:f889:b307]) by smtp.gmail.com with ESMTPSA id h10sm158201pfo.181.2020.02.05.10.20.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 10:20:11 -0800 (PST) From: Chia-I Wu To: dri-devel@lists.freedesktop.org Subject: [PATCH 03/11] drm/virtio: add virtio_gpu_vbuf_ctrl_hdr Date: Wed, 5 Feb 2020 10:19:47 -0800 Message-Id: <20200205181955.202485-4-olvaffe@gmail.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200205181955.202485-1-olvaffe@gmail.com> References: <20200205181955.202485-1-olvaffe@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kraxel@redhat.com, gurchetansingh@chromium.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" It is a helper to return the virtio_gpu_ctrl_hdr in a vbuf. Signed-off-by: Chia-I Wu --- drivers/gpu/drm/virtio/virtgpu_vq.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index 63d2df7fb0c98..312fd8a039a1e 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -95,7 +95,8 @@ virtio_gpu_get_vbuf(struct virtio_gpu_device *vgdev, if (!vbuf) return ERR_PTR(-ENOMEM); - BUG_ON(size > MAX_INLINE_CMD_SIZE); + BUG_ON(size > MAX_INLINE_CMD_SIZE || + size < sizeof(struct virtio_gpu_ctrl_hdr)); vbuf->buf = (void *)vbuf + sizeof(*vbuf); vbuf->size = size; @@ -109,6 +110,16 @@ virtio_gpu_get_vbuf(struct virtio_gpu_device *vgdev, return vbuf; } +static struct virtio_gpu_ctrl_hdr * +virtio_gpu_vbuf_ctrl_hdr(struct virtio_gpu_vbuffer *vbuf) +{ + /* this assumes a vbuf contains a command that starts with a + * virtio_gpu_ctrl_hdr, which is true for both ctrl and cursor + * virtqueues. + */ + return (struct virtio_gpu_ctrl_hdr *)vbuf->buf; +} + static void *virtio_gpu_alloc_cmd(struct virtio_gpu_device *vgdev, struct virtio_gpu_vbuffer **vbuffer_p, int size) @@ -211,7 +222,7 @@ void virtio_gpu_dequeue_ctrl_func(struct work_struct *work) if (resp->type != cpu_to_le32(VIRTIO_GPU_RESP_OK_NODATA)) { if (resp->type >= cpu_to_le32(VIRTIO_GPU_RESP_ERR_UNSPEC)) { struct virtio_gpu_ctrl_hdr *cmd; - cmd = (struct virtio_gpu_ctrl_hdr *)entry->buf; + cmd = virtio_gpu_vbuf_ctrl_hdr(entry); DRM_ERROR("response 0x%x (command 0x%x)\n", le32_to_cpu(resp->type), le32_to_cpu(cmd->type)); @@ -338,8 +349,7 @@ static bool virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev, ret = virtqueue_add_sgs(vq, sgs, outcnt, incnt, vbuf, GFP_ATOMIC); WARN_ON(ret); - trace_virtio_gpu_cmd_queue(vq, - (struct virtio_gpu_ctrl_hdr *)vbuf->buf); + trace_virtio_gpu_cmd_queue(vq, virtio_gpu_vbuf_ctrl_hdr(vbuf)); notify = virtqueue_kick_prepare(vq); @@ -458,7 +468,7 @@ static void virtio_gpu_queue_cursor(struct virtio_gpu_device *vgdev, goto retry; } else { trace_virtio_gpu_cmd_queue(vq, - (struct virtio_gpu_ctrl_hdr *)vbuf->buf); + virtio_gpu_vbuf_ctrl_hdr(vbuf)); notify = virtqueue_kick_prepare(vq); } From patchwork Wed Feb 5 18:19:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chia-I Wu X-Patchwork-Id: 11366887 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A8D3921 for ; Wed, 5 Feb 2020 18:20:21 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6905D217BA for ; Wed, 5 Feb 2020 18:20:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Xd1d1mEx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6905D217BA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1D4A36F91E; Wed, 5 Feb 2020 18:20:15 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7664F6F91B for ; Wed, 5 Feb 2020 18:20:13 +0000 (UTC) Received: by mail-pj1-x102b.google.com with SMTP id ep11so1326363pjb.2 for ; Wed, 05 Feb 2020 10:20:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qYN8uuCgeNU5326wK92cHEPLxRUKs1hPqvq5kfDZKdk=; b=Xd1d1mEx5qSxJj5YbXnXjzh+xCAdxUYK21QimdBk0IzeInKwqYMWo6CKTV3okYDHRz e3m4dcL96qb/S7WEgspc2b6cADL7JUTzMrF0E9eYSseRtRH2PaQI9CC124dpLkuSvKs0 ReoGMVC3Asl+PmKG/Rcav1f+aY9YNhoqmUbMhG0l+lgWJESI47Xn7U3XkPYf+NlgcRdr dz/+PYCLFt8FwBywzVECL8gG6efCTFpoY+XGswRRKg10CDe24+5WuK3UbwsrhPxVZ0Q2 3W/iEWsOWG9P+p13f6QOgdch1GvUg4en1aUZ2O4vUmRk4O/LLg1+QLmATs04RmegU21k 6rpQ== 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:mime-version:content-transfer-encoding; bh=qYN8uuCgeNU5326wK92cHEPLxRUKs1hPqvq5kfDZKdk=; b=CsXkp+SSZvs+CiHFq71B7iroRX5rOr3NIOJ7rJ3d34MCM7q0PIcMIkpbcMmHVOsxFB oUZeyuQXXbG7ManNqeRuoxEwQknVx0G2TNI2hMevSAXZkjoQlcqJRBGDz8O1fZ9SRVF0 NSxeiszwqiweN3OkvzzHThDtXbi55ytLbiJ7aVqD09oeaDUI6Gk/gabVglIr0lDAnUiL 2GGsmEearHp6zcO2aIkV/NkMN8TOEjuhoSfew78GMoMNeLIBmCe4XAcGNQQ+LVcSLZ7S Swq4dTzz5JZa80No+ivIlZe7crGarovdOHGRYfw1r8ZlBGbVshNLX5X1XOpjSODr5a5f KlYg== X-Gm-Message-State: APjAAAW4UIkrf62Ok+o75/Cv3nz3jTytCluO9QBgy8ww5L7qE0y41/H8 tLrp8DGbmLCuV4M36tcFDmSC/mQv X-Google-Smtp-Source: APXvYqzRonbNCfuK99HlF4giR/WqqVVOfqLmA8TD4fKsRYUCJ+1rXAgrT34c0yOjHeVIy9IpSHRoeQ== X-Received: by 2002:a17:90a:6545:: with SMTP id f5mr7265340pjs.42.1580926812661; Wed, 05 Feb 2020 10:20:12 -0800 (PST) Received: from olv0.mtv.corp.google.com ([2620:15c:202:201:9649:82d6:f889:b307]) by smtp.gmail.com with ESMTPSA id h10sm158201pfo.181.2020.02.05.10.20.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 10:20:12 -0800 (PST) From: Chia-I Wu To: dri-devel@lists.freedesktop.org Subject: [PATCH 04/11] drm/virtio: no need to pass virtio_gpu_ctrl_hdr Date: Wed, 5 Feb 2020 10:19:48 -0800 Message-Id: <20200205181955.202485-5-olvaffe@gmail.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200205181955.202485-1-olvaffe@gmail.com> References: <20200205181955.202485-1-olvaffe@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kraxel@redhat.com, gurchetansingh@chromium.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" We can get it from vbuf. Signed-off-by: Chia-I Wu --- drivers/gpu/drm/virtio/virtgpu_vq.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index 312fd8a039a1e..5815c7d50dc20 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -358,7 +358,6 @@ static bool virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev, static void virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, struct virtio_gpu_vbuffer *vbuf, - struct virtio_gpu_ctrl_hdr *hdr, struct virtio_gpu_fence *fence) { struct virtqueue *vq = vgdev->ctrlq.vq; @@ -399,8 +398,9 @@ static void virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, goto again; } - if (hdr && fence) { - virtio_gpu_fence_emit(vgdev, hdr, fence); + if (fence) { + virtio_gpu_fence_emit(vgdev, virtio_gpu_vbuf_ctrl_hdr(vbuf), + fence); if (vbuf->objs) { virtio_gpu_array_add_fence(vbuf->objs, &fence->f); virtio_gpu_array_unlock_resv(vbuf->objs); @@ -439,7 +439,7 @@ void virtio_gpu_enable_notify(struct virtio_gpu_device *vgdev) static void virtio_gpu_queue_ctrl_buffer(struct virtio_gpu_device *vgdev, struct virtio_gpu_vbuffer *vbuf) { - virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, NULL, NULL); + virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, NULL); } static void virtio_gpu_queue_cursor(struct virtio_gpu_device *vgdev, @@ -503,7 +503,7 @@ void virtio_gpu_cmd_create_resource(struct virtio_gpu_device *vgdev, cmd_p->width = cpu_to_le32(params->width); cmd_p->height = cpu_to_le32(params->height); - virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, &cmd_p->hdr, fence); + virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, fence); bo->created = true; } @@ -535,7 +535,7 @@ static void virtio_gpu_cmd_resource_inval_backing(struct virtio_gpu_device *vgde cmd_p->hdr.type = cpu_to_le32(VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING); cmd_p->resource_id = cpu_to_le32(resource_id); - virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, &cmd_p->hdr, fence); + virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, fence); } void virtio_gpu_cmd_set_scanout(struct virtio_gpu_device *vgdev, @@ -610,7 +610,7 @@ void virtio_gpu_cmd_transfer_to_host_2d(struct virtio_gpu_device *vgdev, cmd_p->r.x = cpu_to_le32(x); cmd_p->r.y = cpu_to_le32(y); - virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, &cmd_p->hdr, fence); + virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, fence); } static void @@ -633,7 +633,7 @@ virtio_gpu_cmd_resource_attach_backing(struct virtio_gpu_device *vgdev, vbuf->data_buf = ents; vbuf->data_size = sizeof(*ents) * nents; - virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, &cmd_p->hdr, fence); + virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, fence); } static void virtio_gpu_cmd_get_display_info_cb(struct virtio_gpu_device *vgdev, @@ -992,7 +992,7 @@ virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev, cmd_p->nr_samples = cpu_to_le32(params->nr_samples); cmd_p->flags = cpu_to_le32(params->flags); - virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, &cmd_p->hdr, fence); + virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, fence); bo->created = true; } @@ -1025,7 +1025,7 @@ void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev, cmd_p->offset = cpu_to_le64(offset); cmd_p->level = cpu_to_le32(level); - virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, &cmd_p->hdr, fence); + virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, fence); } void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev, @@ -1051,7 +1051,7 @@ void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev, cmd_p->offset = cpu_to_le64(offset); cmd_p->level = cpu_to_le32(level); - virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, &cmd_p->hdr, fence); + virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, fence); } void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev, @@ -1074,7 +1074,7 @@ void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev, cmd_p->hdr.ctx_id = cpu_to_le32(ctx_id); cmd_p->size = cpu_to_le32(data_size); - virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, &cmd_p->hdr, fence); + virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, fence); } int virtio_gpu_object_attach(struct virtio_gpu_device *vgdev, From patchwork Wed Feb 5 18:19:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chia-I Wu X-Patchwork-Id: 11366889 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9DE7C921 for ; Wed, 5 Feb 2020 18:20:23 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7C7C320674 for ; Wed, 5 Feb 2020 18:20:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sfG5QWG8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7C7C320674 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 031786F91F; Wed, 5 Feb 2020 18:20:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by gabe.freedesktop.org (Postfix) with ESMTPS id 52EE06F91D for ; Wed, 5 Feb 2020 18:20:14 +0000 (UTC) Received: by mail-pf1-x444.google.com with SMTP id k29so1605712pfp.13 for ; Wed, 05 Feb 2020 10:20:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XORg0aqJcQWmmTNOH1YEuzSo/o+dN5ZC3N87GWWCK7Y=; b=sfG5QWG8ArV4SOkUtwSZYocieXtDjQ1qveE3m5IioB7yj4lvYDzjVpeYPZ/zG2DLo5 3H9BZOelf9owj05BYQJqhvgjmofpqLsY55DmV/UmsBnoeuQ5DSx8R59dO441M4RZJWJZ +kQ4vPvVpSuPyLXLO48Ub87ghpRj8Dr8acmMs6xXWpceFxXpgBZDjHzSCT23V7AZtD35 nLXknuy1xB6os9zW95XhxMhzBukWuC3LAW3wStoPxqKwr3r280xk9thxOdEeJK/h0MGd 6Cwp0Z2nqtoxDuCUY4zs95rOQlPam2K0seeiwyivtL73+f8sVxkH4rsQUj9bBg8PIhOY 0rBw== 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:mime-version:content-transfer-encoding; bh=XORg0aqJcQWmmTNOH1YEuzSo/o+dN5ZC3N87GWWCK7Y=; b=WFAPaXwl1Vz3pqEk973C0X6vcSuuX/x1fEXYCYVeZ/TRNjkhqaQn/C+osTwN489Nbt uS1pDroYcBtuZ3+1yxTZ0xb4HDjX6zMcq9rxqsbZVu8ZIn9q4F32Mm/hC/ZGprpwaFuI 9ZSbLP/G4YbDww/9fCRxoxgEpXP5aKEaa2Ty9Na681WRQ+6nMBp/CFTdKoP2xIEB1won vt/XBeKDiH7iHlq/aJCCDBVKxflTURtlUJcDHZ9q0OeoyIot8VX1XvaOzbps6fuxc+64 ByPzXVLuFgEa0rYXsC/Cq9TcwO5x7iNKld8eDPQk/hppCDPCzZxqMA72gHL61l2f2j0A LapQ== X-Gm-Message-State: APjAAAVjnw2X8sInmLQbDwNSe18VT7zsbDGZS6huo+mop/hqKgz3zHzQ eLfVosJQhjtgkfMNqcIXcNtKPCRE X-Google-Smtp-Source: APXvYqygovB6m8ovjz/cyStDz1EvI0gHaiEVIQjDRY7H1muBWs47RCVr2GKo7zoIBnTk08aEI76DOA== X-Received: by 2002:a63:3154:: with SMTP id x81mr27413713pgx.32.1580926813282; Wed, 05 Feb 2020 10:20:13 -0800 (PST) Received: from olv0.mtv.corp.google.com ([2620:15c:202:201:9649:82d6:f889:b307]) by smtp.gmail.com with ESMTPSA id h10sm158201pfo.181.2020.02.05.10.20.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 10:20:12 -0800 (PST) From: Chia-I Wu To: dri-devel@lists.freedesktop.org Subject: [PATCH 05/11] drm/virtio: unlock object array on errors Date: Wed, 5 Feb 2020 10:19:49 -0800 Message-Id: <20200205181955.202485-6-olvaffe@gmail.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200205181955.202485-1-olvaffe@gmail.com> References: <20200205181955.202485-1-olvaffe@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kraxel@redhat.com, gurchetansingh@chromium.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" We don't propagate erros to the callers. We have to unlock object arrays on errors. Signed-off-by: Chia-I Wu --- drivers/gpu/drm/virtio/virtgpu_vq.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index 5815c7d50dc20..1e27f4c09341e 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -370,8 +370,11 @@ static void virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, if (is_vmalloc_addr(vbuf->data_buf)) { sgt = vmalloc_to_sgt(vbuf->data_buf, vbuf->data_size, &outcnt); - if (!sgt) + if (!sgt) { + if (fence && vbuf->objs) + virtio_gpu_array_unlock_resv(vbuf->objs); return; + } vout = sgt->sgl; } else { sg_init_one(&sg, vbuf->data_buf, vbuf->data_size); From patchwork Wed Feb 5 18:19:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chia-I Wu X-Patchwork-Id: 11366891 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0AEDE921 for ; Wed, 5 Feb 2020 18:20:25 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DD51E217F4 for ; Wed, 5 Feb 2020 18:20:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R3Exg55x" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DD51E217F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 09DF46F920; Wed, 5 Feb 2020 18:20:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by gabe.freedesktop.org (Postfix) with ESMTPS id A95BC6F91F for ; Wed, 5 Feb 2020 18:20:14 +0000 (UTC) Received: by mail-pl1-x642.google.com with SMTP id a6so1213414plm.3 for ; Wed, 05 Feb 2020 10:20:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eiQ+xTfLWucbWS5TEa/HxnWIrsEOdsrdl2TbLBLm7ms=; b=R3Exg55xaWCAhl6OuGikCDBOgWspHjdZRpFuee8TUSVedQ0qXJnbJayLUO+IQmnwqz BaVv9GedJ8j40UhMaztj/W94G/Yd9dC8Fu/68gvrKgZszjw9OlSknIQ0W66kvi2d31Bv fMTcy516qillnLJSDiGYIam4UJJCvptHyAkv0TQ/yG/70e0EBB16o8zo92Vmys1fayP6 WDwWZ5blUe8szx1FgNY06mggh241a21qFU8tkD9h2x5KNkzzeec5E843M14zngsU0oAK uWnWLRvJYaYUZRp8cVYHoc4oTUCOQdXSKUrKFm82+n8SaSIXgHHrO2fktzEP+dTzCl2N x9jA== 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:mime-version:content-transfer-encoding; bh=eiQ+xTfLWucbWS5TEa/HxnWIrsEOdsrdl2TbLBLm7ms=; b=K3vX4xcXNwNLWfYKxkBnh8Ii3kHgPz/YVB0E98hXMcbY8c4VvoKnh5CzSMCA49cVI4 i/AGxKDXBzX/letwByBjlWoNtesbfHAWZlehPTjlB4VDsZWjp173NaWali1E73y205qL STgLM6a4tX0GPKvEaa0RZBoSLsbGkfZvfcFZMGCnyxFNQl7zQJNy+5sr9sMLY1HW3F1O A+Eind1I3VzbmTbv/ws2rq1rcnvvzCGzINwSR2fz+xiP94Dwd4rSzSO0E8+APTY8WXoC LMIGzfoWb1BoocM80FE5Yhyw0T1PpHZsqo/yC5JJaEkNv/l0tS7y98qMo+5SexND/G9o vK/w== X-Gm-Message-State: APjAAAXGrvvZjV8bXrDZwRVmVmOSMoE+Dr0DnJRvzTVPn1fffeXbXZc9 hTYW75VpJaKTaJTusmvJG3rVjJOV X-Google-Smtp-Source: APXvYqw6NvEw6tR09JQoCZKmpYg45DNKmeOLWMQmoXjkGQ5V6JguPrlYoHQAqqpuyZ2f6Hxi7XFqVg== X-Received: by 2002:a17:90a:2741:: with SMTP id o59mr6823525pje.105.1580926813948; Wed, 05 Feb 2020 10:20:13 -0800 (PST) Received: from olv0.mtv.corp.google.com ([2620:15c:202:201:9649:82d6:f889:b307]) by smtp.gmail.com with ESMTPSA id h10sm158201pfo.181.2020.02.05.10.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 10:20:13 -0800 (PST) From: Chia-I Wu To: dri-devel@lists.freedesktop.org Subject: [PATCH 06/11] drm/virtio: set up virtqueue sgs before locking Date: Wed, 5 Feb 2020 10:19:50 -0800 Message-Id: <20200205181955.202485-7-olvaffe@gmail.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200205181955.202485-1-olvaffe@gmail.com> References: <20200205181955.202485-1-olvaffe@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kraxel@redhat.com, gurchetansingh@chromium.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" sgs setup does not need to be in the critical section. Signed-off-by: Chia-I Wu --- drivers/gpu/drm/virtio/virtgpu_vq.c | 66 +++++++++++++++-------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index 1e27f4c09341e..6ccb2a54dfb3c 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -318,34 +318,19 @@ static struct sg_table *vmalloc_to_sgt(char *data, uint32_t size, int *sg_ents) return sgt; } -static bool virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev, - struct virtio_gpu_vbuffer *vbuf, - struct scatterlist *vout) +static bool virtio_gpu_queue_ctrl_sgs_locked(struct virtio_gpu_device *vgdev, + struct virtio_gpu_vbuffer *vbuf, + struct scatterlist **sgs, + int outcnt, + int incnt) { struct virtqueue *vq = vgdev->ctrlq.vq; - struct scatterlist *sgs[3], vcmd, vresp; - int outcnt = 0, incnt = 0; bool notify = false; int ret; if (!vgdev->vqs_ready) return notify; - sg_init_one(&vcmd, vbuf->buf, vbuf->size); - sgs[outcnt + incnt] = &vcmd; - outcnt++; - - if (vout) { - sgs[outcnt + incnt] = vout; - outcnt++; - } - - if (vbuf->resp_size) { - sg_init_one(&vresp, vbuf->resp_buf, vbuf->resp_size); - sgs[outcnt + incnt] = &vresp; - incnt++; - } - ret = virtqueue_add_sgs(vq, sgs, outcnt, incnt, vbuf, GFP_ATOMIC); WARN_ON(ret); @@ -361,26 +346,45 @@ static void virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, struct virtio_gpu_fence *fence) { struct virtqueue *vq = vgdev->ctrlq.vq; - struct scatterlist *vout = NULL, sg; + struct scatterlist *sgs[3], vcmd, vout, vresp; struct sg_table *sgt = NULL; + int elemcnt = 0, outcnt = 0, incnt = 0; bool notify; - int outcnt = 0; + /* set up vcmd */ + sg_init_one(&vcmd, vbuf->buf, vbuf->size); + elemcnt++; + sgs[outcnt] = &vcmd; + outcnt++; + + /* set up vout */ if (vbuf->data_size) { if (is_vmalloc_addr(vbuf->data_buf)) { + int sg_ents; sgt = vmalloc_to_sgt(vbuf->data_buf, vbuf->data_size, - &outcnt); + &sg_ents); if (!sgt) { if (fence && vbuf->objs) virtio_gpu_array_unlock_resv(vbuf->objs); return; } - vout = sgt->sgl; + + elemcnt += sg_ents; + sgs[outcnt] = sgt->sgl; } else { - sg_init_one(&sg, vbuf->data_buf, vbuf->data_size); - vout = &sg; - outcnt = 1; + sg_init_one(&vout, vbuf->data_buf, vbuf->data_size); + elemcnt++; + sgs[outcnt] = &vout; } + outcnt++; + } + + /* set up vresp */ + if (vbuf->resp_size) { + sg_init_one(&vresp, vbuf->resp_buf, vbuf->resp_size); + elemcnt++; + sgs[outcnt + incnt] = &vresp; + incnt++; } again: @@ -394,10 +398,9 @@ static void virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, * to wait for free space, which can result in fence ids being * submitted out-of-order. */ - if (vq->num_free < 2 + outcnt) { + if (vq->num_free < elemcnt) { spin_unlock(&vgdev->ctrlq.qlock); - wait_event(vgdev->ctrlq.ack_queue, - vq->num_free >= 2 + outcnt); + wait_event(vgdev->ctrlq.ack_queue, vq->num_free >= elemcnt); goto again; } @@ -409,7 +412,8 @@ static void virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, virtio_gpu_array_unlock_resv(vbuf->objs); } } - notify = virtio_gpu_queue_ctrl_buffer_locked(vgdev, vbuf, vout); + notify = virtio_gpu_queue_ctrl_sgs_locked(vgdev, vbuf, sgs, outcnt, + incnt); spin_unlock(&vgdev->ctrlq.qlock); if (notify) { if (vgdev->disable_notify) From patchwork Wed Feb 5 18:19:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chia-I Wu X-Patchwork-Id: 11366895 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E28031820 for ; Wed, 5 Feb 2020 18:20:27 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BF95D20674 for ; Wed, 5 Feb 2020 18:20:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HGVvJHVP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BF95D20674 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 71DDC6F925; Wed, 5 Feb 2020 18:20:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3A7F46F91F for ; Wed, 5 Feb 2020 18:20:15 +0000 (UTC) Received: by mail-pf1-x444.google.com with SMTP id 2so1608343pfg.12 for ; Wed, 05 Feb 2020 10:20:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IXuYS8x0SfcLd26IJJ54TWYfxysAwotI9/Qd09g7qPU=; b=HGVvJHVPXxjDsqNmoL91fvH84Dk8WUH5HgyNiEQYFjPb+yGR0GMUMTNxnRUla4f0Pt Os+m7QSBQweH42y3J/OC1cuhlnToI0WM3KVqlMTg2B1sOQBP5CHs+NC2yMfMRhs1vLUK VGmBIRgT3W4i2OST8HB/hw7SrSgM2W3D+sO8b8MZ/w3zi4EiF6SmrzmF1bnpLjnCV2Kr 8biGifRRlxZCQYI8TQGWHbHWX9cmrudxvpLmH7rYg0D9KE5hVuGEnJPB/ISeDT1HISc1 6MNppz/XJBSN1JgcQ2KCl71euz/8+L+vjRvX3PT2E8CdtdbV5hZZAaG52ttoq7BZA/sz JeZg== 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:mime-version:content-transfer-encoding; bh=IXuYS8x0SfcLd26IJJ54TWYfxysAwotI9/Qd09g7qPU=; b=h07jr4QWuwGkRBLaZ4jyAKK306oxooV2MZbYVvW0Qx+nM78sv/jIqC9+jewDL/B10T ImD3B4yx3IWCRM7DhVX9VPuCofCM6p2kzI0Gln7MZUMaGsON4qHYkDSNcGkWkyiAPJz9 htAGBmA7QFjAqAX/LiTUBptHO0pRgtzX/WbHRJRivXpqvNbd7IGexMoRcjBEVInimO82 nQh8oNZ+/CSuT5Dhf+At5L+k01hc8FSh9lZWl8+JfUK27shYI8srq9xI2zZA1/kzauIy GqpGwldmvVpBNAWAHJjG14BXvVQEXhLsVai9cKDeo5OTP3vjZvbzmTFCT+tuROJyl61i IovQ== X-Gm-Message-State: APjAAAXLMcw2yaG/inqP2K5YAb0eZ2UGBQJ5combJlsblehGOzw+qI+0 wZW4sLk1l0XcmBcdFmo2ZCazHRbr X-Google-Smtp-Source: APXvYqzcBx/n/B1V2ntiwRwi0EVqJK8Ur7aDkn5J2ev1nKGRu4Netgrk7AcRt4/iyOak6wUE4heb+Q== X-Received: by 2002:aa7:9218:: with SMTP id 24mr37332703pfo.145.1580926814519; Wed, 05 Feb 2020 10:20:14 -0800 (PST) Received: from olv0.mtv.corp.google.com ([2620:15c:202:201:9649:82d6:f889:b307]) by smtp.gmail.com with ESMTPSA id h10sm158201pfo.181.2020.02.05.10.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 10:20:14 -0800 (PST) From: Chia-I Wu To: dri-devel@lists.freedesktop.org Subject: [PATCH 07/11] drm/virtio: move locking into virtio_gpu_queue_ctrl_sgs Date: Wed, 5 Feb 2020 10:19:51 -0800 Message-Id: <20200205181955.202485-8-olvaffe@gmail.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200205181955.202485-1-olvaffe@gmail.com> References: <20200205181955.202485-1-olvaffe@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kraxel@redhat.com, gurchetansingh@chromium.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Signed-off-by: Chia-I Wu --- drivers/gpu/drm/virtio/virtgpu_vq.c | 70 ++++++++++++++--------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index 6ccb2a54dfb3c..299470aac281a 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -318,18 +318,43 @@ static struct sg_table *vmalloc_to_sgt(char *data, uint32_t size, int *sg_ents) return sgt; } -static bool virtio_gpu_queue_ctrl_sgs_locked(struct virtio_gpu_device *vgdev, - struct virtio_gpu_vbuffer *vbuf, - struct scatterlist **sgs, - int outcnt, - int incnt) +static bool virtio_gpu_queue_ctrl_sgs(struct virtio_gpu_device *vgdev, + struct virtio_gpu_vbuffer *vbuf, + struct virtio_gpu_fence *fence, + int elemcnt, + struct scatterlist **sgs, + int outcnt, + int incnt) { struct virtqueue *vq = vgdev->ctrlq.vq; bool notify = false; int ret; - if (!vgdev->vqs_ready) +again: + spin_lock(&vgdev->ctrlq.qlock); + + if (vq->num_free < elemcnt) { + spin_unlock(&vgdev->ctrlq.qlock); + wait_event(vgdev->ctrlq.ack_queue, vq->num_free >= elemcnt); + goto again; + } + + /* now that the position of the vbuf in the virtqueue is known, we can + * finally set the fence id + */ + if (fence) { + virtio_gpu_fence_emit(vgdev, virtio_gpu_vbuf_ctrl_hdr(vbuf), + fence); + if (vbuf->objs) { + virtio_gpu_array_add_fence(vbuf->objs, &fence->f); + virtio_gpu_array_unlock_resv(vbuf->objs); + } + } + + if (!vgdev->vqs_ready) { + spin_unlock(&vgdev->ctrlq.qlock); return notify; + } ret = virtqueue_add_sgs(vq, sgs, outcnt, incnt, vbuf, GFP_ATOMIC); WARN_ON(ret); @@ -338,6 +363,8 @@ static bool virtio_gpu_queue_ctrl_sgs_locked(struct virtio_gpu_device *vgdev, notify = virtqueue_kick_prepare(vq); + spin_unlock(&vgdev->ctrlq.qlock); + return notify; } @@ -345,7 +372,6 @@ static void virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, struct virtio_gpu_vbuffer *vbuf, struct virtio_gpu_fence *fence) { - struct virtqueue *vq = vgdev->ctrlq.vq; struct scatterlist *sgs[3], vcmd, vout, vresp; struct sg_table *sgt = NULL; int elemcnt = 0, outcnt = 0, incnt = 0; @@ -387,34 +413,8 @@ static void virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, incnt++; } -again: - spin_lock(&vgdev->ctrlq.qlock); - - /* - * Make sure we have enouth space in the virtqueue. If not - * wait here until we have. - * - * Without that virtio_gpu_queue_ctrl_buffer_nolock might have - * to wait for free space, which can result in fence ids being - * submitted out-of-order. - */ - if (vq->num_free < elemcnt) { - spin_unlock(&vgdev->ctrlq.qlock); - wait_event(vgdev->ctrlq.ack_queue, vq->num_free >= elemcnt); - goto again; - } - - if (fence) { - virtio_gpu_fence_emit(vgdev, virtio_gpu_vbuf_ctrl_hdr(vbuf), - fence); - if (vbuf->objs) { - virtio_gpu_array_add_fence(vbuf->objs, &fence->f); - virtio_gpu_array_unlock_resv(vbuf->objs); - } - } - notify = virtio_gpu_queue_ctrl_sgs_locked(vgdev, vbuf, sgs, outcnt, - incnt); - spin_unlock(&vgdev->ctrlq.qlock); + notify = virtio_gpu_queue_ctrl_sgs(vgdev, vbuf, fence, elemcnt, sgs, + outcnt, incnt); if (notify) { if (vgdev->disable_notify) vgdev->pending_notify = true; From patchwork Wed Feb 5 18:19:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chia-I Wu X-Patchwork-Id: 11366893 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9BA93921 for ; Wed, 5 Feb 2020 18:20:26 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 66E3724650 for ; Wed, 5 Feb 2020 18:20:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Xx85uhPv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 66E3724650 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3B2A46F923; Wed, 5 Feb 2020 18:20:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2EE386F91F for ; Wed, 5 Feb 2020 18:20:16 +0000 (UTC) Received: by mail-pg1-x542.google.com with SMTP id z7so1353363pgk.7 for ; Wed, 05 Feb 2020 10:20:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O4GxhHLv8gok+Xa5FqUXZgaSThcpfeAonWMQgh5xO1M=; b=Xx85uhPvNYHak21e5HVDZC3k7dOtP4flGLc79e1430MdokBrO7i/myUeJ5YhvhtMqm mX4gEFix9NuVI98JpcUlV2yJNw4DTJyND0u0VJZ87O9I7PSEbtUXqWXYalVORjlcZsMi +Jy4MRgFXc2xrJX0pJpe3L72pTJl9O0vjsmLntKkG4J/BLFriekqSYIzfs7LuScBjWP3 RxmJrHVJ8BZElU70xQh2V/nqudfd/pxMfgUjhyT+i3l6MvaeC5McWQSpjjbO1/SB40/g 0SjS2iuuNEhr2A7DLm5Y/WOLsyY9vn/cO6xw0UXo3Efv+J4nOkeXrx6N+J3dOIL9tin/ htjw== 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:mime-version:content-transfer-encoding; bh=O4GxhHLv8gok+Xa5FqUXZgaSThcpfeAonWMQgh5xO1M=; b=UThCwMRbZFpnF14fVVQt7V+yUdMpOUBFjEnQ4D0iE9uqyBQkxOIA6p7vCHpcIp946C +d+hEicC7EP/FAqJsAHbOGpY4suOYVC5Ml22AHRmOjvzUb8jCt5Y46y1SYrboueOI+4I MxLAXvZHCpirMDebUqGjVPahjEgeGBN8JNzz44PFczxctjb0v/eDmIQvsaN3m0Lt4yjj 9v+1jzBhOn6Ko8Rpvd2MZ4AZ0Jf7HVPPM4U0ncgAYIydK5TEudn/CVnLXA7dro3/NfTV +iQyWLxUycGdrxreO55tTQ/iKRUpYC5wYe6slBYQd32WkeUX8HGd7d476c6ndnL4tj3G odZw== X-Gm-Message-State: APjAAAW8cqcKhqLe1ddY/Bc7SULWmhTmY+M7f47e5+YZIJzrmmj3kqNo ew+Veekub6FT+ac8g6DxI3SSuucI X-Google-Smtp-Source: APXvYqyzZekArHsLe91rvf1+69FK4Pz399tjYhqk5bqftTv6CoTAb5p/At9lWtWHx+qIpyiygcUWkQ== X-Received: by 2002:a62:7b54:: with SMTP id w81mr37981528pfc.127.1580926815515; Wed, 05 Feb 2020 10:20:15 -0800 (PST) Received: from olv0.mtv.corp.google.com ([2620:15c:202:201:9649:82d6:f889:b307]) by smtp.gmail.com with ESMTPSA id h10sm158201pfo.181.2020.02.05.10.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 10:20:15 -0800 (PST) From: Chia-I Wu To: dri-devel@lists.freedesktop.org Subject: [PATCH 08/11] drm/virtio: move the check for vqs_ready earlier Date: Wed, 5 Feb 2020 10:19:52 -0800 Message-Id: <20200205181955.202485-9-olvaffe@gmail.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200205181955.202485-1-olvaffe@gmail.com> References: <20200205181955.202485-1-olvaffe@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kraxel@redhat.com, gurchetansingh@chromium.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" When vqs_ready is false, vq should be considered invalid and we should not check vq->num_free. After this change, a fenced command queued before the vqs are ready will have fence id 0 and will be considered done. Signed-off-by: Chia-I Wu --- drivers/gpu/drm/virtio/virtgpu_vq.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index 299470aac281a..0bf82cff8da37 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -333,6 +333,14 @@ static bool virtio_gpu_queue_ctrl_sgs(struct virtio_gpu_device *vgdev, again: spin_lock(&vgdev->ctrlq.qlock); + if (!vgdev->vqs_ready) { + spin_unlock(&vgdev->ctrlq.qlock); + + if (fence && vbuf->objs) + virtio_gpu_array_unlock_resv(vbuf->objs); + return notify; + } + if (vq->num_free < elemcnt) { spin_unlock(&vgdev->ctrlq.qlock); wait_event(vgdev->ctrlq.ack_queue, vq->num_free >= elemcnt); @@ -351,11 +359,6 @@ static bool virtio_gpu_queue_ctrl_sgs(struct virtio_gpu_device *vgdev, } } - if (!vgdev->vqs_ready) { - spin_unlock(&vgdev->ctrlq.qlock); - return notify; - } - ret = virtqueue_add_sgs(vq, sgs, outcnt, incnt, vbuf, GFP_ATOMIC); WARN_ON(ret); From patchwork Wed Feb 5 18:19:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chia-I Wu X-Patchwork-Id: 11366897 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 42C0817E0 for ; Wed, 5 Feb 2020 18:20:29 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1FBA62464B for ; Wed, 5 Feb 2020 18:20:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Me0vDa+U" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1FBA62464B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 033F06F928; Wed, 5 Feb 2020 18:20:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by gabe.freedesktop.org (Postfix) with ESMTPS id 497B36F924 for ; Wed, 5 Feb 2020 18:20:17 +0000 (UTC) Received: by mail-pl1-x644.google.com with SMTP id y8so1196218pll.13 for ; Wed, 05 Feb 2020 10:20:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t3xz12wqoLJgJ3jWkSnEVpo+RAYySs+cnFEeiTl/b54=; b=Me0vDa+U2zTFdUZBlIeKb3B3fi6TlUjIEYn9U/sjmPuItmkO96MyZIYnlgJ2Za5J/K VxTd7fbZgri74huUWXvBaVE+SlVLlVCYWxw4XTxffSOOseVv+aQRAv1Wq8p/ymMDcQ7m JA3eKlkCzu8QkqnKW1UKiYhSXOX8WnFijwwIG4YDf/LhMtZHFQoP9FGulhUSh+qZeeHa p2er1TCrITqf0kXgMqiVNDKJm0ZQoUNKtu9ah01kOfUsEW6qbdl4wB6qK8xpUdcqXcxk GTOAaLUc42PyVdj3A7JYiWobaKSoBowo/R9VNocdScGxBPEQcaHDZUF+AdmDlmPu4V// RTlQ== 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:mime-version:content-transfer-encoding; bh=t3xz12wqoLJgJ3jWkSnEVpo+RAYySs+cnFEeiTl/b54=; b=oTUoDABn4Uw91EZWvEfUdkPv4rygOmz2jIYVr9UBC76TWiMJMYN4eStFi068LmE+uA hlFohGfkCxnxdRQC9tqfGuuC/qm0GfGHpTxcWtRpkF1MFXEgSRHkwI+EwaW9SZmWoyeN W3uBUJhFIrD02a0a5GdGf5iobYogfaWzzXtJx66j2Zy9Nh3VQdIXg0JQjYfDa8hA1QEj IzTqjcU65kqK1EUF1i4Yy3fJVVZCqBaLSDKAIY1HU85lE0eoosLCS3d5aaD9vw+CIeix aeNqHhFG46tA7kE/LlEOmtOPyE4rIB0Ob2Gi81Jct6WfIs2VXLRuQlWnYCNni0AUz2zD 0yHA== X-Gm-Message-State: APjAAAXdVCJjNcJpEVjlS8C1Ph27tUXBXvpRm3X504M9zx91fHzmw7QN PAGtoXPMXm8qExFpoHGlk8sTz4qi X-Google-Smtp-Source: APXvYqyNgXU/eRgqUTHmp3wohalEF/0CAHpf9g69ThL0LQ78o6F7myK1lwjjnapYasBqryUvH8SrPg== X-Received: by 2002:a17:90a:9dc3:: with SMTP id x3mr6985725pjv.45.1580926816467; Wed, 05 Feb 2020 10:20:16 -0800 (PST) Received: from olv0.mtv.corp.google.com ([2620:15c:202:201:9649:82d6:f889:b307]) by smtp.gmail.com with ESMTPSA id h10sm158201pfo.181.2020.02.05.10.20.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 10:20:15 -0800 (PST) From: Chia-I Wu To: dri-devel@lists.freedesktop.org Subject: [PATCH 09/11] drm/virtio: avoid an infinite loop Date: Wed, 5 Feb 2020 10:19:53 -0800 Message-Id: <20200205181955.202485-10-olvaffe@gmail.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200205181955.202485-1-olvaffe@gmail.com> References: <20200205181955.202485-1-olvaffe@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kraxel@redhat.com, gurchetansingh@chromium.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Make sure elemcnt does not exceed the maximum element count in virtio_gpu_queue_ctrl_sgs. We should improve our error handling or impose a size limit on execbuffer, which are TODOs. Signed-off-by: Chia-I Wu Cc: David Riley --- drivers/gpu/drm/virtio/virtgpu_drv.h | 1 + drivers/gpu/drm/virtio/virtgpu_ioctl.c | 3 +++ drivers/gpu/drm/virtio/virtgpu_kms.c | 2 ++ drivers/gpu/drm/virtio/virtgpu_vq.c | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index 7e69c06e168ea..f7520feb39d4b 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -143,6 +143,7 @@ struct virtio_gpu_framebuffer { struct virtio_gpu_queue { struct virtqueue *vq; + unsigned int max_free; spinlock_t qlock; wait_queue_head_t ack_queue; struct work_struct dequeue_work; diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index 205ec4abae2b9..0954f61d2000f 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -132,6 +132,9 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, goto out_unused_fd; } + /* XXX virtio_gpu_cmd_submit may fail silently when exbuf->size is + * huge + */ buf = vmemdup_user(u64_to_user_ptr(exbuf->command), exbuf->size); if (IS_ERR(buf)) { ret = PTR_ERR(buf); diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c index 2f5773e43557c..e7d5840e432dc 100644 --- a/drivers/gpu/drm/virtio/virtgpu_kms.c +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c @@ -170,7 +170,9 @@ int virtio_gpu_init(struct drm_device *dev) goto err_vqs; } vgdev->ctrlq.vq = vqs[0]; + vgdev->ctrlq.max_free = vqs[0]->num_free; vgdev->cursorq.vq = vqs[1]; + vgdev->cursorq.max_free = vqs[1]->num_free; ret = virtio_gpu_alloc_vbufs(vgdev); if (ret) { DRM_ERROR("failed to alloc vbufs\n"); diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index 0bf82cff8da37..725cfe93bcef8 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -333,7 +333,7 @@ static bool virtio_gpu_queue_ctrl_sgs(struct virtio_gpu_device *vgdev, again: spin_lock(&vgdev->ctrlq.qlock); - if (!vgdev->vqs_ready) { + if (unlikely(!vgdev->vqs_ready || elemcnt > vgdev->ctrlq.max_free)) { spin_unlock(&vgdev->ctrlq.qlock); if (fence && vbuf->objs) From patchwork Wed Feb 5 18:19:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chia-I Wu X-Patchwork-Id: 11366901 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 88B8D17E0 for ; Wed, 5 Feb 2020 18:20:30 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6678B2465B for ; Wed, 5 Feb 2020 18:20:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jSdqCuLp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6678B2465B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BE5EB6F921; Wed, 5 Feb 2020 18:20:20 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by gabe.freedesktop.org (Postfix) with ESMTPS id E3F586F921 for ; Wed, 5 Feb 2020 18:20:17 +0000 (UTC) Received: by mail-pl1-x644.google.com with SMTP id e8so1203338plt.9 for ; Wed, 05 Feb 2020 10:20:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wS3JQcVZ5maNSXGf9GQ6jqqO4T8spIB6XidZE0Phrqo=; b=jSdqCuLpXGVDTnRpZqnFSSzXghqUTwzisSZoXKM5JOnuAr3Z/sZS+OuXYBzXrIESl1 EFi7TOs/zC0LvwUc5HM7RgVHqSLYSCNVh4KqKSPZK9yFNd3HbAE0nNEJ86KjbVxBs7Wh xA2IGOhJILpnoC0cp3bBPlKyEcOQArPpMxa1DaW9MYD3yzmohgSsH1gbFaJiZz3gv2Eo L5AwJjhE4hFpklU27M1SpuBBvZm14KNnv+h4uqwDflIDwezkbaqPWaTn5ajYwWwC3/bH x+uE9LniN7kmHkqXit9dakjgaF7keeCdHJqF/unbILSeMBWCRrIp8d5wAi4fzrDzW09V LmeA== 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:mime-version:content-transfer-encoding; bh=wS3JQcVZ5maNSXGf9GQ6jqqO4T8spIB6XidZE0Phrqo=; b=fwqf3aJNRo4oKg1vdxmRoqqNo3UKFUEwhmYgXtQQscijTAZrle2Q+e9PBHyXKWA0QL tIFizuZ584+0cRoZaIT1oYDY/nLdbOb7+kF1/78Pf1KB0ZM4xcxJiwmXu1qgJHOBTTqO oagSdLEFh4VFe2T//Mfjt2kYRWRUYPHsRBS0x4xW1S8aAeLmzFtGg0VAIdoEVhhEg6Gk w19HRofG34/PAMMnsYv0B4J6msOr5KML6VDzY717QG5EWK5Dxerr/DmO2j+d19zeVYdS hzn4Sm8ZE/9zfwSbNex8LcZWg4NssJxGaAFjaafPUm7vW4v5tQqUIPxDVNB3r6nsJfBS TtSA== X-Gm-Message-State: APjAAAXeL4F9d4ImmYfrxQq8BUT29KlgdLlQB4SQ3y0AUgGt5OP6+BvQ udaU7/8JwhLpbiuH9WG7WHTyWona X-Google-Smtp-Source: APXvYqy9TuWPXAm8QsVbidiyJWgwAG7GPUb6SM+KVfGb1Sz55e5zeW8XrwOLYJqpDvpFGqGAf8NUlA== X-Received: by 2002:a17:902:9349:: with SMTP id g9mr36204422plp.110.1580926817097; Wed, 05 Feb 2020 10:20:17 -0800 (PST) Received: from olv0.mtv.corp.google.com ([2620:15c:202:201:9649:82d6:f889:b307]) by smtp.gmail.com with ESMTPSA id h10sm158201pfo.181.2020.02.05.10.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 10:20:16 -0800 (PST) From: Chia-I Wu To: dri-devel@lists.freedesktop.org Subject: [PATCH 10/11] drm/virtio: move virtqueue_notify into virtio_gpu_queue_ctrl_sgs Date: Wed, 5 Feb 2020 10:19:54 -0800 Message-Id: <20200205181955.202485-11-olvaffe@gmail.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200205181955.202485-1-olvaffe@gmail.com> References: <20200205181955.202485-1-olvaffe@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kraxel@redhat.com, gurchetansingh@chromium.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" It becomes clear that virtio_gpu_queue_fenced_ctrl_buffer should be responsible for setting up sgs and virtio_gpu_queue_ctrl_sgs should be responsible for queuing sgs. Signed-off-by: Chia-I Wu --- drivers/gpu/drm/virtio/virtgpu_vq.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index 725cfe93bcef8..0961475e68105 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -318,7 +318,7 @@ static struct sg_table *vmalloc_to_sgt(char *data, uint32_t size, int *sg_ents) return sgt; } -static bool virtio_gpu_queue_ctrl_sgs(struct virtio_gpu_device *vgdev, +static void virtio_gpu_queue_ctrl_sgs(struct virtio_gpu_device *vgdev, struct virtio_gpu_vbuffer *vbuf, struct virtio_gpu_fence *fence, int elemcnt, @@ -338,7 +338,7 @@ static bool virtio_gpu_queue_ctrl_sgs(struct virtio_gpu_device *vgdev, if (fence && vbuf->objs) virtio_gpu_array_unlock_resv(vbuf->objs); - return notify; + return; } if (vq->num_free < elemcnt) { @@ -368,7 +368,12 @@ static bool virtio_gpu_queue_ctrl_sgs(struct virtio_gpu_device *vgdev, spin_unlock(&vgdev->ctrlq.qlock); - return notify; + if (notify) { + if (vgdev->disable_notify) + vgdev->pending_notify = true; + else + virtqueue_notify(vq); + } } static void virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, @@ -378,7 +383,6 @@ static void virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, struct scatterlist *sgs[3], vcmd, vout, vresp; struct sg_table *sgt = NULL; int elemcnt = 0, outcnt = 0, incnt = 0; - bool notify; /* set up vcmd */ sg_init_one(&vcmd, vbuf->buf, vbuf->size); @@ -416,14 +420,8 @@ static void virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, incnt++; } - notify = virtio_gpu_queue_ctrl_sgs(vgdev, vbuf, fence, elemcnt, sgs, - outcnt, incnt); - if (notify) { - if (vgdev->disable_notify) - vgdev->pending_notify = true; - else - virtqueue_notify(vgdev->ctrlq.vq); - } + virtio_gpu_queue_ctrl_sgs(vgdev, vbuf, fence, elemcnt, sgs, outcnt, + incnt); if (sgt) { sg_free_table(sgt); From patchwork Wed Feb 5 18:19:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chia-I Wu X-Patchwork-Id: 11366903 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BBCFD17E0 for ; Wed, 5 Feb 2020 18:20:31 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 99A422464B for ; Wed, 5 Feb 2020 18:20:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GnIdRWwM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 99A422464B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9AF766F926; Wed, 5 Feb 2020 18:20:22 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6A4B86F924 for ; Wed, 5 Feb 2020 18:20:18 +0000 (UTC) Received: by mail-pl1-x643.google.com with SMTP id j7so1219547plt.1 for ; Wed, 05 Feb 2020 10:20:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HCUksZDKsyiRackGGI1q2bb6B3864G8jYGwVQTnYIsI=; b=GnIdRWwMAPHcTVMhCUvJ5vfA3UIZeryzVrmT7S/n9yvlUX2+vE8FAoEb4OHww6AuTq TQ0dmTD3d08Ckl3UAsnRjSzjqEF3OQMNFtFU5a1nQApPlMtlTWkVCWZCA02RdVK8MAvS SP8uF9cI9245mH0vcx1idpC8MV2kX52b8XCKDJ8r7pDw8ImWTuNJVMLx998XO6gxDUdf wrbngJo4UlwqYp/o5U7M7Ly79nXPVq/lMzCk4lh0BirlflxRdqrGwsIUbNBUyPX3Uy0O q0pp+1OR0SEQ+Sp7oJAW1CTtnx7upYbCnn5DSL7yjgF3Dbg24pJk3mV9FEmK2mZhOXPa sHow== 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:mime-version:content-transfer-encoding; bh=HCUksZDKsyiRackGGI1q2bb6B3864G8jYGwVQTnYIsI=; b=rHuyVV43DhgY3ae5pzUWVqkPzZJLdOrgxC1ZGvwlnVUfEp2njIqAU2u8S7wzmi/48z BTKO55AFNUM9P3TCcp9wamTKbBwczay7Ip2mIZa0lR8+U7clugrc+lcmXCfgK6niYsn8 MGhBx6ODf8hDk04oeABkKwHFIPKLhwf5b1hHnQeCxac55C+0jc4ARvZRXNf6+7+2TRcP Nu/AdiYwc+1HwdGoIDMcumIzIgkIx44viA7BGRGdJsQvLt53Ybl5EfuXdV2YXsH6Y8oO 3gQx8n8X4w8YBp0hIUJwbjeE/6ii6ZGh9eeReXx+rsma/5290xv5FEkCD6PNEPMI5oVN lOFQ== X-Gm-Message-State: APjAAAUUT1jF0mun8+JOTblelKHpgwmUQtYugdfFNneuxhBJseA9hZiZ 9utVnizCTI7IQfGBUNPBGhIYdYWf X-Google-Smtp-Source: APXvYqwn3Qc/6f0O4CAgOzwTSlpHR+Bq0NYmvqqUWkkUn5DvU0KFCSk7cPnj4EZRjMCxEACtCJ9e5Q== X-Received: by 2002:a17:90a:191:: with SMTP id 17mr7142645pjc.88.1580926817712; Wed, 05 Feb 2020 10:20:17 -0800 (PST) Received: from olv0.mtv.corp.google.com ([2620:15c:202:201:9649:82d6:f889:b307]) by smtp.gmail.com with ESMTPSA id h10sm158201pfo.181.2020.02.05.10.20.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 10:20:17 -0800 (PST) From: Chia-I Wu To: dri-devel@lists.freedesktop.org Subject: [PATCH 11/11] drm/virtio: rework virtio_gpu_enable_notify Date: Wed, 5 Feb 2020 10:19:55 -0800 Message-Id: <20200205181955.202485-12-olvaffe@gmail.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200205181955.202485-1-olvaffe@gmail.com> References: <20200205181955.202485-1-olvaffe@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kraxel@redhat.com, gurchetansingh@chromium.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Call virtqueue_kick_prepare once in virtio_gpu_enable_notify, not whenever a command is added. This should be more efficient since the intention is to batch commands. Signed-off-by: Chia-I Wu --- drivers/gpu/drm/virtio/virtgpu_drv.h | 1 - drivers/gpu/drm/virtio/virtgpu_vq.c | 28 +++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index f7520feb39d4b..f0e7130ac9e27 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -179,7 +179,6 @@ struct virtio_gpu_device { bool vqs_ready; bool disable_notify; - bool pending_notify; struct ida resource_ida; diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index 0961475e68105..aea1be68e99c4 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -364,16 +364,13 @@ static void virtio_gpu_queue_ctrl_sgs(struct virtio_gpu_device *vgdev, trace_virtio_gpu_cmd_queue(vq, virtio_gpu_vbuf_ctrl_hdr(vbuf)); - notify = virtqueue_kick_prepare(vq); + if (!vgdev->disable_notify) + notify = virtqueue_kick_prepare(vq); spin_unlock(&vgdev->ctrlq.qlock); - if (notify) { - if (vgdev->disable_notify) - vgdev->pending_notify = true; - else - virtqueue_notify(vq); - } + if (notify) + virtqueue_notify(vq); } static void virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, @@ -436,12 +433,21 @@ void virtio_gpu_disable_notify(struct virtio_gpu_device *vgdev) void virtio_gpu_enable_notify(struct virtio_gpu_device *vgdev) { + struct virtqueue *vq = vgdev->ctrlq.vq; + bool notify; + vgdev->disable_notify = false; - if (!vgdev->pending_notify) - return; - vgdev->pending_notify = false; - virtqueue_notify(vgdev->ctrlq.vq); + spin_lock(&vgdev->ctrlq.qlock); + notify = virtqueue_kick_prepare(vq); + spin_unlock(&vgdev->ctrlq.qlock); + + /* Do not call virtqueue_notify with the lock held because + * virtio_gpu_dequeue_ctrl_func may contend for the lock if an irq is + * generated while we are in virtqueue_notify. + */ + if (notify) + virtqueue_notify(vq); } static void virtio_gpu_queue_ctrl_buffer(struct virtio_gpu_device *vgdev,