On Tue, Mar 05, 2024 at 12:22:00PM -0800, Yonghong Song wrote: SNIP > + > +int bpf_skmsg_link_create(const union bpf_attr *attr, struct bpf_prog *prog) > +{ > + struct bpf_link_primer link_primer; > + struct bpf_skmsg_link *skmsg_link; > + enum bpf_attach_type attach_type; > + struct bpf_map *map; > + int ret; > + > + if (attr->link_create.flags) > + return -EINVAL; > + > + map = bpf_map_get_with_uref(attr->link_create.target_fd); > + if (IS_ERR(map)) > + return PTR_ERR(map); > + > + skmsg_link = kzalloc(sizeof(*skmsg_link), GFP_USER); > + if (!skmsg_link) { > + ret = -ENOMEM; > + goto out; > + } > + > + attach_type = attr->link_create.attach_type; > + bpf_link_init(&skmsg_link->link, BPF_LINK_TYPE_SK_MSG, &bpf_skmsg_link_ops, prog); > + skmsg_link->map = map; > + skmsg_link->attach_type = attach_type; > + > + ret = bpf_link_prime(&skmsg_link->link, &link_primer); > + if (ret) { > + kfree(skmsg_link); > + goto out; > + } > + > + ret = sock_map_prog_update(map, prog, NULL, attach_type); > + if (ret) { > + bpf_link_cleanup(&link_primer); > + goto out; > + } > + > + bpf_prog_inc(prog); there's already prog ref taken in link_create, is this needed? also I might be missing some skmsg logic, but I can't see thi being released jirka > + > + return bpf_link_settle(&link_primer); > + > +out: > + bpf_map_put_with_uref(map); > + return ret; > +} > diff --git a/net/core/sock_map.c b/net/core/sock_map.c > index 27d733c0f65e..63372bc368f1 100644 > --- a/net/core/sock_map.c > +++ b/net/core/sock_map.c > @@ -24,8 +24,6 @@ struct bpf_stab { > #define SOCK_CREATE_FLAG_MASK \ > (BPF_F_NUMA_NODE | BPF_F_RDONLY | BPF_F_WRONLY) > > -static int sock_map_prog_update(struct bpf_map *map, struct bpf_prog *prog, > - struct bpf_prog *old, u32 which); > static struct sk_psock_progs *sock_map_progs(struct bpf_map *map); > > static struct bpf_map *sock_map_alloc(union bpf_attr *attr) > @@ -1488,8 +1486,8 @@ static int sock_map_prog_lookup(struct bpf_map *map, struct bpf_prog ***pprog, > return 0; > } > > -static int sock_map_prog_update(struct bpf_map *map, struct bpf_prog *prog, > - struct bpf_prog *old, u32 which) > +int sock_map_prog_update(struct bpf_map *map, struct bpf_prog *prog, > + struct bpf_prog *old, u32 which) > { > struct bpf_prog **pprog; > int ret; > diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h > index a241f407c234..c7d2a5fcf37a 100644 > --- a/tools/include/uapi/linux/bpf.h > +++ b/tools/include/uapi/linux/bpf.h > @@ -1129,6 +1129,7 @@ enum bpf_link_type { > BPF_LINK_TYPE_TCX = 11, > BPF_LINK_TYPE_UPROBE_MULTI = 12, > BPF_LINK_TYPE_NETKIT = 13, > + BPF_LINK_TYPE_SK_MSG = 14, > __MAX_BPF_LINK_TYPE, > }; > > @@ -6699,6 +6700,10 @@ struct bpf_link_info { > __u32 ifindex; > __u32 attach_type; > } netkit; > + struct { > + __u32 map_id; > + __u32 attach_type; > + } skmsg; > }; > } __attribute__((aligned(8))); > > -- > 2.43.0 > >