From patchwork Thu May 5 08:32:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 9021751 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1434A9F1C1 for ; Thu, 5 May 2016 08:35:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7CC1F203F3 for ; Thu, 5 May 2016 08:35:07 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C66A320394 for ; Thu, 5 May 2016 08:35:06 +0000 (UTC) Received: from localhost ([::1]:52635 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayEkQ-0002V3-Fv for patchwork-qemu-devel@patchwork.kernel.org; Thu, 05 May 2016 04:35:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayEiE-0006rs-R5 for qemu-devel@nongnu.org; Thu, 05 May 2016 04:32:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ayEi3-00014c-6l for qemu-devel@nongnu.org; Thu, 05 May 2016 04:32:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35738) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayEi3-00010e-1Z for qemu-devel@nongnu.org; Thu, 05 May 2016 04:32:35 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EB92EC000703; Thu, 5 May 2016 08:32:23 +0000 (UTC) Received: from localhost (ovpn-112-47.ams2.redhat.com [10.36.112.47]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u458WMKn004943; Thu, 5 May 2016 04:32:23 -0400 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Thu, 5 May 2016 09:32:14 +0100 Message-Id: <1462437137-19824-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1462437137-19824-1-git-send-email-stefanha@redhat.com> References: <1462437137-19824-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/5] libqos: fix virtio num_free descriptor counter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc=20Mar=C3=AD?= , Paolo Bonzini , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The num_free variable is only ever decremented and never used for anything. Although it is currently useless and could be removed, it will become important once a function is added to pop buffers from a virtqueue. This patch adds the missing num_free initialization and adds assertions to check that there is enough space to add new descriptors. Signed-off-by: Stefan Hajnoczi --- tests/libqos/virtio.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index d3e4c02..939e5d3 100644 --- a/tests/libqos/virtio.c +++ b/tests/libqos/virtio.c @@ -140,6 +140,7 @@ void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr) vq->used = (uint64_t)((vq->avail + sizeof(uint16_t) * (3 + vq->size) + vq->align - 1) & ~(vq->align - 1)); vq->free_head = 0; + vq->num_free = vq->size; for (i = 0; i < vq->size - 1; i++) { /* vq->desc[i].addr */ @@ -212,6 +213,7 @@ uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write, uint16_t flags = 0; uint16_t idx = vq->free_head; + g_assert_cmpint(vq->num_free, >=, 1); vq->num_free--; if (write) { @@ -243,6 +245,7 @@ uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect) g_assert_cmpint(vq->size, >=, indirect->elem); g_assert_cmpint(indirect->index, ==, indirect->elem); + g_assert_cmpint(vq->num_free, >=, 1); vq->num_free--; /* vq->desc[vq->free_head].addr */