* [PATCH net-next v3 0/4] vsock/virtio: reduce RX per-packet socket overhead
@ 2026-10-13 6:31 Jia Jia
2026-10-13 6:31 ` [PATCH net-next v3 1/4] vsock/virtio: split socket lookup from locked RX processing Jia Jia
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Jia Jia @ 2026-10-13 6:31 UTC (permalink / raw)
To: Stefan Hajnoczi, Stefano Garzarella
Cc: Michael S . Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, virtualization, kvm, netdev, linux-kernel
This series reduces per-packet socket overhead in the virtio-vsock RX
worker.
Patch 1: separate socket lookup from locked packet processing.
Patch 2: keep one socket lock across a bounded run of established
STREAM/RW packets for the same native socket, and reuse the locked socket
for later same-flow packets.
Patch 3: coalesce default write-space notifications while that
lock is held.
Patch 4: defer the default readable callback until after the batch
unlocks.
Performance:
Tested on a single-stream vsock connection (one Guest receiver thread on
CPU0, virtio-vsock IRQ on Guest CPU1, fresh QEMU Guest per state, 16
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 fixed-64K table uses a 64K buffer; the matched
table uses the sender's request size. 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().
Latency uses a custom user-space vsock ping-pong tool.
The measurements below were collected for the RX batching series.
This benchmark does not run vsock_perf on both ends. Instead, it uses
vsock_perf as the sender on the host (vhost-vsock) side and a custom
blocking recv() program without poll() on the Guest side, with the receiver
thread pinned to Guest CPU0 (and the virtio-vsock RX worker pinned to Guest
CPU1). Plain blocking recv() combined with strict core pinning gives
audit-level determinism for tracing a single-threaded TID.
I think it is necessary to do further testing on the large I/O throughput
peak observed at 4K to find the root cause (and rule out anything
introduced by the measurement method). I used kprobe and temporary
trace_printk in the source for mechanism diagnostics. The diagnostic
data shows that lock wait time and contention at 4K both decrease strictly
monotonically as payload size increases;
wire-level tracing also confirms that 4K is split into two packets, and
that all sizes can reach the 64K batching limit.
The nature of the prominent 4K throughput gain most likely lies in it
sitting exactly at the end-to-end pipeline sweet spot between host and
guest:
Compared with 1K and smaller payloads: 4K halves the packet intensity, so
upstream host-side syscall and interrupt injection overhead is no longer
the bottleneck across the whole path, allowing the host to supply data
adequately.
Compared with larger 8K to 64K payloads: 4K keeps the payload size
moderate, and combined with the observed syscall reduction and cycle
improvement, the batch-draining benefit from notification coalescing is
fully realized.
As payload size increases further from 8K to 64K, the overall gain shrinks
smoothly, consistent with Amdahl's law, because system execution time
shifts toward page copying and VQ processing.
With all patches applied:
End-to-end RX throughput (64K Guest recv() size, SO_RCVLOWAT=1; Gbit/s):
payload baseline RX PATCH RX throughput change (95% CI)
(Gbit/s) (Gbit/s)
64B 0.1065 0.2503 +135.00% [+130.35%, +139.74%]
256B 0.5722 1.0286 +79.76% [+75.40%, +84.23%]
512B 1.1464 1.9779 +72.53% [+69.50%, +75.63%]
1K 2.2714 3.6368 +60.12% [+56.92%, +63.37%]
4K 3.9095 7.7160 +97.37% [+92.09%, +102.79%]
8K 3.3436 5.3111 +58.84% [+53.49%, +64.38%]
16K 3.8876 5.7456 +47.80% [+45.45%, +50.18%]
64K 4.0056 5.3590 +33.79% [+29.37%, +38.36%]
Fixed-syscall stress test (receiver recv() size = sender write size;
Gbit/s):
payload baseline PATCH throughput change (95% CI) recv()
RX RX (base/patch)
(Gbit/s) (Gbit/s)
64B 0.1259 0.2651 +110.52% [+99.08%, +122.62%] 1048577/1048577
256B 0.3790 0.9444 +149.20% [+134.70%, +164.60%] 1048577/1048577
512B 0.7768 1.7009 +118.97% [+103.94%, +135.11%] 1048577/1048577
1K 1.4886 2.9477 +98.02% [+84.82%, +112.17%] 1048577/1048577
4K 2.1129 4.7331 +124.01% [+115.40%, +132.96%] 537436/525524
8K 2.8698 5.3683 +87.06% [+80.96%, +93.37%] 276448/264109
16K 3.5156 5.8463 +66.30% [+63.10%, +69.55%] 147849/132267
64K 4.2459 5.8576 +37.96% [+35.26%, +40.71%] 48447/33144
Request-response latency (Ping-Pong RTT, 10,000 requests):
payload baseline mean RTT (us) PATCH mean RTT (us) change (95% CI)
64B 221.968 218.144 -1.72%
[-4.23%, +0.85%]
256B 126.968 124.541 -1.91%
[-3.35%, -0.45%]
4K 130.362 126.664 -2.84%
[-5.12%, -0.50%]
Diagnostic Guest CPU1 system-wide cycles (fixed-64K receiver, with perf):
Buffer size baseline cycles/B PATCH cycles/B cycles change (95% CI)
64B 62.032 52.370 -15.58% [-17.16%, -13.96%]
256B 15.287 13.630 -10.84% [-12.51%, -9.14%]
512B 7.306 6.611 -9.51% [-10.92%, -8.08%]
1K 3.811 3.458 -9.25% [-10.96%, -7.50%]
4K 1.850 1.669 -9.75% [-11.78%, -7.67%]
8K 1.504 1.363 -9.36% [-12.97%, -5.60%]
16K 1.321 1.210 -8.37% [-10.61%, -6.07%]
64K 1.342 1.227 -8.57% [-10.87%, -6.21%]
Patch-scope measurements and attribution:
The series was tested cumulatively in two ranges, using the same
single-stream setup and paired AB/BA runs. The table below shows results
from patches 1–2 only, before the notification changes in patches 3–4.
payload baseline RX PATCH RX throughput change (95% CI)
(Gbit/s) (Gbit/s)
64B 0.1211 0.2534 +109.26% [+106.34%, +112.23%]
256B 0.5671 0.9989 +76.15% [+70.63%, +81.85%]
512B 1.1334 1.9000 +67.64% [+64.64%, +70.69%]
1K 2.2650 3.5610 +57.22% [+50.91%, +63.79%]
4K 3.8331 7.2888 +90.15% [+83.46%, +97.09%]
8K 4.8244 7.6636 +58.85% [+53.71%, +64.16%]
16K 5.4979 8.2469 +50.00% [+45.57%, +54.57%]
64K 3.8875 4.7588 +22.41% [+17.77%, +27.24%]
Fixed-syscall stress test (receiver recv() size = sender write size;
no perf; Gbit/s):
payload baseline PATCH throughput change (95% CI) recv()
RX RX (base/patch)
(Gbit/s) (Gbit/s)
64B 0.1397 0.2646 +89.40% [+80.92%, +98.27%] 1048577/1048577
256B 0.3960 0.9516 +140.34% [+117.48%, +165.60%] 1048577/1048577
512B 0.7541 1.6496 +118.74% [+101.42%, +137.55%] 1048577/1048577
1K 1.4903 2.8793 +93.21% [+77.06%, +110.82%] 1048577/1048577
4K 2.9466 6.2284 +111.37% [+97.52%, +126.20%] 538192/525220
8K 4.0043 6.9249 +72.94% [+60.18%, +86.71%] 276313/263852
16K 4.8981 7.5599 +54.34% [+49.77%, +59.06%] 147576/131600
64K 5.9294 7.7897 +31.37% [+27.18%, +35.70%] 50207/33014
Ping-Pong RTT (10,000 requests; no perf):
payload baseline mean RTT (us) PATCH mean RTT (us) change (95% CI)
64B 119.688 119.739 +0.04%
[-2.61%, +2.77%]
256B 120.603 124.485 +3.22%
[-0.44%, +7.01%]
4K 121.921 122.491 +0.47%
[-3.51%, +4.61%]
Guest CPU1 system-wide aggregate cycles (fixed-64K receiver, with perf;
cycles/byte):
Buffer size baseline cycles/B PATCH cycles/B cycles change (95% CI)
64B 66.838 60.012 -10.21% [-13.03%, -7.30%]
256B 13.446 12.305 -8.49% [-11.23%, -5.66%]
512B 6.833 6.317 -7.54% [ -9.52%, -5.52%]
1K 3.558 3.434 -3.48% [ -6.02%, -0.87%]
4K 1.806 1.686 -6.64% [ -8.69%, -4.54%]
8K 1.457 1.403 -3.73% [ -5.64%, -1.78%]
16K 1.295 1.279 -1.24% [ -5.21%, +2.89%]
64K 1.214 1.198 -1.30% [ -4.06%, +1.53%]
The split-patch tests show that PATCH 2 mainly contributes to the
improvement in I/O Throughput, while PATCH 3 and PATCH 4 mainly contribute
to the improvements in cycles and RTT latency (although PATCH 2 shows no
obvious regression here).
---
v3:
- restrict RX batching to sockets using the original protocol and
data-ready/write-space callbacks
- exclude sockets carrying the psock marker published before sockmap
protocol/callback replacement, and recheck it at each packet boundary
- preserve existing sockmap update return values; an attach racing a
native batch makes the next packet end the batch without queued-skb
handoff
- remove a leftover blank line after an opening brace
- remove callback handoff work and attach/detach kicks, preserving the
existing per-packet behavior for sockmap and other non-native sockets
- avoid making this series drain queued or partially consumed skbs when a
socket is added to or removed from a sockmap
- clarify that Patch 1 prepares for batching and intends no functional
change
- inline address decoding and receive tracing, simplify the socket lookup
helper, and pass locked receive arguments directly
- fold same-flow lookup reuse into Patch 2 and match packets against the
locked socket state, reducing the series from five patches to four
v2:
- stop a batch after it consumes the last skb metadata slot, sharing the
admission predicate with virtio_transport_inc_rx_pkt()
- move replacement-callback handoff into vsock, process queued skbs one
at a time, and trigger the handoff from vsock_bpf_update_proto() on
attach and detach
- reduce the packet-context diff in the locked receive helper
- keep RX batch counters in the batch state and reset them in the finish
path
- use the vsock/virtio subject prefix and add the requested measurements
v1: https://lore.kernel.org/virtualization/20261002074551.318789-1-physicalmtea@gmail.com/
Jia Jia (4):
vsock/virtio: split socket lookup from locked RX processing
vsock/virtio: amortize RX socket locking for stream packets
vsock/virtio: coalesce RX write-space notifications in lock batches
vsock/virtio: defer RX readable notifications until batch unlock
include/linux/virtio_vsock.h | 13 +
include/net/af_vsock.h | 3 +
net/vmw_vsock/af_vsock.c | 2 +
net/vmw_vsock/virtio_transport.c | 29 +-
net/vmw_vsock/virtio_transport_common.c | 335 +++++++++++++++++++-----
5 files changed, 321 insertions(+), 61 deletions(-)
base-commit: 8df0638138d3e0344fd1fb36cf2d1ca1cf5028f0
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next v3 1/4] vsock/virtio: split socket lookup from locked RX processing
2026-10-13 6:31 [PATCH net-next v3 0/4] vsock/virtio: reduce RX per-packet socket overhead Jia Jia
@ 2026-10-13 6:31 ` Jia Jia
2026-10-13 6:31 ` [PATCH net-next v3 2/4] vsock/virtio: amortize RX socket locking for stream packets Jia Jia
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Jia Jia @ 2026-10-13 6:31 UTC (permalink / raw)
To: Stefan Hajnoczi, Stefano Garzarella
Cc: Michael S . Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, virtualization, kvm, netdev, linux-kernel
Split virtio_transport_recv_pkt() so socket lookup is separate from the
receive state machine that runs under the socket lock. This prepares the
receive path for keeping a looked-up socket across multiple packets in a
later change.
Keep virtio_transport_recv_pkt() on its existing per-packet locking path.
Pass the network namespace and decoded address tuple directly to the locked
receive path, preserving source validation and failure handling.
No functional change intended.
Signed-off-by: Jia Jia <physicalmtea@gmail.com>
---
net/vmw_vsock/virtio_transport_common.c | 153 ++++++++++++++----------
1 file changed, 87 insertions(+), 66 deletions(-)
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index f225f53ed4bab..8a930bc42fdc3 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -1774,6 +1774,87 @@ static bool virtio_transport_valid_type(u16 type)
(type == VIRTIO_VSOCK_TYPE_SEQPACKET);
}
+static struct sock *
+virtio_transport_find_socket(struct sk_buff *skb, struct sockaddr_vm *src,
+ struct sockaddr_vm *dst, struct net *net)
+{
+ struct virtio_vsock_hdr *hdr = virtio_vsock_hdr(skb);
+ struct sock *sk;
+
+ if (!virtio_transport_valid_type(le16_to_cpu(hdr->type)))
+ return NULL;
+
+ sk = vsock_find_connected_socket_net(src, dst, net);
+ if (!sk)
+ sk = vsock_find_bound_socket_net(dst, net);
+ if (!sk)
+ return NULL;
+
+ if (virtio_transport_get_type(sk) != le16_to_cpu(hdr->type)) {
+ sock_put(sk);
+ return NULL;
+ }
+
+ return sk;
+}
+
+/*
+ * The caller holds sk's socket lock and must free skb if this returns true.
+ */
+static bool
+virtio_transport_recv_pkt_locked(struct virtio_transport *t,
+ struct sk_buff *skb, struct sock *sk,
+ const struct sockaddr_vm *src,
+ const struct sockaddr_vm *dst,
+ struct net *net)
+{
+ struct vsock_sock *vsk = vsock_sk(sk);
+ bool space_available;
+
+ /* Listener sockets accept packets from any source and are not assigned to
+ * a transport.
+ */
+ if (sock_flag(sk, SOCK_DONE) ||
+ (sk->sk_state != TCP_LISTEN &&
+ !vsock_check_source(vsk, &t->transport, src))) {
+ (void)virtio_transport_reset_no_sock(t, skb, net);
+ return true;
+ }
+
+ space_available = virtio_transport_space_update(sk, skb);
+
+ /* Update CID in case it has changed after a transport reset event */
+ if (vsk->local_addr.svm_cid != VMADDR_CID_ANY)
+ vsk->local_addr.svm_cid = dst->svm_cid;
+
+ if (space_available)
+ sk->sk_write_space(sk);
+
+ switch (sk->sk_state) {
+ case TCP_LISTEN:
+ virtio_transport_recv_listen(sk, skb, t);
+ kfree_skb(skb);
+ break;
+ case TCP_SYN_SENT:
+ virtio_transport_recv_connecting(sk, skb);
+ kfree_skb(skb);
+ break;
+ case TCP_ESTABLISHED:
+ virtio_transport_recv_connected(sk, skb);
+ break;
+ case TCP_CLOSING:
+ virtio_transport_recv_disconnecting(sk, skb);
+ kfree_skb(skb);
+ break;
+ default:
+ (void)virtio_transport_reset_no_sock(t, skb, net);
+ kfree_skb(skb);
+ break;
+ }
+
+ return false;
+}
+
/* We are under the virtio-vsock's vsock->rx_lock or vhost-vsock's vq->mutex
* lock.
*/
@@ -1782,9 +1863,8 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
{
struct virtio_vsock_hdr *hdr = virtio_vsock_hdr(skb);
struct sockaddr_vm src, dst;
- struct vsock_sock *vsk;
struct sock *sk;
- bool space_available;
+ bool free_pkt;
vsock_addr_init(&src, le64_to_cpu(hdr->src_cid),
le32_to_cpu(hdr->src_port));
@@ -1800,26 +1880,9 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
le32_to_cpu(hdr->buf_alloc),
le32_to_cpu(hdr->fwd_cnt));
- if (!virtio_transport_valid_type(le16_to_cpu(hdr->type))) {
- (void)virtio_transport_reset_no_sock(t, skb, net);
- goto free_pkt;
- }
-
- /* The socket must be in connected or bound table
- * otherwise send reset back
- */
- sk = vsock_find_connected_socket_net(&src, &dst, net);
+ sk = virtio_transport_find_socket(skb, &src, &dst, net);
if (!sk) {
- sk = vsock_find_bound_socket_net(&dst, net);
- if (!sk) {
- (void)virtio_transport_reset_no_sock(t, skb, net);
- goto free_pkt;
- }
- }
-
- if (virtio_transport_get_type(sk) != le16_to_cpu(hdr->type)) {
(void)virtio_transport_reset_no_sock(t, skb, net);
- sock_put(sk);
goto free_pkt;
}
@@ -1828,59 +1891,17 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
goto free_pkt;
}
- vsk = vsock_sk(sk);
-
lock_sock(sk);
-
- /* Check if sk has been closed or assigned to another transport before
- * lock_sock (note: listener sockets are not assigned to any transport)
- */
- if (sock_flag(sk, SOCK_DONE) ||
- (sk->sk_state != TCP_LISTEN &&
- !vsock_check_source(vsk, &t->transport, &src))) {
- (void)virtio_transport_reset_no_sock(t, skb, net);
- release_sock(sk);
- sock_put(sk);
- goto free_pkt;
- }
-
- space_available = virtio_transport_space_update(sk, skb);
-
- /* Update CID in case it has changed after a transport reset event */
- if (vsk->local_addr.svm_cid != VMADDR_CID_ANY)
- vsk->local_addr.svm_cid = dst.svm_cid;
-
- if (space_available)
- sk->sk_write_space(sk);
-
- switch (sk->sk_state) {
- case TCP_LISTEN:
- virtio_transport_recv_listen(sk, skb, t);
- kfree_skb(skb);
- break;
- case TCP_SYN_SENT:
- virtio_transport_recv_connecting(sk, skb);
- kfree_skb(skb);
- break;
- case TCP_ESTABLISHED:
- virtio_transport_recv_connected(sk, skb);
- break;
- case TCP_CLOSING:
- virtio_transport_recv_disconnecting(sk, skb);
- kfree_skb(skb);
- break;
- default:
- (void)virtio_transport_reset_no_sock(t, skb, net);
- kfree_skb(skb);
- break;
- }
-
+ free_pkt = virtio_transport_recv_pkt_locked(t, skb, sk, &src, &dst,
+ net);
release_sock(sk);
/* Release refcnt obtained when we fetched this socket out of the
* bound or connected list.
*/
sock_put(sk);
+ if (free_pkt)
+ kfree_skb(skb);
return;
free_pkt:
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next v3 2/4] vsock/virtio: amortize RX socket locking for stream packets
2026-10-13 6:31 [PATCH net-next v3 0/4] vsock/virtio: reduce RX per-packet socket overhead Jia Jia
2026-10-13 6:31 ` [PATCH net-next v3 1/4] vsock/virtio: split socket lookup from locked RX processing Jia Jia
@ 2026-10-13 6:31 ` Jia Jia
2026-10-13 6:31 ` [PATCH net-next v3 3/4] vsock/virtio: coalesce RX write-space notifications in lock batches Jia Jia
2026-10-13 6:31 ` [PATCH net-next v3 4/4] vsock/virtio: defer RX readable notifications until batch unlock Jia Jia
3 siblings, 0 replies; 5+ messages in thread
From: Jia Jia @ 2026-10-13 6:31 UTC (permalink / raw)
To: Stefan Hajnoczi, Stefano Garzarella
Cc: Michael S . Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, virtualization, kvm, netdev, linux-kernel
The virtio-vsock RX worker currently acquires and releases the socket lock
and looks up the socket for every received packet. Keep the lock and lookup
reference across a bounded run of packets that belongs to the same socket.
Only ordinary RW packets for an established STREAM socket whose transport
and protocol remain unchanged are eligible. Control packets, SEQPACKET
traffic, state or transport changes, malformed packets, and sockets whose
protocol has been replaced end the active batch and retain their existing
handling.
A psock is published in sk_user_data before sockmap replaces the protocol
or callbacks. Exclude sockets carrying that marker from batching, and check
it again at every packet boundary. Thus an attach racing an active native
batch makes the next packet end the batch without changing the sockmap
update result.
Serialize the initial eligibility check with sk_callback_lock because
sockmap removal restores the protocol and callbacks without taking the
socket lock.
Limit each batch to 64 packets or 64KB of payload. The packet limit bounds
per-packet work for small payloads, while the byte limit bounds how much
data can queue before a reader can acquire the socket lock.
For later STREAM/RW packets, match the packet against the locked socket
state and reuse the batch socket for the same flow. Release the batch
before looking up a different flow. The cached path still traces every
packet, takes an skb owner reference, validates the source and transport,
updates credit, and runs the receive state machine.
Keep a batch only while another skb metadata charge fits in the receive
buffer. Share this predicate with virtio_transport_inc_rx_pkt(). When an
enqueued skb consumes the final metadata slot, finish the batch and release
the socket lock before processing another packet, restoring the reader's
scheduling opportunity from the per-packet path.
The virtqueue callback remains a queue_work() callback. Batching runs only
in the process-context RX worker.
Introduce virtio_transport_rx_batch_finish() to tear down the batch and
release the socket lock and lookup reference.
Signed-off-by: Jia Jia <physicalmtea@gmail.com>
---
include/linux/virtio_vsock.h | 11 ++
net/vmw_vsock/virtio_transport.c | 29 +++-
net/vmw_vsock/virtio_transport_common.c | 170 +++++++++++++++++++++++-
3 files changed, 203 insertions(+), 7 deletions(-)
diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
index f91704731057e..26dde6909c4ed 100644
--- a/include/linux/virtio_vsock.h
+++ b/include/linux/virtio_vsock.h
@@ -282,6 +282,17 @@ void virtio_transport_destruct(struct vsock_sock *vsk);
void virtio_transport_recv_pkt(struct virtio_transport *t,
struct sk_buff *skb, struct net *net);
+
+struct virtio_transport_rx_batch {
+ struct sock *sk;
+ unsigned int pkts;
+ size_t bytes;
+};
+
+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/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index 4f9aa9c4c3aa5..ef076732158d4 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -629,8 +629,16 @@ virtio_transport_seqpacket_allow(struct vsock_sock *vsk, u32 remote_cid)
return seqpacket_allow;
}
+/*
+ * Keep a bounded run of packets for one socket under a single socket lock.
+ * Limit packet count and payload size to bound the work done while locked.
+ */
+#define VIRTIO_TRANSPORT_RX_BATCH_MAX_PKTS 64
+#define VIRTIO_TRANSPORT_RX_BATCH_MAX_BYTES (64 * 1024)
+
static void virtio_transport_rx_work(struct work_struct *work)
{
+ struct virtio_transport_rx_batch batch = {};
struct virtio_vsock *vsock =
container_of(work, struct virtio_vsock, rx_work);
struct virtqueue *vq;
@@ -666,6 +674,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 +682,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;
}
@@ -680,16 +690,33 @@ static void virtio_transport_rx_work(struct work_struct *work)
if (payload_len)
virtio_vsock_skb_put(skb, payload_len);
+ if (batch.sk &&
+ payload_len > VIRTIO_TRANSPORT_RX_BATCH_MAX_BYTES -
+ batch.bytes) {
+ virtio_transport_rx_batch_finish(&batch);
+ }
+
virtio_transport_deliver_tap_pkt(skb);
/* 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);
+
+ if (batch.sk) {
+ batch.pkts++;
+ batch.bytes += payload_len;
+ if (batch.pkts >= VIRTIO_TRANSPORT_RX_BATCH_MAX_PKTS ||
+ batch.bytes >= VIRTIO_TRANSPORT_RX_BATCH_MAX_BYTES) {
+ virtio_transport_rx_batch_finish(&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 8a930bc42fdc3..bfe40ecf0b2f0 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -576,11 +576,16 @@ virtio_transport_collapse_rx_queue(struct virtio_vsock_sock *vvs,
skb_queue_splice(&new_queue, &vvs->rx_queue);
}
+static bool
+virtio_transport_rx_skb_has_headroom(struct virtio_vsock_sock *vvs)
+{
+ return (u64)(skb_queue_len(&vvs->rx_queue) + 1) * SKB_TRUESIZE(0) <=
+ vvs->buf_alloc;
+}
+
static bool virtio_transport_inc_rx_pkt(struct virtio_vsock_sock *vvs,
u32 len)
{
- u64 skb_overhead = (skb_queue_len(&vvs->rx_queue) + 1) * SKB_TRUESIZE(0);
-
/* Allow at most buf_alloc * 2 total budget (payload + overhead),
* similar to how SO_RCVBUF is doubled to reserve space for sk_buff
* metadata. Check payload against buf_alloc to be sure the other
@@ -588,7 +593,7 @@ static bool virtio_transport_inc_rx_pkt(struct virtio_vsock_sock *vvs,
* queue growth.
*/
if ((u64)vvs->buf_used + len > vvs->buf_alloc ||
- skb_overhead > vvs->buf_alloc)
+ !virtio_transport_rx_skb_has_headroom(vvs))
return false;
vvs->rx_bytes += len;
@@ -1798,19 +1803,47 @@ virtio_transport_find_socket(struct sk_buff *skb, struct sockaddr_vm *src,
return sk;
}
+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;
+}
+
+static bool
+virtio_transport_recv_pkt_batchable(struct virtio_transport *t,
+ struct sock *sk)
+{
+ struct vsock_sock *vsk = vsock_sk(sk);
+ struct virtio_vsock_sock *vvs = vsk->trans;
+
+ return sk->sk_state == TCP_ESTABLISHED &&
+ sk->sk_type == SOCK_STREAM &&
+ READ_ONCE(sk->sk_prot) == sk->sk_prot_creator &&
+ !sock_flag(sk, SOCK_DONE) &&
+ vsk->transport == &t->transport &&
+ vvs && virtio_transport_rx_skb_has_headroom(vvs) &&
+ !virtio_transport_sock_has_psock(sk);
+}
+
/*
- * The caller holds sk's socket lock and must free skb if this returns true.
+ * The caller holds sk's socket lock. Set @batchable if the socket can remain
+ * locked for another ordinary STREAM/RW packet. Return true if the caller
+ * must free @skb.
*/
static bool
virtio_transport_recv_pkt_locked(struct virtio_transport *t,
struct sk_buff *skb, struct sock *sk,
const struct sockaddr_vm *src,
const struct sockaddr_vm *dst,
- struct net *net)
+ struct net *net, bool *batchable)
{
struct vsock_sock *vsk = vsock_sk(sk);
bool space_available;
+ if (batchable)
+ *batchable = false;
+
/* Listener sockets accept packets from any source and are not assigned to
* a transport.
*/
@@ -1852,6 +1885,9 @@ virtio_transport_recv_pkt_locked(struct virtio_transport *t,
break;
}
+ if (batchable)
+ *batchable = virtio_transport_recv_pkt_batchable(t, sk);
+
return false;
}
@@ -1893,7 +1929,7 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
lock_sock(sk);
free_pkt = virtio_transport_recv_pkt_locked(t, skb, sk, &src, &dst,
- net);
+ net, NULL);
release_sock(sk);
/* Release refcnt obtained when we fetched this socket out of the
@@ -1909,6 +1945,128 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
}
EXPORT_SYMBOL_GPL(virtio_transport_recv_pkt);
+/*
+ * Finish the RX batch.
+ * For a non-empty batch, the caller must hold the socket lock acquired with
+ * lock_sock(). This function releases the lock and the batch's lookup
+ * reference.
+ * An empty batch is a no-op.
+ */
+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);
+
+void virtio_transport_recv_pkt_batch(struct virtio_transport *t,
+ struct sk_buff *skb, struct net *net,
+ struct virtio_transport_rx_batch *batch)
+{
+ struct virtio_vsock_hdr *hdr = virtio_vsock_hdr(skb);
+ struct sockaddr_vm src, dst;
+ struct vsock_sock *vsk;
+ bool batchable, start_batch;
+ struct sock *sk;
+ bool free_pkt;
+
+ /* Only STREAM/RW packets can share a socket lock. */
+ if (le16_to_cpu(hdr->type) != VIRTIO_VSOCK_TYPE_STREAM ||
+ le16_to_cpu(hdr->op) != VIRTIO_VSOCK_OP_RW) {
+ virtio_transport_rx_batch_finish(batch);
+ virtio_transport_recv_pkt(t, skb, net);
+ return;
+ }
+
+ vsock_addr_init(&src, le64_to_cpu(hdr->src_cid),
+ le32_to_cpu(hdr->src_port));
+ 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));
+
+ if (batch->sk) {
+ vsk = vsock_sk(batch->sk);
+ if (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) &&
+ virtio_transport_recv_pkt_batchable(t, batch->sk)) {
+ sk = batch->sk;
+ if (!skb_set_owner_sk_safe(skb, sk)) {
+ WARN_ONCE(1, "receiving vsock socket has sk_refcnt == 0\n");
+ virtio_transport_rx_batch_finish(batch);
+ kfree_skb(skb);
+ return;
+ }
+
+ free_pkt = virtio_transport_recv_pkt_locked(t, skb, sk,
+ &src, &dst,
+ net,
+ &batchable);
+ if (!batchable)
+ virtio_transport_rx_batch_finish(batch);
+ if (free_pkt)
+ kfree_skb(skb);
+ return;
+ }
+
+ virtio_transport_rx_batch_finish(batch);
+ }
+
+ sk = virtio_transport_find_socket(skb, &src, &dst, net);
+ if (!sk) {
+ (void)virtio_transport_reset_no_sock(t, skb, net);
+ kfree_skb(skb);
+ return;
+ }
+
+ if (!skb_set_owner_sk_safe(skb, sk)) {
+ WARN_ONCE(1, "receiving vsock socket has sk_refcnt == 0\n");
+ kfree_skb(skb);
+ return;
+ }
+
+ lock_sock(sk);
+ /*
+ * Sockmap removal restores the native protocol under sk_callback_lock.
+ * Serialize this initial eligibility check with that update.
+ */
+ read_lock_bh(&sk->sk_callback_lock);
+ start_batch = virtio_transport_recv_pkt_batchable(t, sk);
+ read_unlock_bh(&sk->sk_callback_lock);
+
+ free_pkt = virtio_transport_recv_pkt_locked(t, skb, sk, &src, &dst,
+ net,
+ start_batch ? &batchable : NULL);
+ if (start_batch && batchable) {
+ /* Keep the lookup reference until the batch is released. */
+ batch->sk = sk;
+ return;
+ }
+
+ release_sock(sk);
+ sock_put(sk);
+ if (free_pkt)
+ kfree_skb(skb);
+}
+EXPORT_SYMBOL_GPL(virtio_transport_recv_pkt_batch);
+
/* Remove skbs found in a queue that have a vsk that matches.
*
* Each skb is freed.
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next v3 3/4] vsock/virtio: coalesce RX write-space notifications in lock batches
2026-10-13 6:31 [PATCH net-next v3 0/4] vsock/virtio: reduce RX per-packet socket overhead Jia Jia
2026-10-13 6:31 ` [PATCH net-next v3 1/4] vsock/virtio: split socket lookup from locked RX processing Jia Jia
2026-10-13 6:31 ` [PATCH net-next v3 2/4] vsock/virtio: amortize RX socket locking for stream packets Jia Jia
@ 2026-10-13 6:31 ` Jia Jia
2026-10-13 6:31 ` [PATCH net-next v3 4/4] vsock/virtio: defer RX readable notifications until batch unlock Jia Jia
3 siblings, 0 replies; 5+ messages in thread
From: Jia Jia @ 2026-10-13 6:31 UTC (permalink / raw)
To: Stefan Hajnoczi, Stefano Garzarella
Cc: Michael S . Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, virtualization, kvm, netdev, linux-kernel
Each received packet updates peer credit and calls sk_write_space() when
send space is available. A writer cannot use the newly advertised credit
until the socket lock is released, so repeated callbacks within one lock
batch cannot let it make progress sooner.
For the callback installed by sock_init_data(), record one pending
write-space notification and deliver it through the saved default callback
before release_sock(). Save that callback when the AF_VSOCK socket is
created because it is not visible to virtio_transport_common when built as
a module.
Keep only sockets using the saved callback eligible for batching. Sockets
whose callback has been replaced, including sockmap sockets, retain their
existing per-packet notification behavior. The psock marker checked by the
batch admission path also excludes a socket before sockmap replaces this
callback.
Set the batch socket before processing its first packet so a batch ending
on that packet cannot lose the notification.
Packets outside the eligible STREAM/RW batch path retain per-packet
notification behavior. The 64-packet and 64KB limits cap the packets whose
notifications can be coalesced.
Signed-off-by: Jia Jia <physicalmtea@gmail.com>
---
include/linux/virtio_vsock.h | 1 +
include/net/af_vsock.h | 2 ++
net/vmw_vsock/af_vsock.c | 1 +
net/vmw_vsock/virtio_transport_common.c | 42 ++++++++++++++++++-------
4 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
index 26dde6909c4ed..bf077ee0ded88 100644
--- a/include/linux/virtio_vsock.h
+++ b/include/linux/virtio_vsock.h
@@ -287,6 +287,7 @@ struct virtio_transport_rx_batch {
struct sock *sk;
unsigned int pkts;
size_t bytes;
+ bool write_space_pending;
};
void virtio_transport_recv_pkt_batch(struct virtio_transport *t,
diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h
index 5549298c1ec6b..9d8ae62209eda 100644
--- a/include/net/af_vsock.h
+++ b/include/net/af_vsock.h
@@ -63,6 +63,8 @@ struct vsock_sock {
u32 peer_shutdown;
bool sent_request;
bool ignore_connecting_rst;
+ /* Initial callback, used to identify replacements. */
+ void (*default_write_space)(struct sock *sk);
/* Protected by lock_sock(sk) */
u64 buffer_size;
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 44cee74519555..fe7f49da6c4bc 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -958,6 +958,7 @@ static struct sock *__vsock_create(struct net *net,
sk->sk_type = type;
vsk = vsock_sk(sk);
+ vsk->default_write_space = sk->sk_write_space;
vsock_addr_init(&vsk->local_addr, VMADDR_CID_ANY, VMADDR_PORT_ANY);
vsock_addr_init(&vsk->remote_addr, VMADDR_CID_ANY, VMADDR_PORT_ANY);
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index bfe40ecf0b2f0..d6ebfde880db6 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -1820,6 +1820,7 @@ virtio_transport_recv_pkt_batchable(struct virtio_transport *t,
return sk->sk_state == TCP_ESTABLISHED &&
sk->sk_type == SOCK_STREAM &&
READ_ONCE(sk->sk_prot) == sk->sk_prot_creator &&
+ READ_ONCE(sk->sk_write_space) == vsk->default_write_space &&
!sock_flag(sk, SOCK_DONE) &&
vsk->transport == &t->transport &&
vvs && virtio_transport_rx_skb_has_headroom(vvs) &&
@@ -1836,7 +1837,8 @@ virtio_transport_recv_pkt_locked(struct virtio_transport *t,
struct sk_buff *skb, struct sock *sk,
const struct sockaddr_vm *src,
const struct sockaddr_vm *dst,
- struct net *net, bool *batchable)
+ struct net *net, bool *batchable,
+ struct virtio_transport_rx_batch *batch)
{
struct vsock_sock *vsk = vsock_sk(sk);
bool space_available;
@@ -1860,8 +1862,12 @@ virtio_transport_recv_pkt_locked(struct virtio_transport *t,
if (vsk->local_addr.svm_cid != VMADDR_CID_ANY)
vsk->local_addr.svm_cid = dst->svm_cid;
- if (space_available)
- sk->sk_write_space(sk);
+ if (space_available) {
+ if (batch)
+ batch->write_space_pending = true;
+ else
+ sk->sk_write_space(sk);
+ }
switch (sk->sk_state) {
case TCP_LISTEN:
@@ -1929,7 +1935,7 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
lock_sock(sk);
free_pkt = virtio_transport_recv_pkt_locked(t, skb, sk, &src, &dst,
- net, NULL);
+ net, NULL, NULL);
release_sock(sk);
/* Release refcnt obtained when we fetched this socket out of the
@@ -1954,15 +1960,20 @@ EXPORT_SYMBOL_GPL(virtio_transport_recv_pkt);
*/
void virtio_transport_rx_batch_finish(struct virtio_transport_rx_batch *batch)
{
+ bool write_space_pending = batch->write_space_pending;
struct sock *sk = batch->sk;
batch->sk = NULL;
batch->pkts = 0;
batch->bytes = 0;
+ batch->write_space_pending = false;
if (!sk)
return;
+ if (write_space_pending)
+ vsock_sk(sk)->default_write_space(sk);
+
release_sock(sk);
sock_put(sk);
}
@@ -2018,7 +2029,8 @@ void virtio_transport_recv_pkt_batch(struct virtio_transport *t,
free_pkt = virtio_transport_recv_pkt_locked(t, skb, sk,
&src, &dst,
net,
- &batchable);
+ &batchable,
+ batch);
if (!batchable)
virtio_transport_rx_batch_finish(batch);
if (free_pkt)
@@ -2044,24 +2056,32 @@ void virtio_transport_recv_pkt_batch(struct virtio_transport *t,
lock_sock(sk);
/*
- * Sockmap removal restores the native protocol under sk_callback_lock.
- * Serialize this initial eligibility check with that update.
+ * Sockmap teardown restores callbacks under sk_callback_lock. Keep the
+ * initial eligibility check consistent with that update.
*/
read_lock_bh(&sk->sk_callback_lock);
start_batch = virtio_transport_recv_pkt_batchable(t, sk);
read_unlock_bh(&sk->sk_callback_lock);
+ if (start_batch)
+ batch->sk = sk;
+
free_pkt = virtio_transport_recv_pkt_locked(t, skb, sk, &src, &dst,
net,
- start_batch ? &batchable : NULL);
+ start_batch ? &batchable : NULL,
+ start_batch ? batch : NULL);
if (start_batch && batchable) {
/* Keep the lookup reference until the batch is released. */
- batch->sk = sk;
return;
}
- release_sock(sk);
- sock_put(sk);
+ if (start_batch) {
+ virtio_transport_rx_batch_finish(batch);
+ } else {
+ release_sock(sk);
+ sock_put(sk);
+ }
+
if (free_pkt)
kfree_skb(skb);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next v3 4/4] vsock/virtio: defer RX readable notifications until batch unlock
2026-10-13 6:31 [PATCH net-next v3 0/4] vsock/virtio: reduce RX per-packet socket overhead Jia Jia
` (2 preceding siblings ...)
2026-10-13 6:31 ` [PATCH net-next v3 3/4] vsock/virtio: coalesce RX write-space notifications in lock batches Jia Jia
@ 2026-10-13 6:31 ` Jia Jia
3 siblings, 0 replies; 5+ messages in thread
From: Jia Jia @ 2026-10-13 6:31 UTC (permalink / raw)
To: Stefan Hajnoczi, Stefano Garzarella
Cc: Michael S . Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, virtualization, kvm, netdev, linux-kernel
An RX batch can make a socket readable while the worker still owns its
socket lock. Waking a reader at that point can make it immediately wait
for the same lock.
For the callback installed by sock_init_data(), record when the existing
low-watermark condition is met and issue one notification after the batch
releases the lock. Save the initial sock_def_readable() callback when the
AF_VSOCK socket is created because virtio_transport_common can be built as
a module and cannot refer to that unexported symbol directly.
Require the original protocol and both saved callbacks for batching.
Sockets with callbacks installed by sockmap or another user retain their
existing per-packet behavior.
A psock is published before sockmap replaces the callbacks and is excluded
by the batch admission checks. If an attach races an active native batch,
only a packet admitted before that publication can complete on the native
path; the next packet ends the batch. No queued skb handoff is needed.
Keep the socket reference until the deferred callback completes. Control
packets, state transitions, transport changes and non-batched sockets keep
their existing behavior.
Signed-off-by: Jia Jia <physicalmtea@gmail.com>
---
include/linux/virtio_vsock.h | 1 +
include/net/af_vsock.h | 3 ++-
net/vmw_vsock/af_vsock.c | 1 +
net/vmw_vsock/virtio_transport_common.c | 22 +++++++++++++++++++---
4 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
index bf077ee0ded88..f1396ca3ad9b5 100644
--- a/include/linux/virtio_vsock.h
+++ b/include/linux/virtio_vsock.h
@@ -288,6 +288,7 @@ struct virtio_transport_rx_batch {
unsigned int pkts;
size_t bytes;
bool write_space_pending;
+ bool data_ready_pending;
};
void virtio_transport_recv_pkt_batch(struct virtio_transport *t,
diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h
index 9d8ae62209eda..a799f08556376 100644
--- a/include/net/af_vsock.h
+++ b/include/net/af_vsock.h
@@ -63,7 +63,8 @@ struct vsock_sock {
u32 peer_shutdown;
bool sent_request;
bool ignore_connecting_rst;
- /* Initial callback, used to identify replacements. */
+ /* Initial callbacks, used to identify replacements. */
+ void (*default_data_ready)(struct sock *sk);
void (*default_write_space)(struct sock *sk);
/* Protected by lock_sock(sk) */
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index fe7f49da6c4bc..f40659ec29df0 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -958,6 +958,7 @@ static struct sock *__vsock_create(struct net *net,
sk->sk_type = type;
vsk = vsock_sk(sk);
+ vsk->default_data_ready = sk->sk_data_ready;
vsk->default_write_space = sk->sk_write_space;
vsock_addr_init(&vsk->local_addr, VMADDR_CID_ANY, VMADDR_PORT_ANY);
vsock_addr_init(&vsk->remote_addr, VMADDR_CID_ANY, VMADDR_PORT_ANY);
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index d6ebfde880db6..84822d6bfb958 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -1588,7 +1588,8 @@ virtio_transport_recv_enqueue(struct vsock_sock *vsk,
static int
virtio_transport_recv_connected(struct sock *sk,
- struct sk_buff *skb)
+ struct sk_buff *skb,
+ bool *data_ready_pending)
{
struct virtio_vsock_hdr *hdr = virtio_vsock_hdr(skb);
struct vsock_sock *vsk = vsock_sk(sk);
@@ -1607,7 +1608,13 @@ virtio_transport_recv_connected(struct sock *sk,
vsock_remove_sock(vsk);
break;
}
- vsock_data_ready(sk);
+ if (!data_ready_pending) {
+ vsock_data_ready(sk);
+ } else if (!*data_ready_pending &&
+ (vsock_stream_has_data(vsk) >= sk->sk_rcvlowat ||
+ sock_flag(sk, SOCK_DONE))) {
+ *data_ready_pending = true;
+ }
return err;
case VIRTIO_VSOCK_OP_CREDIT_REQUEST:
virtio_transport_send_credit_update(vsk);
@@ -1820,6 +1827,7 @@ virtio_transport_recv_pkt_batchable(struct virtio_transport *t,
return sk->sk_state == TCP_ESTABLISHED &&
sk->sk_type == SOCK_STREAM &&
READ_ONCE(sk->sk_prot) == sk->sk_prot_creator &&
+ READ_ONCE(sk->sk_data_ready) == vsk->default_data_ready &&
READ_ONCE(sk->sk_write_space) == vsk->default_write_space &&
!sock_flag(sk, SOCK_DONE) &&
vsk->transport == &t->transport &&
@@ -1879,7 +1887,9 @@ virtio_transport_recv_pkt_locked(struct virtio_transport *t,
kfree_skb(skb);
break;
case TCP_ESTABLISHED:
- virtio_transport_recv_connected(sk, skb);
+ virtio_transport_recv_connected(sk, skb,
+ batch ?
+ &batch->data_ready_pending : NULL);
break;
case TCP_CLOSING:
virtio_transport_recv_disconnecting(sk, skb);
@@ -1961,12 +1971,14 @@ EXPORT_SYMBOL_GPL(virtio_transport_recv_pkt);
void virtio_transport_rx_batch_finish(struct virtio_transport_rx_batch *batch)
{
bool write_space_pending = batch->write_space_pending;
+ bool data_ready_pending = batch->data_ready_pending;
struct sock *sk = batch->sk;
batch->sk = NULL;
batch->pkts = 0;
batch->bytes = 0;
batch->write_space_pending = false;
+ batch->data_ready_pending = false;
if (!sk)
return;
@@ -1975,6 +1987,10 @@ void virtio_transport_rx_batch_finish(struct virtio_transport_rx_batch *batch)
vsock_sk(sk)->default_write_space(sk);
release_sock(sk);
+
+ if (data_ready_pending)
+ vsock_sk(sk)->default_data_ready(sk);
+
sock_put(sk);
}
EXPORT_SYMBOL_GPL(virtio_transport_rx_batch_finish);
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-10-13 6:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-13 6:31 [PATCH net-next v3 0/4] vsock/virtio: reduce RX per-packet socket overhead Jia Jia
2026-10-13 6:31 ` [PATCH net-next v3 1/4] vsock/virtio: split socket lookup from locked RX processing Jia Jia
2026-10-13 6:31 ` [PATCH net-next v3 2/4] vsock/virtio: amortize RX socket locking for stream packets Jia Jia
2026-10-13 6:31 ` [PATCH net-next v3 3/4] vsock/virtio: coalesce RX write-space notifications in lock batches Jia Jia
2026-10-13 6:31 ` [PATCH net-next v3 4/4] vsock/virtio: defer RX readable notifications until batch unlock Jia Jia
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox