Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4439688rdh; Wed, 29 Nov 2023 01:17:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IELt41Bu0re2Sr3C3vCdSqwktx1S02GoG9dAKbRnmrUONX55kb2uGWetEdWt1Hxny4RBTKa X-Received: by 2002:a17:903:1207:b0:1cc:5cbf:50d2 with SMTP id l7-20020a170903120700b001cc5cbf50d2mr20600227plh.59.1701249469129; Wed, 29 Nov 2023 01:17:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701249469; cv=none; d=google.com; s=arc-20160816; b=rIlXL79aHrgcfu+sTfoMHvv+J5Dn+lAqCXsbjzudB7BcYBex1iAIXSkiGFqnpK/6CB OgmHl/CvWawk/dxnIys3BhJI3OIjmPoiskJANLP0gB8avMvN8IaB5GmIuqYUfKijkC4F 8xe8yygD32ZaB47BhM6YrllqdoCQFnujt/HS31gQUqPmKveP0Il9ZhweKr1YEgtNlyKm ZzdvpJwIPqZWRd9YkZYqZPNYUzjfXfnd8CVeCVnJCqY74Mt8+m0zmxDeiLvl7oHle4ZF V+reDeKkwy5tePYlAcEDZkOR6fCuWq9XoC1VoaCZYcQzV8UKUMyhlVq7E0uoR4tp1X27 gLHA== 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=CADU4JVHWbofrhTxkjgO6G/zYvZ/xrMuPSze9yms4VY=; fh=JEq7ZyqHwnKMAbPjHbEHIOO1u1YxTWxtQlCbJmwG+xw=; b=zHKW0sxIs8NhAIVbrWt3KLtxbcnAtqP0A5ncxigzWX8/0S+b/zcC5nU/68t0xEVKgm s74H38uSxZ0IDLbHYaSbTbjEndZkDEJ4JM/fSqATlBiCttxSiiLBVZZEV+OfE9t4dfjD FogN5Lzn5/E8mxasfi2DORnQ6kL67I7k6JGPit/yBeY8xV2Vr2fZbPxCExx+EnIkX4wk p+FQoVG1o9rsk54g/Oh7Xt+MRooh9F8LVacRPu1cN7NCf+U1P95zmd7QcEERbQaeugZg 2/pxM7lGHr1PKsXJOXpsZBvjDLJdRf6ly/MUMhGSwDZKn3YH2XZHK9BeLdBJtsZU3DC1 l9ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IepD+0Af; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id mb5-20020a170903098500b001c60f6cf46bsi172855plb.12.2023.11.29.01.17.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 01:17:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IepD+0Af; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 7C0E4807C854; Wed, 29 Nov 2023 01:17:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230287AbjK2JRa (ORCPT + 99 others); Wed, 29 Nov 2023 04:17:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230142AbjK2JRQ (ORCPT ); Wed, 29 Nov 2023 04:17:16 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A1AC358B for ; Wed, 29 Nov 2023 01:16:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701249380; 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=CADU4JVHWbofrhTxkjgO6G/zYvZ/xrMuPSze9yms4VY=; b=IepD+0AfjVbALHqym8dxM7Re6W1/xcM3TbCSt7v8Rt7+SHkyaf9GxTffJCd2fbKtMPdy7c 4Ti7bsAuem0NkhJsq7/B0RV+JJ9kty7fM8RI4imz0E43/hVgZSZnkC/FMboO+iwW/Bdlfd 8U6xsYwqOnW4FZgrEw14s6V1jHtA8As= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-199-dKULX0OsPSOuWRsRi9qCjg-1; Wed, 29 Nov 2023 04:16:18 -0500 X-MC-Unique: dKULX0OsPSOuWRsRi9qCjg-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-332f62126e9so3528999f8f.3 for ; Wed, 29 Nov 2023 01:16:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701249377; x=1701854177; 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=CADU4JVHWbofrhTxkjgO6G/zYvZ/xrMuPSze9yms4VY=; b=NltENqj5cLFIqrlfgRrjiM0dqZuk0mHKlEhajB3YeOufpjSV3GfT8jIb3lnwZ3y0IW O5cWCFCNi3y5lMtsiafo19EnyhBeLg2mnLI89bZmxPCA1p38rKOvvLdIzNjf9qk7Y5Pk rLVWoXcmQRsCtyBll0BF01Qc9gBETRCeoUwpD8yVuTKdk0RH1dUU3hgZ//w5s+8yCvcN iL3F+gkmCJir+uoW09yCpRHi8lt1ICvzgttwiC9BTQsdATqsEArCWxyJcYqw5B2AomaY QH5jwnEJDlImmmCbmIdG8KswFAt5VIgOecgzBvCtCR9HppamtyK3+dI/BQdYPeV8tMxV zqLA== X-Gm-Message-State: AOJu0YwXxcnqag0nY4H4mTaNT9atIpZ2Ec6JgvFcZ0eHFzCP7AVNmd9U HH/w77X476rxjLl9PlsmDrexchVUrTJTvQpJSXqeW/fnMbX5PuUm69XOtS6ycyEsqL8IpC3opqc k7QMUv5sMEPh++OcJndpPsFtK X-Received: by 2002:a5d:4851:0:b0:332:e9f7:9a97 with SMTP id n17-20020a5d4851000000b00332e9f79a97mr12521031wrs.9.1701249377272; Wed, 29 Nov 2023 01:16:17 -0800 (PST) X-Received: by 2002:a5d:4851:0:b0:332:e9f7:9a97 with SMTP id n17-20020a5d4851000000b00332e9f79a97mr12521015wrs.9.1701249376936; Wed, 29 Nov 2023 01:16:16 -0800 (PST) Received: from sgarzare-redhat (host-79-46-200-199.retail.telecomitalia.it. [79.46.200.199]) by smtp.gmail.com with ESMTPSA id s7-20020a5d5107000000b00332c6a52040sm17152954wrt.100.2023.11.29.01.16.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 01:16:16 -0800 (PST) Date: Wed, 29 Nov 2023 10:16:10 +0100 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: [RFC PATCH v3 3/3] vsock/test: SO_RCVLOWAT + deferred credit update test Message-ID: References: <20231122180510.2297075-1-avkrasnov@salutedevices.com> <20231122180510.2297075-4-avkrasnov@salutedevices.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20231122180510.2297075-4-avkrasnov@salutedevices.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Wed, 29 Nov 2023 01:17:46 -0800 (PST) On Wed, Nov 22, 2023 at 09:05:10PM +0300, Arseniy Krasnov wrote: >Test which checks, that updating SO_RCVLOWAT value also sends credit >update message. Otherwise mutual hungup may happen when receiver didn't >send credit update and then calls 'poll()' with non default SO_RCVLOWAT >value (e.g. waiting enough bytes to read), while sender waits for free >space at receiver's side. Important thing is that this test relies on >kernel's define for maximum packet size for virtio transport and this >value is not exported to user: VIRTIO_VSOCK_MAX_PKT_BUF_SIZE (this >define is used to control moment when to send credit update message). >If this value or its usage will be changed in kernel - this test may >become useless/broken. > >Signed-off-by: Arseniy Krasnov >--- > Changelog: > v1 -> v2: > * Update commit message by removing 'This patch adds XXX' manner. > * Update commit message by adding details about dependency for this > test from kernel internal define VIRTIO_VSOCK_MAX_PKT_BUF_SIZE. > * Add comment for this dependency in 'vsock_test.c' where this define > is duplicated. > v2 -> v3: > * Replace synchronization based on control TCP socket with vsock > data socket - this is needed to allow sender transmit data only > when new buffer size of receiver is visible to sender. Otherwise > there is race and test fails sometimes. > > tools/testing/vsock/vsock_test.c | 142 +++++++++++++++++++++++++++++++ > 1 file changed, 142 insertions(+) > >diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c >index 5b0e93f9996c..773a71260fba 100644 >--- a/tools/testing/vsock/vsock_test.c >+++ b/tools/testing/vsock/vsock_test.c >@@ -1225,6 +1225,143 @@ static void test_double_bind_connect_client(const struct test_opts *opts) > } > } > >+#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 >+ * reading from rx queue of a socket. Value and its usage in >+ * kernel is important for this test. >+ */ >+#define VIRTIO_VSOCK_MAX_PKT_BUF_SIZE (1024 * 64) >+ >+static void test_stream_rcvlowat_def_cred_upd_client(const struct test_opts *opts) >+{ >+ size_t buf_size; >+ void *buf; >+ int fd; >+ >+ fd = vsock_stream_connect(opts->peer_cid, 1234); >+ if (fd < 0) { >+ perror("connect"); >+ exit(EXIT_FAILURE); >+ } >+ >+ /* Send 1 byte more than peer's buffer size. */ >+ buf_size = RCVLOWAT_CREDIT_UPD_BUF_SIZE + 1; >+ >+ buf = malloc(buf_size); >+ if (!buf) { >+ perror("malloc"); >+ exit(EXIT_FAILURE); >+ } >+ >+ /* Wait until peer sets needed buffer size. */ >+ recv_byte(fd, 1, 0); >+ >+ if (send(fd, buf, buf_size, 0) != buf_size) { >+ perror("send failed"); >+ exit(EXIT_FAILURE); >+ } >+ >+ free(buf); >+ close(fd); >+} >+ >+static void test_stream_rcvlowat_def_cred_upd_server(const struct test_opts *opts) >+{ >+ size_t recv_buf_size; >+ struct pollfd fds; >+ size_t buf_size; >+ void *buf; >+ int fd; >+ >+ fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); >+ if (fd < 0) { >+ perror("accept"); >+ exit(EXIT_FAILURE); >+ } >+ >+ buf_size = RCVLOWAT_CREDIT_UPD_BUF_SIZE; >+ >+ if (setsockopt(fd, AF_VSOCK, SO_VM_SOCKETS_BUFFER_SIZE, >+ &buf_size, sizeof(buf_size))) { >+ perror("setsockopt(SO_VM_SOCKETS_BUFFER_SIZE)"); >+ exit(EXIT_FAILURE); >+ } >+ >+ /* Send one dummy byte here, because 'setsockopt()' above also >+ * sends special packet which tells sender to update our buffer >+ * size. This 'send_byte()' will serialize such packet with data >+ * reads in a loop below. Sender starts transmission only when >+ * it receives this single byte. >+ */ >+ send_byte(fd, 1, 0); >+ >+ buf = malloc(buf_size); >+ if (!buf) { >+ perror("malloc"); >+ exit(EXIT_FAILURE); >+ } >+ >+ /* Wait until there will be 128KB of data in rx queue. */ >+ while (1) { >+ ssize_t res; >+ >+ res = recv(fd, buf, buf_size, MSG_PEEK); >+ if (res == buf_size) >+ break; >+ >+ if (res <= 0) { >+ fprintf(stderr, "unexpected 'recv()' return: %zi\n", res); >+ exit(EXIT_FAILURE); >+ } >+ } >+ >+ /* There is 128KB of data in the socket's rx queue, >+ * dequeue first 64KB, credit update is not sent. >+ */ >+ recv_buf_size = VIRTIO_VSOCK_MAX_PKT_BUF_SIZE; >+ recv_buf(fd, buf, recv_buf_size, 0, recv_buf_size); >+ recv_buf_size++; >+ >+ /* Updating SO_RCVLOWAT will send credit update. */ >+ if (setsockopt(fd, SOL_SOCKET, SO_RCVLOWAT, >+ &recv_buf_size, sizeof(recv_buf_size))) { >+ perror("setsockopt(SO_RCVLOWAT)"); >+ exit(EXIT_FAILURE); >+ } >+ >+ memset(&fds, 0, sizeof(fds)); >+ fds.fd = fd; >+ fds.events = POLLIN | POLLRDNORM | POLLERR | >+ POLLRDHUP | POLLHUP; >+ >+ /* This 'poll()' will return once we receive last byte >+ * sent by client. >+ */ >+ if (poll(&fds, 1, -1) < 0) { >+ perror("poll"); >+ exit(EXIT_FAILURE); >+ } >+ >+ if (fds.revents & POLLERR) { >+ fprintf(stderr, "'poll()' error\n"); >+ exit(EXIT_FAILURE); >+ } >+ >+ if (fds.revents & (POLLIN | POLLRDNORM)) { >+ recv_buf(fd, buf, recv_buf_size, 0, recv_buf_size); Should we set the socket non-blocking? Otherwise, here poll() might wake up even if there are not all the expected bytes due to some bug and recv() block waiting for the remaining bytes, so we might not notice the bug. Stefano >+ } else { >+ /* These flags must be set, as there is at >+ * least 64KB of data ready to read. >+ */ >+ fprintf(stderr, "POLLIN | POLLRDNORM expected\n"); >+ exit(EXIT_FAILURE); >+ } >+ >+ free(buf); >+ close(fd); >+} >+ > static struct test_case test_cases[] = { > { > .name = "SOCK_STREAM connection reset", >@@ -1335,6 +1472,11 @@ static struct test_case test_cases[] = { > .run_client = test_double_bind_connect_client, > .run_server = test_double_bind_connect_server, > }, >+ { >+ .name = "SOCK_STREAM virtio SO_RCVLOWAT + deferred cred update", >+ .run_client = test_stream_rcvlowat_def_cred_upd_client, >+ .run_server = test_stream_rcvlowat_def_cred_upd_server, >+ }, > {}, > }; > >-- >2.25.1 >