From nobody Tue Oct 7 18:21:04 2025 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3FE51EF363 for ; Mon, 7 Jul 2025 15:41:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751902894; cv=none; b=XMjW+te/C8A1yRaFMjX81fpZhJ1z+l5EW+xZI2weRhNfsVktIPgGldG5+rg89+4y82D160kfspVNg59nf37mQTAkPywZ3SGDUX/+Pq3RkcOCI1MUdmMtZEo5HTAL3hMBAwp+zocwaWjgKavMHmRiT3J1r3ceLqb0P9wzqz4z/YQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751902894; c=relaxed/simple; bh=ZaJY+MYRoaIr/0lVFQgZKQFF2Duq4I2zTuC7OdfxvhM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L8A+d0RBHUHwCI2H0v1sx/z6ToRyUR8ImxakDDSvlBcSnNkcQzHEfwByRLDo4xUEtMm+7Xk7MmeFjrtYf6Dmtam+LNZAoqWHUHYXIWZC7572Dl4Oazz5vjjzamw/BNpGvmvbOtvogNeKbbdhrlqTidvi70VI5dwSjAMUPmO902E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=cfZKQr3e; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="cfZKQr3e" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1751902889; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eHp2HYDgSGaqO6fcgBBcJQqWWz5jXXONy8ajXCV94I0=; b=cfZKQr3eppwAJ33e030RDoDS1LSnsBGdWiuHLQwWfBtJShlu3BokYE8SRDjtr6WaPx/Vl7 5yoW37yt/7paL02r5V0Aud60/RJjoEZcD3mJgIttVjE8tK69MCPpVtBmlTMo+cgzXpKw/H 6obASIMtg3sX4pO6lyWYnrqGRDcA5FI= From: Tao Chen To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, mattbobrowski@google.com, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, kuniyu@amazon.com, willemb@google.com, jakub@cloudflare.com, pablo@netfilter.org, kadlec@netfilter.org, hawk@kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-trace-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, Tao Chen Subject: [PATCH bpf-next 1/6] bpf: Add attach_type in bpf_link Date: Mon, 7 Jul 2025 23:39:11 +0800 Message-ID: <20250707153916.802802-2-chen.dylane@linux.dev> In-Reply-To: <20250707153916.802802-1-chen.dylane@linux.dev> References: <20250707153916.802802-1-chen.dylane@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Attach_type will be set when link created from user, it is better to record attach_type in bpf_link directly suggested by Andrii. Signed-off-by: Tao Chen --- 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 ++- 13 files changed, 59 insertions(+), 36 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 34dd90ec7fa..12a965362de 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -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 *pro= g, =20 #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); =20 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 typ= e, 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) =20 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) { } =20 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) { } =20 diff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c index 303ab1f42d3..0cbcae72707 100644 --- a/kernel/bpf/bpf_iter.c +++ b/kernel/bpf/bpf_iter.c @@ -552,7 +552,8 @@ int bpf_iter_link_attach(const union bpf_attr *attr, bp= fptr_t uattr, if (!link) return -ENOMEM; =20 - 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 =3D tinfo; =20 err =3D bpf_link_prime(&link->link, &link_primer); diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c index 96113633e39..687a3e9c76f 100644 --- a/kernel/bpf/bpf_struct_ops.c +++ b/kernel/bpf/bpf_struct_ops.c @@ -808,7 +808,7 @@ static long bpf_struct_ops_map_update_elem(struct bpf_m= ap *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++ =3D &link->link; =20 ksym =3D kzalloc(sizeof(*ksym), GFP_USER); @@ -1351,7 +1351,8 @@ int bpf_struct_ops_link_create(union bpf_attr *attr) err =3D -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); =20 err =3D bpf_link_prime(&link->link, &link_primer); if (err) diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index cd220e861d6..bacdd0ca741 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -867,7 +867,7 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp, cgrp->bpf.flags[atype] =3D saved_flags; =20 if (type =3D=3D BPF_LSM_CGROUP) { - err =3D bpf_trampoline_link_cgroup_shim(new_prog, atype); + err =3D 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 =3D cgrp; link->type =3D attr->link_create.attach_type; =20 diff --git a/kernel/bpf/net_namespace.c b/kernel/bpf/net_namespace.c index 868cc2c4389..63702c86275 100644 --- a/kernel/bpf/net_namespace.c +++ b/kernel/bpf/net_namespace.c @@ -501,7 +501,7 @@ int netns_bpf_link_create(const union bpf_attr *attr, s= truct 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 =3D net; net_link->type =3D type; net_link->netns_type =3D netns_type; diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 7db7182a305..14883b3040a 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -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 typ= e, 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 =3D 0; link->ops =3D ops; link->prog =3D prog; + link->attach_type =3D attach_type; } =20 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); } =20 static void bpf_link_free_id(int id) @@ -3443,7 +3445,8 @@ static const struct bpf_link_ops bpf_tracing_link_lop= s =3D { 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 =3D NULL; @@ -3511,7 +3514,8 @@ static int bpf_tracing_prog_attach(struct bpf_prog *p= rog, 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 =3D prog->expected_attach_type; link->link.cookie =3D bpf_cookie; =20 @@ -4049,7 +4053,8 @@ static int bpf_perf_link_attach(const union bpf_attr = *attr, struct bpf_prog *pro err =3D -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 =3D perf_file; =20 err =3D 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 */ =20 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 *pr= og, tp_name =3D 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 *pr= og, } 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 =3D btp; link->cookie =3D cookie; =20 @@ -4168,7 +4174,7 @@ static int bpf_raw_tracepoint_open(const union bpf_at= tr *attr) =20 tp_name =3D u64_to_user_ptr(attr->raw_tracepoint.name); cookie =3D attr->raw_tracepoint.cookie; - fd =3D bpf_raw_tp_link_attach(prog, tp_name, cookie); + fd =3D bpf_raw_tp_link_attach(prog, tp_name, cookie, prog->expected_attac= h_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 =3D 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 =3D=3D BPF_TRACE_RAW_TP) - ret =3D bpf_raw_tp_link_attach(prog, NULL, attr->link_create.tracing.co= okie); + ret =3D bpf_raw_tp_link_attach(prog, NULL, attr->link_create.tracing.co= okie, + attr->link_create.attach_type); else if (prog->expected_attach_type =3D=3D BPF_TRACE_ITER) ret =3D bpf_iter_link_attach(attr, uattr, prog); else if (prog->expected_attach_type =3D=3D BPF_LSM_CGROUP) @@ -5554,7 +5562,8 @@ static int link_create(union bpf_attr *attr, bpfptr_t= uattr) ret =3D 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: diff --git a/kernel/bpf/tcx.c b/kernel/bpf/tcx.c index 2e4885e7781..e6a14f408d9 100644 --- a/kernel/bpf/tcx.c +++ b/kernel/bpf/tcx.c @@ -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 =3D attr->link_create.attach_type; tcx->dev =3D dev; return bpf_link_prime(&tcx->link, link_primer); diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c index b1e358c16ee..0e364614c3a 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -674,7 +674,8 @@ static const struct bpf_link_ops bpf_shim_tramp_link_lo= ps =3D { =20 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 =3D NULL; struct bpf_prog *p; @@ -701,7 +702,7 @@ static struct bpf_shim_tramp_link *cgroup_shim_alloc(co= nst struct bpf_prog *prog p->expected_attach_type =3D 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); =20 return shim_link; @@ -726,7 +727,8 @@ static struct bpf_shim_tramp_link *cgroup_shim_find(str= uct bpf_trampoline *tr, } =20 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 =3D NULL; struct bpf_attach_target_info tgt_info =3D {}; @@ -763,7 +765,7 @@ int bpf_trampoline_link_cgroup_shim(struct bpf_prog *pr= og, =20 /* Allocate and install new shim. */ =20 - shim_link =3D cgroup_shim_alloc(prog, bpf_func, cgroup_atype); + shim_link =3D cgroup_shim_alloc(prog, bpf_func, cgroup_atype, attach_type= ); if (!shim_link) { err =3D -ENOMEM; goto err; diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index e7f97a9a8bb..ffdde840abb 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2986,7 +2986,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr= *attr, struct bpf_prog *pr } =20 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); =20 err =3D 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 =3D flags; =20 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); =20 for (i =3D 0; i < cnt; i++) { uprobes[i].uprobe =3D uprobe_register(d_real_inode(link->path.dentry), diff --git a/net/bpf/bpf_dummy_struct_ops.c b/net/bpf/bpf_dummy_struct_ops.c index f71f67c6896..812457819b5 100644 --- a/net/bpf/bpf_dummy_struct_ops.c +++ b/net/bpf/bpf_dummy_struct_ops.c @@ -171,7 +171,8 @@ int bpf_struct_ops_test_run(struct bpf_prog *prog, cons= t 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); =20 op_idx =3D prog->expected_attach_type; err =3D bpf_struct_ops_prepare_trampoline(tlinks, link, diff --git a/net/core/dev.c b/net/core/dev.c index be97c440ecd..7969fddc94e 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10364,7 +10364,8 @@ int bpf_xdp_link_attach(const union bpf_attr *attr,= struct bpf_prog *prog) goto unlock; } =20 - 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 =3D dev; link->flags =3D attr->link_create.flags; =20 diff --git a/net/core/sock_map.c b/net/core/sock_map.c index 82a14f131d0..fbe9a33ddf1 100644 --- a/net/core/sock_map.c +++ b/net/core/sock_map.c @@ -1866,7 +1866,8 @@ int sock_map_link_create(const union bpf_attr *attr, = struct bpf_prog *prog) } =20 attach_type =3D 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 =3D map; sockmap_link->attach_type =3D attach_type; =20 diff --git a/net/netfilter/nf_bpf_link.c b/net/netfilter/nf_bpf_link.c index 06b08484470..a054d3b216d 100644 --- a/net/netfilter/nf_bpf_link.c +++ b/net/netfilter/nf_bpf_link.c @@ -225,7 +225,8 @@ int bpf_nf_link_attach(const union bpf_attr *attr, stru= ct bpf_prog *prog) if (!link) return -ENOMEM; =20 - bpf_link_init(&link->link, BPF_LINK_TYPE_NETFILTER, &bpf_nf_link_lops, pr= og); + bpf_link_init(&link->link, BPF_LINK_TYPE_NETFILTER, &bpf_nf_link_lops, pr= og, + attr->link_create.attach_type); =20 link->hook_ops.hook =3D nf_hook_run_bpf; link->hook_ops.hook_ops_type =3D NF_HOOK_OP_BPF; --=20 2.48.1 From nobody Tue Oct 7 18:21:04 2025 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF2E11F4CA9 for ; Mon, 7 Jul 2025 15:41:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751902915; cv=none; b=ekK92ESyNtDFnPKzjeyHxzfx208K6ypzUN8iCvh1YEJ6zX/pGUDknHhEevyzMnD5dXimaYAXv9ExtpFboVMz9ieyMAzFH3sS9Plx06PM8hpsutsUj15u8bWT5mSYJ1RUIelbTx1y7Va0l42maNx2BWIg1fXKeVJECgupQ6d6kPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751902915; c=relaxed/simple; bh=YslBrAgYZPoRig7rfxo1T/sFcH28GOBG7fNzhFWjPEU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pzQAuhZ1vytnKvyonOHeexA/8XLGLecfDzrnqovwl0bAM6NjDjUnN53I16AJBMFgVHuPi7TnH2Z9K5XlPZ/xIV7LnTNJ2Ydvr66k/+eHuPkwMsxoAg9gm85ssjK3Rzd0Zjq1/ZKtWYc2Kl5sCgFO/KC4ySBQ5JqYwvT4ZefeXrg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=IvDt4De2; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="IvDt4De2" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1751902912; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nFFj+EmUdX78YSHXH0ceZJh4m8HxnLe9oo1MhOydXdw=; b=IvDt4De2LaFqCfD5xjgB/hwCfOuDhncNa1WDNy+nwsbR7UmWMt/Mz4DeQoE7YzUT1ZJ5yp 19PCAUg6kViNMLhg4UtxCghVc9mo2zFFRYRY09LvLQn83QL/2hcTQ32kWOr6KKi1f9+nKf v05N1f0GlSYR5UmUTkPx3ZgJKLsEgEI= From: Tao Chen To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, mattbobrowski@google.com, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, kuniyu@amazon.com, willemb@google.com, jakub@cloudflare.com, pablo@netfilter.org, kadlec@netfilter.org, hawk@kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-trace-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, Tao Chen Subject: [PATCH bpf-next 2/6] bpf: Remove attach_type in bpf_cgroup_link Date: Mon, 7 Jul 2025 23:39:12 +0800 Message-ID: <20250707153916.802802-3-chen.dylane@linux.dev> In-Reply-To: <20250707153916.802802-1-chen.dylane@linux.dev> References: <20250707153916.802802-1-chen.dylane@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Use attach_type in bpf_link, and remove it in bpf_cgroup_link. Signed-off-by: Tao Chen --- include/linux/bpf-cgroup.h | 1 - kernel/bpf/cgroup.c | 13 ++++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h index 70c8b94e797..082ccd8ad96 100644 --- a/include/linux/bpf-cgroup.h +++ b/include/linux/bpf-cgroup.h @@ -103,7 +103,6 @@ struct bpf_cgroup_storage { struct bpf_cgroup_link { struct bpf_link link; struct cgroup *cgroup; - enum bpf_attach_type type; }; =20 struct bpf_prog_list { diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index bacdd0ca741..72c8b50dca0 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -984,7 +984,7 @@ static int __cgroup_bpf_replace(struct cgroup *cgrp, struct hlist_head *progs; bool found =3D false; =20 - atype =3D bpf_cgroup_atype_find(link->type, new_prog->aux->attach_btf_id); + atype =3D bpf_cgroup_atype_find(link->link.attach_type, new_prog->aux->at= tach_btf_id); if (atype < 0) return -EINVAL; =20 @@ -1396,8 +1396,8 @@ static void bpf_cgroup_link_release(struct bpf_link *= link) } =20 WARN_ON(__cgroup_bpf_detach(cg_link->cgroup, NULL, cg_link, - cg_link->type, 0)); - if (cg_link->type =3D=3D BPF_LSM_CGROUP) + link->attach_type, 0)); + if (link->attach_type =3D=3D BPF_LSM_CGROUP) bpf_trampoline_unlink_cgroup_shim(cg_link->link.prog); =20 cg =3D 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); } =20 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 struc= t bpf_link *link, cgroup_unlock(); =20 info->cgroup.cgroup_id =3D cg_id; - info->cgroup.attach_type =3D cg_link->type; + info->cgroup.attach_type =3D link->attach_type; return 0; } =20 @@ -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 =3D cgrp; - link->type =3D attr->link_create.attach_type; =20 err =3D 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) } =20 err =3D 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) { --=20 2.48.1 From nobody Tue Oct 7 18:21:04 2025 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FB1F1E230E for ; Mon, 7 Jul 2025 15:42:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751902937; cv=none; b=EXcq91p0o9XgbeNJRwhcmTSGR78XbimNgGwSLy7gWyuMNGP/aCifFni7h6zyDVeRaxQqTPyh4y5B19uD22xz1ADcjWPmWjYcFwxSd89IfnmVlG31qZDV4dZrE25VXvMsNPCH32TX2PHv0f0EFIJbxTXMV+xUJHiBCWPaHlDvdF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751902937; c=relaxed/simple; bh=ugVudOCH1QUE1lgwU5uFhMmaWqGYLvdAJPoGrIVsNCY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cYOoVZBLUh3/7O8aDuFOEjmTiQFw9v9EMRbOLUZqt7KqU50UVsnwp9BHKy+bsjXh/lvyhYL/UcR5Cl2hoMQp48hMlbKo0S5To4+Bl7NKe3IEZvPs39WI8DgEfAaEYmClHDmgEpP5G+7D23Xt/yVvqGKI3IriygTpn1lLloMrEq4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ZbREFHhr; arc=none smtp.client-ip=91.218.175.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ZbREFHhr" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1751902932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tMHqMHAxGD1r4fmMDbndGO/4sTwGSp8V807ueJrjmno=; b=ZbREFHhrpkqPz5ufEJ3r8iCI4F5m3Y3LBHfZVE6dnnKBVBdaW9qtEZbR8Kh5mMztKbWyA/ Nhn7gqSlZ38NrFbGXZiAUEUMCEoZIVGwelWLFHrKi1F5yFYasIkU0Dg7achKngBC8zOzVE hil14RyrtW3P5AjsREoEBnXA20zRytQ= From: Tao Chen To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, mattbobrowski@google.com, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, kuniyu@amazon.com, willemb@google.com, jakub@cloudflare.com, pablo@netfilter.org, kadlec@netfilter.org, hawk@kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-trace-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, Tao Chen Subject: [PATCH bpf-next 3/6] bpf: Remove attach_type in bpf_sockmap_link Date: Mon, 7 Jul 2025 23:39:13 +0800 Message-ID: <20250707153916.802802-4-chen.dylane@linux.dev> In-Reply-To: <20250707153916.802802-1-chen.dylane@linux.dev> References: <20250707153916.802802-1-chen.dylane@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Use attach_type in bpf_link, and remove it in bpf_sockmap_link. Signed-off-by: Tao Chen --- net/core/sock_map.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/net/core/sock_map.c b/net/core/sock_map.c index fbe9a33ddf1..5947b38e4f8 100644 --- a/net/core/sock_map.c +++ b/net/core/sock_map.c @@ -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; }; =20 static void sock_map_link_release(struct bpf_link *link) @@ -1721,7 +1720,7 @@ static void sock_map_link_release(struct bpf_link *li= nk) goto out; =20 WARN_ON_ONCE(sock_map_prog_update(sockmap_link->map, NULL, link->prog, li= nk, - sockmap_link->attach_type)); + link->attach_type)); =20 bpf_map_put_with_uref(sockmap_link->map); sockmap_link->map =3D NULL; @@ -1772,7 +1771,7 @@ static int sock_map_link_update_prog(struct bpf_link = *link, } =20 ret =3D sock_map_prog_link_lookup(sockmap_link->map, &pprog, &plink, - sockmap_link->attach_type); + link->attach_type); if (ret) goto out; =20 @@ -1817,7 +1816,7 @@ static int sock_map_link_fill_info(const struct bpf_l= ink *link, u32 map_id =3D sock_map_link_get_map_id(sockmap_link); =20 info->sockmap.map_id =3D map_id; - info->sockmap.attach_type =3D sockmap_link->attach_type; + info->sockmap.attach_type =3D link->attach_type; return 0; } =20 @@ -1828,7 +1827,7 @@ static void sock_map_link_show_fdinfo(const struct bp= f_link *link, u32 map_id =3D sock_map_link_get_map_id(sockmap_link); =20 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); } =20 static const struct bpf_link_ops sock_map_link_ops =3D { @@ -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 =3D map; - sockmap_link->attach_type =3D attach_type; =20 ret =3D bpf_link_prime(&sockmap_link->link, &link_primer); if (ret) { --=20 2.48.1 From nobody Tue Oct 7 18:21:04 2025 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BE4A1EB9E1; Mon, 7 Jul 2025 15:42:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751902969; cv=none; b=gBTKEC6C47gvvVacWYYcjoSOGNZW4dK516BnppO3nSXLV9o429gGmnuAQPX+Om2NM+RX9wa7jzy8Q6I9HZ0CBBY4ZPhxpJh8YzgrmCw4Or7cvC8K81BY8h47YAsHs2sk/7qHzIMFRa4nwZ649T7kpjaszPbEB591XHqQZjRcX7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751902969; c=relaxed/simple; bh=SqfaLR8/C5jzJtwP4LoXDHtISetJup6uWVH5ey3lMaw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tp/O2oeSjlmgrZF4p2svAMqG840sV4WDRw3wpwZSAnYO8pOZXJQa5Tm7Zj2EnKid51r7ag+q75Fl7Sjcbd9K8QtkaXcFHvd/Juvwh3r08kJX6UtVJfdUs+FbFUc37bz7QQNZMPtfU2UkvJQbhpkFjz4m56aUz6S1LGEBzAYF63E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=fpfOk+pE; arc=none smtp.client-ip=95.215.58.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="fpfOk+pE" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1751902955; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iCW68eGUYsLpHCGaD0r9aeEIjmFEKVXrBCPoykv6/AU=; b=fpfOk+pE3Xu0/uduDUuQswqEVYAkphuxG9zkQTuQ20f8+J7amE0masEFM2TrTT0y8gfxlk 2h/dZGQzyd9cdrNfGWm73HPHDLva6FLy/f38RYmBbvryvPAlWKmG5/2sodMcxNPFCcT+Ya uigL8ivvXJ8cH4V7lao0dTtSrp8/cMc= From: Tao Chen To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, mattbobrowski@google.com, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, kuniyu@amazon.com, willemb@google.com, jakub@cloudflare.com, pablo@netfilter.org, kadlec@netfilter.org, hawk@kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-trace-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, Tao Chen Subject: [PATCH bpf-next 4/6] bpf: Remove location field in tcx_link Date: Mon, 7 Jul 2025 23:39:14 +0800 Message-ID: <20250707153916.802802-5-chen.dylane@linux.dev> In-Reply-To: <20250707153916.802802-1-chen.dylane@linux.dev> References: <20250707153916.802802-1-chen.dylane@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Use attach_type in bpf_link to replace the location filed, and remove location field in tcx_link. Signed-off-by: Tao Chen --- include/net/tcx.h | 1 - kernel/bpf/tcx.c | 13 ++++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/net/tcx.h b/include/net/tcx.h index 5ce0ce9e0c0..23a61af1354 100644 --- a/include/net/tcx.h +++ b/include/net/tcx.h @@ -20,7 +20,6 @@ struct tcx_entry { struct tcx_link { struct bpf_link link; struct net_device *dev; - u32 location; }; =20 static inline void tcx_set_ingress(struct sk_buff *skb, bool ingress) diff --git a/kernel/bpf/tcx.c b/kernel/bpf/tcx.c index e6a14f408d9..efd987ea687 100644 --- a/kernel/bpf/tcx.c +++ b/kernel/bpf/tcx.c @@ -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 =3D tcx_link(link); - bool created, ingress =3D tcx->location =3D=3D BPF_TCX_INGRESS; + bool created, ingress =3D link->attach_type =3D=3D BPF_TCX_INGRESS; struct bpf_mprog_entry *entry, *entry_new; struct net_device *dev =3D 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 =3D tcx_link(link); - bool ingress =3D tcx->location =3D=3D BPF_TCX_INGRESS; + bool ingress =3D link->attach_type =3D=3D BPF_TCX_INGRESS; struct bpf_mprog_entry *entry, *entry_new; struct net_device *dev; int ret =3D 0; @@ -204,7 +204,7 @@ static int tcx_link_update(struct bpf_link *link, struc= t bpf_prog *nprog, struct bpf_prog *oprog) { struct tcx_link *tcx =3D tcx_link(link); - bool ingress =3D tcx->location =3D=3D BPF_TCX_INGRESS; + bool ingress =3D link->attach_type =3D=3D BPF_TCX_INGRESS; struct bpf_mprog_entry *entry, *entry_new; struct net_device *dev; int ret =3D 0; @@ -260,8 +260,8 @@ static void tcx_link_fdinfo(const struct bpf_link *link= , struct seq_file *seq) =20 seq_printf(seq, "ifindex:\t%u\n", ifindex); seq_printf(seq, "attach_type:\t%u (%s)\n", - tcx->location, - tcx->location =3D=3D BPF_TCX_INGRESS ? "ingress" : "egress"); + link->attach_type, + link->attach_type =3D=3D BPF_TCX_INGRESS ? "ingress" : "egress"); } =20 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 *li= nk, rtnl_unlock(); =20 info->tcx.ifindex =3D ifindex; - info->tcx.attach_type =3D tcx->location; + info->tcx.attach_type =3D link->attach_type; return 0; } =20 @@ -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 =3D attr->link_create.attach_type; tcx->dev =3D dev; return bpf_link_prime(&tcx->link, link_primer); } --=20 2.48.1 From nobody Tue Oct 7 18:21:04 2025 Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EE731EB9E1 for ; Mon, 7 Jul 2025 15:42:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751902980; cv=none; b=qmloscfMLiuWykghAiYMY6RIcn9XdZphoNH3CJBO2oa6DkXhB2AahVdvSoLYCIb/P3hipBVf2TXIfhrv4IuhEAi33caG8bwrOk6niRP2q/w7iO2SZI5AuVW+5uvG5gQn2zH4HMerEKnxxLSpGg6xj9j9WFRcwQyi5bv7QmmcvDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751902980; c=relaxed/simple; bh=S/4ysQBNXSNRLbsTxzjmiKYVJK4WRI1JFEgfz8Ho5Ko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sVd5LwN1dYA1oOPqCnAvaKKq1PmCp/lVgZl/XsaCIt2wlXsOFVyrGYZ6ELURnicEg7dEeHVmF9t79xXI0qvrh2koaCF1WYK5rS3jq0ZcyC+/toRYS+t5k0bdxIi612zVOe0aN9PT94sCGc/DQoEyI5nSyjE0jpmSfYgD/qHZPUc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=prnlWopf; arc=none smtp.client-ip=95.215.58.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="prnlWopf" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1751902976; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hMuwkXar/JP+QSBlJ36t2NR92ukOZdEZlTj2WN/ipWk=; b=prnlWopfbPFs0WcYB8DKcdKMLHc64MMiSWU8vg9rgUdSS8p1FKrEy+y8e6cUNwd/b8KaXP MTv30VV0ryuMXnYl7eQ1uvv24sH6SIYAo64c1X4aseGj1aKxttGjN9mcEExXcIP1G4ckZo m6dy6mAeT9z1Q31WGFOOEalRBXbX6Og= From: Tao Chen To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, mattbobrowski@google.com, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, kuniyu@amazon.com, willemb@google.com, jakub@cloudflare.com, pablo@netfilter.org, kadlec@netfilter.org, hawk@kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-trace-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, Tao Chen Subject: [PATCH bpf-next 5/6] bpf: Remove attach_type in bpf_netns_link Date: Mon, 7 Jul 2025 23:39:15 +0800 Message-ID: <20250707153916.802802-6-chen.dylane@linux.dev> In-Reply-To: <20250707153916.802802-1-chen.dylane@linux.dev> References: <20250707153916.802802-1-chen.dylane@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Use attach_type in bpf_link, and remove it in bpf_netns_link. Signed-off-by: Tao Chen --- kernel/bpf/net_namespace.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/net_namespace.c b/kernel/bpf/net_namespace.c index 63702c86275..6d27bd97c95 100644 --- a/kernel/bpf/net_namespace.c +++ b/kernel/bpf/net_namespace.c @@ -11,7 +11,6 @@ =20 struct bpf_netns_link { struct bpf_link link; - enum bpf_attach_type type; enum netns_bpf_attach_type netns_type; =20 /* 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_li= nk *link, mutex_unlock(&netns_bpf_mutex); =20 info->netns.netns_ino =3D inum; - info->netns.attach_type =3D net_link->type; + info->netns.attach_type =3D link->attach_type; return 0; } =20 @@ -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); } =20 static const struct bpf_link_ops bpf_netns_link_ops =3D { @@ -503,7 +502,6 @@ int netns_bpf_link_create(const union bpf_attr *attr, s= truct bpf_prog *prog) bpf_link_init(&net_link->link, BPF_LINK_TYPE_NETNS, &bpf_netns_link_ops, prog, type); net_link->net =3D net; - net_link->type =3D type; net_link->netns_type =3D netns_type; =20 err =3D bpf_link_prime(&net_link->link, &link_primer); --=20 2.48.1 From nobody Tue Oct 7 18:21:04 2025 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5116F1E230E for ; Mon, 7 Jul 2025 15:43:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751903001; cv=none; b=JiKbU8+5Ax/PuQwOhElxd2TIoPNG0A5WxeFa68UJbOhaN7C4xH4lsWvVuwzLP6Df0digyxebjqmyledSGJppbbzTJU2sCM39egjhZ9azEBJmYhDKnzdbGYyC5MW3ZULq4t/x0KdZdhBjBH0QfroP1cD14Gdg7z7QFKO9PF9WILU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751903001; c=relaxed/simple; bh=7JjTGV2EjX+W7UtcP012g5rTZpgzgtn1ezb7Y2UDimQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lQAjx411RGq3YHAHwD+p08eN/GhVgWzCiPZjtpsp+F1P8sfavOGpFHHmXIkIXUBkQHZg4b8EgaUpBEMIVTyPw0f99CrUAAf4zw9ZXDQ2YTVQuicGO1B3YObL1dQlQfyl00tGRjEH8sGD+1PUySOt924R38pEJyqwSBNgnajw7dQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=BmVkK7u+; arc=none smtp.client-ip=91.218.175.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="BmVkK7u+" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1751902997; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bDpmQYuK0vQauknx7TQlfoEHnUsAxwnLcxPxoWYrPKA=; b=BmVkK7u+CtV+emNIyiPJlmwv2X3VBQJSqMMnfn3tbTYNgnWS2WT3JAp8kYI0i2uNXSeffr h+kP8OPr6EubIOkPsfN1RrDm0iVgIVENBuM7s81elTBD9YdRZXKsWoRSP7TfAsOBC/lRUx eutM/ZkWcqid0v5Aei3g+Yx1hEk9fjs= From: Tao Chen To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, mattbobrowski@google.com, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, kuniyu@amazon.com, willemb@google.com, jakub@cloudflare.com, pablo@netfilter.org, kadlec@netfilter.org, hawk@kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-trace-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, Tao Chen Subject: [PATCH bpf-next 6/6] bpf: Remove attach_type in bpf_tracing_link Date: Mon, 7 Jul 2025 23:39:16 +0800 Message-ID: <20250707153916.802802-7-chen.dylane@linux.dev> In-Reply-To: <20250707153916.802802-1-chen.dylane@linux.dev> References: <20250707153916.802802-1-chen.dylane@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Use attach_type in bpf_link, and remove it in bpf_tracing_link. Signed-off-by: Tao Chen --- include/linux/bpf.h | 1 - kernel/bpf/syscall.c | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 12a965362de..9c4ed6b372b 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1783,7 +1783,6 @@ struct bpf_shim_tramp_link { =20 struct bpf_tracing_link { struct bpf_tramp_link link; - enum bpf_attach_type attach_type; struct bpf_trampoline *trampoline; struct bpf_prog *tgt_prog; }; diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 14883b3040a..bed523bf92c 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -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 stru= ct bpf_link *link, struct bpf_tracing_link *tr_link =3D container_of(link, struct bpf_tracing_link, link.link); =20 - info->tracing.attach_type =3D tr_link->attach_type; + info->tracing.attach_type =3D link->attach_type; info->tracing.cookie =3D 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 *p= rog, bpf_link_init(&link->link.link, BPF_LINK_TYPE_TRACING, &bpf_tracing_link_lops, prog, attach_type); =20 - link->attach_type =3D prog->expected_attach_type; link->link.cookie =3D bpf_cookie; =20 mutex_lock(&prog->aux->dst_mutex); --=20 2.48.1