From patchwork Thu Jul 11 02:29:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chia-I Wu X-Patchwork-Id: 11039191 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4CE8F6C5 for ; Thu, 11 Jul 2019 02:29:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3389D28A6B for ; Thu, 11 Jul 2019 02:29:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1EC1628A69; Thu, 11 Jul 2019 02:29:56 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,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 2B9C2287E3 for ; Thu, 11 Jul 2019 02:29:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E743689C13; Thu, 11 Jul 2019 02:29:52 +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 582FE89C13 for ; Thu, 11 Jul 2019 02:29:51 +0000 (UTC) Received: by mail-pl1-x644.google.com with SMTP id t14so2170939plr.11 for ; Wed, 10 Jul 2019 19:29:51 -0700 (PDT) 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:mime-version :content-transfer-encoding; bh=qPWrGW+mHyz/zxrmAaiQeG6b1c+y5yhmMgQ1hyiaZR0=; b=PfsO/sEpa+EOHa4NMzhxUPaO90Qgu2cFP2WzQhOKwpb02MPDAM6/wrE94bGiMK4sov FizkNHx/ruYJr0kdKzFaBrMUHTA721oRO9wHyjqUTYXGFfsfjQfhM4pbts51oZJT9l9l 1ykye2pxPCwQ6h9Dn9c2rW2peAzLMO3quBoYGnuYQdQhlBgwcwm6KDuQHYzQUa26cLYz zjfI+CnBIO/dmkqOP7v88/jcpJsEWXBU0mm8oA+sDaK2bO/bRZeQI3A8JxczyG8VvDde 1ikdnlcx10kFwgWbdGsjk+42M+568NOri9RppXb29QKiUKmCjLV5EMHHkcT7BACj3B/4 y55Q== X-Gm-Message-State: APjAAAXiIIhTGTzt7YeGwucKdncJwsCShr5li5oOSt//wB7KaWpVNlo5 4T8nXVpyoFtAzvMkyevFD2VawVjd X-Google-Smtp-Source: APXvYqxN90cLc00cYdWJNjcMcmyHeBOPnCRonXFxzLH+4vQTsAuClh9uNnBz+kEzScj2/zJk48u0Mw== X-Received: by 2002:a17:902:2ec5:: with SMTP id r63mr1710517plb.21.1562812190534; Wed, 10 Jul 2019 19:29:50 -0700 (PDT) Received: from olv0.mtv.corp.google.com ([2620:15c:202:201:9649:82d6:f889:b307]) by smtp.gmail.com with ESMTPSA id x25sm1929986pfa.90.2019.07.10.19.29.49 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 10 Jul 2019 19:29:49 -0700 (PDT) From: Chia-I Wu To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm/virtio: kick vq outside of the vq lock Date: Wed, 10 Jul 2019 19:29:37 -0700 Message-Id: <20190711022937.166015-1-olvaffe@gmail.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qPWrGW+mHyz/zxrmAaiQeG6b1c+y5yhmMgQ1hyiaZR0=; b=qBE3eLC4RA4F+HzzOw79/Ge4/+ES1SdQUKnZaGPTDpEUF8lt0KVkrqVWOAH8gpMusV SG2+KBYLVfOn5pgk4W6rG1t7np0qKA+oz0CdjwjzL6gSCe9eQoYjvZZIVdVUNXG+OVVr D5wKYCee+xGjkEvfLuvpHpwo0W0H6JMlD2Xu1zRBuyaZOZV+gR0FFXFoSMXagudf/RdK uuZK4pJg5lx4taqE1//t+jWtdifCnAgF6B/cKysKRztKwrbLOjmXuxE5eZ4Ls7fV6ZIr GJ+N2Xakvkqq0zyfzswiAJvrKiGDfMQBsRjsuQmPA+Wk9uROukpiddb2+mkaWJHCkFKL 6PGA== 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: David Airlie , linux-kernel@vger.kernel.org, Gerd Hoffmann , virtualization@lists.linux-foundation.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Replace virtqueue_kick by virtqueue_kick_prepare, which requires serialization, and virtqueue_notify, which does not. Repurpose the return values to indicate whether the vq should be notified. This fixes a lock contention with qemu host. When the guest calls vibad rtqueue_notify, the qemu vcpu thread exits the guest and waits for the qemu iothread to perform the MMIO. If the qemu iothread is still processing the prior buffer, and if the prior buffer is cheap to GPU, the iothread will go ahead and generate an IRQ for the guest. A worker thread in the guest will call virtio_gpu_dequeue_ctrl_func. If virtqueue_notify was called with the vq lock held, the worker thread would busy wait inside virtio_gpu_dequeue_ctrl_func. Signed-off-by: Chia-I Wu --- drivers/gpu/drm/virtio/virtgpu_vq.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index 6c1a90717535..e96f88fe5c83 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -291,11 +291,9 @@ static int virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev, trace_virtio_gpu_cmd_queue(vq, (struct virtio_gpu_ctrl_hdr *)vbuf->buf); - virtqueue_kick(vq); + ret = virtqueue_kick_prepare(vq); } - if (!ret) - ret = vq->num_free; return ret; } @@ -307,6 +305,10 @@ static int virtio_gpu_queue_ctrl_buffer(struct virtio_gpu_device *vgdev, spin_lock(&vgdev->ctrlq.qlock); rc = virtio_gpu_queue_ctrl_buffer_locked(vgdev, vbuf); spin_unlock(&vgdev->ctrlq.qlock); + + if (rc > 0) + virtqueue_notify(vgdev->ctrlq.vq); + return rc; } @@ -339,6 +341,10 @@ static int virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, virtio_gpu_fence_emit(vgdev, hdr, fence); rc = virtio_gpu_queue_ctrl_buffer_locked(vgdev, vbuf); spin_unlock(&vgdev->ctrlq.qlock); + + if (rc > 0) + virtqueue_notify(vgdev->ctrlq.vq); + return rc; } @@ -369,13 +375,14 @@ static int virtio_gpu_queue_cursor(struct virtio_gpu_device *vgdev, trace_virtio_gpu_cmd_queue(vq, (struct virtio_gpu_ctrl_hdr *)vbuf->buf); - virtqueue_kick(vq); + ret = virtqueue_kick_prepare(vq); } spin_unlock(&vgdev->cursorq.qlock); - if (!ret) - ret = vq->num_free; + if (ret > 0) + virtqueue_notify(vq); + return ret; }