From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796315008; b=4oK0w3nZR+7ThbUXvmOXoMurNn/a3PMeFWByG9zPEgAXBOJfLf9TjNt5o1f9P/v9qcGE qohX3YzRtMuToZDrStuFRL9kybQYYYSGTDqxvkbJYp2v5wW5PCghUM2qk+NayARGXZsap hmS1jsmhM10Xu3wtE0G486ZbWE3jEEeSsx4t5fc2X1a/6nktECMPJb/UAXvPvVaCQQu4M m/wfPdImKJx9NmnteQoBFIGKr4HaNaPky6AjqRA8mffkS5BC5YbSbD6kQXwi1HE6nICSb Q1nJubc/hLdspHg1MbcVuUMNDD292sPQpt8ObbdG26j82rYgJ3FwPlx9J/xZXZDI10g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796315008; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=Oou/owd7m1SjBJw+/+oRZaUkDqapAa40gQo/meZ7QYw=; b=dvO9ehgRbqRvEdu4r36ofHO8ypSBlRBzpwcTEFcakC/GWvzlJtSsi5iuGXGO6ws77Av9 GeE2nHYtWHK1h1W6Abh1zl96sviIUefe964PQMtsa/b7H/shlf8u52Am0aVC5VhQT5P3n v8eVDllwavE0vSfGcm8jaTcEyWcQbHrDe0UQtXFca5eS+1P5fEvH/07PNlT6UaIQ+7NRl 9gMiSs6ACCpoMETul3I8MjJrYTWtCJxWuudwuiTSref65IjViA+WKmwxXQw33PzC+UuTv +wRWknDC8xYWvufNKappEeLYjyWu30Jk7LR/xn63gf9NKWPSgb5qtf1pJcrwB2i7XWw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=oUEDrGzw; arc=none smtp.remote-ip=209.85.214.169 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67266606A32F for ; Thu, 3 Dec 2026 16:23:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 67266606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=oUEDrGzw Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2e9ae391a05so9009425ad.1 for ; Thu, 03 Dec 2026 08:23:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796315007; x=1796919807; 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=Oou/owd7m1SjBJw+/+oRZaUkDqapAa40gQo/meZ7QYw=; b=oUEDrGzwJGS9F4iXCG7ydmITQzCg3tWw5obm40gcQgjYrqjNE0ADiyQ4wHuB2aIeHp JFV2MLLBjoi2u8J7bev3lmnDgiP1tFYgQgfkCAwMMD48e/W8ueGASNi29S7n1uqGS3Qn uRfm00LM+mo40J2qGhvOd7Kux8Gb483lIq9Vaa8u+39mq75XN/gJV13dWUXkP+f7kHpK QxR+P7yfx9zQnKRe+rl/XpblrGOBCEQ7qTAOoULwnXpIdtEzF5/i4Rt7XRC/TSEf4mtB dDD6dzDd/PTOYz5RiJDwgQRXNDMD1W+uMSN7TI6nzCBWokOk48FHmDilhla9pN34bwim Xyew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796315007; x=1796919807; 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=Oou/owd7m1SjBJw+/+oRZaUkDqapAa40gQo/meZ7QYw=; b=Ir1LMiIy85yao3au7gYvi17huHpfIEYIfNVsQBeaSqp0RwMoZVXv8WQzhlIHWgT5dp yrCM2t64z8vkXiw+3DvSopwDEuysSKVIJxv4WUFneORx4CTwyXGs4mVOh3t78SO6+u+S quAkANXWRozETS2lN5IQIYue7Sej+FPao6WUKoqTFHVPYDjZULYdG5oZkALxixtFt3k1 Xl3hZdOIdiQhEjDn+qlI0WN+PIHtVpZgqmIt8H1c94b/VV0OBLkYbzPQZVrGQGFt+ET9 Dqc3MyueGjoXQoq8QRiBgI2Rt1R3JWa5cbGto6horDVO9HopSizJZTq7F66BRydtHCck c4qg== X-Forwarded-Encrypted: i=1; AL+hErFKjwJY9Mfs/UxUI5fMyW9U6lLLm8S9xrGSs+vHObosfRcK6GW895VjLUkvOF42V9bzzZqLPxQxlHVwfYE=@vger.kernel.org X-Gm-Message-State: APuU4Z+vi/RX4fMUZ8Lx+1WhukkZNB8l8JHhlVb0KIUplOeLssCZi2Tt lnhnPYZ9ZVBMlsBj7JSQZxcdvLKDqF4BwXTUU6VMnOV4WsPuBdiV1OVl X-Gm-Gg: AZFdTZcsKYZekbjZGD0/OYAyJlVWjVL2Ov1GqFfae4DZgCUgdEY1oGwqgNvtUsH5oKv HOHlKESpuYhNiewYtNh5k5do17EOYT3dqS+2JOigaB9+M/xOZl8RV592StuUTMGRXIw9xZ9bLd6 9BM74Yuvby7WCPnfom3Sdw4bW8nEIzEvvmFWHMA7imS3C4eAUxy3EOD1AEQNIqBWgoRONHvNRwt AGHPfO4O+uOyrCR1cNRScN0ZM9kJknL1OtZNZPvhZIVqwC5Qru2xwR0PXSSt6WrHOXLHcEqeDGG UlQHrYL1H++7hyXvZn7nwoZHELXCEW6N1h3lJxr9pG7W7i77OWXZWJCm5Nvjg+j4+qKEXrGDtGH FHS4/f3rx8qzg/MaSIm11Aviml4AIOJiBHbqzwasT3kJU3gC9HB4A8mFLPTqsRtjyqsFV42GJ8L oZDcJTHNBKCHAZ4gdW4TBk0i1ylhsDaXmypZvqEwY5Ff8JqZYZ9YM5VVaHLVyb/Ln7Yg1OgYCG3 r9uiQpXigEEm+HpjmH3ziKrjQ6ZH2gCaVwWyycfVchjMWi+3Rs3lxvTA5DQD6XYJmDZj4CqGj9J Af+UyIdDhLjOhfDgbFllqTSL X-Received: by 2002:a17:903:144e:b0:2f1:91d5:dcd3 with SMTP id d9443c01a7336-2f19719693fmr19349315ad.35.1796315006401; Thu, 03 Dec 2026 08:23:26 -0800 (PST) Received: from localhost ([2a03:2880:ff:70::]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f1253c6288sm98843195ad.70.2026.12.03.08.23.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 08:23:25 -0800 (PST) Date: Thu, 3 Dec 2026 08:23:25 -0800 From: Bobby Eshleman To: Jia Jia Cc: Stefano Garzarella , "Michael S . Tsirkin" , Jason Wang , Eugenio =?iso-8859-1?Q?P=E9rez?= , Xuan Zhuo , Stefan Hajnoczi , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , virtualization@lists.linux.dev, kvm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: Re: [PATCH net-next v6 2/2] vsock/virtio: amortize RX socket locking for stream packets Message-ID: References: <20261127062700.29387-1-physicalmtea@gmail.com> <20261127062700.29387-3-physicalmtea@gmail.com> X-Mailing-List: linux-kernel@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: On Thu, Dec 03, 2026 at 11:30:40AM +0800, Jia Jia wrote: > > > > On Fri, Nov 27, 2026 at 06:27:00AM +0000, Jia Jia wrote: > > >The virtio-vsock RX worker looks up a socket and takes its lock for every > > >packet. Retain the connected lookup reference and socket lock across a > > >bounded run of STREAM/RW packets for one established native socket. > > > > > >Reuse the locked socket while packets match the same flow. Finish the > > >batch on a malformed packet, flow change, non-RW traffic, or a change to > > >the socket state, transport, protocol, sockmap state, or receive buffer > > >limits. A connected lookup miss falls back to the existing receive path, > > >which can still find a bound socket. > > > > > >Limit an uninterrupted socket-lock ownership interval to 64 packets and > > >64 KiB of payload. The payload limit is one > > >VIRTIO_VSOCK_MAX_PKT_BUF_SIZE. Small or zero-length packets still incur > > >per-packet work, so an independent packet limit is needed. The 64-packet > > >limit uses VHOST_NET_BATCH as a reference; it is a policy choice rather > > >than a protocol limit. > > > > > >Beyond these limits, a larger batch would only further amortize socket > > >lookup and lock/unlock operations, while virtqueue work, validation, > > >tracing, skb ownership, credit update, and queueing remain per-packet. I > > >therefore expect diminishing returns while the uninterrupted socket-lock > > >interval continues to grow, but I have not measured larger limits yet. > > > > > >Only the guest virtio RX worker is changed. The benchmark exercises the > > >host-sender-to-guest-receiver direction, where this worker is on the > > >receive path. I have not measured the corresponding worker and socket-lock > > >overhead in vhost-vsock or vsock_loopback, and they use different worker > > >and locking models. Leave those paths unchanged pending separate policy > > >and validation. I plan to evaluate vhost-vsock separately as follow-up > > >work. > > > > > >Performance: > > > > > >These results cover both patches in this series. > > > > > >Tested on a single-stream vsock connection (one Guest receiver thread on > > >CPU0, virtio-vsock IRQ on Guest CPU1, fresh QEMU Guest per state, with 16 > > >accepted, balanced AB/BA pairs per payload). The host uses vhost-vsock. > > > > > >For throughput, vsock_perf runs on the host as the > > >sender, with a custom single-threaded Guest receiver pinned to Guest CPU0 > > >using blocking recv(). The table uses a 64K buffer. The virtio-vsock > > >IRQ/RX worker is pinned to Guest CPU1. To normalize run times across > > >payloads into a bounded, deterministic window and avoid long runs being > > >skewed by host background noise or virtualization scheduling jitter, > > >transfer sizes scale proportionally with the request size (64B/64M, > > >256B/256M, etc.), capped at 2G for 4K-64K. The custom receiver keeps the > > >recv() size and count explicit; vsock_perf's receiver uses poll()+read(). > > > > > >End-to-end RX throughput > > >(64K Guest recv() size, SO_RCVLOWAT=1; Gbit/s): > > > > > > payload baseline RX series RX throughput change (95% CI) > > > (Gbit/s) (Gbit/s) > > > 64B 0.1212 0.2555 +110.81% [+106.99%, +114.70%] > > > 256B 0.5551 1.0212 +83.95% [+79.94%, +88.06%] > > > 512B 1.0568 1.8761 +77.53% [+73.02%, +82.15%] > > > 1K 1.9260 3.1453 +63.31% [+58.58%, +68.17%] > > > 4K 3.5175 6.3239 +79.78% [+72.79%, +87.06%] > > > 8K 4.1183 5.6867 +38.08% [+31.06%, +45.48%] > > > 16K 5.0155 6.8346 +36.27% [+31.12%, +41.62%] > > > 64K 5.0541 5.8403 +15.56% [+11.12%, +20.17%] > > > > > >Fixed-syscall stress test > > >(receiver recv() size = sender write size; Gbit/s): > > > > > > payload baseline RX series RX throughput change (95% CI) > > > (Gbit/s) (Gbit/s) > > > 64B 0.1435 0.2750 +91.60% [+82.19%, +101.50%] > > > recv() calls (baseline/series): 1048577/1048577 > > > 256B 0.4218 0.9659 +129.00% [+110.65%, +148.95%] > > > recv() calls (baseline/series): 1048577/1048577 > > > 512B 0.8062 1.6979 +110.60% [+94.49%, +128.04%] > > > recv() calls (baseline/series): 1048577/1048577 > > > 1K 1.5116 2.9585 +95.72% [+85.22%, +106.82%] > > > recv() calls (baseline/series): 1048577/1048577 > > > 4K 2.9234 6.3365 +116.75% [+110.78%, +122.89%] > > > recv() calls (baseline/series): 538537/525565 > > > 8K 4.0430 7.1193 +76.09% [+69.04%, +83.44%] > > > recv() calls (baseline/series): 276901/264412 > > > 16K 4.9182 7.7688 +57.96% [+54.40%, +61.60%] > > > recv() calls (baseline/series): 147674/132088 > > > 64K 5.6683 7.1636 +26.38% [+20.49%, +32.56%] > > > recv() calls (baseline/series): 50615/33343 > > > > > >Signed-off-by: Jia Jia > > >--- > > > include/linux/virtio_vsock.h | 23 ++ > > > .../events/vsock_virtio_transport_common.h | 40 +-- > > > net/vmw_vsock/virtio_transport.c | 7 +- > > > net/vmw_vsock/virtio_transport_common.c | 268 +++++++++++++++++- > > > 4 files changed, 297 insertions(+), 41 deletions(-) > > > > > >diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h > > >index f91704731057e..748633aa0cc81 100644 > > >--- a/include/linux/virtio_vsock.h > > >+++ b/include/linux/virtio_vsock.h > > >@@ -282,6 +282,29 @@ void virtio_transport_destruct(struct vsock_sock *vsk); > > > > > > void virtio_transport_recv_pkt(struct virtio_transport *t, > > > struct sk_buff *skb, struct net *net); > > >+ > > >+/* > > >+ * Initialize a batch to zero before use. A non-empty batch owns @sk's socket > > >+ * lock and the reference returned by vsock_find_connected_socket_net(). The > > >+ * caller retains both until it calls virtio_transport_rx_batch_finish(). An > > >+ * empty batch owns neither. > > >+ */ > > >+struct virtio_transport_rx_batch { > > >+ struct sock *sk; > > >+ unsigned int pkts; > > >+ size_t bytes; > > >+}; > > >+ > > >+static inline bool > > >+virtio_transport_rx_batch_empty(const struct virtio_transport_rx_batch *batch) > > >+{ > > >+ return !batch->sk; > > >+} > > >+ > > >+void virtio_transport_recv_pkt_batch(struct virtio_transport *t, > > >+ struct sk_buff *skb, struct net *net, > > >+ struct virtio_transport_rx_batch *batch); > > >+void virtio_transport_rx_batch_finish(struct virtio_transport_rx_batch *batch); > > > void virtio_transport_inc_tx_pkt(struct virtio_vsock_sock *vvs, struct sk_buff *skb); > > > u32 virtio_transport_get_credit(struct virtio_vsock_sock *vvs, u32 wanted); > > > void virtio_transport_put_credit(struct virtio_vsock_sock *vvs, u32 credit); > > >diff --git a/include/trace/events/vsock_virtio_transport_common.h b/include/trace/events/vsock_virtio_transport_common.h > > >index f1ebe36787c3d..53a4c9ec47dae 100644 > > >--- a/include/trace/events/vsock_virtio_transport_common.h > > >+++ b/include/trace/events/vsock_virtio_transport_common.h > > >@@ -88,24 +88,12 @@ TRACE_EVENT(virtio_transport_alloc_pkt, > > > > > > TRACE_EVENT(virtio_transport_recv_pkt, > > > TP_PROTO( > > >- __u32 src_cid, __u32 src_port, > > >- __u32 dst_cid, __u32 dst_port, > > >- __u32 len, > > >- __u16 type, > > >- __u16 op, > > >- __u32 flags, > > >- __u32 buf_alloc, > > >- __u32 fwd_cnt > > >+ const struct virtio_vsock_hdr *hdr, > > >+ const struct sockaddr_vm *src, > > >+ const struct sockaddr_vm *dst > > > ), > > > TP_ARGS( > > >- src_cid, src_port, > > >- dst_cid, dst_port, > > >- len, > > >- type, > > >- op, > > >- flags, > > >- buf_alloc, > > >- fwd_cnt > > >+ hdr, src, dst > > > ), > > > TP_STRUCT__entry( > > > __field(__u32, src_cid) > > >@@ -120,16 +108,16 @@ TRACE_EVENT(virtio_transport_recv_pkt, > > > __field(__u32, fwd_cnt) > > > ), > > > TP_fast_assign( > > >- __entry->src_cid = src_cid; > > >- __entry->src_port = src_port; > > >- __entry->dst_cid = dst_cid; > > >- __entry->dst_port = dst_port; > > >- __entry->len = len; > > >- __entry->type = type; > > >- __entry->op = op; > > >- __entry->flags = flags; > > >- __entry->buf_alloc = buf_alloc; > > >- __entry->fwd_cnt = fwd_cnt; > > >+ __entry->src_cid = src->svm_cid; > > >+ __entry->src_port = src->svm_port; > > >+ __entry->dst_cid = dst->svm_cid; > > >+ __entry->dst_port = dst->svm_port; > > >+ __entry->len = le32_to_cpu(hdr->len); > > >+ __entry->type = le16_to_cpu(hdr->type); > > >+ __entry->op = le16_to_cpu(hdr->op); > > >+ __entry->flags = le32_to_cpu(hdr->flags); > > >+ __entry->buf_alloc = le32_to_cpu(hdr->buf_alloc); > > >+ __entry->fwd_cnt = le32_to_cpu(hdr->fwd_cnt); > > > ), > > > TP_printk("%u:%u -> %u:%u len=%u type=%s op=%s flags=%#x " > > > "buf_alloc=%u fwd_cnt=%u", > > >diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c > > >index 4f9aa9c4c3aa5..9af85712bd387 100644 > > >--- a/net/vmw_vsock/virtio_transport.c > > >+++ b/net/vmw_vsock/virtio_transport.c > > >@@ -633,6 +633,7 @@ static void virtio_transport_rx_work(struct work_struct *work) > > > { > > > struct virtio_vsock *vsock = > > > container_of(work, struct virtio_vsock, rx_work); > > >+ struct virtio_transport_rx_batch batch = {}; > > > struct virtqueue *vq; > > > > > > mutex_lock(&vsock->rx_lock); > > >@@ -666,6 +667,7 @@ static void virtio_transport_rx_work(struct work_struct *work) > > > /* Drop short/long packets */ > > > if (unlikely(len < sizeof(*hdr) || > > > len > virtio_vsock_skb_len(skb))) { > > >+ virtio_transport_rx_batch_finish(&batch); > > > kfree_skb(skb); > > > continue; > > > } > > >@@ -673,6 +675,7 @@ static void virtio_transport_rx_work(struct work_struct *work) > > > hdr = virtio_vsock_hdr(skb); > > > payload_len = le32_to_cpu(hdr->len); > > > if (unlikely(payload_len > len - sizeof(*hdr))) { > > >+ virtio_transport_rx_batch_finish(&batch); > > > kfree_skb(skb); > > > continue; > > > } > > >@@ -685,11 +688,13 @@ static void virtio_transport_rx_work(struct work_struct *work) > > > /* Force virtio-transport into global mode since it > > > * does not yet support local-mode namespacing. > > > */ > > >- virtio_transport_recv_pkt(&virtio_transport, skb, NULL); > > >+ virtio_transport_recv_pkt_batch(&virtio_transport, skb, > > >+ NULL, &batch); > > > } > > > } while (!virtqueue_enable_cb(vq)); > > > > > > out: > > >+ virtio_transport_rx_batch_finish(&batch); > > > if (vsock->rx_buf_nr < vsock->rx_buf_max_nr / 2) > > > virtio_vsock_rx_fill(vsock); > > > out_nofill: > > >diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c > > >index bebf63115b263..34d6864917bc9 100644 > > >--- a/net/vmw_vsock/virtio_transport_common.c > > >+++ b/net/vmw_vsock/virtio_transport_common.c > > >@@ -33,6 +33,15 @@ > > > #define MAX_COLLAPSE_LEN \ > > > SKB_MAX_ORDER(VIRTIO_VSOCK_SKB_HEADROOM, PAGE_ALLOC_COSTLY_ORDER) > > > > > >+/* > > >+ * Bound the interval that an RX worker owns a socket lock. One maximum packet > > >+ * buffer (64 KiB) bounds payload in one uninterrupted ownership interval. > > >+ * Small and zero-length packets need a packet limit to bound per-packet work; > > >+ * the 64-packet policy uses VHOST_NET_BATCH as a reference. > > >+ */ > > >+#define VIRTIO_TRANSPORT_RX_BATCH_MAX_PKTS 64 > > >+#define VIRTIO_TRANSPORT_RX_BATCH_MAX_BYTES VIRTIO_VSOCK_MAX_PKT_BUF_SIZE > > >+ > > > static void virtio_transport_cancel_close_work(struct vsock_sock *vsk, > > > bool cancel_timeout); > > > static s64 virtio_transport_has_space(struct virtio_vsock_sock *vvs); > > >@@ -1787,10 +1796,70 @@ virtio_transport_find_socket(struct sockaddr_vm *src, > > > return sk; > > > } > > > > > >+static bool > > >+virtio_transport_recv_pkt_set_owner(struct sk_buff *skb, struct sock *sk) > > >+{ > > >+ if (skb_set_owner_sk_safe(skb, sk)) > > >+ return true; > > >+ > > >+ WARN_ONCE(1, "receiving vsock socket has sk_refcnt == 0\n"); > > >+ return false; > > >+} > > >+ > > >+static bool > > >+virtio_transport_sock_has_psock(const struct sock *sk) > > >+{ > > >+ return (uintptr_t)rcu_access_pointer(__sk_user_data(sk)) & > > >+ SK_USER_DATA_PSOCK; > > >+} > > >+ > > >+/* The caller holds sk's socket lock. */ > > >+static bool > > >+virtio_transport_rx_batch_can_continue(struct virtio_transport *t, > > >+ struct sock *sk, u32 len) > > >+{ > > >+ struct virtio_vsock_sock *vvs; > > >+ struct vsock_sock *vsk; > > >+ > > >+ vsk = vsock_sk(sk); > > >+ vvs = vsk->trans; > > >+ > > >+ /* > > >+ * Keep a connected lookup reference only for the native, established > > >+ * STREAM path. Sockets outside ESTABLISHED can change table membership; > > >+ * a completed or reassigned socket must resume the per-packet path. > > >+ */ > > >+ if (sk->sk_state != TCP_ESTABLISHED || > > >+ sk->sk_type != SOCK_STREAM || > > >+ sock_flag(sk, SOCK_DONE) || > > >+ vsk->transport != &t->transport || !vvs) > > >+ return false; > > >+ > > >+ return (u64)vvs->buf_used + len <= vvs->buf_alloc; > > > > Should we remove this, since it will be checked in > > virtio_transport_inc_rx_pkt() in any case? > > > > I originally added this for the same kind of boundary > case discussed in v5. The v5 case checked the skb > metadata budget, while this checks the payload > against buf_alloc. > > Given that, this special handling probably isn't necessary, > so I'll remove it in the next version. > > > >+} > > >+ > > >+/* The caller holds sk's socket lock. */ > > >+static bool > > >+virtio_transport_rx_batch_can_receive(struct virtio_transport *t, > > >+ struct sock *sk, u32 len) > > >+{ > > >+ if (!virtio_transport_rx_batch_can_continue(t, sk, len)) > > >+ return false; > > >+ > > >+ /* > > >+ * Sockmap can replace sk_prot and publish a psock without the socket lock. > > >+ * Check both at each packet boundary; a boundary that sees a replacement > > >+ * returns to the existing per-packet path. > > >+ */ > > >+ return READ_ONCE(sk->sk_prot) == sk->sk_prot_creator && > > >+ !virtio_transport_sock_has_psock(sk); > > > > Is this a leftover or we really need this check? > > > > Yes, virtio_transport_sock_has_psock() is no longer > needed either. I'll remove it in the next version. Thanks. > > > >+} > > >+ > > > /* > > >- * The caller holds sk's socket lock. > > >+ * The caller holds sk's socket lock. Return false if socket/source validation > > >+ * rejects the packet. > > > */ > > >-static void > > >+static bool > > > virtio_transport_recv_pkt_locked(struct virtio_transport *t, > > > struct sk_buff *skb, struct sock *sk, > > > struct net *net) > > >@@ -1813,7 +1882,7 @@ virtio_transport_recv_pkt_locked(struct virtio_transport *t, > > > !vsock_check_source(vsk, &t->transport, &src))) { > > > (void)virtio_transport_reset_no_sock(t, skb, net); > > > kfree_skb(skb); > > >- return; > > >+ return false; > > > } > > > > > > space_available = virtio_transport_space_update(sk, skb); > > >@@ -1846,6 +1915,8 @@ virtio_transport_recv_pkt_locked(struct virtio_transport *t, > > > kfree_skb(skb); > > > break; > > > } > > >+ > > >+ return true; > > > } > > > > > > /* We are under the virtio-vsock's vsock->rx_lock or vhost-vsock's vq->mutex > > >@@ -1863,14 +1934,7 @@ void virtio_transport_recv_pkt(struct virtio_transport *t, > > > vsock_addr_init(&dst, le64_to_cpu(hdr->dst_cid), > > > le32_to_cpu(hdr->dst_port)); > > > > > >- trace_virtio_transport_recv_pkt(src.svm_cid, src.svm_port, > > >- dst.svm_cid, dst.svm_port, > > >- le32_to_cpu(hdr->len), > > >- le16_to_cpu(hdr->type), > > >- le16_to_cpu(hdr->op), > > >- le32_to_cpu(hdr->flags), > > >- le32_to_cpu(hdr->buf_alloc), > > >- le32_to_cpu(hdr->fwd_cnt)); > > >+ trace_virtio_transport_recv_pkt(hdr, &src, &dst); > > > > Why we are doing these changes in this patch? > > > > In v5, I initially added a helper around this tracepoint for the new > batching call site. Bobby suggested refactoring the tracepoint directly > instead, since the helper was unnecessary. Since this patch has two call > sites for the tracepoint, I kept that refactoring. FTR, between the refactoring and my very first suggestion of not changing the trace calls at all, I still prefer my very first suggestion of not changing them. > > > > > > > if (!virtio_transport_valid_type(le16_to_cpu(hdr->type))) { > > > (void)virtio_transport_reset_no_sock(t, skb, net); > > >@@ -1892,10 +1956,8 @@ void virtio_transport_recv_pkt(struct virtio_transport *t, > > > goto free_pkt; > > > } > > > > > >- if (!skb_set_owner_sk_safe(skb, sk)) { > > >- WARN_ONCE(1, "receiving vsock socket has sk_refcnt == 0\n"); > > >+ if (!virtio_transport_recv_pkt_set_owner(skb, sk)) > > > goto free_pkt; > > >- } > > > > > > lock_sock(sk); > > > virtio_transport_recv_pkt_locked(t, skb, sk, net); > > >@@ -1912,6 +1974,184 @@ void virtio_transport_recv_pkt(struct virtio_transport *t, > > > } > > > EXPORT_SYMBOL_GPL(virtio_transport_recv_pkt); > > > > > >+/* > > >+ * Release an active RX batch. A non-empty batch holds the socket lock and the > > >+ * reference returned by vsock_find_connected_socket_net(). An empty batch > > >+ * holds neither. > > >+ */ > > >+void virtio_transport_rx_batch_finish(struct virtio_transport_rx_batch *batch) > > >+{ > > >+ struct sock *sk = batch->sk; > > >+ > > >+ batch->sk = NULL; > > >+ batch->pkts = 0; > > >+ batch->bytes = 0; > > >+ > > >+ if (!sk) > > >+ return; > > >+ > > >+ release_sock(sk); > > >+ sock_put(sk); > > >+} > > >+EXPORT_SYMBOL_GPL(virtio_transport_rx_batch_finish); > > >+ > > >+static bool > > >+virtio_transport_rx_batch_matches(const struct virtio_transport_rx_batch *batch, > > >+ const struct sockaddr_vm *src, > > >+ const struct sockaddr_vm *dst, > > >+ struct net *net) > > >+{ > > >+ struct vsock_sock *vsk = vsock_sk(batch->sk); > > >+ > > >+ /* The connected table is keyed by peer address and local port. */ > > >+ return vsock_addr_equals_addr(src, &vsk->remote_addr) && > > >+ dst->svm_port == vsk->local_addr.svm_port && > > >+ vsock_net_check_mode(sock_net(batch->sk), net); > > >+} > > >+ > > >+static bool > > >+virtio_transport_rx_batch_can_add(const struct virtio_transport_rx_batch *batch, > > >+ u32 len) > > >+{ > > >+ if (batch->pkts >= VIRTIO_TRANSPORT_RX_BATCH_MAX_PKTS || > > >+ batch->bytes >= VIRTIO_TRANSPORT_RX_BATCH_MAX_BYTES) > > > > Why putting a limit to the total bytes in a batch? > > > > My thinking is that the two limits bound different things: the 64-packet > limit bounds per-packet work for small or zero-length packets, while the > 64 K limit bounds how much data can be queued while the reader is unable > to acquire the socket lock. > > A single packet can carry up to 64K, so a packet-only limit could let one > batch cover up to 4M. Since the receive buffer can be enlarged, the > default 256K buffer is not a substitute for that bound. Keeping the byte > limit also bounds the delay before the reader can dequeue data and return > credit to the peer, since that cannot happen while the batch holds the > socket lock. > > I would therefore prefer to keep both limits. I'm still not sure I entirely understand this point. Bounding the byte count bounds the delay before a reader can dequeue data? Can you point to the part of the code that sees increased delay because of high byte counts? I think my mental model must be missing something. Best, Bobby