net/bpf/test_run.c
Source file repositories/reference/linux-study-clean/net/bpf/test_run.c
File Facts
- System
- Linux kernel
- Corpus path
net/bpf/test_run.c- Extension
.c- Size
- 45666 bytes
- Lines
- 1915
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/bpf.hlinux/btf.hlinux/btf_ids.hlinux/slab.hlinux/init.hlinux/vmalloc.hlinux/etherdevice.hlinux/filter.hlinux/rcupdate_trace.hlinux/sched/signal.hnet/bpf_sk_storage.hnet/hotdata.hnet/sock.hnet/tcp.hnet/net_namespace.hnet/page_pool/helpers.hlinux/error-injection.hlinux/smp.hlinux/sock_diag.hlinux/netfilter.hnet/netdev_rx_queue.hnet/xdp.hnet/netfilter/nf_bpf_link.htrace/events/bpf_test_run.h
Detected Declarations
struct bpf_test_timerstruct xdp_page_headstruct xdp_test_datastruct bpf_fentry_test_tstruct prog_test_member1struct prog_test_memberstruct prog_test_ref_kfuncstruct bpf_raw_tp_test_run_infofunction bpf_test_timer_enterfunction bpf_test_timer_leavefunction bpf_test_timer_continuefunction xdp_test_run_init_pagefunction xdp_test_run_setupfunction xdp_test_run_teardownfunction frame_was_changedfunction ctx_was_changedfunction reset_ctxfunction xdp_recv_framesfunction xdp_test_run_batchfunction bpf_test_run_xdp_livefunction bpf_test_runfunction for_each_cgroup_storage_typefunction bpf_test_finishfunction bpf_fentry_test1function bpf_fentry_test2function bpf_fentry_test3function bpf_fentry_test4function bpf_fentry_test5function bpf_fentry_test6function bpf_fentry_test7function bpf_fentry_test8function bpf_fentry_test9function bpf_fentry_test10function bpf_fentry_test_sinfofunction bpf_modify_return_testfunction bpf_modify_return_test2function bpf_modify_return_test_tpfunction bpf_fentry_shadow_testfunction bpf_kfunc_call_test_releasefunction bpf_kfunc_call_test_release_dtorfunction bpf_kfunc_call_memb_releasefunction bpf_prog_test_run_tracingfunction __bpf_prog_test_run_raw_tpfunction bpf_prog_test_run_raw_tpfunction bpf_ctx_finishfunction range_is_zerofunction convert___skb_to_skbfunction convert_skb_to___skb
Annotated Snippet
struct bpf_test_timer {
u32 i;
u64 time_start, time_spent;
};
static void bpf_test_timer_enter(struct bpf_test_timer *t)
__acquires(rcu)
{
rcu_read_lock_dont_migrate();
t->time_start = ktime_get_ns();
}
static void bpf_test_timer_leave(struct bpf_test_timer *t)
__releases(rcu)
{
t->time_start = 0;
rcu_read_unlock_migrate();
}
static bool bpf_test_timer_continue(struct bpf_test_timer *t, int iterations,
u32 repeat, int *err, u32 *duration)
__must_hold(rcu)
{
t->i += iterations;
if (t->i >= repeat) {
/* We're done. */
t->time_spent += ktime_get_ns() - t->time_start;
do_div(t->time_spent, t->i);
*duration = t->time_spent > U32_MAX ? U32_MAX : (u32)t->time_spent;
*err = 0;
goto reset;
}
if (signal_pending(current)) {
/* During iteration: we've been cancelled, abort. */
*err = -EINTR;
goto reset;
}
if (need_resched()) {
/* During iteration: we need to reschedule between runs. */
t->time_spent += ktime_get_ns() - t->time_start;
bpf_test_timer_leave(t);
cond_resched();
bpf_test_timer_enter(t);
}
/* Do another round. */
return true;
reset:
t->i = 0;
return false;
}
/* We put this struct at the head of each page with a context and frame
* initialised when the page is allocated, so we don't have to do this on each
* repetition of the test run.
*/
struct xdp_page_head {
struct xdp_buff orig_ctx;
struct xdp_buff ctx;
union {
/* ::data_hard_start starts here */
DECLARE_FLEX_ARRAY(struct xdp_frame, frame);
DECLARE_FLEX_ARRAY(u8, data);
};
};
struct xdp_test_data {
struct xdp_buff *orig_ctx;
struct xdp_rxq_info rxq;
struct net_device *dev;
struct page_pool *pp;
struct xdp_frame **frames;
struct sk_buff **skbs;
struct xdp_mem_info mem;
u32 batch_size;
u32 frame_cnt;
};
/* tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c:%MAX_PKT_SIZE
* must be updated accordingly this gets changed, otherwise BPF selftests
* will fail.
*/
#define TEST_XDP_FRAME_SIZE (PAGE_SIZE - sizeof(struct xdp_page_head))
#define TEST_XDP_MAX_BATCH 256
static void xdp_test_run_init_page(netmem_ref netmem, void *arg)
{
Annotation
- Immediate include surface: `linux/bpf.h`, `linux/btf.h`, `linux/btf_ids.h`, `linux/slab.h`, `linux/init.h`, `linux/vmalloc.h`, `linux/etherdevice.h`, `linux/filter.h`.
- Detected declarations: `struct bpf_test_timer`, `struct xdp_page_head`, `struct xdp_test_data`, `struct bpf_fentry_test_t`, `struct prog_test_member1`, `struct prog_test_member`, `struct prog_test_ref_kfunc`, `struct bpf_raw_tp_test_run_info`, `function bpf_test_timer_enter`, `function bpf_test_timer_leave`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.