Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2517753rdb; Wed, 15 Nov 2023 03:11:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFPnTBxbyLYDKvQuTEpwIOxDcSoGsUg6Z18jHkf+JTCOW1nIY6JTe7JQHa7iuzZKPjlv/FI X-Received: by 2002:a05:6a20:9183:b0:160:97a3:cae9 with SMTP id v3-20020a056a20918300b0016097a3cae9mr14492772pzd.54.1700046698696; Wed, 15 Nov 2023 03:11:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700046698; cv=none; d=google.com; s=arc-20160816; b=D8euHP0su8EbW+5ZtbXATSy1ldszb8XJNBGWXe6jj9UdFZug9rP5OpDoKDZv/KNQJ3 FB/w0b/qcNPocj+8fWIh1Mid9hbDTzZRDQQW9hhpCgrKIp4iHTOV5QVO1RgRfKNg+cuT aSQYck78i5XdV47KR9SCoXke5GuV6PF+iff/UmXpUQzrPEhnmu2XGWhr4aS9JbICLMS7 AYCagP9Ar0Miy9aQIJ4cb+zVyiEeNX0y9RSbIphwmD6l+BA181FcVmrM0SJjquizUzyt HNg6Czm4L9UIrVgRQyxADTgAZDTKK9Kb78IomsLPR8oLW1lrHhgoIiiDHQC+ElxOT74r 9B8Q== 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=P+9IBIN2TseVRMl8fITJ/N2WS2NwQD1vqkbQglXI4X4=; fh=JEq7ZyqHwnKMAbPjHbEHIOO1u1YxTWxtQlCbJmwG+xw=; b=XttF5jH3izw/a2V/+Rxy8IeVMBlhZEIXjAv63B2G4pU0xgk/BIoOgKLhpxu3ftAcGf swmeCvr4egMH1rHn0JOxDLbUrnH5eglZ60ZF3QEl1/xoJ/e8WgykrqdpmRCwicDD/d3u bQcNWfEMevfPMxC46LjPdKKTWy7eraGeBorLIvRPPXhRrX0LWBeNUjRuMU0Nq3zIcBfb M/ik5qtEIdt4iBdhvao1SBph7v/K79JTNLumTYYevUi4cn08om3Q1QHU8vzy2bsRsHIY ySscXsOljft3fxfq2xhfYPJcpQSEnVV+/Z32/Qb2YW+xiEG1Tz01RwGWtqkR4YRZTRhi Z4xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hBk0q8WC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id f4-20020a63e304000000b005b9600b9f4asi9970532pgh.228.2023.11.15.03.11.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 03:11:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hBk0q8WC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 5A8BF80BFEDF; Wed, 15 Nov 2023 03:11:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343564AbjKOLLT (ORCPT + 99 others); Wed, 15 Nov 2023 06:11:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234885AbjKOLLQ (ORCPT ); Wed, 15 Nov 2023 06:11: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 ABEA4E1 for ; Wed, 15 Nov 2023 03:11:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700046671; 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=P+9IBIN2TseVRMl8fITJ/N2WS2NwQD1vqkbQglXI4X4=; b=hBk0q8WC1EsTqTSJOHK8rNcLHuiY9Lmh4sLgdMJlQ3vDWRbuyb/M8tyPigUDAps8EAS1og fLCEBBYsuRHXcNAiO7kyvSM7w++lchlxzxpBH5auqArM+aUq9Oy9TR5VeQFCNFS8ZOKeL2 hkvHTjMrZQ3ZpykJ9mMHMLM+FXzfARc= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-299-v4o9SRQiOIGG6Kjirw7D1g-1; Wed, 15 Nov 2023 06:11:10 -0500 X-MC-Unique: v4o9SRQiOIGG6Kjirw7D1g-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-9e31708ad72so460129166b.3 for ; Wed, 15 Nov 2023 03:11:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700046669; x=1700651469; 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=P+9IBIN2TseVRMl8fITJ/N2WS2NwQD1vqkbQglXI4X4=; b=Jx69lecBP4Npkop6fZhgFHqxNbH6K1l0CRYfa5ekEN5rTLfN5lzZtgWXcSJW6qJaFD gcmKu+XWIvF+Pw2sWhkNzUA3Tc8KfDBRzhnu4+o0+1jT6NnnC0A+4tFDbU+DZyFZC5u7 5Xce7p4VpKYxie3lsCyJCcC0ldgZWbOodOfpm9YXFe16sA2oZpLyqAMo1IozyIOzU/lG 5qbWf/gXF1OeDvzbAaDMrtY108iKeDmVMjRibrm/O4oYdw+5sK1IOb1MWHRNqoA6RIy2 WJEnKtEAQAofR9OQW4gA4lz7GzY9n8dOIsQS/pP3n4zfOPv6kUiHRUu8NdZPdHxsH/DH AewQ== X-Gm-Message-State: AOJu0Yyj3rELWBw2tMBiCOlFPLzJ4EqutU+CH5SnJPLoAzyoM5He/JLk ErK45Bjmy43JnE3d2ubUwj/4Oq1bn+eH5ljfbpJXwf3Nho1zQ8P+5oWwf03nNGbnSotLGDCQi4+ sf9icJLwqJHqccEUu8yRRIPqv X-Received: by 2002:a17:906:d292:b0:9dd:f5ba:856d with SMTP id ay18-20020a170906d29200b009ddf5ba856dmr10523742ejb.62.1700046669460; Wed, 15 Nov 2023 03:11:09 -0800 (PST) X-Received: by 2002:a17:906:d292:b0:9dd:f5ba:856d with SMTP id ay18-20020a170906d29200b009ddf5ba856dmr10523724ejb.62.1700046669162; Wed, 15 Nov 2023 03:11:09 -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 e10-20020a170906080a00b009a193a5acffsm6916813ejd.121.2023.11.15.03.11.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 03:11:08 -0800 (PST) Date: Wed, 15 Nov 2023 12:11:02 +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 v1 2/2] vsock/test: SO_RCVLOWAT + deferred credit update test Message-ID: References: <20231108072004.1045669-1-avkrasnov@salutedevices.com> <20231108072004.1045669-3-avkrasnov@salutedevices.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20231108072004.1045669-3-avkrasnov@salutedevices.com> X-Spam-Status: No, score=-1.0 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 groat.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 (groat.vger.email [0.0.0.0]); Wed, 15 Nov 2023 03:11:30 -0800 (PST) On Wed, Nov 08, 2023 at 10:20:04AM +0300, Arseniy Krasnov wrote: >This adds test which checks, that updating SO_RCVLOWAT value also sends You can avoid "This adds", and write just "Add test ...". See https://docs.kernel.org/process/submitting-patches.html#describe-your-changes Describe your changes in imperative mood, e.g. "make xyzzy do frotz" instead of "[This patch] makes xyzzy do frotz" or "[I] changed xyzzy to do frotz", as if you are giving orders to the codebase to change its behaviour. Also in the other patch. >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. > >Signed-off-by: Arseniy Krasnov >--- > tools/testing/vsock/vsock_test.c | 131 +++++++++++++++++++++++++++++++ > 1 file changed, 131 insertions(+) > >diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c >index c1f7bc9abd22..c71b3875fd16 100644 >--- a/tools/testing/vsock/vsock_test.c >+++ b/tools/testing/vsock/vsock_test.c >@@ -1180,6 +1180,132 @@ static void test_stream_shutrd_server(const struct test_opts *opts) > close(fd); > } > >+#define RCVLOWAT_CREDIT_UPD_BUF_SIZE (1024 * 128) >+#define VIRTIO_VSOCK_MAX_PKT_BUF_SIZE (1024 * 64) What about adding a comment like the one in the cover letter about dependency with kernel values? Please add it also in the commit description. I'm thinking if we should move all the defines that depends on the kernel in some special header. >+ >+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. */ >+ control_expectln("SRVREADY"); >+ >+ 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); >+ } >+ >+ buf = malloc(buf_size); >+ if (!buf) { >+ perror("malloc"); >+ exit(EXIT_FAILURE); >+ } >+ >+ control_writeln("SRVREADY"); >+ >+ /* 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); >+ } 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", >@@ -1285,6 +1411,11 @@ static struct test_case test_cases[] = { > .run_client = test_stream_msgzcopy_empty_errq_client, > .run_server = test_stream_msgzcopy_empty_errq_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 >