STRUCT BPF_STRUCT_OPS(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… struct bpf_struct_ops πŸ’…

okay so welcome to the Kernel API Manual page for struct bpf_struct_ops(9) β€” yes bestie, this is that struct. It's literally a structure of callbacks that lets a subsystem define a BPF_MAP_TYPE_STRUCT_OPS map type made up of BPF_PROG_TYPE_STRUCT_OPS progs. iconic behavior, no cap 🫢

✨ NAME ✨

struct bpf_struct_ops β€” a structure of callbacks allowing a subsystem to define a BPF_MAP_TYPE_STRUCT_OPS map type composed of BPF_PROG_TYPE_STRUCT_OPS progs. πŸ’–

🌸 SYNOPSIS 🌸

struct bpf_struct_ops {
    const struct bpf_verifier_ops *verifier_ops;
    int (*init)(struct btf *btf);
    int (*check_member)(const struct btf_type *t, const struct btf_member *member, const struct bpf_prog *prog);
    int (*init_member)(const struct btf_type *t, const struct btf_member *member, void *kdata, const void *udata);
    int (*reg)(void *kdata, struct bpf_link *link);
    void (*unreg)(void *kdata, struct bpf_link *link);
    int (*update)(void *kdata, void *old_kdata, struct bpf_link *link);
    int (*validate)(void *kdata);
    void *cfi_stubs;
    struct module *owner;
    const char *name;
    struct btf_func_model func_models[BPF_STRUCT_OPS_MAX_NR_MEMBERS];
};

πŸ’– Members πŸ’–

  • verifier_ops β€” a structure of callbacks that are invoked by the verifier when it's determining whether the struct_ops progs in the struct_ops map are valid. verifier vibe check, literally πŸ’…
  • init β€” a callback that is invoked a single time, and before any other callback, to initialize the structure. A nonzero return value means the subsystem could not be initialized. first one in, no cap ✨
  • check_member β€” when defined, a callback invoked by the verifier to allow the subsystem to determine if an entry in the struct_ops map is valid. A nonzero return value means that the map is invalid and should be rejected by the verifier. reject the map, periodt 🚫
  • init_member β€” a callback that is invoked for each member of the struct_ops map to allow the subsystem to initialize the member. A nonzero value means the member could not be initialized. This callback is exclusive with the type, type_id, value_type, and value_id fields. mutually exclusive bestie, don't mix 😭
  • reg β€” a callback that is invoked when the struct_ops map has been initialized and is being attached to. Zero means the struct_ops map has been successfully registered and is live. A nonzero return value means the struct_ops map could not be registered. live and registered, slay βœ…
  • unreg β€” a callback that is invoked when the struct_ops map should be unregistered. time to say bye πŸ‘‹
  • update β€” a callback that is invoked when the live struct_ops map is being updated to contain new values. This callback is only invoked when the struct_ops map is loaded with BPF_F_LINK. If not defined, it is assumed that the struct_ops map cannot be updated. only with BPF_F_LINK, iykyk πŸ”₯
  • validate β€” a callback that is invoked after all of the members have been initialized. This callback should perform static checks on the map, meaning that it should either fail or succeed deterministically. A struct_ops map that has been validated may not necessarily succeed in being registered if the call to reg fails. For example, a valid struct_ops map may be loaded, but then fail to be registered due to there being another active struct_ops map on the system in the subsystem already. For this reason, if this callback is not defined, the check is skipped as the struct_ops map will have final verification performed in reg. deterministic checks only, no chaotic energy 🧚
  • cfi_stubs β€” pointer to a structure of stub functions for CFI. These stubs provide the correct Control Flow Integrity hashes for the trampolines generated by BPF struct_ops. CFI stubs giving correct hashes πŸ”
  • owner β€” the module that owns this struct_ops. Used for module reference counting to ensure the module providing the struct_ops cannot be unloaded while in use. keeps the module pinned, no unload-while-in-use drama 🫢
  • name β€” the name of the struct bpf_struct_ops object. name reveal πŸ’«
  • func_models β€” func models. that's the note, bestie πŸ“

πŸ”Ž SEE ALSO πŸ”Ž

  • Kernel file ./include/linux/bpf.h β€” go read it if you want the deep lore πŸ“–

xoxo, your struct_ops bestie πŸ’– β€” from ./include/linux, source/version October 2026, all about struct bpf_struct_ops(9) 🫢

πŸ“¦ where this page comes from