net/vmw_vsock/vsock_bpf.c
Source file repositories/reference/linux-study-clean/net/vmw_vsock/vsock_bpf.c
File Facts
- System
- Linux kernel
- Corpus path
net/vmw_vsock/vsock_bpf.c- Extension
.c- Size
- 4129 bytes
- Lines
- 176
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bpf.hlinux/module.hlinux/skmsg.hlinux/socket.hlinux/wait.hnet/af_vsock.hnet/sock.h
Detected Declarations
function vsock_has_datafunction vsock_msg_wait_datafunction __vsock_recvmsgfunction vsock_bpf_recvmsgfunction vsock_bpf_rebuild_protosfunction vsock_bpf_check_needs_rebuildfunction vsock_bpf_update_protofunction vsock_bpf_build_proto
Annotated Snippet
if (!vsock_msg_wait_data(sk, psock, timeo)) {
copied = -EAGAIN;
break;
}
if (sk_psock_queue_empty(psock)) {
release_sock(sk);
sk_psock_put(sk, psock);
return __vsock_recvmsg(sk, msg, len, flags);
}
copied = sk_msg_recvmsg(sk, psock, msg, len, flags);
}
out:
release_sock(sk);
sk_psock_put(sk, psock);
return copied;
}
static void vsock_bpf_rebuild_protos(struct proto *prot, const struct proto *base)
{
*prot = *base;
prot->close = sock_map_close;
prot->recvmsg = vsock_bpf_recvmsg;
prot->sock_is_readable = sk_msg_is_readable;
}
static void vsock_bpf_check_needs_rebuild(struct proto *ops)
{
/* Paired with the smp_store_release() below. */
if (unlikely(ops != smp_load_acquire(&vsock_prot_saved))) {
spin_lock_bh(&vsock_prot_lock);
if (likely(ops != vsock_prot_saved)) {
vsock_bpf_rebuild_protos(&vsock_bpf_prot, ops);
/* Make sure proto function pointers are updated before publishing the
* pointer to the struct.
*/
smp_store_release(&vsock_prot_saved, ops);
}
spin_unlock_bh(&vsock_prot_lock);
}
}
int vsock_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore)
{
struct vsock_sock *vsk;
if (restore) {
sk->sk_write_space = psock->saved_write_space;
sock_replace_proto(sk, psock->sk_proto);
return 0;
}
vsk = vsock_sk(sk);
if (!vsk->transport)
return -ENODEV;
if (!vsk->transport->read_skb)
return -EOPNOTSUPP;
vsock_bpf_check_needs_rebuild(psock->sk_proto);
sock_replace_proto(sk, &vsock_bpf_prot);
return 0;
}
void __init vsock_bpf_build_proto(void)
{
vsock_bpf_rebuild_protos(&vsock_bpf_prot, &vsock_proto);
}
Annotation
- Immediate include surface: `linux/bpf.h`, `linux/module.h`, `linux/skmsg.h`, `linux/socket.h`, `linux/wait.h`, `net/af_vsock.h`, `net/sock.h`.
- Detected declarations: `function vsock_has_data`, `function vsock_msg_wait_data`, `function __vsock_recvmsg`, `function vsock_bpf_recvmsg`, `function vsock_bpf_rebuild_protos`, `function vsock_bpf_check_needs_rebuild`, `function vsock_bpf_update_proto`, `function vsock_bpf_build_proto`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source 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.