From patchwork Sat Mar 25 22:10:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 74990 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp639434vqo; Sat, 25 Mar 2023 15:46:45 -0700 (PDT) X-Google-Smtp-Source: AKy350YFBANGZAV57qOjmMf4YzEJZV8NTcDgjWTaimiEEu0fQx6BHDML+/AOOUyO3eKB2yUDvzHT X-Received: by 2002:a17:903:294c:b0:19f:35df:5d60 with SMTP id li12-20020a170903294c00b0019f35df5d60mr5601179plb.22.1679784404783; Sat, 25 Mar 2023 15:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679784404; cv=none; d=google.com; s=arc-20160816; b=pWPkBISDWfVVKeVs1udt5SVzzU3KR0U4xroHXPjfYBcBq1L2WVYMjvPiYSdJHY+Ug1 Vbnklj0Xjt2lLQrXKv7FGs6FogkdPVAvJtrdDkEtMgvZo/skygNhT6GD6HuMEFjfsjYX I38ysC6f9IopLjXhOzwS6IBGoR5XfIoYlLw/buy+PoGE87dMN1D/t+8lw5ShS04r92ip Oql2lNRqq0ePoFUO/43tKPsWTFeD6Z05M9ob8Reb/jufMmNX39eqTZPnn0XxlWppeujc iiXjTXzcOwKwcuA6PVUelZAMkoGlcnUC/5eaFtH5CW43Jiv4Ni+c9gVp99zC/pkuz6W+ NMqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:subject:from:cc:to :in-reply-to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=kiXMleL3+A1HmDIHmrLuyeNiMWpJOWtwJnJgV0xtAgs=; b=QeTYG1uGnl3zxmPS6vvUTk4zdEY9GuMybwYzPWm+3Tqn7rENc18EumNW+0QF+MrLl1 2InE50XCSkf6+YHL5Adz6Mioq0Zj5cceaVOO4RQSwtdEIB8aXjtSnCzkeCARoEE7Gx1G QMT9lJUspJSUQzK8G7BBRIcvNJI/dIOR31leKNFgyojn4kGK94zT1Iq3XrLP1irG5rM8 u0f4ZI2XakWW0MRPMLWIZJgQZmjtsT7FyiQZ2fl4NPKjhlm81TeTDFuv7fDkghE74ZhW YcnlbiYrYNGiLPV0fY68+9FJ4bedCjv0y3mGbqKlqJeiMaeXK5tUpMF/dOeQUIKlPwHG jzPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=JznA0B3n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k3-20020a170902c40300b001a22091eea9si3927775plk.225.2023.03.25.15.46.22; Sat, 25 Mar 2023 15:46:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=JznA0B3n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231841AbjCYWNh (ORCPT + 99 others); Sat, 25 Mar 2023 18:13:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbjCYWNf (ORCPT ); Sat, 25 Mar 2023 18:13:35 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEF1140E3; Sat, 25 Mar 2023 15:13:33 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 17E2B5FD02; Sun, 26 Mar 2023 01:13:32 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1679782412; bh=kiXMleL3+A1HmDIHmrLuyeNiMWpJOWtwJnJgV0xtAgs=; h=Message-ID:Date:MIME-Version:To:From:Subject:Content-Type; b=JznA0B3nuGi8+Adr1mU6MkuUdx98fnuVk0+lriFmsqEkNmZeiy9236vE+nA96KXL1 VoDmJ9QmHsiAwOyTiz9F9QJp4vsZSF385JqdDDsS/HtbU9PlMH7t8wjg8vLscUHDyE exR7J4nJkrxpNo+4y0LAPNU/25qsaeTBmFx8uKpGmtlBNV/NJIwr9tgzVUI2soIrvf GRwImZwlGrxUazWkCw0DKUnna/cjLn3FlNkCVlBRFMg04mNENchFtFRZL1P5A0wMpC qKv+Yv0UpccklWVzMF2VeqUJrvAncS8bRHyzlyLTGliL6uEJz+ibv4QtMkz+F52YEk Z11GwDSynveHw== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sun, 26 Mar 2023 01:13:31 +0300 (MSK) Message-ID: <776a30e8-3cd5-35ba-5187-63c9b83eaa44@sberdevices.ru> Date: Sun, 26 Mar 2023 01:10:16 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Content-Language: en-US In-Reply-To: <728181e9-6b35-0092-3d01-3d7aff4521b6@sberdevices.ru> To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Bobby Eshleman CC: , , , , , , From: Arseniy Krasnov Subject: [RFC PATCH v2 3/3] test/vsock: new skbuff appending test X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/03/25 20:38:00 #21009968 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761381612224550782?= X-GMAIL-MSGID: =?utf-8?q?1761381612224550782?= This adds test which checks case when data of newly received skbuff is appended to the last skbuff in the socket's queue. It looks like simple test with 'send()' and 'recv()', but internally it triggers logic which appends one received skbuff to another. Test checks that this feature works correctly. This test is actual only for virtio transport. Signed-off-by: Arseniy Krasnov Reviewed-by: Stefano Garzarella --- tools/testing/vsock/vsock_test.c | 90 ++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index 3de10dbb50f5..12b97c92fbb2 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -968,6 +968,91 @@ static void test_seqpacket_inv_buf_server(const struct test_opts *opts) test_inv_buf_server(opts, false); } +#define HELLO_STR "HELLO" +#define WORLD_STR "WORLD" + +static void test_stream_virtio_skb_merge_client(const struct test_opts *opts) +{ + ssize_t res; + int fd; + + fd = vsock_stream_connect(opts->peer_cid, 1234); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + /* Send first skbuff. */ + res = send(fd, HELLO_STR, strlen(HELLO_STR), 0); + if (res != strlen(HELLO_STR)) { + fprintf(stderr, "unexpected send(2) result %zi\n", res); + exit(EXIT_FAILURE); + } + + control_writeln("SEND0"); + /* Peer reads part of first skbuff. */ + control_expectln("REPLY0"); + + /* Send second skbuff, it will be appended to the first. */ + res = send(fd, WORLD_STR, strlen(WORLD_STR), 0); + if (res != strlen(WORLD_STR)) { + fprintf(stderr, "unexpected send(2) result %zi\n", res); + exit(EXIT_FAILURE); + } + + control_writeln("SEND1"); + /* Peer reads merged skbuff packet. */ + control_expectln("REPLY1"); + + close(fd); +} + +static void test_stream_virtio_skb_merge_server(const struct test_opts *opts) +{ + unsigned char buf[64]; + ssize_t res; + int fd; + + fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); + if (fd < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + control_expectln("SEND0"); + + /* Read skbuff partially. */ + res = recv(fd, buf, 2, 0); + if (res != 2) { + fprintf(stderr, "expected recv(2) returns 2 bytes, got %zi\n", res); + exit(EXIT_FAILURE); + } + + control_writeln("REPLY0"); + control_expectln("SEND1"); + + res = recv(fd, buf + 2, sizeof(buf) - 2, 0); + if (res != 8) { + fprintf(stderr, "expected recv(2) returns 8 bytes, got %zi\n", res); + exit(EXIT_FAILURE); + } + + res = recv(fd, buf, sizeof(buf) - 8 - 2, MSG_DONTWAIT); + if (res != -1) { + fprintf(stderr, "expected recv(2) failure, got %zi\n", res); + exit(EXIT_FAILURE); + } + + if (memcmp(buf, HELLO_STR WORLD_STR, strlen(HELLO_STR WORLD_STR))) { + fprintf(stderr, "pattern mismatch\n"); + exit(EXIT_FAILURE); + } + + control_writeln("REPLY1"); + + close(fd); +} + static struct test_case test_cases[] = { { .name = "SOCK_STREAM connection reset", @@ -1038,6 +1123,11 @@ static struct test_case test_cases[] = { .run_client = test_seqpacket_inv_buf_client, .run_server = test_seqpacket_inv_buf_server, }, + { + .name = "SOCK_STREAM virtio skb merge", + .run_client = test_stream_virtio_skb_merge_client, + .run_server = test_stream_virtio_skb_merge_server, + }, {}, };