From patchwork Tue Jun 1 14:47:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 54214 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E1317B7D43 for ; Wed, 2 Jun 2010 00:53:53 +1000 (EST) Received: from localhost ([127.0.0.1]:42256 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJSqj-0006TE-HW for incoming@patchwork.ozlabs.org; Tue, 01 Jun 2010 10:53:49 -0400 Received: from [140.186.70.92] (port=46366 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJSoa-0005RS-Mz for qemu-devel@nongnu.org; Tue, 01 Jun 2010 10:51:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OJSoW-0001L4-1e for qemu-devel@nongnu.org; Tue, 01 Jun 2010 10:51:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51730) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJSoV-0001Kn-Qw for qemu-devel@nongnu.org; Tue, 01 Jun 2010 10:51:32 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o51EpS3g014445 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 1 Jun 2010 10:51:28 -0400 Received: from redhat.com (dhcp-0-94.tlv.redhat.com [10.35.0.94]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o51EpQoA003184; Tue, 1 Jun 2010 10:51:26 -0400 Date: Tue, 1 Jun 2010 17:47:16 +0300 From: "Michael S. Tsirkin" To: Rusty Russell , linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, qemu-devel@nongnu.org Message-ID: <4e79f8b2536f736f8104804eed23a0a95d0839e4.1275403477.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mutt-Fcc: =sent User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Subject: [Qemu-devel] [PATCHv3 2/2] virtio: publish used idx X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Michael S. Tsirkin --- drivers/net/virtio_net.c | 2 ++ drivers/virtio/virtio_ring.c | 15 +++++++++++++-- include/linux/virtio_ring.h | 10 ++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 78eb319..30e7483 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -1056,6 +1057,7 @@ static unsigned int features[] = { VIRTIO_NET_F_GUEST_ECN, VIRTIO_NET_F_GUEST_UFO, VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, VIRTIO_NET_F_CTRL_VQ, VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN, + VIRTIO_RING_F_PUBLISH_USED, }; static struct virtio_driver virtio_net_driver = { diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 0f684b4..5a8c711 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -92,6 +92,9 @@ struct vring_virtqueue /* Last used index we've seen. */ u16 last_used_idx; + /* Publish last used index we've seen at this location. */ + u16 *publish_last_used_idx; + /* How to notify other side. FIXME: commonalize hcalls! */ void (*notify)(struct virtqueue *vq); @@ -325,7 +328,7 @@ void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len) /* detach_buf clears data, so grab it now. */ ret = vq->data[i]; detach_buf(vq, i); - vq->last_used_idx++; + *vq->publish_last_used_idx = ++vq->last_used_idx; END_USE(vq); return ret; } @@ -425,13 +428,19 @@ struct virtqueue *vring_new_virtqueue(unsigned int num, if (!vq) return NULL; - vring_init(&vq->vring, num, pages, vring_align, false); + vring_init(&vq->vring, num, pages, vring_align, + virtio_has_feature(vdev, VIRTIO_RING_F_PUBLISH_USED)); + if (virtio_has_feature(vdev, VIRTIO_RING_F_PUBLISH_USED)) + vq->publish_last_used_idx = &vq->vring.avail->last_used_idx; + else + vq->publish_last_used_idx = &vq->last_used_idx; vq->vq.callback = callback; vq->vq.vdev = vdev; vq->vq.name = name; vq->notify = notify; vq->broken = false; vq->last_used_idx = 0; + *vq->publish_last_used_idx = 0; vq->num_added = 0; list_add_tail(&vq->vq.list, &vdev->vqs); #ifdef DEBUG @@ -473,6 +482,8 @@ void vring_transport_features(struct virtio_device *vdev) switch (i) { case VIRTIO_RING_F_INDIRECT_DESC: break; + case VIRTIO_RING_F_PUBLISH_USED: + break; default: /* We don't understand this bit. */ clear_bit(i, vdev->features); diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h index 458ce41..87f8fd3 100644 --- a/include/linux/virtio_ring.h +++ b/include/linux/virtio_ring.h @@ -29,6 +29,9 @@ /* We support indirect buffer descriptors */ #define VIRTIO_RING_F_INDIRECT_DESC 28 +/* The Guest publishes last-seen used index at the end of the avail ring. */ +#define VIRTIO_RING_F_PUBLISH_USED 29 + /* Virtio ring descriptors: 16 bytes. These can chain together via "next". */ struct vring_desc { /* Address (guest-physical). */ @@ -51,6 +54,7 @@ struct vring_avail_ctrl { __u16 idx; __u8 pad[254]; __u16 flags; + __u16 last_used_idx; }; /* u32 is used here for ids for padding reasons. */ @@ -75,6 +79,7 @@ struct vring { __u16 *avail_idx; __u16 *avail_flags; __u16 *avail_ring; + __u16 *last_used_idx; struct vring_used *used; }; @@ -100,6 +105,7 @@ struct vring { * __u16 avail_idx; * __u8 pad[254]; // Padding to align flags at cache line boundary. * __u16 avail_flags; + * __u16 last_used_idx; * // Padding to the next align boundary. * char pad[]; * @@ -120,14 +126,18 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p, vr->avail_ring = (void*)avail; vr->avail_idx = &ctrl->idx; vr->avail_flags = &ctrl->flags; + vr->last_used_idx = &ctrl->last_used_idx; } else { vr->avail_idx = &avail->idx; vr->avail_flags = &avail->flags; + vr->last_used_idx = NULL; } vr->used = (void *)ALIGN((unsigned long)&avail->ring[num], align); /* Verify that avail fits before used. */ BUG_ON((unsigned long)(vr->avail_flags + 1) > (unsigned long)vr->used); BUG_ON((unsigned long)(vr->avail_idx + 1) > (unsigned long)vr->used); + BUG_ON(vr->last_used_idx && (unsigned long)(vr->last_used_idx + 1) > + (unsigned long)vr->used); BUG_ON((unsigned long)(&vr->avail_ring[num]) > (unsigned long)vr->used); }