From patchwork Thu May 20 14:13:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 12270511 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MIME_BASE64_TEXT, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E397C433B4 for ; Thu, 20 May 2021 14:14:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 17668608FE for ; Thu, 20 May 2021 14:14:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237492AbhETOP5 (ORCPT ); Thu, 20 May 2021 10:15:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32205 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243629AbhETOOz (ORCPT ); Thu, 20 May 2021 10:14:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621520013; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EQLmeFAYlSq9MUn0ggB4grwFyWkzklNm3btxmw1JEAk=; b=aYewR6HJe8vzqcwNxcxLIaC1CXppMWd+wz6ErOs4uDpvv3hMvhayT2YR0w4DJwuNZ3k/YG ay2foquf2tHgc0zeUYpS+rtAx37CjYQim0UORQrYiuhfobygxoG3ZDD1z9h5Qc2Yad21Zl Zi1rXSWXnyNSm6u1Il3inn++HBG7tsQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-398-LqypewjZMVWBZWKdzJlFSw-1; Thu, 20 May 2021 10:13:31 -0400 X-MC-Unique: LqypewjZMVWBZWKdzJlFSw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4A646872FFE; Thu, 20 May 2021 14:13:30 +0000 (UTC) Received: from localhost (ovpn-115-223.ams2.redhat.com [10.36.115.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71E7719718; Thu, 20 May 2021 14:13:19 +0000 (UTC) From: Stefan Hajnoczi To: virtualization@lists.linux-foundation.org Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Jason Wang , Paolo Bonzini , Jens Axboe , slp@redhat.com, sgarzare@redhat.com, "Michael S. Tsirkin" , Stefan Hajnoczi Subject: [PATCH 1/3] virtio: add virtioqueue_more_used() Date: Thu, 20 May 2021 15:13:03 +0100 Message-Id: <20210520141305.355961-2-stefanha@redhat.com> In-Reply-To: <20210520141305.355961-1-stefanha@redhat.com> References: <20210520141305.355961-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add an API to check whether there are pending used buffers. There is already a similar API called virtqueue_poll() but it only works together with virtqueue_enable_cb_prepare(). The patches that follow add blk-mq ->poll() support to virtio_blk and they need to check for used buffers without re-enabling virtqueue callbacks, so introduce an API for it. Signed-off-by: Stefan Hajnoczi --- include/linux/virtio.h | 2 ++ drivers/virtio/virtio_ring.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/linux/virtio.h b/include/linux/virtio.h index b1894e0323fa..c6ad0f25f412 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -63,6 +63,8 @@ bool virtqueue_kick_prepare(struct virtqueue *vq); bool virtqueue_notify(struct virtqueue *vq); +bool virtqueue_more_used(const struct virtqueue *vq); + void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len); void *virtqueue_get_buf_ctx(struct virtqueue *vq, unsigned int *len, diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 71e16b53e9c1..7c3da75da462 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2032,6 +2032,23 @@ static inline bool more_used(const struct vring_virtqueue *vq) return vq->packed_ring ? more_used_packed(vq) : more_used_split(vq); } +/** + * virtqueue_more_used - check if there are used buffers pending + * @_vq: the struct virtqueue we're talking about. + * + * Returns true if there are used buffers, false otherwise. May be called at + * the same time as other virtqueue operations, but actually calling + * virtqueue_get_buf() requires serialization so be mindful of the race between + * calling virtqueue_more_used() and virtqueue_get_buf(). + */ +bool virtqueue_more_used(const struct virtqueue *_vq) +{ + struct vring_virtqueue *vq = to_vvq(_vq); + + return more_used(vq); +} +EXPORT_SYMBOL_GPL(virtqueue_more_used); + irqreturn_t vring_interrupt(int irq, void *_vq) { struct vring_virtqueue *vq = to_vvq(_vq);