net/vmw_vsock/virtio_transport_common.c
Source file repositories/reference/linux-study-clean/net/vmw_vsock/virtio_transport_common.c
File Facts
- System
- Linux kernel
- Corpus path
net/vmw_vsock/virtio_transport_common.c- Extension
.c- Size
- 45432 bytes
- Lines
- 1817
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/spinlock.hlinux/module.hlinux/sched/signal.hlinux/ctype.hlinux/list.hlinux/virtio_vsock.huapi/linux/vsockmon.hnet/sock.hnet/af_vsock.htrace/events/vsock_virtio_transport_common.h
Detected Declarations
function virtio_transport_get_opsfunction virtio_transport_can_zcopyfunction virtio_transport_fill_skbfunction virtio_transport_init_hdrfunction virtio_transport_deliver_tap_pktfunction virtio_transport_get_typefunction virtio_transport_send_pkt_infofunction skb_zcopy_setfunction virtio_transport_inc_rx_pktfunction virtio_transport_dec_rx_pktfunction virtio_transport_inc_tx_pktfunction virtio_transport_consume_skb_sentfunction virtio_transport_get_creditfunction virtio_transport_put_creditfunction virtio_transport_send_credit_updatefunction virtio_transport_stream_do_peekfunction skb_queue_walkfunction virtio_transport_stream_do_dequeuefunction virtio_transport_seqpacket_do_peekfunction skb_queue_walkfunction virtio_transport_seqpacket_do_dequeuefunction virtio_transport_stream_dequeuefunction virtio_transport_seqpacket_dequeuefunction virtio_transport_tx_buf_sizefunction virtio_transport_seqpacket_enqueuefunction virtio_transport_dgram_dequeuefunction virtio_transport_stream_has_datafunction virtio_transport_seqpacket_has_datafunction virtio_transport_has_spacefunction virtio_transport_stream_has_spacefunction virtio_transport_do_socket_initfunction virtio_transport_notify_buffer_sizefunction virtio_transport_notify_poll_infunction virtio_transport_notify_poll_outfunction virtio_transport_notify_recv_initfunction virtio_transport_notify_recv_pre_blockfunction virtio_transport_notify_recv_pre_dequeuefunction virtio_transport_notify_recv_post_dequeuefunction virtio_transport_notify_send_initfunction virtio_transport_notify_send_pre_blockfunction virtio_transport_notify_send_pre_enqueuefunction virtio_transport_notify_send_post_enqueuefunction virtio_transport_stream_rcvhiwatfunction virtio_transport_stream_is_activefunction virtio_transport_dgram_bindfunction virtio_transport_dgram_allowfunction virtio_transport_connectfunction virtio_transport_shutdown
Annotated Snippet
if (!uarg) {
uarg = msg_zerocopy_realloc(sk_vsock(vsk),
pkt_len, NULL, false);
if (!uarg) {
virtio_transport_put_credit(vvs, pkt_len);
return -ENOMEM;
}
if (!can_zcopy)
uarg_to_msgzc(uarg)->zerocopy = 0;
have_uref = true;
}
}
}
rest_len = pkt_len;
do {
struct sk_buff *skb;
size_t skb_len;
skb_len = min(max_skb_len, rest_len);
skb = virtio_transport_alloc_skb(info, skb_len, can_zcopy,
uarg,
src_cid, src_port,
dst_cid, dst_port);
if (!skb) {
ret = -ENOMEM;
break;
}
virtio_transport_inc_tx_pkt(vvs, skb);
ret = t_ops->send_pkt(skb, info->net);
if (ret < 0)
break;
/* Both virtio and vhost 'send_pkt()' returns 'skb_len',
* but for reliability use 'ret' instead of 'skb_len'.
* Also if partial send happens (e.g. 'ret' != 'skb_len')
* somehow, we break this loop, but account such returned
* value in 'virtio_transport_put_credit()'.
*/
rest_len -= ret;
if (WARN_ONCE(ret != skb_len,
"'send_pkt()' returns %i, but %zu expected\n",
ret, skb_len))
break;
} while (rest_len);
virtio_transport_put_credit(vvs, rest_len);
/* msg_zerocopy_realloc() initializes the ubuf_info refcnt to 1.
* skb_zcopy_set() increases it for each skb, so we can drop that
* initial reference to keep it balanced.
*/
if (have_uref) {
if (rest_len == pkt_len)
/* No data sent, abort the notification. */
net_zcopy_put_abort(uarg, true);
else
net_zcopy_put(uarg);
}
/* Return number of bytes, if any data has been sent. */
if (rest_len != pkt_len)
ret = pkt_len - rest_len;
return ret;
}
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
* peer is respecting the credit, and sk_buff overhead to bound
* queue growth.
*/
if ((u64)vvs->buf_used + len > vvs->buf_alloc ||
skb_overhead > vvs->buf_alloc)
return false;
vvs->rx_bytes += len;
Annotation
- Immediate include surface: `linux/spinlock.h`, `linux/module.h`, `linux/sched/signal.h`, `linux/ctype.h`, `linux/list.h`, `linux/virtio_vsock.h`, `uapi/linux/vsockmon.h`, `net/sock.h`.
- Detected declarations: `function virtio_transport_get_ops`, `function virtio_transport_can_zcopy`, `function virtio_transport_fill_skb`, `function virtio_transport_init_hdr`, `function virtio_transport_deliver_tap_pkt`, `function virtio_transport_get_type`, `function virtio_transport_send_pkt_info`, `function skb_zcopy_set`, `function virtio_transport_inc_rx_pkt`, `function virtio_transport_dec_rx_pkt`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.