Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4447776rdh; Wed, 29 Nov 2023 01:37:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtHgXvYz4LuY6YBUGYf9auga4mRvUE2Yv1rWlxHrrmuZ7m7o+FwEQledOhRoFgQwaPf+QH X-Received: by 2002:a05:6a00:a0c:b0:6bd:b7c5:f776 with SMTP id p12-20020a056a000a0c00b006bdb7c5f776mr19334201pfh.8.1701250631209; Wed, 29 Nov 2023 01:37:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701250631; cv=none; d=google.com; s=arc-20160816; b=s4ykHZnHi9p7XqYHFl9lNb5LPWeDuRDx5mjZK1P7Zufwi9CTpF5m5iPM+xx6Kp9i0s +5u3zI589U6i7mNpOFSsEoOD/WxLUNrcpWtcqdgJtbJ5JB6P6WX7/qG3mmrsBbbkKOYM HMJIKW2kfZQ+9kUdaS2wkOEnkuf3mdVLXmLQAff4mVjVrrD/KmUng6q6l1wtr5oVDdfL pzc4YiutjcSBfKyuf89hBqX62/Q4EdkmEBEDNxZLCgFhE59FAsgztjpedfWOHipgFBrZ QWR/cCw6xgSKDShJUKF8nREjsaGJfGtXLq/aFf3eSzlAROHNr3a7NfnDBGYwGez0nsA/ 11yQ== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=KmfiUoMGCSqDA5zypbVWGdwfGo6gARdw5ZkS+2p63ME=; fh=JEq7ZyqHwnKMAbPjHbEHIOO1u1YxTWxtQlCbJmwG+xw=; b=sEKlUDPl3nSMS761vO5q8uH1PH11lK4FIhMHDSXwxDrjW/JZ4Tb57TMlWdqQs50yjL sB4VseYWalH84AcV+itZVyAN6Zh0Np2pwdgHPU8HM3f4JAXY4l5Gk2o1gGcMCw9Eir41 gHqf+UqbwoOF9Y4mB0G/zl4UllJ1CQXxw8NuRSwFgVZtHRnH3R1Cb0O3/klLoFwqc+gi 1V2vyJSzBDgOQjsiDHR62RBJIPvB7eS2CAfCq/eCCx5UkWokB+VIfIb8Ca25xpmqjwom 6Qpuy+Fit3O/QaxIoF5YmCxeMi6pbza6WCVx87jVjnZLV8iJobcsJuMlDAJZ7YxCDeu+ Zg2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IMZTPVbc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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. [23.128.96.37]) by mx.google.com with ESMTPS id k184-20020a6284c1000000b006cb912b847fsi13219249pfd.123.2023.11.29.01.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 01:37:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IMZTPVbc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 22B0A80BD25C; Wed, 29 Nov 2023 01:37:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229670AbjK2Jg5 (ORCPT + 99 others); Wed, 29 Nov 2023 04:36:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbjK2Jgw (ORCPT ); Wed, 29 Nov 2023 04:36:52 -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 5140119A0 for ; Wed, 29 Nov 2023 01:36:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701250617; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KmfiUoMGCSqDA5zypbVWGdwfGo6gARdw5ZkS+2p63ME=; b=IMZTPVbc7u7/q4kYkllsrV02/6nHuHH2+bFeLfuWvLRID5lw686Yf1uyXGaWtKU6aSHgQz xpHHR0bRdVPbH2PT48PaxVlcMXa8vMIgkv58SGanY3K9c2V/VQaANZTotRrC0sYf0RVNi8 YakltyQS/k7JINbK8fXeg8u2PtIA0Vs= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-387-nPXlZQWHO6Kf5GrpNFcGDQ-1; Wed, 29 Nov 2023 04:36:56 -0500 X-MC-Unique: nPXlZQWHO6Kf5GrpNFcGDQ-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-408695c377dso42804745e9.2 for ; Wed, 29 Nov 2023 01:36:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701250615; x=1701855415; h=in-reply-to:content-transfer-encoding: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=KmfiUoMGCSqDA5zypbVWGdwfGo6gARdw5ZkS+2p63ME=; b=GdeY7Gdd6YV2abjZM2kWRpXsqbMGLM8eXRJ2soL/UUDfC1enlnS0zWn9JHhjjn0PFL LlA6y3tfrpAJVm9EnX8L7Pu877FgnQ8oSjS1MoMA0actlIiD9je6tjab9uKNEdvMwEhI xq0p7Af+2xKGLZW2rdLkm8fK2GioziJJqOeS2iJQ/Y2z1xmHuHSppJmuZV5Y0dZZdw7x Y0rNLsJ3Qv+VXA585WSmwEb1egRmPEHlSLjQsG9QNuuIgRLIeqSoFazzbrPo9Y6Go1+C 0U3TdP9Lv/vqzQ1aZO38U/oovdWYiI3eBV6EqE72eXguEjgQJ1uoHz3H+n7HrE/LytvV JyVA== X-Gm-Message-State: AOJu0YwXVeYoIf7jtv1xG8tRD0GagaBpXsUjc0CrRwHno+NQSGgpFybc 5QicxBoHIoiflpaQlzY062xNOQ3Ni2tluqPgjmG93OxSyrxY08yr4hhI3kyXW+RaJLfLRyTkYlg HrKKFWfWHMult26nSO5rE2BYK X-Received: by 2002:a05:600c:46cc:b0:402:e68f:8896 with SMTP id q12-20020a05600c46cc00b00402e68f8896mr9785476wmo.0.1701250614868; Wed, 29 Nov 2023 01:36:54 -0800 (PST) X-Received: by 2002:a05:600c:46cc:b0:402:e68f:8896 with SMTP id q12-20020a05600c46cc00b00402e68f8896mr9785450wmo.0.1701250614447; Wed, 29 Nov 2023 01:36:54 -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 j7-20020a05600c190700b0040b43da0bbasm1518805wmq.30.2023.11.29.01.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 01:36:53 -0800 (PST) Date: Wed, 29 Nov 2023 10:36:48 +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=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, 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 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, 29 Nov 2023 01:37:10 -0800 (PST) On Wed, Nov 29, 2023 at 12:16:54PM +0300, Arseniy Krasnov wrote: > > >On 29.11.2023 12:16, Stefano Garzarella wrote: >> 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. > >Good point! or just use MSG_DONTWAIT flag for only this 'recv()'. Yep, right! Stefano