From nobody Mon Feb 9 03:17:06 2026 Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [185.226.149.38]) (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 514B16AD3; Wed, 30 Apr 2025 09:11:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.38 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746004291; cv=none; b=Vov3BXCiu7o1E04POK9MxzbFS2LBdTeUc04AQgN9blNf8GuNi9hbrg4uA3yM4u6pOvzVnf0qsMNSxFQ61v7/lnyGSDoepjSNxkjwdhXCea40IyPL5Sk6xcF/3+Fq4lRMc7FrS7dU4SeFPrAJgfTgbRWQ1mmj+9KsW039sS+mZZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746004291; c=relaxed/simple; bh=h2owf59eEgI833PcMlqHoA2GqBM6oQTPhXWSLBaut3I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fe+a0C5u1gEZQEySBqgoW+BBmJXSvVb59rFsyT9pEPJRbsEk5syqJi1Da8QGdGPzSzNRF4SNdB9w/VTVgqd9arC6cougmu3/lMFynCJ1LKGsnTNrIJhFXsVXOVjz6+aiDbvMQzqSgKIVtl1IReknrJoOIVwDmj6qijfels5/Pz8= 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=Uk8aiSiB; arc=none smtp.client-ip=185.226.149.38 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="Uk8aiSiB" Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1uA3TK-008ki9-7W; Wed, 30 Apr 2025 11:11:18 +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=DW7ucJ6dWqPm7JmubDw+SOLAZx/FUUKm5KizEO3YhQI=; b=Uk8aiSiBm+f3k9AQ4xtNgCv4Mx ApF/yvsofovWSB0LCwrJA4agLjugAVEAktvaxtiJg6EfiVstKmDGNJPGq1s8kdJaR8Wl4ih3dPcEo vOciNguLZrw/iak09HUNDIA85MUVXSgxZ4l+JenIPeky3B2lUR5Oq5a2nDBlsaRtQ+30JVyHgmqIh uISmJl0W1KDmTBxNDrCAjfYG5J1779JuHxF2dPU2m75sx2IAAG6aX0QRvRaP+EwhmNZxf5LbYSBGM JakA+JbzGslwA4sUWHOGfcD10ggV6IEy33OtHBDgXtAsqnimoe/x0yrvC/nEfGJ/4SHSOyr7NV31A hlVSkHYQ==; Received: from [10.9.9.72] (helo=submission01.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1uA3TJ-00050f-5s; Wed, 30 Apr 2025 11:11:17 +0200 Received: by submission01.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1uA3TG-00CDEV-Of; Wed, 30 Apr 2025 11:11:14 +0200 From: Michal Luczaj Date: Wed, 30 Apr 2025 11:10:27 +0200 Subject: [PATCH net-next v3 1/4] 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: <20250430-vsock-linger-v3-1-ddbe73b53457@rbox.co> References: <20250430-vsock-linger-v3-0-ddbe73b53457@rbox.co> In-Reply-To: <20250430-vsock-linger-v3-0-ddbe73b53457@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 --- net/vmw_vsock/virtio_transport_common.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio= _transport_common.c index 7f7de6d8809655fe522749fbbc9025df71f071bd..49c6617b467195ba385cc3db86c= aa4321b422d7a 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -1196,12 +1196,16 @@ static void virtio_transport_wait_close(struct sock= *sk, long timeout) { if (timeout) { DEFINE_WAIT_FUNC(wait, woken_wake_function); + ssize_t (*unsent)(struct vsock_sock *vsk); + struct vsock_sock *vsk =3D vsock_sk(sk); + + unsent =3D vsk->transport->unsent_bytes; =20 add_wait_queue(sk_sleep(sk), &wait); =20 do { - if (sk_wait_event(sk, &timeout, - sock_flag(sk, SOCK_DONE), &wait)) + if (sk_wait_event(sk, &timeout, unsent(vsk) =3D=3D 0, + &wait)) break; } while (!signal_pending(current) && timeout); =20 --=20 2.49.0 From nobody Mon Feb 9 03:17:06 2026 Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [185.226.149.38]) (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 9A00721B9DB for ; Wed, 30 Apr 2025 09:11:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.38 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746004291; cv=none; b=DD/h9JNLNuAYuaU3wyMrcbmDgBP8G+WRcu80wxQrykPKU4jPf68puy5EnVPhQuGYjoEKT/uUdXGkYCfAHs2NH8ep5qRPFQpsS2QUy78JJDjUWx34AgJJV2bYNqror12T9jhfdwYCW1V5A72bBvK1CAFqiY6Luto9mTs4r6boNLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746004291; c=relaxed/simple; bh=QOwQWEPmSdsZ1l9v4+trXRCmhOBbQz5fJN9ec4tju+o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M63ub2ZJL2pnXgmuvAq4wn+Hn8HEsW3nJvY0wlWDqzg8PFK2B0FzsC1p+DAq69CokUdHR452iBfRW0yPsuVcifZjK0KvzLtwW+V7J/plfBzXWTwC8DOk0duMzCOOFu87e6s5W3RcDfMtpGbDnv/G1mkiY8TCW7iURxCJVZrcpB8= 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=TWoSFyl9; arc=none smtp.client-ip=185.226.149.38 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="TWoSFyl9" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1uA3TN-008kiS-NS; Wed, 30 Apr 2025 11:11:21 +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=+AFO0qPjos/NBG+JIX67V5Put3nuZOLxt4o4r9L7j7Q=; b=TWoSFyl9JCvkFqqVgMifYk2NCN V2SKHzuEZFd5KrOEnxRbTKosBvU+O2HzL+ctgTvj/4JEOo6zqIa1ueNucO4V2a6bAebkSWPqFYjT4 1Y2H58Sts+tYlWgw+aPCHTQtrKXGpj3r0yKCWENpXe70M3vstPALmUdtZ+xDkEPIXj//VC6B9iKRX Toku4ZPOeWDJk+K1h4HVvq4b9nKVq5xccuuGUPJWihDTZFlzyxrhmLlg/oKopkBaNAfgxb3OtRFAj Q6nTfuPguJBhb9yb76hyCZp4RlP1sEKbd7qncKJLDkS9/rESuTdtopRrS9X9xODpWNuRiScuBRaAL Ceujdtyw==; Received: from [10.9.9.72] (helo=submission01.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1uA3TN-0006Ay-Bx; Wed, 30 Apr 2025 11:11:21 +0200 Received: by submission01.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1uA3TH-00CDEV-HR; Wed, 30 Apr 2025 11:11:15 +0200 From: Michal Luczaj Date: Wed, 30 Apr 2025 11:10:28 +0200 Subject: [PATCH net-next v3 2/4] vsock/virtio: Reduce indentation in virtio_transport_wait_close() 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: <20250430-vsock-linger-v3-2-ddbe73b53457@rbox.co> References: <20250430-vsock-linger-v3-0-ddbe73b53457@rbox.co> In-Reply-To: <20250430-vsock-linger-v3-0-ddbe73b53457@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 Flatten the function. Remove the nested block by inverting the condition: return early on !timeout. No functional change intended. Suggested-by: Stefano Garzarella Signed-off-by: Michal Luczaj --- net/vmw_vsock/virtio_transport_common.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio= _transport_common.c index 49c6617b467195ba385cc3db86caa4321b422d7a..4425802c5d718f65aaea425ea35= 886ad64e2fe6e 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -1194,23 +1194,23 @@ static void virtio_transport_remove_sock(struct vso= ck_sock *vsk) =20 static void virtio_transport_wait_close(struct sock *sk, long timeout) { - if (timeout) { - DEFINE_WAIT_FUNC(wait, woken_wake_function); - ssize_t (*unsent)(struct vsock_sock *vsk); - struct vsock_sock *vsk =3D vsock_sk(sk); + DEFINE_WAIT_FUNC(wait, woken_wake_function); + ssize_t (*unsent)(struct vsock_sock *vsk); + struct vsock_sock *vsk =3D vsock_sk(sk); =20 - unsent =3D vsk->transport->unsent_bytes; + if (!timeout) + return; =20 - add_wait_queue(sk_sleep(sk), &wait); + unsent =3D vsk->transport->unsent_bytes; =20 - do { - if (sk_wait_event(sk, &timeout, unsent(vsk) =3D=3D 0, - &wait)) - break; - } while (!signal_pending(current) && timeout); + add_wait_queue(sk_sleep(sk), &wait); =20 - remove_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); } =20 static void virtio_transport_cancel_close_work(struct vsock_sock *vsk, --=20 2.49.0 From nobody Mon Feb 9 03:17:06 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 B4EF121ADAB; Wed, 30 Apr 2025 09:11:27 +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=1746004291; cv=none; b=iotAAYkmBglMVW82t8zVTZjDIv3v2n0VMUiCQlMZH8PBDPbIL3+YJ29O3mtl5UlFkc3anSKhn7uElVorgyqw0kobvw+u7d1KrKD3oUz57l+F2ezGwaPmRX+sM80BexJMPU0DKswJjLgkLYQGRT/+hDZH2PuH6XygZ2fW8W/VKF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746004291; c=relaxed/simple; bh=B6PUeUS9nTSTlha5n91p/+cQVOJulOurJQNUX1pTWL8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HSrGslVxr/gO6FtmguMEmqEGnPSJZie8tcS9evQ//23wNbfehOLnm72YvgcIlyBe7LInRmbpkiugaUL8jBWvSfKO/uXt+qNOVV88WPSPEXuVu54n7TheX7wnYXrAr/o99QNtzYpTHVo9Kw7loe/MnHHAIZG2rRiwe1cr01B3tAs= 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=ffRb+s5H; 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="ffRb+s5H" 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 1uA3TM-006EEa-3L; Wed, 30 Apr 2025 11:11:20 +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=06COR0tHUw7dwx3cleQDSPa8f7BJblvvOI8tjwdPeEs=; b=ffRb+s5HpGDOPdiZFy+1cNQJsg 720p7GEtohFdCIqTKb+Xci0dCuflIRFQAPczM9Fy2eRltBfmNboHS7UCZhL9KInT2IevMTfkW2io+ EH9M2tYJ1VbURZm8FXdyychvFe70jG6c0wlJrdZZK4ENbZbT/lS3vPHsYgeLgU/h+UtU79hfvpoRh /12wtHiDNv9f9Aq4QKbxpKTm0xfvSvS/jrS97IE86BtWpXyB5mHGJE7tAt9+pNVJWB2szKNKBVwiB K/2FuejfDtRKo4jGliVMxpvIXRmvUDNklz1sFM3ASXHQzpFonLmNvbdbJMy0ljBdthGS0Zxjfyvmp iFNnpGEw==; Received: from [10.9.9.72] (helo=submission01.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1uA3TL-0006As-Or; Wed, 30 Apr 2025 11:11:19 +0200 Received: by submission01.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1uA3TI-00CDEV-A1; Wed, 30 Apr 2025 11:11:16 +0200 From: Michal Luczaj Date: Wed, 30 Apr 2025 11:10:29 +0200 Subject: [PATCH net-next v3 3/4] 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: <20250430-vsock-linger-v3-3-ddbe73b53457@rbox.co> References: <20250430-vsock-linger-v3-0-ddbe73b53457@rbox.co> In-Reply-To: <20250430-vsock-linger-v3-0-ddbe73b53457@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. Guard against an unimplemented vsock_transport::unsent_bytes() callback. Suggested-by: Stefano Garzarella Signed-off-by: Michal Luczaj --- include/net/af_vsock.h | 1 + net/vmw_vsock/af_vsock.c | 25 +++++++++++++++++++++++++ net/vmw_vsock/virtio_transport_common.c | 23 +---------------------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h index 9e85424c834353d016a527070dd62e15ff3bfce1..bd8b88d70423051dd05fc445fe3= 7971af631ba03 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, long timeout); =20 /**** TAP ****/ =20 diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index fc6afbc8d6806a4d98c66abc3af4bd139c583b08..946b37de679a0e68b84cd982a3a= f2a959c60ee57 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1013,6 +1013,31 @@ static int vsock_getname(struct socket *sock, return err; } =20 +void vsock_linger(struct sock *sk, long timeout) +{ + DEFINE_WAIT_FUNC(wait, woken_wake_function); + ssize_t (*unsent)(struct vsock_sock *vsk); + struct vsock_sock *vsk =3D vsock_sk(sk); + + 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 4425802c5d718f65aaea425ea35886ad64e2fe6e..9230b8358ef2ac1f6e72a5961ba= e39f9093c8884 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -1192,27 +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) -{ - DEFINE_WAIT_FUNC(wait, woken_wake_function); - ssize_t (*unsent)(struct vsock_sock *vsk); - struct vsock_sock *vsk =3D vsock_sk(sk); - - if (!timeout) - return; - - unsent =3D vsk->transport->unsent_bytes; - - 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); -} - static void virtio_transport_cancel_close_work(struct vsock_sock *vsk, bool cancel_timeout) { @@ -1283,7 +1262,7 @@ static bool virtio_transport_close(struct vsock_sock = *vsk) (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); + vsock_linger(sk, sk->sk_lingertime); =20 if (sock_flag(sk, SOCK_DONE)) { return true; --=20 2.49.0 From nobody Mon Feb 9 03:17:06 2026 Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [185.226.149.38]) (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 C1A222206B1; Wed, 30 Apr 2025 09:11:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.38 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746004293; cv=none; b=rYHTaC6USqOnGTlP//7o0Zc99HOAKeph3AOOdPAMEeQsmi4um7pOumy0UebMPEwq8zvfjzGimKC2FRonxxHR+8v0ePIULFPsKI+mx3UhHDFtI8bqQpei+wyeYSsy/ODKG28CDRFF2WYhj/JM/a9G98k8ljh10Ha/WW66CdvOk5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746004293; c=relaxed/simple; bh=bU72gZf0Mlr4a1DTEu4p6xddG7QuL34UyWY76ya9fjA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Y7amN1DM8enpElR9Gi21r/frfzZy0Su95lY5GCrBPOb0vEWopNh5KHsvMr4W1+e/kLm6d+Gop1vrVcBRaNfCmPkiMgUi+4wqVRzU9w0ZRw9wuUvq0Rab//ZsnnfkpYdJcBMU6CGT0rlxMLwNJbDHKeoGdDa8RgNlT/LJ+51raSk= 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=Od62oz2g; arc=none smtp.client-ip=185.226.149.38 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="Od62oz2g" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1uA3TK-008kiE-Rw; Wed, 30 Apr 2025 11:11:18 +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=Od62oz2g3gZ2EUHjTYw5tBPwoZ CDxRntznQChxQcpTAJUZvMuRlnTk10YchPg4Cl8TKpSoahDFBxzQeDxX2p+hEHaXQsvf+RPBHFskK 4NsrgRErZqA4aFhqmRSb0G6yhloq4oMNdyIgSR9Y9kel1bbhOQHju1kHxHfh4k1wuVcg5F92ue0rP uSthcxhEycxXcaWdgrgOSkOx34/kd83sX0IBtYQ1aZtBhgf+MHLsjibTc+Gsb/JHtTUBbRQlsO8Rr mAaYwtfHBm6/Yy8PYWg9Xl8wthV5KMzqhozBkd3lCA35BEBBZdvibDsrpFCeYmlCyDTpV0LKP9RCk f4m0FsSQ==; Received: from [10.9.9.72] (helo=submission01.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1uA3TK-0006Am-Ch; Wed, 30 Apr 2025 11:11:18 +0200 Received: by submission01.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1uA3TJ-00CDEV-3C; Wed, 30 Apr 2025 11:11:17 +0200 From: Michal Luczaj Date: Wed, 30 Apr 2025 11:10:30 +0200 Subject: [PATCH net-next v3 4/4] 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: <20250430-vsock-linger-v3-4-ddbe73b53457@rbox.co> References: <20250430-vsock-linger-v3-0-ddbe73b53457@rbox.co> In-Reply-To: <20250430-vsock-linger-v3-0-ddbe73b53457@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