From patchwork Thu May 5 08:32:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 9021741 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 57E429F1C1 for ; Thu, 5 May 2016 08:33:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 46B8B203F3 for ; Thu, 5 May 2016 08:33:47 +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 00D34203EC for ; Thu, 5 May 2016 08:33:46 +0000 (UTC) Received: from localhost ([::1]:52624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayEj7-00088o-WE for patchwork-qemu-devel@patchwork.kernel.org; Thu, 05 May 2016 04:33:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayEiI-0006vf-Bm for qemu-devel@nongnu.org; Thu, 05 May 2016 04:32:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ayEi5-00015c-UR for qemu-devel@nongnu.org; Thu, 05 May 2016 04:32:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41375) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayEi5-00011Q-N7 for qemu-devel@nongnu.org; Thu, 05 May 2016 04:32:37 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 9B1E17F093; Thu, 5 May 2016 08:32:26 +0000 (UTC) Received: from localhost (ovpn-112-47.ams2.redhat.com [10.36.112.47]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u458WOih006299; Thu, 5 May 2016 04:32:25 -0400 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Thu, 5 May 2016 09:32:15 +0100 Message-Id: <1462437137-19824-4-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.27 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 3/5] libqos: add virtio buffer token 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 Allow the qvirtqueue_add_buf() caller to associate a void *token with the buffer. The next patch adds a qvirtqueue_get_buf() function which returns the token of the buffer that was popped from the virtqueue. This allows users to identify which buffer was popped. Existing virtio device tests are simple and do not use the token. They pass a NULL token to qvirtqueue_add_buf(). Signed-off-by: Stefan Hajnoczi --- tests/libqos/virtio.c | 9 ++++++-- tests/libqos/virtio.h | 8 +++++-- tests/virtio-blk-test.c | 54 ++++++++++++++++++++++++------------------------ tests/virtio-net-test.c | 6 +++--- tests/virtio-scsi-test.c | 8 +++---- 5 files changed, 47 insertions(+), 38 deletions(-) diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index 939e5d3..bc9c24c 100644 --- a/tests/libqos/virtio.c +++ b/tests/libqos/virtio.c @@ -147,6 +147,8 @@ void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr) writew(vq->desc + (16 * i), 0); /* vq->desc[i].next */ writew(vq->desc + (16 * i) + 14, i + 1); + + vq->tokens[i] = NULL; } /* vq->avail->flags */ @@ -208,7 +210,7 @@ void qvring_indirect_desc_add(QVRingIndirectDesc *indirect, uint64_t data, } uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write, - bool next) + bool next, void *token) { uint16_t flags = 0; uint16_t idx = vq->free_head; @@ -233,11 +235,13 @@ uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write, vq->free_head = readw(vq->desc + sizeof(struct vring_desc) * idx + offsetof(struct vring_desc, next)); + vq->tokens[idx] = token; return idx; } -uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect) +uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect, + void *token) { uint16_t idx = vq->free_head; @@ -258,6 +262,7 @@ uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect) vq->free_head = readw(vq->desc + sizeof(struct vring_desc) * idx + offsetof(struct vring_desc, next)); + vq->tokens[idx] = token; return idx; } diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h index c73fd8c..b5154a9 100644 --- a/tests/libqos/virtio.h +++ b/tests/libqos/virtio.h @@ -15,6 +15,8 @@ #define QVIRTIO_F_BAD_FEATURE 0x40000000 +#define QVIRTIO_QUEUE_MAX 1024 /* descriptors */ + typedef struct QVirtioDevice { /* Device type */ uint16_t device_type; @@ -31,6 +33,7 @@ typedef struct QVirtQueue { uint32_t align; bool indirect; bool event; + void *tokens[QVIRTIO_QUEUE_MAX]; } QVirtQueue; typedef struct QVRingIndirectDesc { @@ -125,8 +128,9 @@ QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d, void qvring_indirect_desc_add(QVRingIndirectDesc *indirect, uint64_t data, uint32_t len, bool write); uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write, - bool next); -uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect); + bool next, void *token); +uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect, + void *token); void qvirtqueue_kick(const QVirtioBus *bus, QVirtioDevice *d, QVirtQueue *vq, uint32_t free_head); diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index fb44840..0ed5cc3 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -187,9 +187,9 @@ static void test_basic(const QVirtioBus *bus, QVirtioDevice *dev, g_free(req.data); - free_head = qvirtqueue_add(vq, req_addr, 16, false, true); - qvirtqueue_add(vq, req_addr + 16, 512, false, true); - qvirtqueue_add(vq, req_addr + 528, 1, true, false); + free_head = qvirtqueue_add(vq, req_addr, 16, false, true, NULL); + qvirtqueue_add(vq, req_addr + 16, 512, false, true, NULL); + qvirtqueue_add(vq, req_addr + 528, 1, true, false, NULL); qvirtqueue_kick(bus, dev, vq, free_head); @@ -209,9 +209,9 @@ static void test_basic(const QVirtioBus *bus, QVirtioDevice *dev, g_free(req.data); - free_head = qvirtqueue_add(vq, req_addr, 16, false, true); - qvirtqueue_add(vq, req_addr + 16, 512, true, true); - qvirtqueue_add(vq, req_addr + 528, 1, true, false); + free_head = qvirtqueue_add(vq, req_addr, 16, false, true, NULL); + qvirtqueue_add(vq, req_addr + 16, 512, true, true, NULL); + qvirtqueue_add(vq, req_addr + 528, 1, true, false, NULL); qvirtqueue_kick(bus, dev, vq, free_head); @@ -239,8 +239,8 @@ static void test_basic(const QVirtioBus *bus, QVirtioDevice *dev, g_free(req.data); - free_head = qvirtqueue_add(vq, req_addr, 528, false, true); - qvirtqueue_add(vq, req_addr + 528, 1, true, false); + free_head = qvirtqueue_add(vq, req_addr, 528, false, true, NULL); + qvirtqueue_add(vq, req_addr + 528, 1, true, false, NULL); qvirtqueue_kick(bus, dev, vq, free_head); qvirtio_wait_queue_isr(bus, dev, vq, QVIRTIO_BLK_TIMEOUT_US); @@ -259,8 +259,8 @@ static void test_basic(const QVirtioBus *bus, QVirtioDevice *dev, g_free(req.data); - free_head = qvirtqueue_add(vq, req_addr, 16, false, true); - qvirtqueue_add(vq, req_addr + 16, 513, true, false); + free_head = qvirtqueue_add(vq, req_addr, 16, false, true, NULL); + qvirtqueue_add(vq, req_addr + 16, 513, true, false, NULL); qvirtqueue_kick(bus, dev, vq, free_head); @@ -360,7 +360,7 @@ static void pci_indirect(void) indirect = qvring_indirect_desc_setup(&dev->vdev, alloc, 2); qvring_indirect_desc_add(indirect, req_addr, 528, false); qvring_indirect_desc_add(indirect, req_addr + 528, 1, true); - free_head = qvirtqueue_add_indirect(&vqpci->vq, indirect); + free_head = qvirtqueue_add_indirect(&vqpci->vq, indirect, NULL); qvirtqueue_kick(&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head); qvirtio_wait_queue_isr(&qvirtio_pci, &dev->vdev, &vqpci->vq, @@ -385,7 +385,7 @@ static void pci_indirect(void) indirect = qvring_indirect_desc_setup(&dev->vdev, alloc, 2); qvring_indirect_desc_add(indirect, req_addr, 16, false); qvring_indirect_desc_add(indirect, req_addr + 16, 513, true); - free_head = qvirtqueue_add_indirect(&vqpci->vq, indirect); + free_head = qvirtqueue_add_indirect(&vqpci->vq, indirect, NULL); qvirtqueue_kick(&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head); qvirtio_wait_queue_isr(&qvirtio_pci, &dev->vdev, &vqpci->vq, @@ -509,9 +509,9 @@ static void pci_msix(void) g_free(req.data); - free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false); + free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true, NULL); + qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, false, true, NULL); + qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false, NULL); qvirtqueue_kick(&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head); qvirtio_wait_queue_isr(&qvirtio_pci, &dev->vdev, &vqpci->vq, @@ -532,9 +532,9 @@ static void pci_msix(void) g_free(req.data); - free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, true, true); - qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false); + free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true, NULL); + qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, true, true, NULL); + qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false, NULL); qvirtqueue_kick(&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head); @@ -616,9 +616,9 @@ static void pci_idx(void) g_free(req.data); - free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false); + free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true, NULL); + qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, false, true, NULL); + qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false, NULL); qvirtqueue_kick(&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head); qvirtio_wait_queue_isr(&qvirtio_pci, &dev->vdev, &vqpci->vq, @@ -637,9 +637,9 @@ static void pci_idx(void) /* Notify after processing the third request */ qvirtqueue_set_used_event(&vqpci->vq, 2); - free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false); + free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true, NULL); + qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, false, true, NULL); + qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false, NULL); qvirtqueue_kick(&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head); /* No notification expected */ @@ -660,9 +660,9 @@ static void pci_idx(void) g_free(req.data); - free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, true, true); - qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false); + free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true, NULL); + qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, true, true, NULL); + qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false, NULL); qvirtqueue_kick(&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head); diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c index 9c8114d..ed21606 100644 --- a/tests/virtio-net-test.c +++ b/tests/virtio-net-test.c @@ -101,7 +101,7 @@ static void rx_test(const QVirtioBus *bus, QVirtioDevice *dev, req_addr = guest_alloc(alloc, 64); - free_head = qvirtqueue_add(vq, req_addr, 64, true, false); + free_head = qvirtqueue_add(vq, req_addr, 64, true, false, NULL); qvirtqueue_kick(bus, dev, vq, free_head); ret = iov_send(socket, iov, 2, 0, sizeof(len) + sizeof(test)); @@ -127,7 +127,7 @@ static void tx_test(const QVirtioBus *bus, QVirtioDevice *dev, req_addr = guest_alloc(alloc, 64); memwrite(req_addr + VNET_HDR_SIZE, "TEST", 4); - free_head = qvirtqueue_add(vq, req_addr, 64, false, false); + free_head = qvirtqueue_add(vq, req_addr, 64, false, false, NULL); qvirtqueue_kick(bus, dev, vq, free_head); qvirtio_wait_queue_isr(bus, dev, vq, QVIRTIO_NET_TIMEOUT_US); @@ -163,7 +163,7 @@ static void rx_stop_cont_test(const QVirtioBus *bus, QVirtioDevice *dev, req_addr = guest_alloc(alloc, 64); - free_head = qvirtqueue_add(vq, req_addr, 64, true, false); + free_head = qvirtqueue_add(vq, req_addr, 64, true, false, NULL); qvirtqueue_kick(bus, dev, vq, free_head); qmp("{ 'execute' : 'stop'}"); diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c index 71f5aeb..8eb251f 100644 --- a/tests/virtio-scsi-test.c +++ b/tests/virtio-scsi-test.c @@ -103,20 +103,20 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb, /* Add request header */ req_addr = qvirtio_scsi_alloc(vs, sizeof(req), &req); - free_head = qvirtqueue_add(vq, req_addr, sizeof(req), false, true); + free_head = qvirtqueue_add(vq, req_addr, sizeof(req), false, true, NULL); if (data_out_len) { data_out_addr = qvirtio_scsi_alloc(vs, data_out_len, data_out); - qvirtqueue_add(vq, data_out_addr, data_out_len, false, true); + qvirtqueue_add(vq, data_out_addr, data_out_len, false, true, NULL); } /* Add response header */ resp_addr = qvirtio_scsi_alloc(vs, sizeof(resp), &resp); - qvirtqueue_add(vq, resp_addr, sizeof(resp), true, !!data_in_len); + qvirtqueue_add(vq, resp_addr, sizeof(resp), true, !!data_in_len, NULL); if (data_in_len) { data_in_addr = qvirtio_scsi_alloc(vs, data_in_len, data_in); - qvirtqueue_add(vq, data_in_addr, data_in_len, true, false); + qvirtqueue_add(vq, data_in_addr, data_in_len, true, false, NULL); } qvirtqueue_kick(&qvirtio_pci, vs->dev, vq, free_head);