[PATCH bpf-next v2 0/7] Add attach_type in bpf_link

Tao Chen posted 7 patches 3 months ago
There is a newer version of this series
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(-)
[PATCH bpf-next v2 0/7] Add attach_type in bpf_link
Posted by Tao Chen 3 months ago
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_elem
bpf_raw_tracepoint_open
bpf_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/20250707153916.802802-1-chen.dylane@linux.dev
-- 
2.48.1
Re: [PATCH bpf-next v2 0/7] Add attach_type in bpf_link
Posted by Jiri Olsa 3 months ago
On Tue, Jul 08, 2025 at 04:22:21PM +0800, Tao Chen wrote:
> 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_elem
> bpf_raw_tracepoint_open
> bpf_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

with the other comment solved

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka


> 
>  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/20250707153916.802802-1-chen.dylane@linux.dev
> -- 
> 2.48.1
>