drivers/net/netdevsim/bpf.c
Source file repositories/reference/linux-study-clean/drivers/net/netdevsim/bpf.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/netdevsim/bpf.c- Extension
.c- Size
- 15936 bytes
- Lines
- 655
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- 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/bpf_verifier.hlinux/debugfs.hlinux/kernel.hlinux/mutex.hlinux/rtnetlink.hnet/pkt_cls.hnetdevsim.h
Detected Declarations
struct nsim_bpf_bound_progstruct nsim_bpf_bound_mapstruct nsim_map_entryfunction nsim_bpf_string_showfunction nsim_bpf_verify_insnfunction nsim_bpf_finalizefunction nsim_xdp_offload_activefunction nsim_prog_set_loadedfunction nsim_bpf_offloadfunction nsim_bpf_setup_tc_block_cbfunction nsim_bpf_disable_tcfunction nsim_xdp_offload_progfunction nsim_xdp_set_progfunction nsim_bpf_create_progfunction nsim_bpf_verifier_prepfunction nsim_bpf_translatefunction nsim_bpf_destroy_progfunction nsim_setup_prog_checksfunction nsim_setup_prog_hw_checksfunction nsim_map_key_matchfunction nsim_map_key_findfunction nsim_map_alloc_elemfunction nsim_map_get_next_keyfunction nsim_map_lookup_elemfunction nsim_map_update_elemfunction nsim_map_delete_elemfunction nsim_bpf_map_allocfunction nsim_bpf_map_freefunction nsim_bpffunction nsim_bpf_dev_initfunction nsim_bpf_dev_exitfunction nsim_bpf_initfunction nsim_bpf_uninit
Annotated Snippet
struct nsim_bpf_bound_prog {
struct nsim_dev *nsim_dev;
struct bpf_prog *prog;
struct dentry *ddir;
const char *state;
bool is_loaded;
struct list_head l;
};
#define NSIM_BPF_MAX_KEYS 2
struct nsim_bpf_bound_map {
struct netdevsim *ns;
struct bpf_offloaded_map *map;
struct mutex mutex;
struct nsim_map_entry {
void *key;
void *value;
} entry[NSIM_BPF_MAX_KEYS];
struct list_head l;
};
static int nsim_bpf_string_show(struct seq_file *file, void *data)
{
const char **str = file->private;
if (*str)
seq_printf(file, "%s\n", *str);
return 0;
}
DEFINE_SHOW_ATTRIBUTE(nsim_bpf_string);
static int
nsim_bpf_verify_insn(struct bpf_verifier_env *env, int insn_idx, int prev_insn)
{
struct nsim_bpf_bound_prog *state;
int ret = 0;
state = env->prog->aux->offload->dev_priv;
if (state->nsim_dev->bpf_bind_verifier_delay && !insn_idx)
msleep(state->nsim_dev->bpf_bind_verifier_delay);
if (insn_idx == env->prog->len - 1) {
pr_vlog(env, "Hello from netdevsim!\n");
if (!state->nsim_dev->bpf_bind_verifier_accept)
ret = -EOPNOTSUPP;
}
return ret;
}
static int nsim_bpf_finalize(struct bpf_verifier_env *env)
{
return 0;
}
static bool nsim_xdp_offload_active(struct netdevsim *ns)
{
return ns->xdp_hw.prog;
}
static void nsim_prog_set_loaded(struct bpf_prog *prog, bool loaded)
{
struct nsim_bpf_bound_prog *state;
if (!prog || !bpf_prog_is_offloaded(prog->aux))
return;
state = prog->aux->offload->dev_priv;
state->is_loaded = loaded;
}
static int
nsim_bpf_offload(struct netdevsim *ns, struct bpf_prog *prog, bool oldprog)
{
nsim_prog_set_loaded(ns->bpf_offloaded, false);
WARN(!!ns->bpf_offloaded != oldprog,
"bad offload state, expected offload %sto be active",
oldprog ? "" : "not ");
ns->bpf_offloaded = prog;
ns->bpf_offloaded_id = prog ? prog->aux->id : 0;
nsim_prog_set_loaded(prog, true);
return 0;
}
int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type,
Annotation
- Immediate include surface: `linux/bpf.h`, `linux/bpf_verifier.h`, `linux/debugfs.h`, `linux/kernel.h`, `linux/mutex.h`, `linux/rtnetlink.h`, `net/pkt_cls.h`, `netdevsim.h`.
- Detected declarations: `struct nsim_bpf_bound_prog`, `struct nsim_bpf_bound_map`, `struct nsim_map_entry`, `function nsim_bpf_string_show`, `function nsim_bpf_verify_insn`, `function nsim_bpf_finalize`, `function nsim_xdp_offload_active`, `function nsim_prog_set_loaded`, `function nsim_bpf_offload`, `function nsim_bpf_setup_tc_block_cb`.
- Atlas domain: Driver Families / drivers/net.
- 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.