Add attach_type in bpf_link
Subsystems (13)
v2 cover Add attach_type in bpf_link
Andrii suggested moving the attach_type into bpf_link, the previous discussion is as follows:
https://lore.kernel.org/bpf/CAEf4BzY7TZRjxpCJM-+LYgEqe23YFj5Uv3isb7gat2-HU4OSng@mail.gmail.com
patch1 add attach_type in bpf_link, and pass it to bpf_link_init, which will init the attach_type field.
patch2-7 remove the attach_type in struct bpf_xx_link, update the info with bpf_link attach_type.
There are some functions finally call bpf_link_init but do not have bpf_attr from user or do not need to init attach_type from user like bpf_raw_tracepoint_open, now use prog->expected_attach_type to init attach_type.
bpf_struct_ops_map_update_elembpf_raw_tracepoint_openbpf_struct_ops_test_run
Feedback of any kind is welcome, thanks.
Tao Chen (7):
bpf: Add attach_type in bpf_link
bpf: Remove attach_type in bpf_cgroup_link
bpf: Remove attach_type in sockmap_link
bpf: Remove location field in tcx_link
bpf: Remove attach_type in bpf_netns_link
bpf: Remove attach_type in bpf_tracing_link
netkit: Remove location field in netkit_link
drivers/net/netkit.c | 10 ++++----- include/linux/bpf-cgroup.h | 1 - include/linux/bpf.h | 18 +++++++++------ include/net/tcx.h | 1 - kernel/bpf/bpf_iter.c | 3 ++- kernel/bpf/bpf_struct_ops.c | 5 +++-- kernel/bpf/cgroup.c | 17 +++++++-------- kernel/bpf/net_namespace.c | 8 +++---- kernel/bpf/syscall.c | 40 ++++++++++++++++++++-------------- kernel/bpf/tcx.c | 16 +++++++------- kernel/bpf/trampoline.c | 10 +++++---- kernel/trace/bpf_trace.c | 4 ++-- net/bpf/bpf_dummy_struct_ops.c | 3 ++- net/core/dev.c | 3 ++- net/core/sock_map.c | 13 +++++------ net/netfilter/nf_bpf_link.c | 3 ++- 16 files changed, 83 insertions(+), 72 deletions(-)
Change list:
v1 -> v2:
- fix build error.(Jiri)
v1:
- https://lore.kernel.org/bpf/[email protected]
Signature · 1 line
2.48.1
PATCH v2 1/7 bpf: Add attach_type in bpf_link
Attach_type will be set when link created from user, it is better to record attach_type in bpf_link directly suggested by Andrii.
--- drivers/net/netkit.c | 2 +- include/linux/bpf.h | 17 +++++++++++------ kernel/bpf/bpf_iter.c | 3 ++- kernel/bpf/bpf_struct_ops.c | 5 +++-- kernel/bpf/cgroup.c | 4 ++-- kernel/bpf/net_namespace.c | 2 +- kernel/bpf/syscall.c | 35 +++++++++++++++++++++------------- kernel/bpf/tcx.c | 3 ++- kernel/bpf/trampoline.c | 10 ++++++---- kernel/trace/bpf_trace.c | 4 ++-- net/bpf/bpf_dummy_struct_ops.c | 3 ++- net/core/dev.c | 3 ++- net/core/sock_map.c | 3 ++- net/netfilter/nf_bpf_link.c | 3 ++- 14 files changed, 60 insertions(+), 37 deletions(-)
drivers/net/netkit.c +1 -1
@@ -775,7 +775,7 @@ static int netkit_link_init(struct netkit_link *nkl, struct bpf_prog *prog) {bpf_link_init (&nkl->link,BPF_LINK_TYPE_NETKIT , - &netkit_link_lops, prog); + &netkit_link_lops, prog, attr->link_create.attach_type); nkl->location = attr->link_create.attach_type; nkl->dev = dev;return bpf_link_prime (&nkl->link, link_primer);
include/linux/bpf.h +11 -6
@@ -1735,6 +1735,8 @@ struct bpf_link {*/ bool sleepable;u32 flags; +enum bpf_attach_type attach_type; +/* rcu is used before freeing, work can be used to schedule that * RCU-based freeing before that, so they never overlap */
@@ -2034,11 +2036,13 @@ int bpf_prog_ctx_arg_info_init(struct bpf_prog *prog,#if defined(CONFIG_CGROUP_BPF ) && defined(CONFIG_BPF_LSM )int bpf_trampoline_link_cgroup_shim (struct bpf_prog *prog, -int cgroup_atype); +int cgroup_atype, +enum bpf_attach_type attach_type);void bpf_trampoline_unlink_cgroup_shim (struct bpf_prog *prog);#else static inline int bpf_trampoline_link_cgroup_shim (struct bpf_prog *prog, -int cgroup_atype) +int cgroup_atype, +enum bpf_attach_type attach_type) {return -EOPNOTSUPP ; }
@@ -2528,10 +2532,11 @@ int bpf_map_new_fd(struct bpf_map *map, int flags);int bpf_prog_new_fd (struct bpf_prog *prog);void bpf_link_init (struct bpf_link *link,enum bpf_link_type type, -const struct bpf_link_ops *ops,struct bpf_prog *prog); +const struct bpf_link_ops *ops,struct bpf_prog *prog, +enum bpf_attach_type attach_type);void bpf_link_init_sleepable (struct bpf_link *link,enum bpf_link_type type,const struct bpf_link_ops *ops,struct bpf_prog *prog, -bool sleepable); +bool sleepable,enum bpf_attach_type attach_type);int bpf_link_prime (struct bpf_link *link,struct bpf_link_primer *primer);int bpf_link_settle (struct bpf_link_primer *primer);void bpf_link_cleanup (struct bpf_link_primer *primer);
@@ -2883,13 +2888,13 @@ bpf_prog_inc_not_zero(struct bpf_prog *prog)static inline void bpf_link_init (struct bpf_link *link,enum bpf_link_type type,const struct bpf_link_ops *ops, -struct bpf_prog *prog) +struct bpf_prog *prog,enum bpf_attach_type attach_type) { }static inline void bpf_link_init_sleepable (struct bpf_link *link,enum bpf_link_type type,const struct bpf_link_ops *ops,struct bpf_prog *prog, -bool sleepable) +bool sleepable,enum bpf_attach_type attach_type) { }
kernel/bpf/bpf_iter.c +2 -1
@@ -552,7 +552,8 @@ int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,if (!link)return -ENOMEM ; -bpf_link_init (&link->link,BPF_LINK_TYPE_ITER , &bpf_iter_link_lops, prog); +bpf_link_init (&link->link,BPF_LINK_TYPE_ITER , &bpf_iter_link_lops, prog, + attr->link_create.attach_type); link->tinfo = tinfo; err =bpf_link_prime (&link->link, &link_primer);
kernel/bpf/bpf_struct_ops.c +3 -2
@@ -808,7 +808,7 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key, goto reset_unlock; }bpf_link_init (&link->link,BPF_LINK_TYPE_STRUCT_OPS , - &bpf_struct_ops_link_lops, prog); + &bpf_struct_ops_link_lops, prog, prog->expected_attach_type); *plink++ = &link->link; ksym =kzalloc (sizeof (*ksym),GFP_USER );
@@ -1351,7 +1351,8 @@ int bpf_struct_ops_link_create(union bpf_attr *attr) err = -ENOMEM ; goto err_out; } -bpf_link_init (&link->link,BPF_LINK_TYPE_STRUCT_OPS , &bpf_struct_ops_map_lops,NULL ); +bpf_link_init (&link->link,BPF_LINK_TYPE_STRUCT_OPS , &bpf_struct_ops_map_lops,NULL , + attr->link_create.attach_type); err =bpf_link_prime (&link->link, &link_primer);if (err)
kernel/bpf/cgroup.c +2 -2
@@ -867,7 +867,7 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp, cgrp->bpf.flags[atype] = saved_flags;if (type ==BPF_LSM_CGROUP ) { - err =bpf_trampoline_link_cgroup_shim (new_prog, atype); + err =bpf_trampoline_link_cgroup_shim (new_prog, atype, type);if (err) goto cleanup; }
@@ -1495,7 +1495,7 @@ int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) goto out_put_cgroup; }bpf_link_init (&link->link,BPF_LINK_TYPE_CGROUP , &bpf_cgroup_link_lops, - prog); + prog, attr->link_create.attach_type); link->cgroup = cgrp; link->type = attr->link_create.attach_type;
kernel/bpf/net_namespace.c +1 -1
@@ -501,7 +501,7 @@ int netns_bpf_link_create(const union bpf_attr *attr, struct bpf_prog *prog) goto out_put_net; }bpf_link_init (&net_link->link,BPF_LINK_TYPE_NETNS , - &bpf_netns_link_ops, prog); + &bpf_netns_link_ops, prog, type); net_link->net = net; net_link->type = type; net_link->netns_type = netns_type;
kernel/bpf/syscall.c +22 -13
@@ -3069,7 +3069,7 @@ static int bpf_obj_get(const union bpf_attr *attr)*/ void bpf_link_init_sleepable (struct bpf_link *link,enum bpf_link_type type,const struct bpf_link_ops *ops,struct bpf_prog *prog, -bool sleepable) +bool sleepable,enum bpf_attach_type attach_type) {WARN_ON (ops->dealloc && ops->dealloc_deferred);atomic64_set (&link->refcnt,1 );
@@ -3078,12 +3078,14 @@ void bpf_link_init_sleepable(struct bpf_link *link, enum bpf_link_type type, link->id =0 ; link->ops = ops; link->prog = prog; + link->attach_type = attach_type; }void bpf_link_init (struct bpf_link *link,enum bpf_link_type type, -const struct bpf_link_ops *ops,struct bpf_prog *prog) +const struct bpf_link_ops *ops,struct bpf_prog *prog, +enum bpf_attach_type attach_type) { -bpf_link_init_sleepable (link, type, ops, prog, false); +bpf_link_init_sleepable (link, type, ops, prog, false, attach_type); }static void bpf_link_free_id (int id)
@@ -3443,7 +3445,8 @@ static const struct bpf_link_ops bpf_tracing_link_lops = {static int bpf_tracing_prog_attach (struct bpf_prog *prog,int tgt_prog_fd,u32 btf_id, -u64 bpf_cookie) +u64 bpf_cookie, +enum bpf_attach_type attach_type) {struct bpf_link_primer link_primer;struct bpf_prog *tgt_prog =NULL ;
@@ -3511,7 +3514,8 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog, goto out_put_prog; }bpf_link_init (&link->link.link,BPF_LINK_TYPE_TRACING , - &bpf_tracing_link_lops, prog); + &bpf_tracing_link_lops, prog, attach_type); + link->attach_type = prog->expected_attach_type; link->link.cookie = bpf_cookie;
@@ -4049,7 +4053,8 @@ static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *pro err = -ENOMEM ; goto out_put_file; } -bpf_link_init (&link->link,BPF_LINK_TYPE_PERF_EVENT , &bpf_perf_link_lops, prog); +bpf_link_init (&link->link,BPF_LINK_TYPE_PERF_EVENT , &bpf_perf_link_lops, prog, + attr->link_create.attach_type); link->perf_file = perf_file; err =bpf_link_prime (&link->link, &link_primer);
@@ -4081,7 +4086,8 @@ static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *pro#endif /* CONFIG_PERF_EVENTS */ static int bpf_raw_tp_link_attach (struct bpf_prog *prog, -const char __user *user_tp_name,u64 cookie) +const char __user *user_tp_name,u64 cookie, +enum bpf_attach_type attach_type) {struct bpf_link_primer link_primer;struct bpf_raw_tp_link *link;
@@ -4104,7 +4110,7 @@ static int bpf_raw_tp_link_attach(struct bpf_prog *prog, tp_name = prog->aux->attach_func_name;break ; } -return bpf_tracing_prog_attach (prog,0 ,0 ,0 ); +return bpf_tracing_prog_attach (prog,0 ,0 ,0 , attach_type);case BPF_PROG_TYPE_RAW_TRACEPOINT :case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE :if (strncpy_from_user (buf, user_tp_name,sizeof (buf) -1 ) <0 )
@@ -4127,7 +4133,7 @@ static int bpf_raw_tp_link_attach(struct bpf_prog *prog, }bpf_link_init_sleepable (&link->link,BPF_LINK_TYPE_RAW_TRACEPOINT , &bpf_raw_tp_link_lops, prog, -tracepoint_is_faultable (btp->tp)); +tracepoint_is_faultable (btp->tp), attach_type); link->btp = btp; link->cookie = cookie;
@@ -4168,7 +4174,7 @@ static int bpf_raw_tracepoint_open(const union bpf_attr *attr) tp_name =u64_to_user_ptr (attr->raw_tracepoint.name); cookie = attr->raw_tracepoint.cookie; - fd =bpf_raw_tp_link_attach (prog, tp_name, cookie); + fd =bpf_raw_tp_link_attach (prog, tp_name, cookie, prog->expected_attach_type);if (fd <0 )bpf_prog_put (prog);return fd;
@@ -5536,7 +5542,8 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr) ret =bpf_tracing_prog_attach (prog, attr->link_create.target_fd, attr->link_create.target_btf_id, - attr->link_create.tracing.cookie); + attr->link_create.tracing.cookie, + attr->link_create.attach_type);break ;case BPF_PROG_TYPE_LSM :case BPF_PROG_TYPE_TRACING :
@@ -5545,7 +5552,8 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr) goto out; }if (prog->expected_attach_type ==BPF_TRACE_RAW_TP ) - ret =bpf_raw_tp_link_attach (prog,NULL , attr->link_create.tracing.cookie); + ret =bpf_raw_tp_link_attach (prog,NULL , attr->link_create.tracing.cookie, + attr->link_create.attach_type);else if (prog->expected_attach_type ==BPF_TRACE_ITER ) ret =bpf_iter_link_attach (attr, uattr, prog);else if (prog->expected_attach_type ==BPF_LSM_CGROUP )
@@ -5554,7 +5562,8 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr) ret =bpf_tracing_prog_attach (prog, attr->link_create.target_fd, attr->link_create.target_btf_id, - attr->link_create.tracing.cookie); + attr->link_create.tracing.cookie, + attr->link_create.attach_type);break ;case BPF_PROG_TYPE_FLOW_DISSECTOR :case BPF_PROG_TYPE_SK_LOOKUP :
kernel/bpf/tcx.c +2 -1
@@ -301,7 +301,8 @@ static int tcx_link_init(struct tcx_link *tcx,struct net_device *dev, struct bpf_prog *prog) { - bpf_link_init(&tcx->link, BPF_LINK_TYPE_TCX, &tcx_link_lops, prog); + bpf_link_init(&tcx->link, BPF_LINK_TYPE_TCX, &tcx_link_lops, prog, + attr->link_create.attach_type); tcx->location = attr->link_create.attach_type; tcx->dev = dev;return bpf_link_prime (&tcx->link, link_primer);
kernel/bpf/trampoline.c +6 -4
@@ -674,7 +674,8 @@ static const struct bpf_link_ops bpf_shim_tramp_link_lops = {static struct bpf_shim_tramp_link *cgroup_shim_alloc (const struct bpf_prog *prog,bpf_func_t bpf_func, -int cgroup_atype) +int cgroup_atype, +enum bpf_attach_type attach_type) {struct bpf_shim_tramp_link *shim_link =NULL ;struct bpf_prog *p;
@@ -701,7 +702,7 @@ static struct bpf_shim_tramp_link *cgroup_shim_alloc(const struct bpf_prog *prog p->expected_attach_type =BPF_LSM_MAC ;bpf_prog_inc (p);bpf_link_init (&shim_link->link.link,BPF_LINK_TYPE_UNSPEC , - &bpf_shim_tramp_link_lops, p); + &bpf_shim_tramp_link_lops, p, attach_type);bpf_cgroup_atype_get (p->aux->attach_btf_id, cgroup_atype);return shim_link;
@@ -726,7 +727,8 @@ static struct bpf_shim_tramp_link *cgroup_shim_find(struct bpf_trampoline *tr, }int bpf_trampoline_link_cgroup_shim (struct bpf_prog *prog, -int cgroup_atype) +int cgroup_atype, +enum bpf_attach_type attach_type) {struct bpf_shim_tramp_link *shim_link =NULL ;struct bpf_attach_target_info tgt_info = {};
@@ -763,7 +765,7 @@ int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog,/* Allocate and install new shim. */ - shim_link =cgroup_shim_alloc (prog, bpf_func, cgroup_atype); + shim_link =cgroup_shim_alloc (prog, bpf_func, cgroup_atype, attach_type);if (!shim_link) { err = -ENOMEM ; goto err;
kernel/trace/bpf_trace.c +2 -2
@@ -2986,7 +2986,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr }bpf_link_init (&link->link,BPF_LINK_TYPE_KPROBE_MULTI , - &bpf_kprobe_multi_link_lops, prog); + &bpf_kprobe_multi_link_lops, prog, attr->link_create.attach_type); err =bpf_link_prime (&link->link, &link_primer);if (err)
@@ -3441,7 +3441,7 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr link->link.flags = flags;bpf_link_init (&link->link,BPF_LINK_TYPE_UPROBE_MULTI , - &bpf_uprobe_multi_link_lops, prog); + &bpf_uprobe_multi_link_lops, prog, attr->link_create.attach_type);for (i =0 ; i < cnt; i++) { uprobes[i].uprobe = uprobe_register(d_real_inode(link->path.dentry),
net/bpf/bpf_dummy_struct_ops.c +2 -1
@@ -171,7 +171,8 @@ int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr, }/* prog doesn't take the ownership of the reference from caller */ bpf_prog_inc (prog); -bpf_link_init (&link->link,BPF_LINK_TYPE_STRUCT_OPS , &bpf_struct_ops_link_lops, prog); +bpf_link_init (&link->link,BPF_LINK_TYPE_STRUCT_OPS , &bpf_struct_ops_link_lops, prog, + prog->expected_attach_type); op_idx = prog->expected_attach_type; err = bpf_struct_ops_prepare_trampoline(tlinks, link,
net/core/dev.c +2 -1
@@ -10364,7 +10364,8 @@ int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) goto unlock; } -bpf_link_init (&link->link,BPF_LINK_TYPE_XDP , &bpf_xdp_link_lops, prog); +bpf_link_init (&link->link,BPF_LINK_TYPE_XDP , &bpf_xdp_link_lops, prog, + attr->link_create.attach_type); link->dev = dev; link->flags = attr->link_create.flags;
net/core/sock_map.c +2 -1
@@ -1866,7 +1866,8 @@ int sock_map_link_create(const union bpf_attr *attr, struct bpf_prog *prog) } attach_type = attr->link_create.attach_type; -bpf_link_init (&sockmap_link->link,BPF_LINK_TYPE_SOCKMAP , &sock_map_link_ops, prog); +bpf_link_init (&sockmap_link->link,BPF_LINK_TYPE_SOCKMAP , &sock_map_link_ops, prog, + attach_type); sockmap_link->map = map; sockmap_link->attach_type = attach_type;
net/netfilter/nf_bpf_link.c +2 -1
@@ -225,7 +225,8 @@ int bpf_nf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)if (!link)return -ENOMEM ; -bpf_link_init (&link->link,BPF_LINK_TYPE_NETFILTER , &bpf_nf_link_lops, prog); +bpf_link_init (&link->link,BPF_LINK_TYPE_NETFILTER , &bpf_nf_link_lops, prog, + attr->link_create.attach_type); link->hook_ops.hook = nf_hook_run_bpf; link->hook_ops.hook_ops_type =NF_HOOK_OP_BPF ;
Signature · 1 line
2.48.1
PATCH v2 2/7 bpf: Remove attach_type in bpf_cgroup_link
In reply to Tao ChenUse attach_type in bpf_link, and remove it in bpf_cgroup_link.
--- include/linux/bpf-cgroup.h | 1 - kernel/bpf/cgroup.c | 13 ++++++------- 2 files changed, 6 insertions(+), 8 deletions(-)
include/linux/bpf-cgroup.h +0 -1
@@ -103,7 +103,6 @@ struct bpf_cgroup_storage {struct bpf_cgroup_link {struct bpf_link link;struct cgroup *cgroup; -enum bpf_attach_type type; };struct bpf_prog_list {
kernel/bpf/cgroup.c +6 -7
@@ -984,7 +984,7 @@ static int __cgroup_bpf_replace(struct cgroup *cgrp,struct hlist_head *progs;bool found = false; - atype =bpf_cgroup_atype_find (link->type, new_prog->aux->attach_btf_id); + atype =bpf_cgroup_atype_find (link->link.attach_type, new_prog->aux->attach_btf_id);if (atype <0 )return -EINVAL ;
@@ -1396,8 +1396,8 @@ static void bpf_cgroup_link_release(struct bpf_link *link) }WARN_ON (__cgroup_bpf_detach (cg_link->cgroup,NULL , cg_link, - cg_link->type,0 )); -if (cg_link->type ==BPF_LSM_CGROUP ) + link->attach_type,0 )); +if (link->attach_type ==BPF_LSM_CGROUP )bpf_trampoline_unlink_cgroup_shim (cg_link->link.prog); cg = cg_link->cgroup;
@@ -1439,7 +1439,7 @@ static void bpf_cgroup_link_show_fdinfo(const struct bpf_link *link,"cgroup_id:\t%llu\n" "attach_type:\t%d\n" , cg_id, - cg_link->type); + link->attach_type); } static int bpf_cgroup_link_fill_link_info(const struct bpf_link *link,
@@ -1455,7 +1455,7 @@ static int bpf_cgroup_link_fill_link_info(const struct bpf_link *link,cgroup_unlock (); info->cgroup.cgroup_id = cg_id; - info->cgroup.attach_type = cg_link->type; + info->cgroup.attach_type = link->attach_type;return 0 ; }
@@ -1497,7 +1497,6 @@ int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)bpf_link_init (&link->link,BPF_LINK_TYPE_CGROUP , &bpf_cgroup_link_lops, prog, attr->link_create.attach_type); link->cgroup = cgrp; - link->type = attr->link_create.attach_type; err =bpf_link_prime (&link->link, &link_primer);if (err) {
@@ -1506,7 +1505,7 @@ int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) } err =cgroup_bpf_attach (cgrp,NULL ,NULL , link, - link->type,BPF_F_ALLOW_MULTI | attr->link_create.flags, + link->link.attach_type,BPF_F_ALLOW_MULTI | attr->link_create.flags, attr->link_create.cgroup.relative_fd, attr->link_create.cgroup.expected_revision);if (err) {
Signature · 1 line
2.48.1
PATCH v2 3/7 bpf: Remove attach_type in sockmap_link
In reply to Tao ChenUse attach_type in bpf_link, and remove it in sockmap_link.
--- net/core/sock_map.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
net/core/sock_map.c +4 -6
@@ -1709,7 +1709,6 @@ EXPORT_SYMBOL_GPL(sock_map_close);struct sockmap_link {struct bpf_link link;struct bpf_map *map; -enum bpf_attach_type attach_type; };static void sock_map_link_release (struct bpf_link *link)
@@ -1721,7 +1720,7 @@ static void sock_map_link_release(struct bpf_link *link) goto out;WARN_ON_ONCE (sock_map_prog_update (sockmap_link->map,NULL , link->prog, link, - sockmap_link->attach_type)); + link->attach_type));bpf_map_put_with_uref (sockmap_link->map); sockmap_link->map =NULL ;
@@ -1772,7 +1771,7 @@ static int sock_map_link_update_prog(struct bpf_link *link, } ret =sock_map_prog_link_lookup (sockmap_link->map, &pprog, &plink, - sockmap_link->attach_type); + link->attach_type);if (ret) goto out;
@@ -1817,7 +1816,7 @@ static int sock_map_link_fill_info(const struct bpf_link *link,u32 map_id =sock_map_link_get_map_id (sockmap_link); info->sockmap.map_id = map_id; - info->sockmap.attach_type = sockmap_link->attach_type; + info->sockmap.attach_type = link->attach_type;return 0 ; }
@@ -1828,7 +1827,7 @@ static void sock_map_link_show_fdinfo(const struct bpf_link *link,u32 map_id =sock_map_link_get_map_id (sockmap_link);seq_printf (seq,"map_id:\t%u\n" , map_id); -seq_printf (seq,"attach_type:\t%u\n" , sockmap_link->attach_type); +seq_printf (seq,"attach_type:\t%u\n" , link->attach_type); }static const struct bpf_link_ops sock_map_link_ops = {
@@ -1869,7 +1868,6 @@ int sock_map_link_create(const union bpf_attr *attr, struct bpf_prog *prog)bpf_link_init (&sockmap_link->link,BPF_LINK_TYPE_SOCKMAP , &sock_map_link_ops, prog, attach_type); sockmap_link->map = map; - sockmap_link->attach_type = attach_type; ret =bpf_link_prime (&sockmap_link->link, &link_primer);if (ret) {
Signature · 1 line
2.48.1
PATCH v2 4/7 bpf: Remove location field in tcx_link
In reply to Tao ChenUse attach_type in bpf_link to replace the location filed, and remove location field in tcx_link.
--- include/net/tcx.h | 1 - kernel/bpf/tcx.c | 13 ++++++------- 2 files changed, 6 insertions(+), 8 deletions(-)
include/net/tcx.h +0 -1
@@ -20,7 +20,6 @@ struct tcx_entry {struct tcx_link {struct bpf_link link;struct net_device *dev; -u32 location; };static inline void tcx_set_ingress (struct sk_buff *skb,bool ingress)
kernel/bpf/tcx.c +6 -7
@@ -142,7 +142,7 @@ static int tcx_link_prog_attach(struct bpf_link *link, u32 flags, u32 id_or_fd, u64 revision) {struct tcx_link *tcx =tcx_link (link); -bool created, ingress = tcx->location ==BPF_TCX_INGRESS ; +bool created, ingress = link->attach_type ==BPF_TCX_INGRESS ;struct bpf_mprog_entry *entry, *entry_new;struct net_device *dev = tcx->dev;int ret;
@@ -169,7 +169,7 @@ static int tcx_link_prog_attach(struct bpf_link *link, u32 flags, u32 id_or_fd,static void tcx_link_release (struct bpf_link *link) {struct tcx_link *tcx =tcx_link (link); -bool ingress = tcx->location ==BPF_TCX_INGRESS ; +bool ingress = link->attach_type ==BPF_TCX_INGRESS ;struct bpf_mprog_entry *entry, *entry_new;struct net_device *dev;int ret =0 ;
@@ -204,7 +204,7 @@ static int tcx_link_update(struct bpf_link *link, struct bpf_prog *nprog, struct bpf_prog *oprog) {struct tcx_link *tcx =tcx_link (link); -bool ingress = tcx->location ==BPF_TCX_INGRESS ; +bool ingress = link->attach_type ==BPF_TCX_INGRESS ;struct bpf_mprog_entry *entry, *entry_new;struct net_device *dev;int ret =0 ;
@@ -260,8 +260,8 @@ static void tcx_link_fdinfo(const struct bpf_link *link, struct seq_file *seq)seq_printf (seq,"ifindex:\t%u\n" , ifindex);seq_printf (seq,"attach_type:\t%u (%s)\n" , - tcx->location, - tcx->location ==BPF_TCX_INGRESS ?"ingress" :"egress" ); + link->attach_type, + link->attach_type ==BPF_TCX_INGRESS ?"ingress" :"egress" ); } static int tcx_link_fill_info(const struct bpf_link *link,
@@ -276,7 +276,7 @@ static int tcx_link_fill_info(const struct bpf_link *link,rtnl_unlock (); info->tcx.ifindex = ifindex; - info->tcx.attach_type = tcx->location; + info->tcx.attach_type = link->attach_type;return 0 ; }
@@ -303,7 +303,6 @@ static int tcx_link_init(struct tcx_link *tcx, {bpf_link_init (&tcx->link,BPF_LINK_TYPE_TCX , &tcx_link_lops, prog, attr->link_create.attach_type); - tcx->location = attr->link_create.attach_type; tcx->dev = dev;return bpf_link_prime (&tcx->link, link_primer); }
Signature · 1 line
2.48.1
PATCH v2 5/7 bpf: Remove attach_type in bpf_netns_link
In reply to Tao ChenUse attach_type in bpf_link, and remove it in bpf_netns_link.
--- kernel/bpf/net_namespace.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
kernel/bpf/net_namespace.c +2 -4
@@ -11,7 +11,6 @@struct bpf_netns_link {struct bpf_link link; -enum bpf_attach_type type;enum netns_bpf_attach_type netns_type;/* We don't hold a ref to net in order to auto-detach the link
@@ -216,7 +215,7 @@ static int bpf_netns_link_fill_info(const struct bpf_link *link,mutex_unlock (&netns_bpf_mutex); info->netns.netns_ino = inum; - info->netns.attach_type = net_link->type; + info->netns.attach_type = link->attach_type;return 0 ; }
@@ -230,7 +229,7 @@ static void bpf_netns_link_show_fdinfo(const struct bpf_link *link,"netns_ino:\t%u\n" "attach_type:\t%u\n" , info.netns.netns_ino, - info.netns.attach_type); + link->attach_type); }static const struct bpf_link_ops bpf_netns_link_ops = {
@@ -503,7 +502,6 @@ int netns_bpf_link_create(const union bpf_attr *attr, struct bpf_prog *prog)bpf_link_init (&net_link->link,BPF_LINK_TYPE_NETNS , &bpf_netns_link_ops, prog, type); net_link->net = net; - net_link->type = type; net_link->netns_type = netns_type; err =bpf_link_prime (&net_link->link, &link_primer);
Signature · 1 line
2.48.1
PATCH v2 6/7 bpf: Remove attach_type in bpf_tracing_link
In reply to Tao ChenUse attach_type in bpf_link, and remove it in bpf_tracing_link.
--- include/linux/bpf.h | 1 - kernel/bpf/syscall.c | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-)
include/linux/bpf.h +0 -1
@@ -1783,7 +1783,6 @@ struct bpf_shim_tramp_link {struct bpf_tracing_link {struct bpf_tramp_link link; -enum bpf_attach_type attach_type;struct bpf_trampoline *trampoline;struct bpf_prog *tgt_prog; };
kernel/bpf/syscall.c +2 -3
@@ -3414,7 +3414,7 @@ static void bpf_tracing_link_show_fdinfo(const struct bpf_link *link,"target_obj_id:\t%u\n" "target_btf_id:\t%u\n" "cookie:\t%llu\n" , - tr_link->attach_type, + link->attach_type, target_obj_id, target_btf_id, tr_link->link.cookie);
@@ -3426,7 +3426,7 @@ static int bpf_tracing_link_fill_link_info(const struct bpf_link *link,struct bpf_tracing_link *tr_link = container_of(link, struct bpf_tracing_link, link.link); - info->tracing.attach_type = tr_link->attach_type; + info->tracing.attach_type = link->attach_type; info->tracing.cookie = tr_link->link.cookie; bpf_trampoline_unpack_key(tr_link->trampoline->key, &info->tracing.target_obj_id,
@@ -3516,7 +3516,6 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,bpf_link_init (&link->link.link,BPF_LINK_TYPE_TRACING , &bpf_tracing_link_lops, prog, attach_type); - link->attach_type = prog->expected_attach_type; link->link.cookie = bpf_cookie;mutex_lock (&prog->aux->dst_mutex);
Signature · 1 line
2.48.1
PATCH v2 7/7 netkit: Remove location field in netkit_link
In reply to Tao ChenUse attach_type in bpf_link to replace the location field, and remove location field in netkit_link.
--- drivers/net/netkit.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/netkit.c +3 -5
@@ -32,7 +32,6 @@ struct netkit {struct netkit_link {struct bpf_link link;struct net_device *dev; -u32 location; };static __always_inline int
@@ -733,8 +732,8 @@ static void netkit_link_fdinfo(const struct bpf_link *link, struct seq_file *seqseq_printf (seq,"ifindex:\t%u\n" , ifindex);seq_printf (seq,"attach_type:\t%u (%s)\n" , - nkl->location, - nkl->location ==BPF_NETKIT_PRIMARY ?"primary" :"peer" ); + link->attach_type, + link->attach_type ==BPF_NETKIT_PRIMARY ?"primary" :"peer" ); } static int netkit_link_fill_info(const struct bpf_link *link,
@@ -749,7 +748,7 @@ static int netkit_link_fill_info(const struct bpf_link *link,rtnl_unlock (); info->netkit.ifindex = ifindex; - info->netkit.attach_type = nkl->location; + info->netkit.attach_type = link->attach_type;return 0 ; }
@@ -776,7 +775,6 @@ static int netkit_link_init(struct netkit_link *nkl, {bpf_link_init (&nkl->link,BPF_LINK_TYPE_NETKIT , &netkit_link_lops, prog, attr->link_create.attach_type); - nkl->location = attr->link_create.attach_type; nkl->dev = dev;return bpf_link_prime (&nkl->link, link_primer); }
Signature · 1 line
2.48.1
Re: [PATCH bpf-next v2 1/7] bpf: Add attach_type in bpf_link
In reply to Tao ChenQuoted 39 lines · Tao Chen
Attach_typewill be set when link created from user, it is better to recordattach_typeinbpf_linkdirectly suggested by Andrii.Signed-off-by Tao Chen <[email protected]>--- drivers/net/netkit.c | 2 +- include/linux/bpf.h | 17 +++++++++++------ kernel/bpf/bpf_iter.c | 3 ++- kernel/bpf/bpf_struct_ops.c | 5 +++-- kernel/bpf/cgroup.c | 4 ++-- kernel/bpf/net_namespace.c | 2 +- kernel/bpf/syscall.c | 35 +++++++++++++++++++++------------- kernel/bpf/tcx.c | 3 ++- kernel/bpf/trampoline.c | 10 ++++++---- kernel/trace/bpf_trace.c | 4 ++-- net/bpf/bpf_dummy_struct_ops.c | 3 ++- net/core/dev.c | 3 ++- net/core/sock_map.c | 3 ++- net/netfilter/nf_bpf_link.c | 3 ++- 14 files changed, 60 insertions(+), 37 deletions(-)drivers/net/netkit.c +1
-1@@ -775,7 +775,7 @@ static int netkit_link_init(struct netkit_link *nkl, struct bpf_prog *prog) {bpf_link_init (&nkl->link,BPF_LINK_TYPE_NETKIT , - &netkit_link_lops, prog); + &netkit_link_lops, prog, attr->link_create.attach_type); nkl->location = attr->link_create.attach_type; nkl->dev = dev;return bpf_link_prime (&nkl->link, link_primer);include/linux/bpf.h +0
-0
include/linux/bpf.h struct bpf_link { · line 1739
Quoted 5 lines
include/linux/bpf.h +2
-0@@ -1735,6 +1735,8 @@ struct bpf_link {*/ bool sleepable;u32 flags; +enum bpf_attach_type attach_type; +
there's now 4 byte hole:
jolsa@krava:~/kernel/linux-qemu-1$ pahole -C bpf_link ./vmlinux
struct bpf_link {
atomic64_t refcnt; /* 0 8 */
u32 id; /* 8 4 */
enum bpf_link_type type; /* 12 4 */
const struct bpf_link_ops * ops; /* 16 8 */
struct bpf_prog * prog; /* 24 8 */
bool sleepable; /* 32 1 */ /* XXX 3 bytes hole, try to pack */
u32 flags; /* 36 4 */
enum bpf_attach_type attach_type; /* 40 4 */
/* XXX 4 bytes hole, try to pack */
union {
struct callback_head rcu __attribute__((__aligned__(8))); /* 48 16 */
struct work_struct work; /* 48 80 */
} __attribute__((__aligned__(8))); /* 48 80 */
/* size: 128, cachelines: 2, members: 9 */
/* sum members: 121, holes: 2, sum holes: 7 */
/* forced alignments: 1, forced holes: 1, sum forced holes: 4 */
} __attribute__((__aligned__(8)));I wonder we could just move sleepable bool to the end to have all aligned
jirka
Quoted 385 lines
include/linux/bpf.h +9
-6/* rcu is used before freeing, work can be used to schedule that * RCU-based freeing before that, so they never overlap */ @@ -2034,11 +2036,13 @@ int bpf_prog_ctx_arg_info_init(struct bpf_prog *prog,#if defined(CONFIG_CGROUP_BPF ) && defined(CONFIG_BPF_LSM )int bpf_trampoline_link_cgroup_shim (struct bpf_prog *prog, -int cgroup_atype); +int cgroup_atype, +enum bpf_attach_type attach_type);void bpf_trampoline_unlink_cgroup_shim (struct bpf_prog *prog);#else static inline int bpf_trampoline_link_cgroup_shim (struct bpf_prog *prog, -int cgroup_atype) +int cgroup_atype, +enum bpf_attach_type attach_type) {return -EOPNOTSUPP ; }@@ -2528,10 +2532,11 @@ int bpf_map_new_fd(struct bpf_map *map, int flags);int bpf_prog_new_fd (struct bpf_prog *prog);void bpf_link_init (struct bpf_link *link,enum bpf_link_type type, -const struct bpf_link_ops *ops,struct bpf_prog *prog); +const struct bpf_link_ops *ops,struct bpf_prog *prog, +enum bpf_attach_type attach_type);void bpf_link_init_sleepable (struct bpf_link *link,enum bpf_link_type type,const struct bpf_link_ops *ops,struct bpf_prog *prog, -bool sleepable); +bool sleepable,enum bpf_attach_type attach_type);int bpf_link_prime (struct bpf_link *link,struct bpf_link_primer *primer);int bpf_link_settle (struct bpf_link_primer *primer);void bpf_link_cleanup (struct bpf_link_primer *primer);@@ -2883,13 +2888,13 @@ bpf_prog_inc_not_zero(struct bpf_prog *prog)static inline void bpf_link_init (struct bpf_link *link,enum bpf_link_type type,const struct bpf_link_ops *ops, -struct bpf_prog *prog) +struct bpf_prog *prog,enum bpf_attach_type attach_type) { }static inline void bpf_link_init_sleepable (struct bpf_link *link,enum bpf_link_type type,const struct bpf_link_ops *ops,struct bpf_prog *prog, -bool sleepable) +bool sleepable,enum bpf_attach_type attach_type) { }kernel/bpf/bpf_iter.c +2
-1@@ -552,7 +552,8 @@ int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,if (!link)return -ENOMEM ; -bpf_link_init (&link->link,BPF_LINK_TYPE_ITER , &bpf_iter_link_lops, prog); +bpf_link_init (&link->link,BPF_LINK_TYPE_ITER , &bpf_iter_link_lops, prog, + attr->link_create.attach_type); link->tinfo = tinfo; err =bpf_link_prime (&link->link, &link_primer);kernel/bpf/bpf_struct_ops.c +3
-2@@ -808,7 +808,7 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key, goto reset_unlock; }bpf_link_init (&link->link,BPF_LINK_TYPE_STRUCT_OPS , - &bpf_struct_ops_link_lops, prog); + &bpf_struct_ops_link_lops, prog, prog->expected_attach_type); *plink++ = &link->link; ksym =kzalloc (sizeof (*ksym),GFP_USER );@@ -1351,7 +1351,8 @@ int bpf_struct_ops_link_create(union bpf_attr *attr) err = -ENOMEM ; goto err_out; } -bpf_link_init (&link->link,BPF_LINK_TYPE_STRUCT_OPS , &bpf_struct_ops_map_lops,NULL ); +bpf_link_init (&link->link,BPF_LINK_TYPE_STRUCT_OPS , &bpf_struct_ops_map_lops,NULL , + attr->link_create.attach_type); err =bpf_link_prime (&link->link, &link_primer);if (err)kernel/bpf/cgroup.c +2
-2@@ -867,7 +867,7 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp, cgrp->bpf.flags[atype] = saved_flags;if (type ==BPF_LSM_CGROUP ) { - err =bpf_trampoline_link_cgroup_shim (new_prog, atype); + err =bpf_trampoline_link_cgroup_shim (new_prog, atype, type);if (err) goto cleanup; }@@ -1495,7 +1495,7 @@ int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) goto out_put_cgroup; }bpf_link_init (&link->link,BPF_LINK_TYPE_CGROUP , &bpf_cgroup_link_lops, - prog); + prog, attr->link_create.attach_type); link->cgroup = cgrp; link->type = attr->link_create.attach_type;kernel/bpf/net_namespace.c +1
-1@@ -501,7 +501,7 @@ int netns_bpf_link_create(const union bpf_attr *attr, struct bpf_prog *prog) goto out_put_net; }bpf_link_init (&net_link->link,BPF_LINK_TYPE_NETNS , - &bpf_netns_link_ops, prog); + &bpf_netns_link_ops, prog, type); net_link->net = net; net_link->type = type; net_link->netns_type = netns_type;kernel/bpf/syscall.c +22
-13@@ -3069,7 +3069,7 @@ static int bpf_obj_get(const union bpf_attr *attr)*/ void bpf_link_init_sleepable (struct bpf_link *link,enum bpf_link_type type,const struct bpf_link_ops *ops,struct bpf_prog *prog, -bool sleepable) +bool sleepable,enum bpf_attach_type attach_type) {WARN_ON (ops->dealloc && ops->dealloc_deferred);atomic64_set (&link->refcnt,1 );@@ -3078,12 +3078,14 @@ void bpf_link_init_sleepable(struct bpf_link *link, enum bpf_link_type type, link->id =0 ; link->ops = ops; link->prog = prog; + link->attach_type = attach_type; }void bpf_link_init (struct bpf_link *link,enum bpf_link_type type, -const struct bpf_link_ops *ops,struct bpf_prog *prog) +const struct bpf_link_ops *ops,struct bpf_prog *prog, +enum bpf_attach_type attach_type) { -bpf_link_init_sleepable (link, type, ops, prog, false); +bpf_link_init_sleepable (link, type, ops, prog, false, attach_type); }static void bpf_link_free_id (int id)@@ -3443,7 +3445,8 @@ static const struct bpf_link_ops bpf_tracing_link_lops = {static int bpf_tracing_prog_attach (struct bpf_prog *prog,int tgt_prog_fd,u32 btf_id, -u64 bpf_cookie) +u64 bpf_cookie, +enum bpf_attach_type attach_type) {struct bpf_link_primer link_primer;struct bpf_prog *tgt_prog =NULL ;@@ -3511,7 +3514,8 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog, goto out_put_prog; }bpf_link_init (&link->link.link,BPF_LINK_TYPE_TRACING , - &bpf_tracing_link_lops, prog); + &bpf_tracing_link_lops, prog, attach_type); + link->attach_type = prog->expected_attach_type; link->link.cookie = bpf_cookie;@@ -4049,7 +4053,8 @@ static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *pro err = -ENOMEM ; goto out_put_file; } -bpf_link_init (&link->link,BPF_LINK_TYPE_PERF_EVENT , &bpf_perf_link_lops, prog); +bpf_link_init (&link->link,BPF_LINK_TYPE_PERF_EVENT , &bpf_perf_link_lops, prog, + attr->link_create.attach_type); link->perf_file = perf_file; err =bpf_link_prime (&link->link, &link_primer);@@ -4081,7 +4086,8 @@ static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *pro#endif /* CONFIG_PERF_EVENTS */ static int bpf_raw_tp_link_attach (struct bpf_prog *prog, -const char __user *user_tp_name,u64 cookie) +const char __user *user_tp_name,u64 cookie, +enum bpf_attach_type attach_type) {struct bpf_link_primer link_primer;struct bpf_raw_tp_link *link;@@ -4104,7 +4110,7 @@ static int bpf_raw_tp_link_attach(struct bpf_prog *prog, tp_name = prog->aux->attach_func_name;break ; } -return bpf_tracing_prog_attach (prog,0 ,0 ,0 ); +return bpf_tracing_prog_attach (prog,0 ,0 ,0 , attach_type);case BPF_PROG_TYPE_RAW_TRACEPOINT :case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE :if (strncpy_from_user (buf, user_tp_name,sizeof (buf) -1 ) <0 )@@ -4127,7 +4133,7 @@ static int bpf_raw_tp_link_attach(struct bpf_prog *prog, }bpf_link_init_sleepable (&link->link,BPF_LINK_TYPE_RAW_TRACEPOINT , &bpf_raw_tp_link_lops, prog, -tracepoint_is_faultable (btp->tp)); +tracepoint_is_faultable (btp->tp), attach_type); link->btp = btp; link->cookie = cookie;@@ -4168,7 +4174,7 @@ static int bpf_raw_tracepoint_open(const union bpf_attr *attr) tp_name =u64_to_user_ptr (attr->raw_tracepoint.name); cookie = attr->raw_tracepoint.cookie; - fd =bpf_raw_tp_link_attach (prog, tp_name, cookie); + fd =bpf_raw_tp_link_attach (prog, tp_name, cookie, prog->expected_attach_type);if (fd <0 )bpf_prog_put (prog);return fd;@@ -5536,7 +5542,8 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr) ret =bpf_tracing_prog_attach (prog, attr->link_create.target_fd, attr->link_create.target_btf_id, - attr->link_create.tracing.cookie); + attr->link_create.tracing.cookie, + attr->link_create.attach_type);break ;case BPF_PROG_TYPE_LSM :case BPF_PROG_TYPE_TRACING :@@ -5545,7 +5552,8 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr) goto out; }if (prog->expected_attach_type ==BPF_TRACE_RAW_TP ) - ret =bpf_raw_tp_link_attach (prog,NULL , attr->link_create.tracing.cookie); + ret =bpf_raw_tp_link_attach (prog,NULL , attr->link_create.tracing.cookie, + attr->link_create.attach_type);else if (prog->expected_attach_type ==BPF_TRACE_ITER ) ret =bpf_iter_link_attach (attr, uattr, prog);else if (prog->expected_attach_type ==BPF_LSM_CGROUP )@@ -5554,7 +5562,8 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr) ret =bpf_tracing_prog_attach (prog, attr->link_create.target_fd, attr->link_create.target_btf_id, - attr->link_create.tracing.cookie); + attr->link_create.tracing.cookie, + attr->link_create.attach_type);break ;case BPF_PROG_TYPE_FLOW_DISSECTOR :case BPF_PROG_TYPE_SK_LOOKUP :kernel/bpf/tcx.c +2
-1@@ -301,7 +301,8 @@ static int tcx_link_init(struct tcx_link *tcx,struct net_device *dev, struct bpf_prog *prog) { - bpf_link_init(&tcx->link, BPF_LINK_TYPE_TCX, &tcx_link_lops, prog); + bpf_link_init(&tcx->link, BPF_LINK_TYPE_TCX, &tcx_link_lops, prog, + attr->link_create.attach_type); tcx->location = attr->link_create.attach_type; tcx->dev = dev;return bpf_link_prime (&tcx->link, link_primer);kernel/bpf/trampoline.c +6
-4@@ -674,7 +674,8 @@ static const struct bpf_link_ops bpf_shim_tramp_link_lops = {static struct bpf_shim_tramp_link *cgroup_shim_alloc (const struct bpf_prog *prog,bpf_func_t bpf_func, -int cgroup_atype) +int cgroup_atype, +enum bpf_attach_type attach_type) {struct bpf_shim_tramp_link *shim_link =NULL ;struct bpf_prog *p;@@ -701,7 +702,7 @@ static struct bpf_shim_tramp_link *cgroup_shim_alloc(const struct bpf_prog *prog p->expected_attach_type =BPF_LSM_MAC ;bpf_prog_inc (p);bpf_link_init (&shim_link->link.link,BPF_LINK_TYPE_UNSPEC , - &bpf_shim_tramp_link_lops, p); + &bpf_shim_tramp_link_lops, p, attach_type);bpf_cgroup_atype_get (p->aux->attach_btf_id, cgroup_atype);return shim_link;@@ -726,7 +727,8 @@ static struct bpf_shim_tramp_link *cgroup_shim_find(struct bpf_trampoline *tr, }int bpf_trampoline_link_cgroup_shim (struct bpf_prog *prog, -int cgroup_atype) +int cgroup_atype, +enum bpf_attach_type attach_type) {struct bpf_shim_tramp_link *shim_link =NULL ;struct bpf_attach_target_info tgt_info = {};@@ -763,7 +765,7 @@ int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog,/* Allocate and install new shim. */ - shim_link =cgroup_shim_alloc (prog, bpf_func, cgroup_atype); + shim_link =cgroup_shim_alloc (prog, bpf_func, cgroup_atype, attach_type);if (!shim_link) { err = -ENOMEM ; goto err;kernel/trace/bpf_trace.c +2
-2@@ -2986,7 +2986,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr }bpf_link_init (&link->link,BPF_LINK_TYPE_KPROBE_MULTI , - &bpf_kprobe_multi_link_lops, prog); + &bpf_kprobe_multi_link_lops, prog, attr->link_create.attach_type); err =bpf_link_prime (&link->link, &link_primer);if (err)@@ -3441,7 +3441,7 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr link->link.flags = flags;bpf_link_init (&link->link,BPF_LINK_TYPE_UPROBE_MULTI , - &bpf_uprobe_multi_link_lops, prog); + &bpf_uprobe_multi_link_lops, prog, attr->link_create.attach_type);for (i =0 ; i < cnt; i++) { uprobes[i].uprobe = uprobe_register(d_real_inode(link->path.dentry),net/bpf/bpf_dummy_struct_ops.c +2
-1@@ -171,7 +171,8 @@ int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr, }/* prog doesn't take the ownership of the reference from caller */ bpf_prog_inc (prog); -bpf_link_init (&link->link,BPF_LINK_TYPE_STRUCT_OPS , &bpf_struct_ops_link_lops, prog); +bpf_link_init (&link->link,BPF_LINK_TYPE_STRUCT_OPS , &bpf_struct_ops_link_lops, prog, + prog->expected_attach_type); op_idx = prog->expected_attach_type; err = bpf_struct_ops_prepare_trampoline(tlinks, link,net/core/dev.c +2
-1@@ -10364,7 +10364,8 @@ int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) goto unlock; } -bpf_link_init (&link->link,BPF_LINK_TYPE_XDP , &bpf_xdp_link_lops, prog); +bpf_link_init (&link->link,BPF_LINK_TYPE_XDP , &bpf_xdp_link_lops, prog, + attr->link_create.attach_type); link->dev = dev; link->flags = attr->link_create.flags;net/core/sock_map.c +2
-1@@ -1866,7 +1866,8 @@ int sock_map_link_create(const union bpf_attr *attr, struct bpf_prog *prog) } attach_type = attr->link_create.attach_type; -bpf_link_init (&sockmap_link->link,BPF_LINK_TYPE_SOCKMAP , &sock_map_link_ops, prog); +bpf_link_init (&sockmap_link->link,BPF_LINK_TYPE_SOCKMAP , &sock_map_link_ops, prog, + attach_type); sockmap_link->map = map; sockmap_link->attach_type = attach_type;net/netfilter/nf_bpf_link.c +2
-1@@ -225,7 +225,8 @@ int bpf_nf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)if (!link)return -ENOMEM ; -bpf_link_init (&link->link,BPF_LINK_TYPE_NETFILTER , &bpf_nf_link_lops, prog); +bpf_link_init (&link->link,BPF_LINK_TYPE_NETFILTER , &bpf_nf_link_lops, prog, + attr->link_create.attach_type); link->hook_ops.hook = nf_hook_run_bpf; link->hook_ops.hook_ops_type =NF_HOOK_OP_BPF ;Signature · 1 line
2.48.1
Quoted 20 lines · Tao Chen
Andrii suggested moving the
attach_typeintobpf_link, the previous discussion is as follows:
https://lore.kernel.org/bpf/CAEf4BzY7TZRjxpCJM-+LYgEqe23YFj5Uv3isb7gat2-HU4OSng@mail.gmail.compatch1 add
attach_typeinbpf_link, and pass it tobpf_link_init, which will init theattach_typefield.patch2-7 remove the
attach_typein structbpf_xx_link, update the info withbpf_linkattach_type.There are some functions finally call
bpf_link_initbut do not havebpf_attrfrom user or do not need to initattach_typefrom user likebpf_raw_tracepoint_open, now useprog->expected_attach_typeto initattach_type.
bpf_struct_ops_map_update_elembpf_raw_tracepoint_openbpf_struct_ops_test_runFeedback of any kind is welcome, thanks.
Quoted 8 lines
Tao Chen (7):
bpf: Addattach_typeinbpf_link
bpf: Removeattach_typeinbpf_cgroup_link
bpf: Removeattach_typeinsockmap_link
bpf: Remove location field intcx_link
bpf: Removeattach_typeinbpf_netns_link
bpf: Removeattach_typeinbpf_tracing_link
netkit: Remove location field innetkit_link
with the other comment solved
thanks,
jirka
Quoted 27 lines
drivers/net/netkit.c | 10 ++++----- include/linux/bpf-cgroup.h | 1 - include/linux/bpf.h | 18 +++++++++------ include/net/tcx.h | 1 - kernel/bpf/bpf_iter.c | 3 ++- kernel/bpf/bpf_struct_ops.c | 5 +++-- kernel/bpf/cgroup.c | 17 +++++++-------- kernel/bpf/net_namespace.c | 8 +++---- kernel/bpf/syscall.c | 40 ++++++++++++++++++++-------------- kernel/bpf/tcx.c | 16 +++++++------- kernel/bpf/trampoline.c | 10 +++++---- kernel/trace/bpf_trace.c | 4 ++-- net/bpf/bpf_dummy_struct_ops.c | 3 ++- net/core/dev.c | 3 ++- net/core/sock_map.c | 13 +++++------ net/netfilter/nf_bpf_link.c | 3 ++- 16 files changed, 83 insertions(+), 72 deletions(-)Change list:
v1 -> v2:
- fix build error.(Jiri)
v1:
- https://lore.kernel.org/bpf/[email protected]Signature · 1 line
2.48.1
Re: [PATCH bpf-next v2 1/7] bpf: Add attach_type in bpf_link
In reply to Jiri OlsaQuoted 75 lines · Jiri Olsa
Quoted 39 lines · Tao Chen
Attach_typewill be set when link created from user, it is better to recordattach_typeinbpf_linkdirectly suggested by Andrii.Signed-off-by Tao Chen <[email protected]>--- drivers/net/netkit.c | 2 +- include/linux/bpf.h | 17 +++++++++++------ kernel/bpf/bpf_iter.c | 3 ++- kernel/bpf/bpf_struct_ops.c | 5 +++-- kernel/bpf/cgroup.c | 4 ++-- kernel/bpf/net_namespace.c | 2 +- kernel/bpf/syscall.c | 35 +++++++++++++++++++++------------- kernel/bpf/tcx.c | 3 ++- kernel/bpf/trampoline.c | 10 ++++++---- kernel/trace/bpf_trace.c | 4 ++-- net/bpf/bpf_dummy_struct_ops.c | 3 ++- net/core/dev.c | 3 ++- net/core/sock_map.c | 3 ++- net/netfilter/nf_bpf_link.c | 3 ++- 14 files changed, 60 insertions(+), 37 deletions(-)drivers/net/netkit.c +1
-1@@ -775,7 +775,7 @@ static int netkit_link_init(struct netkit_link *nkl, struct bpf_prog *prog) {bpf_link_init (&nkl->link,BPF_LINK_TYPE_NETKIT , - &netkit_link_lops, prog); + &netkit_link_lops, prog, attr->link_create.attach_type); nkl->location = attr->link_create.attach_type; nkl->dev = dev;return bpf_link_prime (&nkl->link, link_primer);include/linux/bpf.h +0
-0include/linux/bpf.h struct bpf_link { · line 1739
Quoted 5 lines
include/linux/bpf.h +2
-0@@ -1735,6 +1735,8 @@ struct bpf_link {*/ bool sleepable;u32 flags; +enum bpf_attach_type attach_type; +there's now 4 byte hole:
jolsa@krava:~/kernel/linux-qemu-1$ pahole -C bpf_link ./vmlinux struct bpf_link { atomic64_t refcnt; /* 0 8 */ u32 id; /* 8 4 */ enum bpf_link_type type; /* 12 4 */ const struct bpf_link_ops * ops; /* 16 8 */ struct bpf_prog * prog; /* 24 8 */ bool sleepable; /* 32 1 *//* XXX 3 bytes hole, try to pack */ u32 flags; /* 36 4 */ enum bpf_attach_type attach_type; /* 40 4 */ /* XXX 4 bytes hole, try to pack */ union { struct callback_head rcu __attribute__((__aligned__(8))); /* 48 16 */ struct work_struct work; /* 48 80 */ } __attribute__((__aligned__(8))); /* 48 80 */ /* size: 128, cachelines: 2, members: 9 */ /* sum members: 121, holes: 2, sum holes: 7 */ /* forced alignments: 1, forced holes: 1, sum forced holes: 4 */ } __attribute__((__aligned__(8)));
Quoted 2 lines
I wonder we could just move sleepable bool to the end to have all aligned
sounds good, i will change it in v3, thanks.
Quoted 388 lines
jirka
Quoted 385 lines
include/linux/bpf.h +9
-6/* rcu is used before freeing, work can be used to schedule that * RCU-based freeing before that, so they never overlap */ @@ -2034,11 +2036,13 @@ int bpf_prog_ctx_arg_info_init(struct bpf_prog *prog,#if defined(CONFIG_CGROUP_BPF ) && defined(CONFIG_BPF_LSM )int bpf_trampoline_link_cgroup_shim (struct bpf_prog *prog, -int cgroup_atype); +int cgroup_atype, +enum bpf_attach_type attach_type);void bpf_trampoline_unlink_cgroup_shim (struct bpf_prog *prog);#else static inline int bpf_trampoline_link_cgroup_shim (struct bpf_prog *prog, -int cgroup_atype) +int cgroup_atype, +enum bpf_attach_type attach_type) {return -EOPNOTSUPP ; }@@ -2528,10 +2532,11 @@ int bpf_map_new_fd(struct bpf_map *map, int flags);int bpf_prog_new_fd (struct bpf_prog *prog);void bpf_link_init (struct bpf_link *link,enum bpf_link_type type, -const struct bpf_link_ops *ops,struct bpf_prog *prog); +const struct bpf_link_ops *ops,struct bpf_prog *prog, +enum bpf_attach_type attach_type);void bpf_link_init_sleepable (struct bpf_link *link,enum bpf_link_type type,const struct bpf_link_ops *ops,struct bpf_prog *prog, -bool sleepable); +bool sleepable,enum bpf_attach_type attach_type);int bpf_link_prime (struct bpf_link *link,struct bpf_link_primer *primer);int bpf_link_settle (struct bpf_link_primer *primer);void bpf_link_cleanup (struct bpf_link_primer *primer);@@ -2883,13 +2888,13 @@ bpf_prog_inc_not_zero(struct bpf_prog *prog)static inline void bpf_link_init (struct bpf_link *link,enum bpf_link_type type,const struct bpf_link_ops *ops, -struct bpf_prog *prog) +struct bpf_prog *prog,enum bpf_attach_type attach_type) { }static inline void bpf_link_init_sleepable (struct bpf_link *link,enum bpf_link_type type,const struct bpf_link_ops *ops,struct bpf_prog *prog, -bool sleepable) +bool sleepable,enum bpf_attach_type attach_type) { }kernel/bpf/bpf_iter.c +2
-1@@ -552,7 +552,8 @@ int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,if (!link)return -ENOMEM ; -bpf_link_init (&link->link,BPF_LINK_TYPE_ITER , &bpf_iter_link_lops, prog); +bpf_link_init (&link->link,BPF_LINK_TYPE_ITER , &bpf_iter_link_lops, prog, + attr->link_create.attach_type); link->tinfo = tinfo; err =bpf_link_prime (&link->link, &link_primer);kernel/bpf/bpf_struct_ops.c +3
-2@@ -808,7 +808,7 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key, goto reset_unlock; }bpf_link_init (&link->link,BPF_LINK_TYPE_STRUCT_OPS , - &bpf_struct_ops_link_lops, prog); + &bpf_struct_ops_link_lops, prog, prog->expected_attach_type); *plink++ = &link->link; ksym =kzalloc (sizeof (*ksym),GFP_USER );@@ -1351,7 +1351,8 @@ int bpf_struct_ops_link_create(union bpf_attr *attr) err = -ENOMEM ; goto err_out; } -bpf_link_init (&link->link,BPF_LINK_TYPE_STRUCT_OPS , &bpf_struct_ops_map_lops,NULL ); +bpf_link_init (&link->link,BPF_LINK_TYPE_STRUCT_OPS , &bpf_struct_ops_map_lops,NULL , + attr->link_create.attach_type); err =bpf_link_prime (&link->link, &link_primer);if (err)kernel/bpf/cgroup.c +2
-2@@ -867,7 +867,7 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp, cgrp->bpf.flags[atype] = saved_flags;if (type ==BPF_LSM_CGROUP ) { - err =bpf_trampoline_link_cgroup_shim (new_prog, atype); + err =bpf_trampoline_link_cgroup_shim (new_prog, atype, type);if (err) goto cleanup; }@@ -1495,7 +1495,7 @@ int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) goto out_put_cgroup; }bpf_link_init (&link->link,BPF_LINK_TYPE_CGROUP , &bpf_cgroup_link_lops, - prog); + prog, attr->link_create.attach_type); link->cgroup = cgrp; link->type = attr->link_create.attach_type;kernel/bpf/net_namespace.c +1
-1@@ -501,7 +501,7 @@ int netns_bpf_link_create(const union bpf_attr *attr, struct bpf_prog *prog) goto out_put_net; }bpf_link_init (&net_link->link,BPF_LINK_TYPE_NETNS , - &bpf_netns_link_ops, prog); + &bpf_netns_link_ops, prog, type); net_link->net = net; net_link->type = type; net_link->netns_type = netns_type;kernel/bpf/syscall.c +22
-13@@ -3069,7 +3069,7 @@ static int bpf_obj_get(const union bpf_attr *attr)*/ void bpf_link_init_sleepable (struct bpf_link *link,enum bpf_link_type type,const struct bpf_link_ops *ops,struct bpf_prog *prog, -bool sleepable) +bool sleepable,enum bpf_attach_type attach_type) {WARN_ON (ops->dealloc && ops->dealloc_deferred);atomic64_set (&link->refcnt,1 );@@ -3078,12 +3078,14 @@ void bpf_link_init_sleepable(struct bpf_link *link, enum bpf_link_type type, link->id =0 ; link->ops = ops; link->prog = prog; + link->attach_type = attach_type; }void bpf_link_init (struct bpf_link *link,enum bpf_link_type type, -const struct bpf_link_ops *ops,struct bpf_prog *prog) +const struct bpf_link_ops *ops,struct bpf_prog *prog, +enum bpf_attach_type attach_type) { -bpf_link_init_sleepable (link, type, ops, prog, false); +bpf_link_init_sleepable (link, type, ops, prog, false, attach_type); }static void bpf_link_free_id (int id)@@ -3443,7 +3445,8 @@ static const struct bpf_link_ops bpf_tracing_link_lops = {static int bpf_tracing_prog_attach (struct bpf_prog *prog,int tgt_prog_fd,u32 btf_id, -u64 bpf_cookie) +u64 bpf_cookie, +enum bpf_attach_type attach_type) {struct bpf_link_primer link_primer;struct bpf_prog *tgt_prog =NULL ;@@ -3511,7 +3514,8 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog, goto out_put_prog; }bpf_link_init (&link->link.link,BPF_LINK_TYPE_TRACING , - &bpf_tracing_link_lops, prog); + &bpf_tracing_link_lops, prog, attach_type); + link->attach_type = prog->expected_attach_type; link->link.cookie = bpf_cookie;@@ -4049,7 +4053,8 @@ static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *pro err = -ENOMEM ; goto out_put_file; } -bpf_link_init (&link->link,BPF_LINK_TYPE_PERF_EVENT , &bpf_perf_link_lops, prog); +bpf_link_init (&link->link,BPF_LINK_TYPE_PERF_EVENT , &bpf_perf_link_lops, prog, + attr->link_create.attach_type); link->perf_file = perf_file; err =bpf_link_prime (&link->link, &link_primer);@@ -4081,7 +4086,8 @@ static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *pro#endif /* CONFIG_PERF_EVENTS */ static int bpf_raw_tp_link_attach (struct bpf_prog *prog, -const char __user *user_tp_name,u64 cookie) +const char __user *user_tp_name,u64 cookie, +enum bpf_attach_type attach_type) {struct bpf_link_primer link_primer;struct bpf_raw_tp_link *link;@@ -4104,7 +4110,7 @@ static int bpf_raw_tp_link_attach(struct bpf_prog *prog, tp_name = prog->aux->attach_func_name;break ; } -return bpf_tracing_prog_attach (prog,0 ,0 ,0 ); +return bpf_tracing_prog_attach (prog,0 ,0 ,0 , attach_type);case BPF_PROG_TYPE_RAW_TRACEPOINT :case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE :if (strncpy_from_user (buf, user_tp_name,sizeof (buf) -1 ) <0 )@@ -4127,7 +4133,7 @@ static int bpf_raw_tp_link_attach(struct bpf_prog *prog, }bpf_link_init_sleepable (&link->link,BPF_LINK_TYPE_RAW_TRACEPOINT , &bpf_raw_tp_link_lops, prog, -tracepoint_is_faultable (btp->tp)); +tracepoint_is_faultable (btp->tp), attach_type); link->btp = btp; link->cookie = cookie;@@ -4168,7 +4174,7 @@ static int bpf_raw_tracepoint_open(const union bpf_attr *attr) tp_name =u64_to_user_ptr (attr->raw_tracepoint.name); cookie = attr->raw_tracepoint.cookie; - fd =bpf_raw_tp_link_attach (prog, tp_name, cookie); + fd =bpf_raw_tp_link_attach (prog, tp_name, cookie, prog->expected_attach_type);if (fd <0 )bpf_prog_put (prog);return fd;@@ -5536,7 +5542,8 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr) ret =bpf_tracing_prog_attach (prog, attr->link_create.target_fd, attr->link_create.target_btf_id, - attr->link_create.tracing.cookie); + attr->link_create.tracing.cookie, + attr->link_create.attach_type);break ;case BPF_PROG_TYPE_LSM :case BPF_PROG_TYPE_TRACING :@@ -5545,7 +5552,8 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr) goto out; }if (prog->expected_attach_type ==BPF_TRACE_RAW_TP ) - ret =bpf_raw_tp_link_attach (prog,NULL , attr->link_create.tracing.cookie); + ret =bpf_raw_tp_link_attach (prog,NULL , attr->link_create.tracing.cookie, + attr->link_create.attach_type);else if (prog->expected_attach_type ==BPF_TRACE_ITER ) ret =bpf_iter_link_attach (attr, uattr, prog);else if (prog->expected_attach_type ==BPF_LSM_CGROUP )@@ -5554,7 +5562,8 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr) ret =bpf_tracing_prog_attach (prog, attr->link_create.target_fd, attr->link_create.target_btf_id, - attr->link_create.tracing.cookie); + attr->link_create.tracing.cookie, + attr->link_create.attach_type);break ;case BPF_PROG_TYPE_FLOW_DISSECTOR :case BPF_PROG_TYPE_SK_LOOKUP :kernel/bpf/tcx.c +2
-1@@ -301,7 +301,8 @@ static int tcx_link_init(struct tcx_link *tcx,struct net_device *dev, struct bpf_prog *prog) { - bpf_link_init(&tcx->link, BPF_LINK_TYPE_TCX, &tcx_link_lops, prog); + bpf_link_init(&tcx->link, BPF_LINK_TYPE_TCX, &tcx_link_lops, prog, + attr->link_create.attach_type); tcx->location = attr->link_create.attach_type; tcx->dev = dev;return bpf_link_prime (&tcx->link, link_primer);kernel/bpf/trampoline.c +6
-4@@ -674,7 +674,8 @@ static const struct bpf_link_ops bpf_shim_tramp_link_lops = {static struct bpf_shim_tramp_link *cgroup_shim_alloc (const struct bpf_prog *prog,bpf_func_t bpf_func, -int cgroup_atype) +int cgroup_atype, +enum bpf_attach_type attach_type) {struct bpf_shim_tramp_link *shim_link =NULL ;struct bpf_prog *p;@@ -701,7 +702,7 @@ static struct bpf_shim_tramp_link *cgroup_shim_alloc(const struct bpf_prog *prog p->expected_attach_type =BPF_LSM_MAC ;bpf_prog_inc (p);bpf_link_init (&shim_link->link.link,BPF_LINK_TYPE_UNSPEC , - &bpf_shim_tramp_link_lops, p); + &bpf_shim_tramp_link_lops, p, attach_type);bpf_cgroup_atype_get (p->aux->attach_btf_id, cgroup_atype);return shim_link;@@ -726,7 +727,8 @@ static struct bpf_shim_tramp_link *cgroup_shim_find(struct bpf_trampoline *tr, }int bpf_trampoline_link_cgroup_shim (struct bpf_prog *prog, -int cgroup_atype) +int cgroup_atype, +enum bpf_attach_type attach_type) {struct bpf_shim_tramp_link *shim_link =NULL ;struct bpf_attach_target_info tgt_info = {};@@ -763,7 +765,7 @@ int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog,/* Allocate and install new shim. */ - shim_link =cgroup_shim_alloc (prog, bpf_func, cgroup_atype); + shim_link =cgroup_shim_alloc (prog, bpf_func, cgroup_atype, attach_type);if (!shim_link) { err = -ENOMEM ; goto err;kernel/trace/bpf_trace.c +2
-2@@ -2986,7 +2986,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr }bpf_link_init (&link->link,BPF_LINK_TYPE_KPROBE_MULTI , - &bpf_kprobe_multi_link_lops, prog); + &bpf_kprobe_multi_link_lops, prog, attr->link_create.attach_type); err =bpf_link_prime (&link->link, &link_primer);if (err)@@ -3441,7 +3441,7 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr link->link.flags = flags;bpf_link_init (&link->link,BPF_LINK_TYPE_UPROBE_MULTI , - &bpf_uprobe_multi_link_lops, prog); + &bpf_uprobe_multi_link_lops, prog, attr->link_create.attach_type);for (i =0 ; i < cnt; i++) { uprobes[i].uprobe = uprobe_register(d_real_inode(link->path.dentry),net/bpf/bpf_dummy_struct_ops.c +2
-1@@ -171,7 +171,8 @@ int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr, }/* prog doesn't take the ownership of the reference from caller */ bpf_prog_inc (prog); -bpf_link_init (&link->link,BPF_LINK_TYPE_STRUCT_OPS , &bpf_struct_ops_link_lops, prog); +bpf_link_init (&link->link,BPF_LINK_TYPE_STRUCT_OPS , &bpf_struct_ops_link_lops, prog, + prog->expected_attach_type); op_idx = prog->expected_attach_type; err = bpf_struct_ops_prepare_trampoline(tlinks, link,net/core/dev.c +2
-1@@ -10364,7 +10364,8 @@ int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) goto unlock; } -bpf_link_init (&link->link,BPF_LINK_TYPE_XDP , &bpf_xdp_link_lops, prog); +bpf_link_init (&link->link,BPF_LINK_TYPE_XDP , &bpf_xdp_link_lops, prog, + attr->link_create.attach_type); link->dev = dev; link->flags = attr->link_create.flags;net/core/sock_map.c +2
-1@@ -1866,7 +1866,8 @@ int sock_map_link_create(const union bpf_attr *attr, struct bpf_prog *prog) } attach_type = attr->link_create.attach_type; -bpf_link_init (&sockmap_link->link,BPF_LINK_TYPE_SOCKMAP , &sock_map_link_ops, prog); +bpf_link_init (&sockmap_link->link,BPF_LINK_TYPE_SOCKMAP , &sock_map_link_ops, prog, + attach_type); sockmap_link->map = map; sockmap_link->attach_type = attach_type;net/netfilter/nf_bpf_link.c +2
-1@@ -225,7 +225,8 @@ int bpf_nf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)if (!link)return -ENOMEM ; -bpf_link_init (&link->link,BPF_LINK_TYPE_NETFILTER , &bpf_nf_link_lops, prog); +bpf_link_init (&link->link,BPF_LINK_TYPE_NETFILTER , &bpf_nf_link_lops, prog, + attr->link_create.attach_type); link->hook_ops.hook = nf_hook_run_bpf; link->hook_ops.hook_ops_type =NF_HOOK_OP_BPF ;Signature · 1 line
2.48.1
Signature · 2 lines
Best Regards Tao Chen