From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796135614; b=PzctT64iZO3Gkkg5GybU2Jky/RhZjMIcoMaTDQ7oeXatqOKdI++R7bDdpyn6QClyuUQk xbgM8t3VWd6W2/d0hVAF8OjhxREnopRcxzXUDg6oOeo0MFdXjiuOvtyZnxH3GIdi7UFlB 8hTcV64DFD9WcsIwJtzkcz2ZRvq9GdXsnoMEgmG6kAnEzUX038aPFcf0L6fxAuHSzjrnf pVV/BsbReCo5KWrjInBdi/i5pTMxRM4fQc4QUUpbxPUBLkcSjdvHwliAUWoX+AEXlNTjO Jspvj38fKIw2jx6W3L26hUdJj6i5lblM1NBNh1vaU1nrnonGtVSY2NX6bgkxFctzTSw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796135614; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received: X-Received:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=WSusl5792GZP9GHF0XW43mj40nvpHpXKFvSJktndXsA=; b=pFKoFvKY+LOb7YySMJs8s+ByrorbPdDAPcAP5Ctm2/tiUZ7FWd/dYxosm0Y1b9GnmVox pWN2m6ts/3ucCU4vGYA40j4lnckfo3/UxgKtBYxWNaJK/YfSgEcsq7jYSaHyNs5leEgZ0 5o6Zyhlo5UBzfehaG10YRhWUydBlAUSaVWV2wZtzGofFmLIcDMGyJf2rQtKEUvgtUaA25 qewQWSl4APHn+xWw82/GvEUjmEDQOn4adGUn3Vo9bzwzDTL1Zh2h4ptnjq7RpcbqSEl63 QSU4lC9jTp/zRPnPTvoekMjp7Nbd1zXiJ6ogjdM0aoz7Lj0hJg0vPiFee0aPi/LvJvw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OJT9zFD9; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=baqop7Uu; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C84BD606A31A for ; Tue, 1 Dec 2026 14:33:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C84BD606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OJT9zFD9; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=baqop7Uu DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796135612; 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=WSusl5792GZP9GHF0XW43mj40nvpHpXKFvSJktndXsA=; b=OJT9zFD9R998jyBZC2yq1CRHoCoITsrA7iDwuH0wKRsAUTRA2fPbcBg/5yCQmdhGEgVWPp 7Ook89XRDppApwuPhotB3x1GDbM1aQvNpEDOBTJJF6la7o7ifsnxXI6sjncskDeVrOcXl5 EWia56WHcX6NcGLoGNDzqdV6V9L+Fyo= 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-601-8oSMKIdhP_CScNnbSamSmQ-1; Tue, 1 Dec 2026 14:33:30 +0000 X-MC-Unique: 8oSMKIdhP_CScNnbSamSmQ-1 X-Mimecast-MFC-AGG-ID: 8oSMKIdhP_CScNnbSamSmQ_1796135610 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-48e0fc747a7so7644401f8f.1 for ; Tue, 01 Dec 2026 06:33:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1796135609; x=1796740409; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=WSusl5792GZP9GHF0XW43mj40nvpHpXKFvSJktndXsA=; b=baqop7UurIjBjbv8LARcGSf2f2hmUj+Iwy9L66o4hPNAOsVP6uyvQK3sFwGzNJUNKD xgxlBKamZpnSEzUKK7ZBn+G/gfeXBXYr40N7K9ANiWKevdbuBEtJFlkhGvscHPaU88C7 3hvnsIqevzz+DL49Sucv1FjMa/I1qOkUm86QEqVG5q80MvU07wOYxAm64JFWXXWox7PA okyQ7X475uJDefmKpCEkbuqcMTBl+BFQ/1pjbjtbo6+xQ3e33Q7z+UzCXUGhTTEwWhJr okaAz3BznR8/ocxhabt685d76RCOs3U8jj6YL4B010aR053BdRqQPbxE4pkDSU1q3P+e 42rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796135609; x=1796740409; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=WSusl5792GZP9GHF0XW43mj40nvpHpXKFvSJktndXsA=; b=nZ5nYnC1YA6YhQffhU9FB2scqWrhZeBGB3eXWNVNt5EpN1kK6LpPD0hhZUorh2Vc6M FOc7FyogyFOxXHXUm0Oezx3mqGFjsh1mtu+/bG1+lculkg2su3Jt6Id1G5QZbWKLoPXb iVkgrHkiooU1Q83g5qhRg/CMyTTsA0g4RgG8XPsLY4IodAUWCRqVfcDLPisq6/gj/WyC /i5DLzLgWb3mMptr0IFUk7BbaBQ6eCJETwdiyG70ve0x0ZhcCOqOGzYQkoYFewgQp5UR mMkmXD7jcUPDrn7XckmwTnSV59MK0/Jb2NDVQn0kMyKf51aGjNUnjTcDU10CbvbguyAb GvvA== X-Forwarded-Encrypted: i=1; AL+hErGmjUVGlAiLj6SC9UrD2V6yQHZ+t4Ma/WNzFRu8QAz9jNunKdNa2YUrtHWjWWiRBQ0qilnvdt0=@vger.kernel.org X-Gm-Message-State: APuU4Z9/2iiTlUthbj8CtkSYYyoAsnWIIpQpweYytJFk1VcGk5nygXgq MwcsQ8Ldmeg9+16FrnTQRSJU6M9yZ1MwgLoEhbYKD5C9CVid4/HZT2mNJkSnUeOLdPPXhQ4rgcR R8I0poEBlpf0DLTO0droMo0YjrKLvx8QPMVW6P84rzbK5Krfy5XeiEZxNUg== X-Gm-Gg: AZFdTZfRLRsHWG9v9AoHTmc89z03rbwxkasWDdpGq7iRnKL7bBbRCffoIWSmLUTlOio V+n5vHpJmo18shLngOnFRp1TcVCnbqZ20TlPoya8Ko7hXJBuaZ8Cdmdp78/16K65LNoawI4bJdm cY8iLqmL733+KBBs5p2OOfWR7i1QH/f2Ikt93XDDOyoG8+tG33aaS5fwazlhPiyYa2/BgQZLDTc Ct46JO5otPBV0qaaRSFz43xjtMBOObcL09IpZq73uB9a14X7q4TY4HDvhM8bJFv5Kq1+TsJhbQQ izxpAYqciS7CwJf/TL6iUTp4jSkeBe4EHLz3N+hoSjjXfecstH22Lig1XQXLXseiqQuUOQLXkiT 5fE6TRF9EuStHzHFHOUv0NKWuXTjPL8kSVqhjUzH5MmKekdTuILLnkwIw0LfIO37I3JhbxdA+/+ n6dXBFK+47EtNyMg== X-Received: by 2002:a5d:574e:0:b0:4a4:f208:6a4c with SMTP id ffacd0b85a97d-4abb41f4dbbmr56608768f8f.43.1796135609520; Tue, 01 Dec 2026 06:33:29 -0800 (PST) X-Received: by 2002:a5d:574e:0:b0:4a4:f208:6a4c with SMTP id ffacd0b85a97d-4abb41f4dbbmr56608722f8f.43.1796135608910; Tue, 01 Dec 2026 06:33:28 -0800 (PST) Received: from sgarzare-redhat (ip190-139-192-82.pool-bba.aruba.it. [82.192.139.190]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6baa3882sm69992877f8f.49.2026.12.01.06.33.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 06:33:27 -0800 (PST) Date: Tue, 1 Dec 2026 15:33:23 +0100 From: Stefano Garzarella To: Ren Wei Cc: virtualization@lists.linux.dev, netdev@vger.kernel.org, bobbyeshleman@meta.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, horms@kernel.org, arseny.krasnov@kaspersky.com, vega@nebusec.ai, caoruide123@gmail.com Subject: Re: [PATCH net 2/2] vsock/test: add stream MSG_WAITALL receive timeout test Message-ID: References: <503c1d5538f5b41f8eda756f5ea4491f0bd44518.1795591531.git.caoruide123@gmail.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <503c1d5538f5b41f8eda756f5ea4491f0bd44518.1795591531.git.caoruide123@gmail.com> On Fri, Nov 27, 2026 at 01:19:14PM +0800, Ren Wei wrote: > From: Ruide Cao > > test_seqpacket_timeout covers SOCK_SEQPACKET with SO_RCVTIMEO, but there > is no SOCK_STREAM test for a cumulative receive timeout across partial > reads. > > Have the peer drip-feed one byte every 0.8s while the client issues > recv(MSG_WAITALL) with a 1s SO_RCVTIMEO. Without the timeout being > preserved, the wait budget is restarted after each byte and the recv > completes after several intervals. With the fix, the call must return > around the original timeout, either with EAGAIN or with a partial read > shorter than the MSG_WAITALL request. > > Keep the data socket open until both sides confirm: the client writes > WAITDONE after recv returns, the server finishes sending all six bytes > and acknowledges, and only then is the socket closed. Failure paths > complete the same handshake so the server does not hang. > > Signed-off-by: Ruide Cao > Signed-off-by: Ren Wei > --- > tools/testing/vsock/vsock_test.c | 112 +++++++++++++++++++++++++++++++ > 1 file changed, 112 insertions(+) > > diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c > index 10b9074fb87f..868792f7729c 100644 > --- a/tools/testing/vsock/vsock_test.c > +++ b/tools/testing/vsock/vsock_test.c > @@ -662,6 +662,113 @@ static void test_seqpacket_timeout_server(const struct test_opts *opts) > close(fd); > } > > +#define STREAM_RCVTIMEO_DRIP_BYTES 6 > +#define STREAM_RCVTIMEO_DRIP_USEC 800000 /* 0.8s, inside the 1s timeout */ > + > +/* Keep the data socket open until both sides confirm. The client > + * writes WAITDONE when recv() returns, but must not close until the > + * server has finished drip-feeding all 6 bytes and acknowledged; > + * otherwise later sends hit EPIPE. Failure paths complete the same > + * handshake so the server is not left in control_expectln("WAITDONE"). > + */ > +static void test_stream_timeout_waitall_done(int fd) why we need this function? Can we inline those since this is called in a single point. > +{ > + control_writeln("WAITDONE"); Why we need this sync point (i.e. WAITDONE)? > + control_expectln("SRVDONE"); > + close(fd); > +} > + > +static void test_stream_timeout_waitall_client(const struct test_opts *opts) > +{ > + char buf[STREAM_RCVTIMEO_DRIP_BYTES]; > + time_t read_enter_ns; > + struct timeval tv; > + time_t read_ns; > + int failed = 0; > + ssize_t n; > + int fd; > + > + fd = vsock_stream_connect(opts->peer_cid, opts->peer_port); > + if (fd < 0) { > + perror("connect"); > + exit(EXIT_FAILURE); > + } > + > + tv.tv_sec = RCVTIMEO_TIMEOUT_SEC; > + tv.tv_usec = 0; > + > + setsockopt_timeval_check(fd, SOL_SOCKET, SO_RCVTIMEO, tv, > + "setsockopt(SO_RCVTIMEO)"); > + > + /* Enter recv() before the peer starts drip-feeding, so the first > + * byte cannot already be queued. > + */ > + control_writeln("CLNSENT"); > + > + read_enter_ns = current_nsec(); > + n = recv(fd, buf, sizeof(buf), MSG_WAITALL); > + read_ns = current_nsec() - read_enter_ns; > + > + /* Unfixed kernels restart the full SO_RCVTIMEO after each partial > + * read, so this recv() returns 6 bytes after ~4.8s. A cumulative > + * 1s timeout returns much sooner; use 2s as the cap so the two > + * outcomes cannot be confused. > + */ > + if (read_ns >= 2ULL * NSEC_PER_SEC * RCVTIMEO_TIMEOUT_SEC) { > + fprintf(stderr, > + "recv(MSG_WAITALL) exceeded SO_RCVTIMEO, %lu ns\n", > + read_ns); > + failed = 1; > + } > + > + if (n == sizeof(buf)) { > + fprintf(stderr, > + "recv(MSG_WAITALL) completed under drip-feed\n"); > + failed = 1; > + } > + > + if (n < 0 && errno != EAGAIN) { > + perror("EAGAIN expected"); > + failed = 1; > + } > + > + if (n == 0) { > + fprintf(stderr, "unexpected EOF on recv(MSG_WAITALL)\n"); > + failed = 1; > + } > + > + test_stream_timeout_waitall_done(fd); > + if (failed) > + exit(EXIT_FAILURE); > +} > + > +static void test_stream_timeout_waitall_server(const struct test_opts *opts) > +{ > + int fd; > + int i; > + > + fd = vsock_stream_accept(VMADDR_CID_ANY, opts->peer_port, NULL); > + if (fd < 0) { > + perror("accept"); > + exit(EXIT_FAILURE); > + } > + > + control_expectln("CLNSENT"); > + > + /* Drip-feed all 6 bytes even after the client times out, so an > + * unfixed kernel still collects a full 6-byte recv and fails. > + * The client keeps the data socket open until SRVDONE. > + */ > + for (i = 0; i < STREAM_RCVTIMEO_DRIP_BYTES; i++) { > + timeout_usleep(STREAM_RCVTIMEO_DRIP_USEC); > + send_byte(fd, 1, 0); > + } > + > + control_expectln("WAITDONE"); > + control_writeln("SRVDONE"); > + close(fd); > +} > + > static void test_seqpacket_bigmsg_client(const struct test_opts *opts) > { > unsigned long long sock_buf_size; > @@ -2739,6 +2846,11 @@ static struct test_case test_cases[] = { > .run_client = test_seqpacket_timeout_client, > .run_server = test_seqpacket_timeout_server, > }, > + { > + .name = "SOCK_STREAM MSG_WAITALL timeout", > + .run_client = test_stream_timeout_waitall_client, > + .run_server = test_stream_timeout_waitall_server, > + }, Please add new test at the bottom, we used id to skip them, so we should not put tests in the middle (I need to add a comment about that in the code). Thanks, Stefano > { > .name = "SOCK_SEQPACKET invalid receive buffer", > .run_client = test_seqpacket_invalid_rec_buffer_client, > -- > 2.47.3 >