From patchwork Tue Dec 15 18:42:53 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shirley Ma X-Patchwork-Id: 67707 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nBFIhlxc012098 for ; Tue, 15 Dec 2009 18:43:47 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757665AbZLOSnD (ORCPT ); Tue, 15 Dec 2009 13:43:03 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756627AbZLOSnA (ORCPT ); Tue, 15 Dec 2009 13:43:00 -0500 Received: from e2.ny.us.ibm.com ([32.97.182.142]:39721 "EHLO e2.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756283AbZLOSm6 (ORCPT ); Tue, 15 Dec 2009 13:42:58 -0500 Received: from d01relay07.pok.ibm.com (d01relay07.pok.ibm.com [9.56.227.147]) by e2.ny.us.ibm.com (8.14.3/8.13.1) with ESMTP id nBFIYLfX009455; Tue, 15 Dec 2009 13:34:21 -0500 Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay07.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id nBFIguB51806380; Tue, 15 Dec 2009 13:42:56 -0500 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id nBFIgtar003612; Tue, 15 Dec 2009 16:42:56 -0200 Received: from [9.48.59.35] (sig-9-48-59-35.mts.ibm.com [9.48.59.35]) by d01av03.pok.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id nBFIgrHX003564; Tue, 15 Dec 2009 16:42:54 -0200 Subject: [RFC PATCH] Subject: virtio: Add unused buffers detach from vring From: Shirley Ma To: Rusty Russell , "Michael S. Tsirkin" Cc: Avi Kivity , netdev@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Anthony Liguori In-Reply-To: <20091215163901.GA24015@redhat.com> References: <1258697359.7416.14.camel@localhost.localdomain> <200911231123.18898.rusty@rustcorp.com.au> <20091208122134.GA17286@redhat.com> <1260534506.30371.6.camel@localhost.localdomain> <1260535613.30371.24.camel@localhost.localdomain> <20091213114320.GC7074@redhat.com> <1260828518.8716.105.camel@localhost.localdomain> <20091215113327.GC13110@redhat.com> <1260894320.4387.64.camel@localhost.localdomain> <20091215163901.GA24015@redhat.com> Date: Tue, 15 Dec 2009 10:42:53 -0800 Message-Id: <1260902573.4387.76.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.24.5 (2.24.5-2.fc10) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index fbd2ecd..f847bc3 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -334,6 +334,29 @@ static bool vring_enable_cb(struct virtqueue *_vq) return true; } +/* This function is used to return vring unused buffers to caller for free */ +static void *vring_detach_bufs(struct virtqueue *_vq) +{ + struct vring_virtqueue *vq = to_vvq(_vq); + unsigned int i; + + START_USE(vq); + + for (i = 0; i < vq->vring.num; ++i) { + if (vq->data[i]) { + /* detach_buf clears data, so grab it now. */ + detach_buf(vq, i); + END_USE(vq); + return vq->data[i]; + } + } + /* That should have freed everything. */ + BUG_ON(vq->num_free != vq->vring.num); + + END_USE(vq); + return NULL; +} + irqreturn_t vring_interrupt(int irq, void *_vq) { struct vring_virtqueue *vq = to_vvq(_vq); @@ -360,6 +383,7 @@ static struct virtqueue_ops vring_vq_ops = { .kick = vring_kick, .disable_cb = vring_disable_cb, .enable_cb = vring_enable_cb, + .detach_bufs = vring_detach_bufs, }; struct virtqueue *vring_new_virtqueue(unsigned int num, diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 057a2e0..d7da456 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -71,6 +71,7 @@ struct virtqueue_ops { void (*disable_cb)(struct virtqueue *vq); bool (*enable_cb)(struct virtqueue *vq); + void *(*detach_bufs)(struct virtqueue *vq); }; /**