From patchwork Mon Apr 8 13:37:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luigi Leonardi X-Patchwork-Id: 13621189 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04olkn2084.outbound.protection.outlook.com [40.92.74.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DAD512E1DB; Mon, 8 Apr 2024 13:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.74.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712583487; cv=fail; b=KcuVJL3uj1tO1MRd0rZx6lRbdIRtJtYOjWK+ONHMYuZla1TQfkwaQm/vZbGCXPXM57+l80qaHKwaa+6SNlI7Rgi+AwxwKNfSRCM3gSzvkKV650g9yR8yTZPBFAnx+KeFvR7tVh1KAGw1Ix6lEZ8QQ54hFfroBlNCNH4nIzDEeu4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712583487; c=relaxed/simple; bh=kMkbuSouMVyfx9e17I2jia19HrSAMQA6Vxiyr4jC7TY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=n4HlFrwUlB7rbJpJQ0kdP3foavb8kPJKDWzqSnbbiGxHB+uZTcuH7dlvPxH1/ygbJmatcxaLKsGib1V93er55tLnFNtvfsnpvD+bsnR2KSZh+MhBICGJEzdVq/Snp4S+aujJj59kIblalA93OiutMxifRiCALmK1odUnavRiOFY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=KXtFA0Ss; arc=fail smtp.client-ip=40.92.74.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="KXtFA0Ss" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jt6uIzF/4h1kqkxkaJLVIb03TeuBpRLK0zlkGd1elnkDUyWhP1CnmXNgQP3KBjyCPuUfrKuoZBYXqpJh5tfinXuPcKLhFRmhXDOTIJmkriN1krxI2m0H3HSCujYf7KWskGN4lErJRVjcNaa/B2ybuRZyIMgSW+cKPtb5lkWocOBQeUaCaawj0OKSjF+IEwLhKD8VeibaQ7XoyaxywFj1BzNQvpn2QV8+ZpbrVBdE1YpzHVHphEr6M0UJUQsuk47kAqgwEx+hFl8pLkbP3MJPZfi+GgPOI/Zfmi7UBXxP1PexA5UYejMDZ2rPehcg5xbbUq6NscxvfDQ05ZWQZNCj9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7WJsOAcjdVDt7Vxd6SdrBgUI2q3HCWMcb42jSXmBoAI=; b=WdLB1+cppQ/dDZVjGhmxb0yLziLBQoDRsZVpOOkieq650v2dBfI5bbTKs80H6F7CiGV0JdTHHuPeVYsM+S5oOwXwLVo62gyYl+1k72/xCJSs/REZSpkAUpVIA7iDaWWA7iCjgZygFhZUXP4G5nxJ79OgDBMrmmyd22WIKHOpVzlhc6PKRQAs4XBV3xpKHr+K7+SWOdrfF5nOoDMU+awBPp5NmZH9o/ipThWiqL6UZQ1aqAacDeOW6NxH9jOIzr3Ns4Zzeu/uzSFOt+yf+VYkv/DFAhlwEQJrUPbCHihiFjkEHN0YkYsx35OyxTgQ7aLKHDdWo33x6n13tLymWbXbNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7WJsOAcjdVDt7Vxd6SdrBgUI2q3HCWMcb42jSXmBoAI=; b=KXtFA0SsGemNrSCqoNB4Ghd/tVY31F9erv1IYXfI7JV9L4E7UTSHYi5R2l//fgJmMo6VvDMkWbxQ3Uk2a9n4UCfQbXO8QRnxS/4/nfCpVsL44dPKxXefUAinu58M9zQBtDSOFRycYyo+JrqSjI8pmt4x/9xSq5HwRpQP/oJHXB8Mv3rRElJPVBHf4rNcXp8OuwzVQ/SgmqG9bj6uksTfdwHm70T9MntA0jB48efRD19OJ6Rf2ZeGuRYJfhHZCZoPZ4jIexUCunzJaoraJKO+eM9kfFf21b8FUmRdMFF3I8EuFtNfwcZ/4VrfB/KTgGIsj4O3tx0DVMpMxTlRiHkx5Q== Received: from AS2P194MB2170.EURP194.PROD.OUTLOOK.COM (2603:10a6:20b:642::8) by AM8P194MB1662.EURP194.PROD.OUTLOOK.COM (2603:10a6:20b:321::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.47; Mon, 8 Apr 2024 13:37:58 +0000 Received: from AS2P194MB2170.EURP194.PROD.OUTLOOK.COM ([fe80::56f0:1717:f1a8:ea4e]) by AS2P194MB2170.EURP194.PROD.OUTLOOK.COM ([fe80::56f0:1717:f1a8:ea4e%2]) with mapi id 15.20.7409.042; Mon, 8 Apr 2024 13:37:58 +0000 From: Luigi Leonardi To: mst@redhat.com, xuanzhuo@linux.alibaba.com, virtualization@lists.linux.dev, sgarzare@redhat.com, netdev@vger.kernel.org, kuba@kernel.org, stefanha@redhat.com, davem@davemloft.net, pabeni@redhat.com, edumazet@google.com, kvm@vger.kernel.org, jasowang@redhat.com Cc: Luigi Leonardi Subject: [PATCH net-next v2 3/3] test/vsock: add ioctl unsent bytes test Date: Mon, 8 Apr 2024 15:37:49 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240408133749.510520-1-luigi.leonardi@outlook.com> References: <20240408133749.510520-1-luigi.leonardi@outlook.com> X-TMN: [dILONH51rufQGRaOkOyWZiPNRtnd5OWN] X-ClientProxiedBy: MI0P293CA0013.ITAP293.PROD.OUTLOOK.COM (2603:10a6:290:44::18) To AS2P194MB2170.EURP194.PROD.OUTLOOK.COM (2603:10a6:20b:642::8) X-Microsoft-Original-Message-ID: <20240408133749.510520-4-luigi.leonardi@outlook.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS2P194MB2170:EE_|AM8P194MB1662:EE_ X-MS-Office365-Filtering-Correlation-Id: cf91efde-5ae0-495c-9032-08dc57d11a9d X-MS-Exchange-SLBlob-MailProps: znQPCv1HvwW17eFZrekaPBZuDTSQRy8lIpg5mhFRKw0dzIef8ex5pMt4k4PMUxPPmFkwPMy3AtVzRP7WjFRwAkckTI3gHEUIXuIjgJqWtPyLF2zlL2K6qCydptc1rmAOf/gqw5QaHcwwXvE0kL/kybgxJLw0x1AIlOOfhHOmDwA/cV9lmbHQf50rfglG/Xk6oish/+4Mx7O4T0BLluXhM4ufip09AuDGsX7DUTWn9niRBDwckLNw5V7I6dJUYiPf6FO30zNe60wtYKa8SN6iPOar3azooJC7i8uZYZXO/LbvJyjvAX/wlOW6jcfHK8QbQxm0BXEIWgouYqAI+ksrepXEqpcslmb+EV4rGrBDRMZ6VsxQFHcLzZKoRFoh8Gxnl0sw/8iHcqfkh9vj0dTPuXkU6G7Mv13LP+fChuc3haj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84C875JA+TPPf6dAgEOWk6HWG28IWs7Ew3WuDC2NGmG899NH98f2+PuU5T5z5Vnb7pxfJHhEx5RircpgW34aq5V6iMbsmiddEAWpuSIdr2ov8a8mXsHr+OThXgwVQ8mlJKlywf0hhBNK3bpe9Q6FFBUIFDeIU2WIPwvp9bEq1ojIoczrsuDI3n+R/nyfCozLJQKzSRBUXticP2MCHSadPPhhZ9EP2C X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: cf91efde-5ae0-495c-9032-08dc57d11a9d X-MS-Exchange-CrossTenant-AuthSource: AS2P194MB2170.EURP194.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2024 13:37:58.8173 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8P194MB1662 This test that after a packet is delivered the number of unsent bytes is zero. Signed-off-by: Luigi Leonardi --- tools/testing/vsock/util.c | 6 +-- tools/testing/vsock/util.h | 3 ++ tools/testing/vsock/vsock_test.c | 85 ++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c index 554b290fefdc..a3d448a075e3 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c @@ -139,7 +139,7 @@ int vsock_bind_connect(unsigned int cid, unsigned int port, unsigned int bind_po } /* Connect to and return the file descriptor. */ -static int vsock_connect(unsigned int cid, unsigned int port, int type) +int vsock_connect(unsigned int cid, unsigned int port, int type) { union { struct sockaddr sa; @@ -226,8 +226,8 @@ static int vsock_listen(unsigned int cid, unsigned int port, int type) /* Listen on and return the first incoming connection. The remote * address is stored to clientaddrp. clientaddrp may be NULL. */ -static int vsock_accept(unsigned int cid, unsigned int port, - struct sockaddr_vm *clientaddrp, int type) +int vsock_accept(unsigned int cid, unsigned int port, + struct sockaddr_vm *clientaddrp, int type) { union { struct sockaddr sa; diff --git a/tools/testing/vsock/util.h b/tools/testing/vsock/util.h index e95e62485959..fff22d4a14c0 100644 --- a/tools/testing/vsock/util.h +++ b/tools/testing/vsock/util.h @@ -39,6 +39,9 @@ struct test_case { void init_signals(void); unsigned int parse_cid(const char *str); unsigned int parse_port(const char *str); +int vsock_connect(unsigned int cid, unsigned int port, int type); +int vsock_accept(unsigned int cid, unsigned int port, + struct sockaddr_vm *clientaddrp, int type); int vsock_stream_connect(unsigned int cid, unsigned int port); int vsock_bind_connect(unsigned int cid, unsigned int port, unsigned int bind_port, int type); diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index f851f8961247..c19ffbcca9dd 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include "vsock_test_zerocopy.h" #include "timeout.h" @@ -1238,6 +1240,79 @@ static void test_double_bind_connect_client(const struct test_opts *opts) } } +#define MSG_BUF_IOCTL_LEN 64 +static void test_unsent_bytes_server(const struct test_opts *opts, int type) +{ + unsigned char buf[MSG_BUF_IOCTL_LEN]; + int client_fd; + + client_fd = vsock_accept(VMADDR_CID_ANY, 1234, NULL, type); + if (client_fd < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + recv_buf(client_fd, buf, sizeof(buf), 0, sizeof(buf)); + control_writeln("RECEIVED"); + + close(client_fd); +} + +static void test_unsent_bytes_client(const struct test_opts *opts, int type) +{ + unsigned char buf[MSG_BUF_IOCTL_LEN]; + int ret, fd, sock_bytes_unsent; + + fd = vsock_connect(opts->peer_cid, 1234, type); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + for (int i = 0; i < sizeof(buf); i++) + buf[i] = rand() & 0xFF; + + send_buf(fd, buf, sizeof(buf), 0, sizeof(buf)); + control_expectln("RECEIVED"); + + ret = ioctl(fd, SIOCOUTQ, &sock_bytes_unsent); + if (ret < 0) { + perror("ioctl"); + + if (errno != EOPNOTSUPP) + exit(EXIT_FAILURE); + + fprintf(stderr, "Test skipped\n"); + } else if (ret == 0 && sock_bytes_unsent != 0) { + fprintf(stderr, + "Unexpected 'SIOCOUTQ' value, expected 0, got %i\n", + sock_bytes_unsent); + exit(EXIT_FAILURE); + } + + close(fd); +} + +static void test_stream_unsent_bytes_client(const struct test_opts *opts) +{ + test_unsent_bytes_client(opts, SOCK_STREAM); +} + +static void test_stream_unsent_bytes_server(const struct test_opts *opts) +{ + test_unsent_bytes_server(opts, SOCK_STREAM); +} + +static void test_seqpacket_unsent_bytes_client(const struct test_opts *opts) +{ + test_unsent_bytes_client(opts, SOCK_SEQPACKET); +} + +static void test_seqpacket_unsent_bytes_server(const struct test_opts *opts) +{ + test_unsent_bytes_server(opts, SOCK_SEQPACKET); +} + #define RCVLOWAT_CREDIT_UPD_BUF_SIZE (1024 * 128) /* This define is the same as in 'include/linux/virtio_vsock.h': * it is used to decide when to send credit update message during @@ -1523,6 +1598,16 @@ static struct test_case test_cases[] = { .run_client = test_stream_rcvlowat_def_cred_upd_client, .run_server = test_stream_cred_upd_on_low_rx_bytes, }, + { + .name = "SOCK_STREAM ioctl(SIOCOUTQ) 0 unsent bytes", + .run_client = test_stream_unsent_bytes_client, + .run_server = test_stream_unsent_bytes_server, + }, + { + .name = "SOCK_SEQPACKET ioctl(SIOCOUTQ) 0 unsent bytes", + .run_client = test_seqpacket_unsent_bytes_client, + .run_server = test_seqpacket_unsent_bytes_server, + }, {}, };