Re: [PATCH bpf-next v5 2/7] bpf: Support associating BPF program with struct_ops

Martin KaFai Lau
2025-11-06T00:57:50Z

On 11/4/25 9:26 AM, Amery Hung wrote:
> +void *bpf_prog_get_assoc_struct_ops(const struct bpf_prog_aux *aux)
> +{
> + struct bpf_map *st_ops_assoc = READ_ONCE(aux->st_ops_assoc);
> + struct bpf_struct_ops_map *st_map;
> +
> + if (!st_ops_assoc || st_ops_assoc == BPF_PTR_POISON)
> + return NULL;
> +
> + st_map = (struct bpf_struct_ops_map *)st_ops_assoc;
> +
> + if (smp_load_acquire(&st_map->kvalue.common.state) == BPF_STRUCT_OPS_STATE_INIT) {
> + bpf_map_put(st_ops_assoc);

hmm... why bpf_map_put is needed?

Should the state be checked only once during assoc time instead of
checking it every time bpf_prog_get_assoc_struct_ops is called?

> + return NULL;
> + }
> +
> + return &st_map->kvalue.data;
> +}