From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756178AbdLTUMN (ORCPT ); Wed, 20 Dec 2017 15:12:13 -0500 Received: from 9.mo1.mail-out.ovh.net ([178.32.108.172]:38063 "EHLO 9.mo1.mail-out.ovh.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755222AbdLTUMM (ORCPT ); Wed, 20 Dec 2017 15:12:12 -0500 X-Greylist: delayed 8713 seconds by postgrey-1.27 at vger.kernel.org; Wed, 20 Dec 2017 15:12:11 EST Subject: [PATCH 1/2] virtio: allow to detach a buffer from the virtqueue From: Greg Kurz To: linux-kernel@vger.kernel.org Cc: v9fs-developer@lists.sourceforge.net, "Michael S. Tsirkin" , Jason Wang , Al Viro Date: Wed, 20 Dec 2017 18:46:42 +0100 Message-ID: <151379200283.15509.14269498487565699857.stgit@bahia> In-Reply-To: <151379198727.15509.2771563206512953068.stgit@bahia> References: <151379198727.15509.2771563206512953068.stgit@bahia> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Ovh-Tracer-Id: 11675300561605663121 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtuddrgeeggddutdejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is possible for a device to stop using buffers without pushing them back to the driver. This is the case for example with the 9p virtio device: if the driver flushes an in-flight request, the 9p specification specification [*] mandates the server to "to purge the pending response". The reply to the flush request indicates that the 9p server has stopped using the buffers of the flushed in-flight request. But since the server doesn't push back the associated buffers, they don't go back to the free list. This leads the virtqueue to end up with a single slot to handle all the dialog with the device, ie, serialize all I/Os. This patch hence gives the possibility for device specific code to explicitly detach a given buffer from the used ring and put it back to the free list. [*] http://man.cat-v.org/plan_9/5/flush Signed-off-by: Greg Kurz --- drivers/virtio/virtio_ring.c | 28 ++++++++++++++++++++++++++++ include/linux/virtio.h | 1 + 2 files changed, 29 insertions(+) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index eb30f3e09a47..886e9d054de3 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -936,6 +936,34 @@ void *virtqueue_detach_unused_buf(struct virtqueue *_vq) } EXPORT_SYMBOL_GPL(virtqueue_detach_unused_buf); +/** + * virtqueue_detach_buf - detach specific buffer + * @vq: the struct virtqueue we're talking about. + * + * Returns NULL or the "data" token handed to virtqueue_add_*(). + * This should only be used if the driver really knows the buffer + * isn't needed anymore by the device. + */ +void *virtqueue_detach_buf(struct virtqueue *_vq, void *buf) +{ + struct vring_virtqueue *vq = to_vvq(_vq); + unsigned int i; + + START_USE(vq); + + for (i = 0; i < vq->vring.num; i++) { + if (vq->desc_state[i].data != buf) + continue; + detach_buf(vq, i, NULL); + END_USE(vq); + return buf; + } + + END_USE(vq); + return NULL; +} +EXPORT_SYMBOL_GPL(virtqueue_detach_buf); + irqreturn_t vring_interrupt(int irq, void *_vq) { struct vring_virtqueue *vq = to_vvq(_vq); diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 988c7355bc22..850158518ce5 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -80,6 +80,7 @@ bool virtqueue_poll(struct virtqueue *vq, unsigned); bool virtqueue_enable_cb_delayed(struct virtqueue *vq); void *virtqueue_detach_unused_buf(struct virtqueue *vq); +void *virtqueue_detach_buf(struct virtqueue *vq, void *buf); unsigned int virtqueue_get_vring_size(struct virtqueue *vq);