🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #11425

[PATCH net 1/3] vhost/vsock: release the accounting of packets dropped on rx errors

#11425
From: Oleg Drokin
Date: Thu, 05 Nov 2026 00:01
87 lines
10178 bytes
When vhost_transport_do_send_pkt() fails to deliver a packet to the guest
(unexpected output buffers, a buffer smaller than the header, a fault
while copying the header or the payload) it frees the skb with
kfree_skb() and gives up. The success path does more:
virtio_transport_consume_skb_sent() subtracts the payload from the
socket's bytes_unsent (SIOCOUTQ), and for a reply the queued_replies
counter is decremented, restarting the guest's tx queue once it drops
below the ring size.

The error paths skip both. Every such drop leaves SIOCOUTQ too high for
the life of the socket, and every dropped reply permanently takes one
slot of the queued_replies budget, so that after a ring's worth of them
vhost stops processing the guest's tx queue for good.

Release both on the error paths, as the success path does.

Fixes: 433fc58e6bf2 ("VSOCK: Introduce vhost_vsock.ko")
Fixes: e6ab45005772 ("vsock/virtio: add SIOCOUTQ support for all virtio based transports")
Signed-off-by: Oleg Drokin <green@linuxhacker.ru>
---
 drivers/vhost/vsock.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index 88a310390eb0..b0004cb48999 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -104,6 +104,21 @@ static bool vhost_transport_has_remote_cid(struct vsock_sock *vsk, u32 cid)
 	return found;
 }
 
+/* Undo the send accounting of an undelivered skb; true if tx may restart. */
+static bool vhost_vsock_drop_skb(struct vhost_vsock *vsock, struct sk_buff *skb)
+{
+	bool restart_tx = false;
+
+	if (virtio_vsock_skb_reply(skb)) {
+		int val = atomic_dec_return(&vsock->queued_replies);
+
+		restart_tx = val + 1 == vsock->vqs[VSOCK_VQ_TX].num;
+	}
+	virtio_transport_consume_skb_sent(skb, false);
+	kfree_skb(skb);
+	return restart_tx;
+}
+
 static void
 vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
 			    struct vhost_virtqueue *vq)
@@ -162,14 +177,14 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
 		}
 
 		if (out) {
-			kfree_skb(skb);
+			restart_tx |= vhost_vsock_drop_skb(vsock, skb);
 			vq_err(vq, "Expected 0 output buffers, got %u\n", out);
 			break;
 		}
 
 		iov_len = iov_length(&vq->iov[out], in);
 		if (iov_len < sizeof(*hdr)) {
-			kfree_skb(skb);
+			restart_tx |= vhost_vsock_drop_skb(vsock, skb);
 			vq_err(vq, "Buffer len [%zu] too small\n", iov_len);
 			break;
 		}
@@ -212,7 +227,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
 
 		nbytes = copy_to_iter(hdr, sizeof(*hdr), &iov_iter);
 		if (nbytes != sizeof(*hdr)) {
-			kfree_skb(skb);
+			restart_tx |= vhost_vsock_drop_skb(vsock, skb);
 			vq_err(vq, "Faulted on copying pkt hdr\n");
 			break;
 		}
@@ -221,7 +236,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
 					   offset,
 					   &iov_iter,
 					   payload_len)) {
-			kfree_skb(skb);
+			restart_tx |= vhost_vsock_drop_skb(vsock, skb);
 			vq_err(vq, "Faulted on copying pkt buf\n");
 			break;
 		}
-- 
2.56.0
Technical Details
Message-ID: <20261105000141.3617241-2-green@linuxhacker.ru>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356997-linux-kernel-netdev=dewy.ru
References: <20261105000141.3617241-1-green@linuxhacker.ru>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356997-linux-kernel-netdev=dewy.ru
From: green@linuxhacker.ru (Oleg Drokin)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net 1/3] vhost/vsock: release the accounting of packets dropped on rx errors
Date: Wed,  4 Nov 2026 19:01:39 -0500
Organization: Usenet Network
Message-ID: <20261105000141.3617241-2-green@linuxhacker.ru>
References: <20261105000141.3617241-1-green@linuxhacker.ru>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3532439"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:vRbj5fSuXzGAf/LVwByXA+OR7Cw= sha256:Fsoy9BKyeie2pDXjAp86pwONNx8YI8Sy3AzoRAphvQg=
	sha1:7dulA2TDy04GJGov+0z8KUxyPrA= sha256:igtkycXzXGyJG509pnCACRt3QjLauyWHOUa3QjOvkD4=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 2548A112E3B; Thu,  5 Nov 2026 04:13:18 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.951
