From patchwork Fri Dec 24 11:22:00 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshiaki Tamura X-Patchwork-Id: 431891 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBOBM7nm013560 for ; Fri, 24 Dec 2010 11:22:08 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752093Ab0LXLWE (ORCPT ); Fri, 24 Dec 2010 06:22:04 -0500 Received: from mail-wy0-f174.google.com ([74.125.82.174]:39965 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751870Ab0LXLWD convert rfc822-to-8bit (ORCPT ); Fri, 24 Dec 2010 06:22:03 -0500 Received: by wyb28 with SMTP id 28so6885561wyb.19 for ; Fri, 24 Dec 2010 03:22:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=JsmizGUqVSaLaLhCMZdqIDrGmhjlw+4i4/ZZmYXZSz8=; b=OxF0Q6/kxh1DNVpYfcgrbsewoFa+plA6ihfoX4a0HjGhj1IGJQ9vPMAfjjuyT+YGqO Qp4CJkuqnYeOcq1zD09SSOI8bzqJXHjYpjp0oQmT6kQVPmXo83h/Qn/r2dqFlTC1JC7u Dmio9/f6TwoJzdFXDiu1sPFspcGuCi+T0tgeo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=nhuv2xbco/2cNKUCjT/Gi2sGKa+0d1Q0NyD3Us/YKUw+R3vFvVLkJTlWkzofaQFYNQ iu+G4pvAoe0iNf0SpJpeD/BF/sph90V+Bn59pmrzXfNjFwfvbpBaoKmNlK0DZwl0xTUa LEAvGQjnzpaw4Jbunv77rGbrg8q6onQCPF5PU= MIME-Version: 1.0 Received: by 10.216.162.84 with SMTP id x62mr10094807wek.106.1293189720149; Fri, 24 Dec 2010 03:22:00 -0800 (PST) Received: by 10.216.10.3 with HTTP; Fri, 24 Dec 2010 03:22:00 -0800 (PST) In-Reply-To: <20101224094416.GB23271@redhat.com> References: <1293160708-30881-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> <1293160708-30881-7-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> <20101224094416.GB23271@redhat.com> Date: Fri, 24 Dec 2010 20:22:00 +0900 X-Google-Sender-Auth: iYyjIdSW1h9fexiSCkLBJLGpkZ0 Message-ID: Subject: Re: [PATCH 06/19] virtio: update last_avail_idx when inuse is decreased. From: Yoshiaki Tamura To: "Michael S. Tsirkin" Cc: kvm@vger.kernel.org, qemu-devel@nongnu.org, avi@redhat.com, anthony@codemonkey.ws, aliguori@us.ibm.com, mtosatti@redhat.com, dlaor@redhat.com, kwolf@redhat.com, ananth@in.ibm.com, psuriset@linux.vnet.ibm.com, vatsa@linux.vnet.ibm.com, stefanha@linux.vnet.ibm.com, ohmura.kei@lab.ntt.co.jp Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Fri, 24 Dec 2010 11:22:08 +0000 (UTC) diff --git a/hw/virtio.c b/hw/virtio.c index 07dbf86..b1586da 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -198,7 +198,7 @@ int virtio_queue_ready(VirtQueue *vq) int virtio_queue_empty(VirtQueue *vq) { - return vring_avail_idx(vq) == vq->last_avail_idx; + return vring_avail_idx(vq) == vq->last_avail_idx + vq->inuse; } void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, @@ -238,6 +238,7 @@ void virtqueue_flush(VirtQueue *vq, unsigned int count) wmb(); trace_virtqueue_flush(vq, count); vring_used_idx_increment(vq, count); + vq->last_avail_idx += count; vq->inuse -= count; } @@ -306,7 +307,7 @@ int virtqueue_avail_bytes(VirtQueue *vq, int in_bytes, int o unsigned int idx; int total_bufs, in_total, out_total; - idx = vq->last_avail_idx; + idx = vq->last_avail_idx + vq->inuse; total_bufs = in_total = out_total = 0; while (virtqueue_num_heads(vq, idx)) { @@ -386,7 +387,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) unsigned int i, head, max; target_phys_addr_t desc_pa = vq->vring.desc; - if (!virtqueue_num_heads(vq, vq->last_avail_idx)) + if (!virtqueue_num_heads(vq, vq->last_avail_idx + vq->inuse)) return 0; /* When we start there are none of either input nor output. */ @@ -394,7 +395,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) max = vq->vring.num; - i = head = virtqueue_get_head(vq, vq->last_avail_idx++); + i = head = virtqueue_get_head(vq, vq->last_avail_idx + vq->inuse); if (vring_desc_flags(desc_pa, i) & VRING_DESC_F_INDIRECT) { if (vring_desc_len(desc_pa, i) % sizeof(VRingDesc)) { @@ -626,7 +627,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq) /* Always notify when queue is empty (when feature acknowledge) */ if ((vring_avail_flags(vq) & VRING_AVAIL_F_NO_INTERRUPT) && (!(vdev->guest_features & (1 << VIRTIO_F_NOTIFY_ON_EMPTY)) || - (vq->inuse || vring_avail_idx(vq) != vq->last_avail_idx))) + (vq->inuse || vring_avail_idx(vq) != vq->last_avail_idx + vq->inuse))) return; trace_virtio_notify(vdev, vq);