On 7/9/25 5:07 AM, Tao Chen wrote:
Attach_type will be set when link created from user, it is better
to record attach_type in bpf_link directly suggested by Andrii. So
add the attach_type field in bpf_link and move the sleepable field to
the end just to fill the byte hole.

Acked-by: Jiri Olsa <jo...@kernel.org>
Signed-off-by: Tao Chen <chen.dyl...@linux.dev>
---
  drivers/net/netkit.c           |  2 +-
  include/linux/bpf.h            | 28 ++++++++++++++++-----------
  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, 66 insertions(+), 42 deletions(-)
[...]

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 34dd90ec7fa..dd5070039de 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -1729,12 +1729,10 @@ struct bpf_link {
        enum bpf_link_type type;
        const struct bpf_link_ops *ops;
        struct bpf_prog *prog;
-       /* whether BPF link itself has "sleepable" semantics, which can differ
-        * from underlying BPF program having a "sleepable" semantics, as BPF
-        * link's semantics is determined by target attach hook
-        */
-       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
         */
@@ -1742,6 +1740,11 @@ struct bpf_link {
                struct rcu_head rcu;
                struct work_struct work;
        };
+       /* whether BPF link itself has "sleepable" semantics, which can differ
+        * from underlying BPF program having a "sleepable" semantics, as BPF
+        * link's semantics is determined by target attach hook
+        */
+       bool sleepable;
  };

lgtm, it looks a bit weird at the end here after rcu/work but in future if other
attributes get added to the link obj and a new hole frees up we can move it up
again. Definitely good the rationale for the move is documented in the commit 
msg.

Acked-by: Daniel Borkmann <dan...@iogearbox.net>

Reply via email to