X-Spam-Status: No, score=-2.951 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id GHeY3wbcz_sx;
	Thu,  5 Nov 2026 04:13:14 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-356997-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linuxhacker.ru
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id F0714112E39; Thu,  5 Nov 2026 04:13:08 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 3DE781273B5; Thu,  5 Nov 2026 00:02:36 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail;
	t=1793836931;
	b=Cmm7mzrB88zH1ffCP0gnnXBGA2QdkNjCph5vgquI9quIFrslhNnAGINdXxq9HCIXltMf
	 GKGPPjol+qqHyneqI4X/kaTj+Icm7mrJF2qqTiYHHX08bZQXahBlMrCA8gxps5k+hjYLJ
	 lhr7qlHbl+7551ViETvNgKhckNUCq0m5cM7Tn3OC9D2PQ5tH3LETlC/t0YBamwcMhTDYy
	 TDLE26EIwtiylgmzdcpYR6jzAMQeGyUhJzvH54yczOSnxzwnLa1ovVLQRj4b28ayty/Ie
	 uSMMmQilEcI8lGI6JZ8+CA8jH6NOB9WHlFHrPOyjR/juw6cJH+LQzvxdaGggQDhSlmQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793836931;
	h=X-Original-To:Received:DMARC-Filter:Received:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Transfer-Encoding;
	bh=Ql92w/EiEUHh3ETzdYT66p95Yh+dSsK+3cUt8nG9sDg=;
	b=hS6J9w3W61kIcpdqR74C9uvNMbk+JpnEcktBVhX61dn17bi9RO+XsUdtxO+TFj9Y2PEm
	 us0XlPnXx//7c94rdTmO4zAaTVONqprr2G/mTW2TcE3t4eqJnKgfN2uIh12rsK7JelV7C
	 QMQ+TjUGQ4xwjaP1BIBJ+iD65xZXF3o1dwAFAVKFAFt+7XAtnzU2tymu3+uZy6lpbb0Dy
	 tnkxB+7gFDrcqDonSzSK4LQjTRt/i92hncdubhbkuGIxjG8GYQi+tl3pHoSJUFVMKybTw
	 7qPjWbCygwvDHXEGqVObJ192JiyBkj4HPD0gerRAtjOdg19v8lvMtLsTRIy22hoTwEQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dmarc=none header.from=linuxhacker.ru;
	spf=none smtp.mailfrom=linuxhacker.ru;
	arc=fail smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 8DA22606EE82;
	Thu,  5 Nov 2026 00:02:11 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=159.69.87.85
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793836930;
	b=MHQqJtDMoxar1nFY6JUikxoPJiIccxP1fQ5ItCkxavNIzlBVeXFGcMpcinibKn9jCHd9
	 nuESJjcgi6Wyn2wC2gCfIg1fi39I+7jtcrR8GzjsgT9cIOjD8DRieEumOmV8RXReap3fL
	 QXPuR8EihBTJW4od0McBqRVuVpfNtxdmudAF/5DfGskHvkVXS84bI14kSPRGXDXxNa/os
	 237p0ByIpIZskR/+3RyZeLYxgayXB0ffdBhBq7vg4+pj+Sd2/n7zJPSwiYAqI5F8V3rL3
	 eE/hBVAAWA32fYghqUrUCyijmip05YIemzxHuo6FYxWNab4KGcW6v4/o4TWAkJH0jfg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793836930;
	h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:
	 X-Spam-Status:X-Spam-Checker-Version;
	bh=Ql92w/EiEUHh3ETzdYT66p95Yh+dSsK+3cUt8nG9sDg=;
	b=GfgBMV9BT2aMau05YEI/z4flJosfCt0cMNcPae+1DZz+xIjFMn+30WYaRNLp5lq11mNO
	 Dhza0YlQPodtCYK6fwGeOmfiS4QAvroZIGjjKORKGdPWEpN6mNHcxmLssGf3AlD10zQjS
	 irM9jIB7ugy3n026ECfB/ZUm7zoxVzxwW95V3jD2hhq6lu5TpSVSNiACsm7++t0Ooohub
	 N9fS7GSzeBv5nZyoDMlB0Mwi1LmaH7QLqZmjTWj/gIv07dsyFnoaBI3Dhi3tUwV9NFlYL
	 N0GipdisulC/Mvl5Wn5Siw5YanrbVUQsI/Ll28vDW0dZ77h3EJia5E3VkXaII3X5ElQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=none header.from=linuxhacker.ru;
	spf=none smtp.mailfrom=linuxhacker.ru;
	arc=none smtp.remote-ip=159.69.87.85
X-Received: from eagle.linuxhacker.ru (linuxhacker.ru [159.69.87.85])
	(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 4A110606D829;
	Thu,  5 Nov 2026 00:02:10 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4A110606D829
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linuxhacker.ru
X-Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linuxhacker.ru
X-Received: from intelbox1.virtnet (unknown [162.81.204.199])
	by eagle.linuxhacker.ru (Postfix) with ESMTPSA id 09E13BEE67;
	Thu,  5 Nov 2026 00:02:00 +0000 (UTC)
X-Cc: jasowangio@gmail.com,
	eperezma@redhat.com,
	xuanzhuo@linux.alibaba.com,
	bobbyeshleman@meta.com,
	davem@davemloft.net,
	edumazet@kernel.org,
	kuba@kernel.org,
	pabeni@redhat.com,
	horms@kernel.org,
	netdev@vger.kernel.org,
	virtualization@lists.linux.dev,
	kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.56.0
X-In-Reply-To: <20261105000141.3617241-1-green@linuxhacker.ru>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list