Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2697375rdb; Wed, 4 Oct 2023 08:49:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMcTJ93J9X6JNMuPc2bM8PnWu7m8Fe1vUGbx50if1pjoQMb19hbU9ODnvOyOQelqeVtCEO X-Received: by 2002:a05:6a20:1589:b0:15b:b83c:9b48 with SMTP id h9-20020a056a20158900b0015bb83c9b48mr15535pzj.24.1696434550931; Wed, 04 Oct 2023 08:49:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696434550; cv=none; d=google.com; s=arc-20160816; b=yQq7T4mlHYVuHTCjNtS8GS7ng+iOhgPk83WoOEoFrx69emog3LesVptl8WqgfP1UYr 9aP9DzyYhWMOwlN8JaM9k0iW37xJGKluUX5AVwgTvrCDwrpC99dNhrH04SelujVyCcNA MmVg+hFfykfBRPLS6zlThyLy7/B5en+sqPp0p3eWcZd0EY6M3GEqzUoN4wC5n/IZXrHz rdY58vHGfh0h0kwED4iiGbKhmQ/A3Ago/Mm/jVE3lkCbmxq2YXAeuMRVV2580H3P7J4C Ufhpfl02dwIN1dNN6pUZ2gQNKYpY4eO2VPuNHN3e1ygmc67NtS6wTEVN2ODpE2iBc2jy XMjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=rZ8aDKUrpN2q/s8i97pAGn8PQgXbCGC0dTTfu9VD+mg=; fh=JEq7ZyqHwnKMAbPjHbEHIOO1u1YxTWxtQlCbJmwG+xw=; b=DKDkFU3ih1ayuSaWsaSv8sIpdEd2b6Dh0QZhSEt5uqwyj7I3jScCg+gRiw7SYGrcsS GivNGTLDkMRYX5kCJWipYV8RSspHDiNt2ulzVkeRgjMMyxnjPuOKzyxWdkswDapAydZr OoWayjQ5d06WTjY6dHEX3Q3v7ZlwlN7W+7tzTPIRPMY78IEmMkEzffF6rnJuai5kZder asFe3P8ARq7kWuj6lUlJx+ib5vHbA9+ZUz3vEA9qsm/VYU41sUaVg20b93Wg7OoGuFEm r5JWRf8/1bghv1PNaE4z1PiGD1DggIgLKfaO+rX2TSdP770sRy0oEJYE+SLp8QlQUUqg W9jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VvDioVj6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id a72-20020a63904b000000b0055e48c43ab7si4007218pge.470.2023.10.04.08.49.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 08:49:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VvDioVj6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 902C48239DED; Wed, 4 Oct 2023 08:49:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242929AbjJDPtI (ORCPT + 99 others); Wed, 4 Oct 2023 11:49:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233774AbjJDPtH (ORCPT ); Wed, 4 Oct 2023 11:49:07 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAD63D8 for ; Wed, 4 Oct 2023 08:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696434497; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rZ8aDKUrpN2q/s8i97pAGn8PQgXbCGC0dTTfu9VD+mg=; b=VvDioVj6hYVlAC+3WMePYBqyyo+4A1t3huhpMciyLkp7EIK6j07a4QYLXrJyhtKiSTlP87 zgQBi9Ku0t4hpbFkfNMkBEaxVuN8XU7BV3HjbItoIq2qnztQT6cwVPEVanWHfEyiYjQkjq g3KZQTHEPgbGAdEDz39x0w7xcDM8LMs= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-356-1bW_3GvyPNWpxM2xWtkr4Q-1; Wed, 04 Oct 2023 11:48:15 -0400 X-MC-Unique: 1bW_3GvyPNWpxM2xWtkr4Q-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-65b08994e15so15994006d6.0 for ; Wed, 04 Oct 2023 08:48:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696434495; x=1697039295; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=rZ8aDKUrpN2q/s8i97pAGn8PQgXbCGC0dTTfu9VD+mg=; b=I1VKadLgoDrc9eipMehIxK/C/688YRo0coTmQTYeCR+5R9Zix5xqdhMz7nppYfNyQ/ loJv2ZKC3y35KMd6UYBpgV6vXQ68qMbKPbn/WIZwkgSzCKS4l1a9A9UvZ9I81bxrD6hP D8GcTEmZsq8K6T6wDff+bkRQRrflb7tbaaFJDX6JE7W+4nla7l/7B/U9tGb+gg6K3Vf5 hb3fwyYK/p++7LXlurBEofLndoo/54uV7nouP9cHa8D4UlDFBns//lPJSSPXH+jGrgzx 5ABqRPPzXeOa4asYnd8xLkqAHJtUBMd6TMMD+rqbFnmZ62At+wcnJJ45JB9pMiGK0C0L 2huQ== X-Gm-Message-State: AOJu0Yy0YQgSf1xLutph4Y6M1vvnNGE69YWpRybS176cyx5bHSpUMT8i htKyeaBQugHJP3MKQ71krPl/H8abGuQabZeCqY4cmAqmqVIDyS4hkylIyGIH21R8nuIRNDx4QJG r8wCYW2QysR1nRRmKpQwP/Ym/ X-Received: by 2002:a0c:f491:0:b0:668:e6f7:3d42 with SMTP id i17-20020a0cf491000000b00668e6f73d42mr12919qvm.9.1696434495046; Wed, 04 Oct 2023 08:48:15 -0700 (PDT) X-Received: by 2002:a0c:f491:0:b0:668:e6f7:3d42 with SMTP id i17-20020a0cf491000000b00668e6f73d42mr12884qvm.9.1696434494754; Wed, 04 Oct 2023 08:48:14 -0700 (PDT) Received: from sgarzare-redhat (host-82-57-51-114.retail.telecomitalia.it. [82.57.51.114]) by smtp.gmail.com with ESMTPSA id op52-20020a05620a537400b0076d9e298928sm1349795qkn.66.2023.10.04.08.48.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 08:48:14 -0700 (PDT) Date: Wed, 4 Oct 2023 17:48:10 +0200 From: Stefano Garzarella To: Arseniy Krasnov Cc: Stefan Hajnoczi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@sberdevices.ru, oxffffaa@gmail.com Subject: Re: [PATCH net-next v2 12/12] test/vsock: io_uring rx/tx tests Message-ID: References: <20230930210308.2394919-1-avkrasnov@salutedevices.com> <20230930210308.2394919-13-avkrasnov@salutedevices.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20230930210308.2394919-13-avkrasnov@salutedevices.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 04 Oct 2023 08:49:09 -0700 (PDT) On Sun, Oct 01, 2023 at 12:03:08AM +0300, Arseniy Krasnov wrote: >This adds set of tests which use io_uring for rx/tx. This test suite is >implemented as separated util like 'vsock_test' and has the same set of >input arguments as 'vsock_test'. These tests only cover cases of data >transmission (no connect/bind/accept etc). > >Signed-off-by: Arseniy Krasnov >--- > Changelog: > v1 -> v2: > * Add 'LDLIBS = -luring' to the target 'vsock_uring_test'. > * Add 'vsock_uring_test' to the target 'test'. > > tools/testing/vsock/Makefile | 7 +- > tools/testing/vsock/vsock_uring_test.c | 321 +++++++++++++++++++++++++ > 2 files changed, 326 insertions(+), 2 deletions(-) > create mode 100644 tools/testing/vsock/vsock_uring_test.c > >diff --git a/tools/testing/vsock/Makefile b/tools/testing/vsock/Makefile >index 1a26f60a596c..b80e7c7def1e 100644 >--- a/tools/testing/vsock/Makefile >+++ b/tools/testing/vsock/Makefile >@@ -1,12 +1,15 @@ > # SPDX-License-Identifier: GPL-2.0-only > all: test vsock_perf >-test: vsock_test vsock_diag_test >+test: vsock_test vsock_diag_test vsock_uring_test > vsock_test: vsock_test.o vsock_test_zerocopy.o timeout.o control.o util.o > vsock_diag_test: vsock_diag_test.o timeout.o control.o util.o > vsock_perf: vsock_perf.o > >+vsock_uring_test: LDLIBS = -luring >+vsock_uring_test: control.o util.o vsock_uring_test.o timeout.o >+ > CFLAGS += -g -O2 -Werror -Wall -I. -I../../include -I../../../usr/include -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE -D_GNU_SOURCE > .PHONY: all test clean > clean: >- ${RM} *.o *.d vsock_test vsock_diag_test vsock_perf >+ ${RM} *.o *.d vsock_test vsock_diag_test vsock_perf vsock_uring_test > -include *.d >diff --git a/tools/testing/vsock/vsock_uring_test.c b/tools/testing/vsock/vsock_uring_test.c >new file mode 100644 >index 000000000000..725895350697 >--- /dev/null >+++ b/tools/testing/vsock/vsock_uring_test.c >@@ -0,0 +1,321 @@ >+// SPDX-License-Identifier: GPL-2.0-only >+/* io_uring tests for vsock >+ * >+ * Copyright (C) 2023 SberDevices. >+ * >+ * Author: Arseniy Krasnov >+ */ >+ >+#include >+#include >+#include >+#include >+#include >+#include >+#include >+#include >+#include >+ >+#include "util.h" >+#include "control.h" >+ >+#define PAGE_SIZE 4096 >+#define RING_ENTRIES_NUM 4 >+ >+static struct vsock_test_data test_data_array[] = { Ah, I see vsock_test_data is used here, but we are using a subset of fields that are not exposed outside of this file. So, let's define a custom struct in this file for this (e.g. struct vsock_io_uring_tests) The rest LGTM! >+ /* All elements have page aligned base and size. */ >+ { >+ .vecs_cnt = 3, >+ { >+ { NULL, PAGE_SIZE }, >+ { NULL, 2 * PAGE_SIZE }, >+ { NULL, 3 * PAGE_SIZE }, >+ } >+ }, >+ /* Middle element has both non-page aligned base and size. */ >+ { >+ .vecs_cnt = 3, >+ { >+ { NULL, PAGE_SIZE }, >+ { (void *)1, 200 }, >+ { NULL, 3 * PAGE_SIZE }, >+ } >+ } >+}; >+ >+static void vsock_io_uring_client(const struct test_opts *opts, >+ const struct vsock_test_data *test_data, >+ bool msg_zerocopy) >+{ >+ struct io_uring_sqe *sqe; >+ struct io_uring_cqe *cqe; >+ struct io_uring ring; >+ struct iovec *iovec; >+ struct msghdr msg; >+ int fd; >+ >+ fd = vsock_stream_connect(opts->peer_cid, 1234); >+ if (fd < 0) { >+ perror("connect"); >+ exit(EXIT_FAILURE); >+ } >+ >+ if (msg_zerocopy) >+ enable_so_zerocopy(fd); >+ >+ iovec = iovec_from_test_data(test_data); >+ >+ if (io_uring_queue_init(RING_ENTRIES_NUM, &ring, 0)) >+ error(1, errno, "io_uring_queue_init"); >+ >+ if (io_uring_register_buffers(&ring, iovec, test_data->vecs_cnt)) >+ error(1, errno, "io_uring_register_buffers"); >+ >+ memset(&msg, 0, sizeof(msg)); >+ msg.msg_iov = iovec; >+ msg.msg_iovlen = test_data->vecs_cnt; >+ sqe = io_uring_get_sqe(&ring); >+ >+ if (msg_zerocopy) >+ io_uring_prep_sendmsg_zc(sqe, fd, &msg, 0); >+ else >+ io_uring_prep_sendmsg(sqe, fd, &msg, 0); >+ >+ if (io_uring_submit(&ring) != 1) >+ error(1, errno, "io_uring_submit"); >+ >+ if (io_uring_wait_cqe(&ring, &cqe)) >+ error(1, errno, "io_uring_wait_cqe"); >+ >+ io_uring_cqe_seen(&ring, cqe); >+ >+ control_writeulong(iovec_hash_djb2(iovec, test_data->vecs_cnt)); >+ >+ control_writeln("DONE"); >+ io_uring_queue_exit(&ring); >+ free_iovec_test_data(test_data, iovec); >+ close(fd); >+} >+ >+static void vsock_io_uring_server(const struct test_opts *opts, >+ const struct vsock_test_data *test_data) >+{ >+ unsigned long remote_hash; >+ unsigned long local_hash; >+ struct io_uring_sqe *sqe; >+ struct io_uring_cqe *cqe; >+ struct io_uring ring; >+ struct iovec iovec; >+ size_t data_len; >+ void *data; >+ int fd; >+ >+ fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); >+ if (fd < 0) { >+ perror("accept"); >+ exit(EXIT_FAILURE); >+ } >+ >+ data_len = iovec_bytes(test_data->vecs, test_data->vecs_cnt); >+ >+ data = malloc(data_len); >+ if (!data) { >+ perror("malloc"); >+ exit(EXIT_FAILURE); >+ } >+ >+ if (io_uring_queue_init(RING_ENTRIES_NUM, &ring, 0)) >+ error(1, errno, "io_uring_queue_init"); >+ >+ sqe = io_uring_get_sqe(&ring); >+ iovec.iov_base = data; >+ iovec.iov_len = data_len; >+ >+ io_uring_prep_readv(sqe, fd, &iovec, 1, 0); >+ >+ if (io_uring_submit(&ring) != 1) >+ error(1, errno, "io_uring_submit"); >+ >+ if (io_uring_wait_cqe(&ring, &cqe)) >+ error(1, errno, "io_uring_wait_cqe"); >+ >+ if (cqe->res != data_len) { >+ fprintf(stderr, "expected %zu, got %u\n", data_len, >+ cqe->res); >+ exit(EXIT_FAILURE); >+ } >+ >+ local_hash = hash_djb2(data, data_len); >+ >+ remote_hash = control_readulong(); >+ if (remote_hash != local_hash) { >+ fprintf(stderr, "hash mismatch\n"); >+ exit(EXIT_FAILURE); >+ } >+ >+ control_expectln("DONE"); >+ io_uring_queue_exit(&ring); >+ free(data); >+} >+ >+void test_stream_uring_server(const struct test_opts *opts) >+{ >+ int i; >+ >+ for (i = 0; i < ARRAY_SIZE(test_data_array); i++) >+ vsock_io_uring_server(opts, &test_data_array[i]); >+} >+ >+void test_stream_uring_client(const struct test_opts *opts) >+{ >+ int i; >+ >+ for (i = 0; i < ARRAY_SIZE(test_data_array); i++) >+ vsock_io_uring_client(opts, &test_data_array[i], false); >+} >+ >+void test_stream_uring_msg_zc_server(const struct test_opts *opts) >+{ >+ int i; >+ >+ for (i = 0; i < ARRAY_SIZE(test_data_array); i++) >+ vsock_io_uring_server(opts, &test_data_array[i]); >+} >+ >+void test_stream_uring_msg_zc_client(const struct test_opts *opts) >+{ >+ int i; >+ >+ for (i = 0; i < ARRAY_SIZE(test_data_array); i++) >+ vsock_io_uring_client(opts, &test_data_array[i], true); >+} >+ >+static struct test_case test_cases[] = { >+ { >+ .name = "SOCK_STREAM io_uring test", >+ .run_server = test_stream_uring_server, >+ .run_client = test_stream_uring_client, >+ }, >+ { >+ .name = "SOCK_STREAM io_uring MSG_ZEROCOPY test", >+ .run_server = test_stream_uring_msg_zc_server, >+ .run_client = test_stream_uring_msg_zc_client, >+ }, >+ {}, >+}; >+ >+static const char optstring[] = ""; >+static const struct option longopts[] = { >+ { >+ .name = "control-host", >+ .has_arg = required_argument, >+ .val = 'H', >+ }, >+ { >+ .name = "control-port", >+ .has_arg = required_argument, >+ .val = 'P', >+ }, >+ { >+ .name = "mode", >+ .has_arg = required_argument, >+ .val = 'm', >+ }, >+ { >+ .name = "peer-cid", >+ .has_arg = required_argument, >+ .val = 'p', >+ }, >+ { >+ .name = "help", >+ .has_arg = no_argument, >+ .val = '?', >+ }, >+ {}, >+}; >+ >+static void usage(void) >+{ >+ fprintf(stderr, "Usage: vsock_uring_test [--help] [--control-host=] --control-port= --mode=client|server --peer-cid=\n" >+ "\n" >+ " Server: vsock_uring_test --control-port=1234 --mode=server --peer-cid=3\n" >+ " Client: vsock_uring_test --control-host=192.168.0.1 --control-port=1234 --mode=client --peer-cid=2\n" >+ "\n" >+ "Run transmission tests using io_uring. Usage is the same as\n" >+ "in ./vsock_test\n" >+ "\n" >+ "Options:\n" >+ " --help This help message\n" >+ " --control-host Server IP address to connect to\n" >+ " --control-port Server port to listen on/connect to\n" >+ " --mode client|server Server or client mode\n" >+ " --peer-cid CID of the other side\n" >+ ); >+ exit(EXIT_FAILURE); >+} >+ >+int main(int argc, char **argv) >+{ >+ const char *control_host = NULL; >+ const char *control_port = NULL; >+ struct test_opts opts = { >+ .mode = TEST_MODE_UNSET, >+ .peer_cid = VMADDR_CID_ANY, >+ }; >+ >+ init_signals(); >+ >+ for (;;) { >+ int opt = getopt_long(argc, argv, optstring, longopts, NULL); >+ >+ if (opt == -1) >+ break; >+ >+ switch (opt) { >+ case 'H': >+ control_host = optarg; >+ break; >+ case 'm': >+ if (strcmp(optarg, "client") == 0) { >+ opts.mode = TEST_MODE_CLIENT; >+ } else if (strcmp(optarg, "server") == 0) { >+ opts.mode = TEST_MODE_SERVER; >+ } else { >+ fprintf(stderr, "--mode must be \"client\" or \"server\"\n"); >+ return EXIT_FAILURE; >+ } >+ break; >+ case 'p': >+ opts.peer_cid = parse_cid(optarg); >+ break; >+ case 'P': >+ control_port = optarg; >+ break; >+ case '?': >+ default: >+ usage(); >+ } >+ } >+ >+ if (!control_port) >+ usage(); >+ if (opts.mode == TEST_MODE_UNSET) >+ usage(); >+ if (opts.peer_cid == VMADDR_CID_ANY) >+ usage(); >+ >+ if (!control_host) { >+ if (opts.mode != TEST_MODE_SERVER) >+ usage(); >+ control_host = "0.0.0.0"; >+ } >+ >+ control_init(control_host, control_port, >+ opts.mode == TEST_MODE_SERVER); >+ >+ run_tests(test_cases, &opts); >+ >+ control_cleanup(); >+ >+ return 0; >+} >-- >2.25.1 >