net/xdp/xsk_buff_pool.c
Source file repositories/reference/linux-study-clean/net/xdp/xsk_buff_pool.c
File Facts
- System
- Linux kernel
- Corpus path
net/xdp/xsk_buff_pool.c- Extension
.c- Size
- 17490 bytes
- Lines
- 781
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/netdevice.hnet/netdev_lock.hnet/xsk_buff_pool.hnet/xdp_sock.hnet/xdp_sock_drv.hxsk_queue.hxdp_umem.hxsk.h
Detected Declarations
function xp_add_xskfunction xp_del_xskfunction xp_destroyfunction xp_alloc_tx_descsfunction xp_set_rxq_infofunction xp_fill_cbfunction xp_disable_drv_zcfunction xp_assign_devfunction xp_assign_dev_sharedfunction xp_clear_devfunction xp_release_deferredfunction xp_get_poolfunction xp_put_poolfunction list_for_each_entryfunction xp_destroy_dma_mapfunction __xp_dma_unmapfunction xp_dma_unmapfunction xp_check_dma_contiguityfunction xp_init_dma_infofunction xp_dma_mapfunction xp_addr_crosses_non_contig_pgfunction xp_check_unalignedfunction xp_check_alignedfunction xp_alloc_new_from_fqfunction xp_alloc_reusedfunction xp_alloc_slowfunction xp_alloc_batchfunction xp_can_allocfunction xp_freefunction __xp_raw_get_addrfunction __xp_raw_get_dmafunction xp_raw_get_dmafunction xp_raw_get_ctxexport xp_set_rxq_infoexport xp_fill_cbexport xp_dma_unmapexport xp_dma_mapexport xp_allocexport xp_alloc_batchexport xp_can_allocexport xp_freeexport xp_raw_get_dataexport xp_raw_get_dmaexport xp_raw_get_ctx
Annotated Snippet
if (segs == 1) {
err = -EOPNOTSUPP;
goto err_unreg_pool;
}
} else {
segs = 1;
}
/* open-code xsk_pool_get_rx_frame_size() as pool->dev is not
* set yet at this point; we are before getting down to driver
*/
frame_size = __xsk_pool_get_rx_frame_size(pool) -
xsk_pool_get_tailroom(mbuf);
frame_size = ALIGN_DOWN(frame_size, 128);
if (needed > frame_size * segs) {
err = -EINVAL;
goto err_unreg_pool;
}
if (dev_get_min_mp_channel_count(netdev)) {
err = -EBUSY;
goto err_unreg_pool;
}
bpf.command = XDP_SETUP_XSK_POOL;
bpf.xsk.pool = pool;
bpf.xsk.queue_id = queue_id;
netdev_assert_locked_ops_compat(netdev);
err = netdev->netdev_ops->ndo_bpf(netdev, &bpf);
if (err)
goto err_unreg_pool;
if (!pool->dma_pages) {
WARN(1, "Driver did not DMA map zero-copy buffers");
err = -EINVAL;
goto err_unreg_xsk;
}
pool->umem->zc = true;
pool->xdp_zc_max_segs = netdev->xdp_zc_max_segs;
return 0;
err_unreg_xsk:
xp_disable_drv_zc(pool);
err_unreg_pool:
if (!force_zc)
err = 0; /* fallback to copy mode */
if (err) {
xsk_clear_pool_at_qid(netdev, queue_id);
dev_put(netdev);
}
return err;
}
int xp_assign_dev_shared(struct xsk_buff_pool *pool, struct xdp_sock *umem_xs,
struct net_device *dev, u16 queue_id)
{
u16 flags;
struct xdp_umem *umem = umem_xs->umem;
flags = umem->zc ? XDP_ZEROCOPY : XDP_COPY;
if (umem->flags & XDP_UMEM_SG_FLAG)
flags |= XDP_USE_SG;
if (umem_xs->pool->uses_need_wakeup)
flags |= XDP_USE_NEED_WAKEUP;
return xp_assign_dev(pool, dev, queue_id, flags);
}
void xp_clear_dev(struct xsk_buff_pool *pool)
{
struct net_device *netdev = pool->netdev;
if (!pool->netdev)
return;
netdev_lock_ops(netdev);
xp_disable_drv_zc(pool);
xsk_clear_pool_at_qid(pool->netdev, pool->queue_id);
pool->netdev = NULL;
netdev_unlock_ops(netdev);
dev_put(netdev);
}
static void xp_release_deferred(struct work_struct *work)
{
struct xsk_buff_pool *pool = container_of(work, struct xsk_buff_pool,
Annotation
- Immediate include surface: `linux/netdevice.h`, `net/netdev_lock.h`, `net/xsk_buff_pool.h`, `net/xdp_sock.h`, `net/xdp_sock_drv.h`, `xsk_queue.h`, `xdp_umem.h`, `xsk.h`.
- Detected declarations: `function xp_add_xsk`, `function xp_del_xsk`, `function xp_destroy`, `function xp_alloc_tx_descs`, `function xp_set_rxq_info`, `function xp_fill_cb`, `function xp_disable_drv_zc`, `function xp_assign_dev`, `function xp_assign_dev_shared`, `function xp_clear_dev`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.