From nobody Sun Feb 8 07:14:43 2026 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [185.226.149.37]) (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 1C57C1E883A; Thu, 1 May 2025 08:05:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746086754; cv=none; b=vCJIRof7u8CJLRcdcgMa3Aov2iJOmDCgr/rWvTA40cPTSR1ZKkY/woy1ycehg/Pvapr9FzG7oQ4bzKvGXcFptTFu6RS/1q6fPYlTBI6FQFw7RNZV3wSSMZVHyWO/i9Du49We6W1DoRAH6rUXexIsafcyYKMDeulMVwsJ2CzaGmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746086754; c=relaxed/simple; bh=Mu6prwauj7B3bCqGpqGc0KCidlcsB8GchOCM8+2XE5s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uOT/U+zBKKB40kWneCErWTyXS26eH9dLQVQbe5OLgxuhZ5h1TonUwpDKGMYhzbIIr5gPkGyLT5ps3BGf0IiOn3ULZqqntid1lvUGvIUCqS53q/WAQkt6Q3vhaTY40qy4RA66JElfldJabf75x0Wc/uHuY/kZFWJFPw6IiQbCFko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co; spf=pass smtp.mailfrom=rbox.co; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b=RbZPxq11; arc=none smtp.client-ip=185.226.149.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rbox.co Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b="RbZPxq11" Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1uAOvR-009GJ9-N9; Thu, 01 May 2025 10:05:45 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector1; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From; bh=ryPcbNb/7eJcu1W3+cY8RMwSBA+GuC6dYVOgjIg/Z2w=; b=RbZPxq11clJsd+Hu6q6D9NWLN4 awvLEpO2WJUUZTNQRLYsFwxQuPeY24AIQHeDMm/NVuKxufBIZ10sGoGBDBoI1gxhKFq3MuGcK6NCk YVWXlhDYlrHZ9gIUh+qabyZf6ztjZ4DbDINDpbhQ928Wv7/5u5Gk/itzOGUftBsjgew1+chJt1ijN 3Tc/mdJtsfCRtDUOm04j5BgRPH7vigAlV0a1ylPldY8QYhVbhKqeAxcPxP4nuQEfNnnDvVqX6yhQx NSqoRsSnlMprYCkRiP4CKA4NcYgURw0hFfSxVQMQqhRNRb3+UecIV1LaD3gOYwedS9BiYs7JySQP3 ld+yE2RA==; Received: from [10.9.9.74] (helo=submission03.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1uAOvQ-0007we-Cv; Thu, 01 May 2025 10:05:44 +0200 Received: by submission03.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1uAOvI-005lsv-QR; Thu, 01 May 2025 10:05:36 +0200 From: Michal Luczaj Date: Thu, 01 May 2025 10:05:22 +0200 Subject: [PATCH net-next v4 1/3] vsock/virtio: Linger on unsent data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250501-vsock-linger-v4-1-beabbd8a0847@rbox.co> References: <20250501-vsock-linger-v4-0-beabbd8a0847@rbox.co> In-Reply-To: <20250501-vsock-linger-v4-0-beabbd8a0847@rbox.co> To: Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , Stefan Hajnoczi Cc: virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Michal Luczaj X-Mailer: b4 0.14.2 Currently vsock's lingering effectively boils down to waiting (or timing out) until packets are consumed or dropped by the peer; be it by receiving the data, closing or shutting down the connection. To align with the semantics described in the SO_LINGER section of man socket(7) and to mimic AF_INET's behaviour more closely, change the logic of a lingering close(): instead of waiting for all data to be handled, block until data is considered sent from the vsock's transport point of view. That is until worker picks the packets for processing and decrements virtio_vsock_sock::bytes_unsent down to 0. Note that (some interpretation of) lingering was always limited to transports that called virtio_transport_wait_close() on transport release. This does not change, i.e. under Hyper-V and VMCI no lingering would be observed. The implementation does not adhere strictly to man page's interpretation of SO_LINGER: shutdown() will not trigger the lingering. This follows AF_INET. Signed-off-by: Michal Luczaj Reviewed-by: Stefano Garzarella --- net/vmw_vsock/virtio_transport_common.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio= _transport_common.c index 7f7de6d8809655fe522749fbbc9025df71f071bd..045ac53f69735e1979162aea8c9= ab5961407640c 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -1196,12 +1196,14 @@ static void virtio_transport_wait_close(struct sock= *sk, long timeout) { if (timeout) { DEFINE_WAIT_FUNC(wait, woken_wake_function); + struct vsock_sock *vsk =3D vsock_sk(sk); =20 add_wait_queue(sk_sleep(sk), &wait); =20 do { if (sk_wait_event(sk, &timeout, - sock_flag(sk, SOCK_DONE), &wait)) + virtio_transport_unsent_bytes(vsk) =3D=3D 0, + &wait)) break; } while (!signal_pending(current) && timeout); =20 --=20 2.49.0 From nobody Sun Feb 8 07:14:43 2026 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [185.226.149.37]) (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 E6BBC1EB1BC; Thu, 1 May 2025 08:05:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746086754; cv=none; b=oZq+Wx3W7QZYSfuf++4QiVtn5PITRQk5wMAVMc3+oXqPpczEJmELDlVtxZl+AvLe724Mf6gr9Zc8XTJ04E1mH8LC1/HLvdy2E66uhOM0WXw7w0ydf0m2aq4yLjWp7lfsDfkmBRxhDov3k8nzISvkXhnXSfvlUlCbVPh5Ll+PyDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746086754; c=relaxed/simple; bh=sG2QEyQbrobbnyUhVWEtJMUwJvJ74lxMh2X+TVU/j8Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cTOPhIDxylehN341umQNjXZbv6q34N5UiBtCKlhw6LrzzxvRSL2lCgIJR6NhBrk/QpeNkqZj8vfRH64VuSgcrckgET8/oPKKVsx4R5+8/GT154GKpgVK869cjoaTd+6w73ippuXK9LluJisHI/ol1jlEKzcF1z8q8VOrNf8M2Tc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co; spf=pass smtp.mailfrom=rbox.co; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b=G751hQCu; arc=none smtp.client-ip=185.226.149.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rbox.co Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b="G751hQCu" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1uAOvU-009GJK-I6; Thu, 01 May 2025 10:05:48 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector1; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From; bh=2+Pq8Xix56XtZggy9D9QenLSKFUy39lDf1vpQzvRUiU=; b=G751hQCu0JZMaPkaorZdkE1h9o i9d0NdWrxcOy8IhaePt6pvZN+zX5OWaDJ1qz709RzRp7uXe9FEwlE2Z1kAQ8VsOiQ1W0v73eupzx2 vn4KbyUfOZ4u+kSqBdAa6zXHj1aEdNMEYcia0haFA+44wex6TCyjMLXsSA7UyrO8h/YJMPFcfk77V 3qaWTUMVixpxefpue4SnBiFxfhHs/jUCKuFjLo1pXqzffCsGuZ49hW4I6s+dECB4obvVZV/S3sFMc Z/0UTI8c5ogXFsohW7Hiz/iSDgc4Dv5ijVO2AZpJLiTznNLc+/KZfgpN40sANqEuJQXTDxUk5Ybxh 7Py8fQig==; Received: from [10.9.9.74] (helo=submission03.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1uAOvU-0001EA-8b; Thu, 01 May 2025 10:05:48 +0200 Received: by submission03.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1uAOvJ-005lsv-Oq; Thu, 01 May 2025 10:05:37 +0200 From: Michal Luczaj Date: Thu, 01 May 2025 10:05:23 +0200 Subject: [PATCH net-next v4 2/3] vsock: Move lingering logic to af_vsock core Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250501-vsock-linger-v4-2-beabbd8a0847@rbox.co> References: <20250501-vsock-linger-v4-0-beabbd8a0847@rbox.co> In-Reply-To: <20250501-vsock-linger-v4-0-beabbd8a0847@rbox.co> To: Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , Stefan Hajnoczi Cc: virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Michal Luczaj X-Mailer: b4 0.14.2 Lingering should be transport-independent in the long run. In preparation for supporting other transports, as well the linger on shutdown(), move code to core. Generalize by querying vsock_transport::unsent_bytes(), guard against the callback being unimplemented. Do not pass sk_lingertime explicitly. Pull SOCK_LINGER check into vsock_linger(). Flatten the function. Remove the nested block by inverting the condition: return early on !timeout. Suggested-by: Stefano Garzarella Signed-off-by: Michal Luczaj --- include/net/af_vsock.h | 1 + net/vmw_vsock/af_vsock.c | 30 ++++++++++++++++++++++++++++++ net/vmw_vsock/virtio_transport_common.c | 23 ++--------------------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h index 9e85424c834353d016a527070dd62e15ff3bfce1..d56e6e135158939087d060dfcf6= 5d3fdaea53bf3 100644 --- a/include/net/af_vsock.h +++ b/include/net/af_vsock.h @@ -221,6 +221,7 @@ void vsock_for_each_connected_socket(struct vsock_trans= port *transport, void (*fn)(struct sock *sk)); int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk); bool vsock_find_cid(unsigned int cid); +void vsock_linger(struct sock *sk); =20 /**** TAP ****/ =20 diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index fc6afbc8d6806a4d98c66abc3af4bd139c583b08..a31ad6b141cd38d1806df4b5d41= 7924bb8607e32 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1013,6 +1013,36 @@ static int vsock_getname(struct socket *sock, return err; } =20 +void vsock_linger(struct sock *sk) +{ + DEFINE_WAIT_FUNC(wait, woken_wake_function); + ssize_t (*unsent)(struct vsock_sock *vsk); + struct vsock_sock *vsk =3D vsock_sk(sk); + long timeout; + + if (!sock_flag(sk, SOCK_LINGER)) + return; + + timeout =3D sk->sk_lingertime; + if (!timeout) + return; + + /* unsent_bytes() may be unimplemented. */ + unsent =3D vsk->transport->unsent_bytes; + if (!unsent) + return; + + add_wait_queue(sk_sleep(sk), &wait); + + do { + if (sk_wait_event(sk, &timeout, unsent(vsk) =3D=3D 0, &wait)) + break; + } while (!signal_pending(current) && timeout); + + remove_wait_queue(sk_sleep(sk), &wait); +} +EXPORT_SYMBOL_GPL(vsock_linger); + static int vsock_shutdown(struct socket *sock, int mode) { int err; diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio= _transport_common.c index 045ac53f69735e1979162aea8c9ab5961407640c..aa308f285bf1bcf4c689407033d= e854c6f85a639 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -1192,25 +1192,6 @@ static void virtio_transport_remove_sock(struct vsoc= k_sock *vsk) vsock_remove_sock(vsk); } =20 -static void virtio_transport_wait_close(struct sock *sk, long timeout) -{ - if (timeout) { - DEFINE_WAIT_FUNC(wait, woken_wake_function); - struct vsock_sock *vsk =3D vsock_sk(sk); - - add_wait_queue(sk_sleep(sk), &wait); - - do { - if (sk_wait_event(sk, &timeout, - virtio_transport_unsent_bytes(vsk) =3D=3D 0, - &wait)) - break; - } while (!signal_pending(current) && timeout); - - remove_wait_queue(sk_sleep(sk), &wait); - } -} - static void virtio_transport_cancel_close_work(struct vsock_sock *vsk, bool cancel_timeout) { @@ -1280,8 +1261,8 @@ static bool virtio_transport_close(struct vsock_sock = *vsk) if ((sk->sk_shutdown & SHUTDOWN_MASK) !=3D SHUTDOWN_MASK) (void)virtio_transport_shutdown(vsk, SHUTDOWN_MASK); =20 - if (sock_flag(sk, SOCK_LINGER) && !(current->flags & PF_EXITING)) - virtio_transport_wait_close(sk, sk->sk_lingertime); + if (!(current->flags & PF_EXITING)) + vsock_linger(sk); =20 if (sock_flag(sk, SOCK_DONE)) { return true; --=20 2.49.0 From nobody Sun Feb 8 07:14:43 2026 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [185.226.149.37]) (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 8291C25B1D9; Thu, 1 May 2025 08:05:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746086755; cv=none; b=LmFJX4BdwjtHhgPzQNSnqPPKfPFhIioBA1LYEH7DbW4K6gvPGwIWXy9OKBM/AkqRWX01DMawNAmbXf2rmwHcy8i0KvgEx64celnkNN0w+UYphfuKy+qe/2VLaJ4Ujj12SxqbSDWXjRy8T2kPHgB9jOc2v4VxL4NvvjZd89WDoDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746086755; c=relaxed/simple; bh=bU72gZf0Mlr4a1DTEu4p6xddG7QuL34UyWY76ya9fjA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dyuNaqaLRDG0i+Tf5aqGwa9D/hZlsX9vEz0GnMZOS88mYp7PypOxPf6ApTqk7vL7zjXczk2KfbRw8gSs7dSeoCNs8/6oBARoHu5iYg6gyNJwbqK2P4UVFGaWNKKSAk2kKizYkVNzpHWb8W+e4ylDLGCP8xUvGI/Bw08ls3Yv4O4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co; spf=pass smtp.mailfrom=rbox.co; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b=X9VGX+yE; arc=none smtp.client-ip=185.226.149.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rbox.co Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b="X9VGX+yE" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1uAOvV-009GJT-NW; Thu, 01 May 2025 10:05:49 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector1; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From; bh=qswCCZ7zdNCGMNQd6xheEFi5M2DI/AzAcjRQmm33v3U=; b=X9VGX+yEM8mMIFvL6YCUB/p0w4 afhAITQoo56D5rWG3BzXb0kTCKpEJIhude326jP7J5GYRUEALgnuY5jlvMypO+gCvGJbHEvt2qgX0 dhkOrlALiQMuSiSGSHdjz8cpjvYhQ9QGrKCtf+YCoGkIWCm8hYbpQY4/ckS2G7l1bGqtAhRYuZu6e P2PSTDjkCLSKy0rOW4mfPIUcETx7dQBVdyWdiWqzUt5iyrja4//QLtADHyQ64fp0q/9pHQHY2hSV3 zkZw3Cyw89XJcmyflJU/lCRmz1l4c0b5ERmrA6hJKTO+il+iheS836VvhtD5eeERdlWMMjQat5CL2 7JCOaaOg==; Received: from [10.9.9.74] (helo=submission03.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1uAOvV-0001EG-EP; Thu, 01 May 2025 10:05:49 +0200 Received: by submission03.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1uAOvK-005lsv-HP; Thu, 01 May 2025 10:05:38 +0200 From: Michal Luczaj Date: Thu, 01 May 2025 10:05:24 +0200 Subject: [PATCH net-next v4 3/3] vsock/test: Expand linger test to ensure close() does not misbehave Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250501-vsock-linger-v4-3-beabbd8a0847@rbox.co> References: <20250501-vsock-linger-v4-0-beabbd8a0847@rbox.co> In-Reply-To: <20250501-vsock-linger-v4-0-beabbd8a0847@rbox.co> To: Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , Stefan Hajnoczi Cc: virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Michal Luczaj X-Mailer: b4 0.14.2 There was an issue with SO_LINGER: instead of blocking until all queued messages for the socket have been successfully sent (or the linger timeout has been reached), close() would block until packets were handled by the peer. Add a check to alert on close() lingering when it should not. Signed-off-by: Michal Luczaj --- tools/testing/vsock/vsock_test.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_t= est.c index d0f6d253ac72d08a957cb81a3c38fcc72bec5a53..82d0bc20dfa75041f04eada1b43= 10be2f7c3a0c1 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -1788,13 +1788,16 @@ static void test_stream_connect_retry_server(const = struct test_opts *opts) close(fd); } =20 +#define LINGER_TIMEOUT 1 /* seconds */ + static void test_stream_linger_client(const struct test_opts *opts) { struct linger optval =3D { .l_onoff =3D 1, - .l_linger =3D 1 + .l_linger =3D LINGER_TIMEOUT }; - int fd; + int bytes_unsent, fd; + time_t ts; =20 fd =3D vsock_stream_connect(opts->peer_cid, opts->peer_port); if (fd < 0) { @@ -1807,7 +1810,28 @@ static void test_stream_linger_client(const struct t= est_opts *opts) exit(EXIT_FAILURE); } =20 + /* Byte left unread to expose any incorrect behaviour. */ + send_byte(fd, 1, 0); + + /* Reuse LINGER_TIMEOUT to wait for bytes_unsent =3D=3D 0. */ + timeout_begin(LINGER_TIMEOUT); + do { + if (ioctl(fd, SIOCOUTQ, &bytes_unsent) < 0) { + perror("ioctl(SIOCOUTQ)"); + exit(EXIT_FAILURE); + } + timeout_check("ioctl(SIOCOUTQ) =3D=3D 0"); + } while (bytes_unsent !=3D 0); + timeout_end(); + + ts =3D current_nsec(); close(fd); + if ((current_nsec() - ts) / NSEC_PER_SEC > 0) { + fprintf(stderr, "Unexpected lingering on close()\n"); + exit(EXIT_FAILURE); + } + + control_writeln("DONE"); } =20 static void test_stream_linger_server(const struct test_opts *opts) @@ -1820,7 +1844,7 @@ static void test_stream_linger_server(const struct te= st_opts *opts) exit(EXIT_FAILURE); } =20 - vsock_wait_remote_close(fd); + control_expectln("DONE"); close(fd); } =20 --=20 2.49.0