From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 832DF35677F for ; Tue, 12 May 2026 08:54:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778576090; cv=none; b=p/dtjeVjmcUXo8I5tmri2TRh72Hw/J4F6XZo0X1IW6yN2zjNxds+v1UQbIw6Pn0GqGNBlz3rQYWg0v4fGALqa+wq+DIAQyfHLJCRP/ha1kC4A4B/nlK0bzyTyqbyoRZaNRU/L5rrYeep2/AeEBrT+kXj0iPbV6Qp3gFOp1j9suU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778576090; c=relaxed/simple; bh=0qkr1rENvV+pyeBAMi1jVWzvQVzUp0uGCFQaBamt9gA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jM0iSP8eeel/Gqfz/ltr4sqamlv55apg+XNBvKhZAlLXZOuTyj/BfCm/Q4wHfRapaJ6k+xfewRlkwSTfDfRJn1xYTk2kw4ti/aX9oMbCxr/+kirBUw72VJFyQ/OBemDO0UFORYGa3W9d6Jqd5aRRJxReaiBTFjhuKtpJZONpBKE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=jVakvSMy; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=bg+Zx+RI; arc=none smtp.client-ip=170.10.133.124 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.b="jVakvSMy"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="bg+Zx+RI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778576081; 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=AIHT9Ne++vEWAmZTxjWDyan9tOz+k8p02hVxW6y8cts=; b=jVakvSMy1AhZF6UNF94QF6T4dgV/Daviy/OZbkl6vhoY0vrX9ZhFa7Vmk+NZUlLy/7CzNN DmKgnnLjK4UA+jk4dLJk8zAGkJbmzVCqPMOmoxDPZIniS9f9ks9Gx2ItYOAD1dUUBltfm/ Sldr3mpvLZIGFG7PcG+48jtxRZgOYZg= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-670-2ntFowYoOc-gN341Ht4R-w-1; Tue, 12 May 2026 04:54:39 -0400 X-MC-Unique: 2ntFowYoOc-gN341Ht4R-w-1 X-Mimecast-MFC-AGG-ID: 2ntFowYoOc-gN341Ht4R-w_1778576079 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-48a55de6fb0so36407475e9.3 for ; Tue, 12 May 2026 01:54:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778576078; x=1779180878; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=AIHT9Ne++vEWAmZTxjWDyan9tOz+k8p02hVxW6y8cts=; b=bg+Zx+RIWVRh7I/YGSd/26iZnRZEhEHXiRvTlID+SUfjBpSOmO8pYwqqp09uXCsY/W 6/VeQqwR3TurQUfKHAdF4TbF7jjTzmaCFNB9tiYxc3M+TO+XcKo1ixYMQ65NQs/7/19S fktWErdgtPZaX7gQpETN6K9romTF9G3GbGTo/JaPCs1v21Fk9NQ0Y+I9mgbxkdRUmnSI geUqB3JGoXk/s2qQ2ZptNuvuMBy/dNE5jFBCX0M7ymjrucGxX2qSiOvt5PXSWki9wf/L LtUgz60MDmMnZeeduBQfMNuusssz2as5xnq5zwCWEtrXbM9UUPaiyjfdFozR45Y0mR5d 5mDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778576078; x=1779180878; h=in-reply-to:content-disposition: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; bh=AIHT9Ne++vEWAmZTxjWDyan9tOz+k8p02hVxW6y8cts=; b=GM/Ss/lkQ4I3QUPovpn/nldIoOoardMloA/URyLrv7PbPENEU/OpRxXopj6qowscHg EFV+IAIMGD9EdmkYR2csIEU3EJ5yHJ/jJa/X1JORrHOSJHu+nyo6MAzRRmuuB7NxDIYe 8HyaxJpDtG21poaG2XigZO0vcVQ1Lo/Kapj9L/7lGi2EKgbMLCnUAyvIeCz6FFEh1Xrv adfMERHTj7lXxLi9HxXnlNghV6aTnrgvyxudwWvKGD58ChXioWYRby0xFqJ5JcweiKFj Wl+BdHAPNt90PA+rTWuhkdysFZFimuv1sol1yNEPpawmVdE+Vhmv+zWRDiH3G8TmkRMs wWuQ== X-Forwarded-Encrypted: i=1; AFNElJ8dzjtB8uExDro1xk+9aoVhUJyIq1cPG3OM0J/8CY3OqTylHSJ1FtmC85k9zWV0nVfVUSoqHLhuO70GHPE=@vger.kernel.org X-Gm-Message-State: AOJu0YxCdWe94vYdjpnpIjefIEVIj+YP6zgBplcoUmX0WrbYJSuWA88G xhXilf9Y89sf4vxIRyjIvr6Kn887kLjiSLs1YJ44tjvcmiLQemj7oIXw94sdmb3wpakvUvLuWgj JenK3ds/lWqk8rHhp/Lss6MuYRmTxBa+OEZv/gUouvP3ICNemV2HKYlBzs+gPmVIvuA== X-Gm-Gg: Acq92OFC7mf5QyQ+wtmDjQm2V9cmIBlkMCyGUwI1oFdFk514Lu9G5daARGLAdQS+zRA RTkN+GNPHlBVwSRksmJwue9ygPC3bn8Q/azZIlgkXG6rAq1F1Q57UHeJNoL7RTFaUoPxopaPdQu YUA7WolLorhqA/08+LoBl31b+OLQcYKdEiR1giSj9eKj0drem3XAGatGIa8WXoJ4qtV6gSDBTeq VQN6MfrWuYD11rFr/IDDcMRxBIkaGOHfni8iPivpc6pa7QwKM/OqjrV8HdTXa4Mup2+P6qe+sWG nuYylStqGITEVObRZ5KbYMD4yW6jvIHk8qVnvZ/HMgoLL2w84AYclwtQgKBVRWrs8A0wnCU8mOQ LjeqaYkVTYZiACl4x2V2Vg1OzU8/T/SCIPDtT/ue2 X-Received: by 2002:a05:600c:26c8:b0:48a:9562:7a30 with SMTP id 5b1f17b1804b1-48e51f4934cmr277143135e9.24.1778576078367; Tue, 12 May 2026 01:54:38 -0700 (PDT) X-Received: by 2002:a05:600c:26c8:b0:48a:9562:7a30 with SMTP id 5b1f17b1804b1-48e51f4934cmr277142775e9.24.1778576077739; Tue, 12 May 2026 01:54:37 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e8f410d9fsm17755735e9.6.2026.05.12.01.54.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 01:54:37 -0700 (PDT) Date: Tue, 12 May 2026 04:54:34 -0400 From: "Michael S. Tsirkin" To: Stefano Garzarella Cc: netdev@vger.kernel.org, Paolo Abeni , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , Eric Dumazet , "David S. Miller" , kvm@vger.kernel.org, Jason Wang , virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, Simon Horman , Jakub Kicinski , Stefan Hajnoczi Subject: Re: [PATCH net v2] vsock/virtio: fix skb overhead accounting to preserve full buf_alloc Message-ID: <20260512044008-mutt-send-email-mst@kernel.org> References: <20260512080737.36787-1-sgarzare@redhat.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20260512080737.36787-1-sgarzare@redhat.com> On Tue, May 12, 2026 at 10:07:37AM +0200, Stefano Garzarella wrote: > From: Stefano Garzarella > > After commit 059b7dbd20a6 ("vsock/virtio: fix potential unbounded skb > queue"), virtio_transport_inc_rx_pkt() subtracts per-skb overhead from > buf_alloc when checking whether a new packet fits. This reduces the > effective receive buffer below what the user configured via > SO_VM_SOCKETS_BUFFER_SIZE, causing legitimate data packets to be > silently dropped and applications that rely on the full buffer size > to deadlock. > > Also, the reduced space is not communicated to the remote peer, so > its credit calculation accounts more credit than the receiver will > actually accept, causing data loss (there is no retransmission). > > With this approach we currently have failures in > tools/testing/vsock/vsock_test.c. Test 18 sometimes fails, while > test 22 always fails in this way: > 18 - SOCK_STREAM MSG_ZEROCOPY...hash mismatch > > 22 - SOCK_STREAM virtio credit update + SO_RCVLOWAT...send failed: > Resource temporarily unavailable > > Fix this by using `buf_alloc * 2` as the total budget for payload plus > skb overhead in virtio_transport_inc_rx_pkt(), similar to how SO_RCVBUF > is doubled to reserve space for sk_buff metadata. This preserves the > full buf_alloc for payload under normal operation, while still bounding > the skb queue growth. > > When the total budget (buf_alloc * 2) is exceeded (e.g. under small-packet > flooding where overhead dominates), the connection is reset and local > socket error set to ENOBUFS, so both peers are explicitly notified of > the failure rather than silently losing data. > > With this patch, all tests in tools/testing/vsock/vsock_test.c are > now passing again. > > A solution to handle small-packet overhead efficiently also for > SEQPACKET (we already do that for STREAM) is planned as follow-up work. > This patch is needed in any case to prevent silent data loss, because > even if we reduce the overhead, we can't eliminate it entirely. > > Fixes: 059b7dbd20a6 ("vsock/virtio: fix potential unbounded skb queue") > Signed-off-by: Stefano Garzarella Thanks for the patch! I'd like to split this: 1. buf alloc boost 2. reset when out of credits this way we can revert 2 easier later. > --- > v2: > - Close the connection when we can no longer queue new packets instead > of losing data. > - No longer announce the reduced buf_alloc to avoid violating the > spec. [MST] > > v1: https://lore.kernel.org/netdev/20260508092330.69690-1-sgarzare@redhat.com/ > --- > net/vmw_vsock/virtio_transport_common.c | 24 ++++++++++++++++++------ > 1 file changed, 18 insertions(+), 6 deletions(-) > > diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c > index 9b8014516f4f..f23bf8a11319 100644 > --- a/net/vmw_vsock/virtio_transport_common.c > +++ b/net/vmw_vsock/virtio_transport_common.c > @@ -449,7 +449,10 @@ static bool virtio_transport_inc_rx_pkt(struct virtio_vsock_sock *vvs, > { > u64 skb_overhead = (skb_queue_len(&vvs->rx_queue) + 1) * SKB_TRUESIZE(0); > > - if (skb_overhead + vvs->buf_used + len > vvs->buf_alloc) > + /* Use buf_alloc * 2 as total budget (payload + overhead), similar to > + * how SO_RCVBUF is doubled to reserve space for sk_buff metadata. > + */ > + if (skb_overhead + vvs->buf_used + len > (u64)vvs->buf_alloc * 2) > return false; > > vvs->rx_bytes += len; > @@ -1365,7 +1368,7 @@ virtio_transport_recv_connecting(struct sock *sk, > return err; > } > > -static void > +static bool > virtio_transport_recv_enqueue(struct vsock_sock *vsk, > struct sk_buff *skb) > { > @@ -1380,10 +1383,8 @@ virtio_transport_recv_enqueue(struct vsock_sock *vsk, > spin_lock_bh(&vvs->rx_lock); > > can_enqueue = virtio_transport_inc_rx_pkt(vvs, len); > - if (!can_enqueue) { > - free_pkt = true; > + if (!can_enqueue) > goto out; > - } > > if (le32_to_cpu(hdr->flags) & VIRTIO_VSOCK_SEQ_EOM) > vvs->msg_count++; > @@ -1423,6 +1424,8 @@ virtio_transport_recv_enqueue(struct vsock_sock *vsk, > spin_unlock_bh(&vvs->rx_lock); > if (free_pkt) > kfree_skb(skb); > + > + return can_enqueue; > } > > static int > @@ -1435,7 +1438,16 @@ virtio_transport_recv_connected(struct sock *sk, > > switch (le16_to_cpu(hdr->op)) { > case VIRTIO_VSOCK_OP_RW: > - virtio_transport_recv_enqueue(vsk, skb); > + if (!virtio_transport_recv_enqueue(vsk, skb)) { > + /* There is no more space to queue the packet, so let's > + * close the connection; otherwise, we'll lose data. > + */ > + (void)virtio_transport_reset(vsk, skb); > + sk->sk_state = TCP_CLOSE; > + sk->sk_err = ENOBUFS; > + sk_error_report(sk); > + break; > + } > vsock_data_ready(sk); > return err; > case VIRTIO_VSOCK_OP_CREDIT_REQUEST: > -- > 2.54.0