From nobody Sun Apr 19 04:00:10 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C053C43334 for ; Thu, 7 Jul 2022 03:00:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234932AbiGGDAX (ORCPT ); Wed, 6 Jul 2022 23:00:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234885AbiGGDAQ (ORCPT ); Wed, 6 Jul 2022 23:00:16 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03D612F672 for ; Wed, 6 Jul 2022 20:00:14 -0700 (PDT) Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp236.sjtu.edu.cn (Postfix) with ESMTPS id A45F41008B38C; Thu, 7 Jul 2022 10:44:30 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 8DEC9200C91EE; Thu, 7 Jul 2022 10:44:30 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 2O45w16mEfGD; Thu, 7 Jul 2022 10:44:30 +0800 (CST) Received: from localhost.localdomain (unknown [202.120.40.82]) (Authenticated sender: qtxuning1999@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id 9B0C4200C91EC; Thu, 7 Jul 2022 10:44:20 +0800 (CST) From: Guo Zhi To: jasowang@redhat.com, mst@redhat.com Cc: eperezma@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, sgarzare@redhat.com, Guo Zhi Subject: [PATCH v2 1/4] virtio_test: kick vhost for a batch of descriptors Date: Thu, 7 Jul 2022 10:44:06 +0800 Message-Id: <20220707024409.1869-2-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220707024409.1869-1-qtxuning1999@sjtu.edu.cn> References: <20220707024409.1869-1-qtxuning1999@sjtu.edu.cn> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Only kick vhost when the batch finishes. Signed-off-by: Guo Zhi --- tools/virtio/virtio_test.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c index 23f142af5..95f78b311 100644 --- a/tools/virtio/virtio_test.c +++ b/tools/virtio/virtio_test.c @@ -208,11 +208,10 @@ static void run_test(struct vdev_info *dev, struct vq= _info *vq, } =20 ++started; - - if (unlikely(!virtqueue_kick(vq->vq))) { - r =3D -1; - break; - } + } + if (unlikely(!virtqueue_kick(vq->vq))) { + r =3D -1; + break; } =20 if (started >=3D bufs) --=20 2.17.1 From nobody Sun Apr 19 04:00:10 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17E8AC43334 for ; Thu, 7 Jul 2022 02:55:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234815AbiGGCzd (ORCPT ); Wed, 6 Jul 2022 22:55:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234177AbiGGCzb (ORCPT ); Wed, 6 Jul 2022 22:55:31 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 036612E9FE for ; Wed, 6 Jul 2022 19:55:30 -0700 (PDT) Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp236.sjtu.edu.cn (Postfix) with ESMTPS id 8A4131008B388; Thu, 7 Jul 2022 10:44:39 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 6F06F200A5BFF; Thu, 7 Jul 2022 10:44:39 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id e5TwBO-loqPR; Thu, 7 Jul 2022 10:44:39 +0800 (CST) Received: from localhost.localdomain (unknown [202.120.40.82]) (Authenticated sender: qtxuning1999@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id 464792009BEA0; Thu, 7 Jul 2022 10:44:30 +0800 (CST) From: Guo Zhi To: jasowang@redhat.com, mst@redhat.com Cc: eperezma@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, sgarzare@redhat.com, Guo Zhi Subject: [PATCH v2 2/4] virtio_test: move magic number in code as defined constant Date: Thu, 7 Jul 2022 10:44:07 +0800 Message-Id: <20220707024409.1869-3-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220707024409.1869-1-qtxuning1999@sjtu.edu.cn> References: <20220707024409.1869-1-qtxuning1999@sjtu.edu.cn> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We should avoid using magic numbers directly. Signed-off-by: Guo Zhi --- tools/virtio/virtio_test.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c index 95f78b311..1ecd64271 100644 --- a/tools/virtio/virtio_test.c +++ b/tools/virtio/virtio_test.c @@ -20,7 +20,10 @@ #include "../../drivers/vhost/test.h" =20 #define RANDOM_BATCH -1 - +#define ALIGN 4096 +#define RINGSIZE 256 +#define TEST_BUF_NUM 0x100000 +#define BUF_SIZE 1024 /* Unused */ void *__kmalloc_fake, *__kfree_ignore_start, *__kfree_ignore_end; =20 @@ -100,8 +103,8 @@ static void vq_reset(struct vq_info *info, int num, str= uct virtio_device *vdev) if (info->vq) vring_del_virtqueue(info->vq); =20 - memset(info->ring, 0, vring_size(num, 4096)); - vring_init(&info->vring, num, info->ring, 4096); + memset(info->ring, 0, vring_size(num, ALIGN)); + vring_init(&info->vring, num, info->ring, ALIGN); info->vq =3D __vring_new_virtqueue(info->idx, info->vring, vdev, true, false, vq_notify, vq_callback, "test"); assert(info->vq); @@ -115,7 +118,7 @@ static void vq_info_add(struct vdev_info *dev, int num) info->idx =3D dev->nvqs; info->kick =3D eventfd(0, EFD_NONBLOCK); info->call =3D eventfd(0, EFD_NONBLOCK); - r =3D posix_memalign(&info->ring, 4096, vring_size(num, 4096)); + r =3D posix_memalign(&info->ring, PAGE_SIZE, vring_size(num, ALIGN)); assert(r >=3D 0); vq_reset(info, num, &dev->vdev); vhost_vq_setup(dev, info); @@ -131,7 +134,7 @@ static void vdev_info_init(struct vdev_info* dev, unsig= ned long long features) dev->vdev.features =3D features; INIT_LIST_HEAD(&dev->vdev.vqs); spin_lock_init(&dev->vdev.vqs_list_lock); - dev->buf_size =3D 1024; + dev->buf_size =3D BUF_SIZE; dev->buf =3D malloc(dev->buf_size); assert(dev->buf); dev->control =3D open("/dev/vhost-test", O_RDWR); @@ -396,7 +399,8 @@ int main(int argc, char **argv) =20 done: vdev_info_init(&dev, features); - vq_info_add(&dev, 256); - run_test(&dev, &dev.vqs[0], delayed, batch, reset, 0x100000); + vq_info_add(&dev, RINGSIZE); + + run_test(&dev, &dev.vqs[0], delayed, batch, reset, TEST_BUF_NUM); return 0; } --=20 2.17.1 From nobody Sun Apr 19 04:00:10 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59A9BC43334 for ; Thu, 7 Jul 2022 02:55:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230246AbiGGCzv (ORCPT ); Wed, 6 Jul 2022 22:55:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234841AbiGGCzo (ORCPT ); Wed, 6 Jul 2022 22:55:44 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 668982E9FE for ; Wed, 6 Jul 2022 19:55:43 -0700 (PDT) Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp236.sjtu.edu.cn (Postfix) with ESMTPS id 86E7B1008B38D; Thu, 7 Jul 2022 10:44:52 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 0172A200A52B4; Thu, 7 Jul 2022 10:44:50 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id kpTCTY_YsFCG; Thu, 7 Jul 2022 10:44:49 +0800 (CST) Received: from localhost.localdomain (unknown [202.120.40.82]) (Authenticated sender: qtxuning1999@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id 9FFD1200A5BFF; Thu, 7 Jul 2022 10:44:39 +0800 (CST) From: Guo Zhi To: jasowang@redhat.com, mst@redhat.com Cc: eperezma@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, sgarzare@redhat.com, Guo Zhi Subject: [PATCH v2 3/4] virtio_test: use random length scatterlists to test descriptor chain Date: Thu, 7 Jul 2022 10:44:08 +0800 Message-Id: <20220707024409.1869-4-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220707024409.1869-1-qtxuning1999@sjtu.edu.cn> References: <20220707024409.1869-1-qtxuning1999@sjtu.edu.cn> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Prior implementation only use one descriptor for each io event, which does't test code of descriptor chain. More importantly, one descriptor will not use indirect feature even indirect feature is specified. Use random length scatterlists here to test descriptor chain. Signed-off-by: Guo Zhi --- tools/virtio/virtio_test.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c index 1ecd64271..363695b33 100644 --- a/tools/virtio/virtio_test.c +++ b/tools/virtio/virtio_test.c @@ -20,6 +20,7 @@ #include "../../drivers/vhost/test.h" =20 #define RANDOM_BATCH -1 +#define MAX_SG_FRAGS 8UL #define ALIGN 4096 #define RINGSIZE 256 #define TEST_BUF_NUM 0x100000 @@ -172,7 +173,8 @@ static void wait_for_interrupt(struct vdev_info *dev) static void run_test(struct vdev_info *dev, struct vq_info *vq, bool delayed, int batch, int reset_n, int bufs) { - struct scatterlist sl; + struct scatterlist sg[MAX_SG_FRAGS]; + int sg_size =3D 0; long started =3D 0, completed =3D 0, next_reset =3D reset_n; long completed_before, started_before; int r, test =3D 1; @@ -197,8 +199,11 @@ static void run_test(struct vdev_info *dev, struct vq_= info *vq, =20 while (started < bufs && (started - completed) < batch) { - sg_init_one(&sl, dev->buf, dev->buf_size); - r =3D virtqueue_add_outbuf(vq->vq, &sl, 1, + sg_size =3D random() % (MAX_SG_FRAGS - 1) + 1; + sg_init_table(sg, sg_size); + for (int i =3D 0; i < sg_size; ++i) + sg_set_buf(&sg[i], dev->buf + i, 0x1); + r =3D virtqueue_add_outbuf(vq->vq, sg, sg_size, dev->buf + started, GFP_ATOMIC); if (unlikely(r !=3D 0)) { --=20 2.17.1 From nobody Sun Apr 19 04:00:10 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D431C43334 for ; Thu, 7 Jul 2022 02:55:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234709AbiGGCzW (ORCPT ); Wed, 6 Jul 2022 22:55:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234177AbiGGCzT (ORCPT ); Wed, 6 Jul 2022 22:55:19 -0400 X-Greylist: delayed 653 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 06 Jul 2022 19:55:17 PDT Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2CB82ED6B for ; Wed, 6 Jul 2022 19:55:17 -0700 (PDT) Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp236.sjtu.edu.cn (Postfix) with ESMTPS id 13BF41008B392; Thu, 7 Jul 2022 10:44:57 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 35268200C91EC; Thu, 7 Jul 2022 10:44:57 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Tnu6H11dLAu7; Thu, 7 Jul 2022 10:44:57 +0800 (CST) Received: from localhost.localdomain (unknown [202.120.40.82]) (Authenticated sender: qtxuning1999@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id 474E4200A4ED3; Thu, 7 Jul 2022 10:44:49 +0800 (CST) From: Guo Zhi To: jasowang@redhat.com, mst@redhat.com Cc: eperezma@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, sgarzare@redhat.com, Guo Zhi Subject: [PATCH v2 4/4] virtio_test: enable indirection feature Date: Thu, 7 Jul 2022 10:44:09 +0800 Message-Id: <20220707024409.1869-5-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220707024409.1869-1-qtxuning1999@sjtu.edu.cn> References: <20220707024409.1869-1-qtxuning1999@sjtu.edu.cn> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Prior implementation don't use indirection feature because there is only one descriptor for every io event, actually prior implementation don't support indirection because vhost can't translate and find the indirect descriptors. This commit enable virtio_test malloc indirect descriptors in a indirect buffer and map this buffer to vhost, thus resolve this problem. Signed-off-by: Guo Zhi --- tools/virtio/virtio_test.c | 50 ++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c index 363695b33..dca408a5c 100644 --- a/tools/virtio/virtio_test.c +++ b/tools/virtio/virtio_test.c @@ -25,7 +25,7 @@ #define RINGSIZE 256 #define TEST_BUF_NUM 0x100000 #define BUF_SIZE 1024 -/* Unused */ +#define INDIRECTS_SIZE (RINGSIZE * sizeof(struct vring_desc) * 8) void *__kmalloc_fake, *__kfree_ignore_start, *__kfree_ignore_end; =20 struct vq_info { @@ -47,6 +47,8 @@ struct vdev_info { int nvqs; void *buf; size_t buf_size; + void *indirects; + size_t indirects_size; struct vhost_memory *mem; }; =20 @@ -131,6 +133,8 @@ static void vq_info_add(struct vdev_info *dev, int num) static void vdev_info_init(struct vdev_info* dev, unsigned long long featu= res) { int r; + int nregions =3D 2; + memset(dev, 0, sizeof *dev); dev->vdev.features =3D features; INIT_LIST_HEAD(&dev->vdev.vqs); @@ -138,19 +142,25 @@ static void vdev_info_init(struct vdev_info* dev, uns= igned long long features) dev->buf_size =3D BUF_SIZE; dev->buf =3D malloc(dev->buf_size); assert(dev->buf); - dev->control =3D open("/dev/vhost-test", O_RDWR); + dev->indirects_size =3D INDIRECTS_SIZE; + dev->indirects =3D malloc(dev->indirects_size); + assert(dev->indirects); + dev->control =3D open("/dev/vhost-test", O_RDWR); assert(dev->control >=3D 0); r =3D ioctl(dev->control, VHOST_SET_OWNER, NULL); assert(r >=3D 0); dev->mem =3D malloc(offsetof(struct vhost_memory, regions) + - sizeof dev->mem->regions[0]); + (sizeof(dev->mem->regions[0])) * nregions); assert(dev->mem); memset(dev->mem, 0, offsetof(struct vhost_memory, regions) + - sizeof dev->mem->regions[0]); - dev->mem->nregions =3D 1; + (sizeof(dev->mem->regions[0])) * nregions); + dev->mem->nregions =3D nregions; dev->mem->regions[0].guest_phys_addr =3D (long)dev->buf; dev->mem->regions[0].userspace_addr =3D (long)dev->buf; dev->mem->regions[0].memory_size =3D dev->buf_size; + dev->mem->regions[1].guest_phys_addr =3D (long)dev->indirects; + dev->mem->regions[1].userspace_addr =3D (long)dev->indirects; + dev->mem->regions[1].memory_size =3D dev->indirects_size; r =3D ioctl(dev->control, VHOST_SET_MEM_TABLE, dev->mem); assert(r >=3D 0); } @@ -170,6 +180,19 @@ static void wait_for_interrupt(struct vdev_info *dev) } } =20 +static int test_virtqueue_add_outbuf(struct virtqueue *vq, + struct scatterlist *sg, unsigned int num, + void *data, void *indirects) +{ + int r; + + __kmalloc_fake =3D indirects; + r =3D virtqueue_add_outbuf(vq, sg, num, data, + GFP_ATOMIC); + __kmalloc_fake =3D NULL; + return r; +} + static void run_test(struct vdev_info *dev, struct vq_info *vq, bool delayed, int batch, int reset_n, int bufs) { @@ -181,6 +204,7 @@ static void run_test(struct vdev_info *dev, struct vq_i= nfo *vq, unsigned len; long long spurious =3D 0; const bool random_batch =3D batch =3D=3D RANDOM_BATCH; + void *indirects; =20 r =3D ioctl(dev->control, VHOST_TEST_RUN, &test); assert(r >=3D 0); @@ -188,10 +212,15 @@ static void run_test(struct vdev_info *dev, struct vq= _info *vq, next_reset =3D INT_MAX; } =20 + /* Don't kfree indirects. */ + __kfree_ignore_start =3D dev->indirects; + __kfree_ignore_end =3D dev->indirects + dev->indirects_size; + for (;;) { virtqueue_disable_cb(vq->vq); completed_before =3D completed; started_before =3D started; + indirects =3D dev->indirects; do { const bool reset =3D completed > next_reset; if (random_batch) @@ -203,9 +232,13 @@ static void run_test(struct vdev_info *dev, struct vq_= info *vq, sg_init_table(sg, sg_size); for (int i =3D 0; i < sg_size; ++i) sg_set_buf(&sg[i], dev->buf + i, 0x1); - r =3D virtqueue_add_outbuf(vq->vq, sg, sg_size, - dev->buf + started, - GFP_ATOMIC); + + // use indirects buffer repeatedly + if (indirects + sg_size * sizeof(struct vring_desc) > + dev->indirects + dev->indirects_size) + indirects =3D dev->indirects; + r =3D test_virtqueue_add_outbuf(vq->vq, sg, sg_size, + dev->buf + started, indirects); if (unlikely(r !=3D 0)) { if (r =3D=3D -ENOSPC && started > started_before) @@ -216,6 +249,7 @@ static void run_test(struct vdev_info *dev, struct vq_i= nfo *vq, } =20 ++started; + indirects +=3D sg_size * sizeof(struct vring_desc); } if (unlikely(!virtqueue_kick(vq->vq))) { r =3D -1; --=20 2.17.1