Re: [PATCHv3 bpf-next 06/24] bpf: Add multi tracing attach types

2026-03-19 Thread kernel test robot
Hi Jiri,

kernel test robot noticed the following build errors:

[auto build test ERROR on bpf-next/master]

url:
https://github.com/intel-lab-lkp/linux/commits/Jiri-Olsa/ftrace-Add-ftrace_hash_count-function/20260316-160117
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
patch link:
https://lore.kernel.org/r/20260316075138.465430-7-jolsa%40kernel.org
patch subject: [PATCHv3 bpf-next 06/24] bpf: Add multi tracing attach types
config: hexagon-allmodconfig 
(https://download.01.org/0day-ci/archive/20260320/[email protected]/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 
6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20260320/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot 
| Closes: 
https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> kernel/bpf/syscall.c:2967:15: error: call to undeclared function 
>> 'is_tracing_multi'; ISO C99 and later do not support implicit function 
>> declarations [-Wimplicit-function-declaration]
2967 | multi_func = is_tracing_multi(attr->expected_attach_type);
 |  ^
   1 error generated.
--
>> kernel/bpf/verifier.c:25059:9: error: call to undeclared function 
>> 'is_tracing_multi'; ISO C99 and later do not support implicit function 
>> declarations [-Wimplicit-function-declaration]
25059 | return is_tracing_multi(prog->expected_attach_type) && 
bpf_multi_func_btf_id[0] == btf_id;
  |^
   kernel/bpf/verifier.c:25059:9: note: did you mean 'is_tracing_multi_id'?
   kernel/bpf/verifier.c:25057:13: note: 'is_tracing_multi_id' declared here
25057 | static bool is_tracing_multi_id(const struct bpf_prog *prog, u32 
btf_id)
  | ^
25058 | {
25059 | return is_tracing_multi(prog->expected_attach_type) && 
bpf_multi_func_btf_id[0] == btf_id;
  |
  |is_tracing_multi_id
   kernel/bpf/verifier.c:25566:6: error: call to undeclared function 
'is_tracing_multi'; ISO C99 and later do not support implicit function 
declarations [-Wimplicit-function-declaration]
25566 | is_tracing_multi(prog->expected_attach_type))
  | ^
   2 errors generated.


vim +/is_tracing_multi +2967 kernel/bpf/syscall.c

  2890  
  2891  static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, u32 
uattr_size)
  2892  {
  2893  enum bpf_prog_type type = attr->prog_type;
  2894  struct bpf_prog *prog, *dst_prog = NULL;
  2895  struct btf *attach_btf = NULL;
  2896  struct bpf_token *token = NULL;
  2897  bool bpf_cap;
  2898  int err;
  2899  char license[128];
  2900  bool multi_func;
  2901  
  2902  if (CHECK_ATTR(BPF_PROG_LOAD))
  2903  return -EINVAL;
  2904  
  2905  if (attr->prog_flags & ~(BPF_F_STRICT_ALIGNMENT |
  2906   BPF_F_ANY_ALIGNMENT |
  2907   BPF_F_TEST_STATE_FREQ |
  2908   BPF_F_SLEEPABLE |
  2909   BPF_F_TEST_RND_HI32 |
  2910   BPF_F_XDP_HAS_FRAGS |
  2911   BPF_F_XDP_DEV_BOUND_ONLY |
  2912   BPF_F_TEST_REG_INVARIANTS |
  2913   BPF_F_TOKEN_FD))
  2914  return -EINVAL;
  2915  
  2916  bpf_prog_load_fixup_attach_type(attr);
  2917  
  2918  if (attr->prog_flags & BPF_F_TOKEN_FD) {
  2919  token = bpf_token_get_from_fd(attr->prog_token_fd);
  2920  if (IS_ERR(token))
  2921  return PTR_ERR(token);
  2922  /* if current token doesn't grant prog loading 
permissions,
  2923   * then we can't use this token, so ignore it and rely 
on
  2924   * system-wide capabilities checks
  2925   */
  2926  if (!bpf_token_allow_cmd(token, BPF_PROG_LOAD) ||
  2927  !bpf_token_allow_prog_type(token, attr->prog_type,
  2928 
attr->expected_attach_type)) {
  2929  bpf_token_put(token);
  2930  token = NULL;
  2931  }
  2932  }
  2933  
  2934  bpf_cap = bpf_token_capable(token, CAP_BPF);
  2935  err = -EPERM

Re: [PATCHv3 bpf-next 06/24] bpf: Add multi tracing attach types

2026-03-19 Thread kernel test robot
Hi Jiri,

kernel test robot noticed the following build errors:

[auto build test ERROR on bpf-next/master]

url:
https://github.com/intel-lab-lkp/linux/commits/Jiri-Olsa/ftrace-Add-ftrace_hash_count-function/20260316-160117
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
patch link:
https://lore.kernel.org/r/20260316075138.465430-7-jolsa%40kernel.org
patch subject: [PATCHv3 bpf-next 06/24] bpf: Add multi tracing attach types
config: sh-allmodconfig 
(https://download.01.org/0day-ci/archive/20260320/[email protected]/config)
compiler: sh4-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20260320/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot 
| Closes: 
https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

   kernel/bpf/syscall.c: In function 'bpf_prog_load':
>> kernel/bpf/syscall.c:2967:22: error: implicit declaration of function 
>> 'is_tracing_multi' [-Wimplicit-function-declaration]
2967 | multi_func = is_tracing_multi(attr->expected_attach_type);
 |  ^~~~
--
   kernel/bpf/verifier.c: In function 'is_tracing_multi_id':
>> kernel/bpf/verifier.c:25059:16: error: implicit declaration of function 
>> 'is_tracing_multi'; did you mean 'is_tracing_multi_id'? 
>> [-Wimplicit-function-declaration]
   25059 | return is_tracing_multi(prog->expected_attach_type) && 
bpf_multi_func_btf_id[0] == btf_id;
 |^~~~
 |is_tracing_multi_id


vim +/is_tracing_multi +2967 kernel/bpf/syscall.c

  2890  
  2891  static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, u32 
uattr_size)
  2892  {
  2893  enum bpf_prog_type type = attr->prog_type;
  2894  struct bpf_prog *prog, *dst_prog = NULL;
  2895  struct btf *attach_btf = NULL;
  2896  struct bpf_token *token = NULL;
  2897  bool bpf_cap;
  2898  int err;
  2899  char license[128];
  2900  bool multi_func;
  2901  
  2902  if (CHECK_ATTR(BPF_PROG_LOAD))
  2903  return -EINVAL;
  2904  
  2905  if (attr->prog_flags & ~(BPF_F_STRICT_ALIGNMENT |
  2906   BPF_F_ANY_ALIGNMENT |
  2907   BPF_F_TEST_STATE_FREQ |
  2908   BPF_F_SLEEPABLE |
  2909   BPF_F_TEST_RND_HI32 |
  2910   BPF_F_XDP_HAS_FRAGS |
  2911   BPF_F_XDP_DEV_BOUND_ONLY |
  2912   BPF_F_TEST_REG_INVARIANTS |
  2913   BPF_F_TOKEN_FD))
  2914  return -EINVAL;
  2915  
  2916  bpf_prog_load_fixup_attach_type(attr);
  2917  
  2918  if (attr->prog_flags & BPF_F_TOKEN_FD) {
  2919  token = bpf_token_get_from_fd(attr->prog_token_fd);
  2920  if (IS_ERR(token))
  2921  return PTR_ERR(token);
  2922  /* if current token doesn't grant prog loading 
permissions,
  2923   * then we can't use this token, so ignore it and rely 
on
  2924   * system-wide capabilities checks
  2925   */
  2926  if (!bpf_token_allow_cmd(token, BPF_PROG_LOAD) ||
  2927  !bpf_token_allow_prog_type(token, attr->prog_type,
  2928 
attr->expected_attach_type)) {
  2929  bpf_token_put(token);
  2930  token = NULL;
  2931  }
  2932  }
  2933  
  2934  bpf_cap = bpf_token_capable(token, CAP_BPF);
  2935  err = -EPERM;
  2936  
  2937  if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) &&
  2938  (attr->prog_flags & BPF_F_ANY_ALIGNMENT) &&
  2939  !bpf_cap)
  2940  goto put_token;
  2941  
  2942  /* Intent here is for unprivileged_bpf_disabled to block BPF 
program
  2943   * creation for unprivileged users; other actions depend
  2944   * on fd availability and access to bpffs, so are dependent on
  2945   * object creation success. Even with unprivileged BPF disabled,
  2946   * capability checks are still carried out for these
  2947   * and other operations.
  2948   */
  2949  if (sysctl_unprivileged_bpf_disabled && !bpf_cap)
  2950  go

[PATCHv3 bpf-next 06/24] bpf: Add multi tracing attach types

2026-03-16 Thread Jiri Olsa
Adding new program attach types multi tracing attachment:
  BPF_TRACE_FENTRY_MULTI
  BPF_TRACE_FEXIT_MULTI

and their base support in verifier code.

Programs with such attach type will use specific link attachment
interface coming in following changes.

This was suggested by Andrii some (long) time ago and turned out
to be easier than having special program flag for that.

Bpf programs with such types have 'bpf_multi_func' function set as
their attach_btf_id and keep module reference when it's specified
by attach_prog_fd.

They are also accepted as sleepable programs during verification,
and the real validation for specific BTF_IDs/functions will happen
during the multi link attachment in following changes.

Suggested-by: Andrii Nakryiko 
Signed-off-by: Jiri Olsa 
---
 include/linux/bpf.h|  5 +
 include/linux/btf_ids.h|  1 +
 include/uapi/linux/bpf.h   |  2 ++
 kernel/bpf/btf.c   |  2 ++
 kernel/bpf/syscall.c   | 33 
 kernel/bpf/trampoline.c|  5 -
 kernel/bpf/verifier.c  | 40 +-
 net/bpf/test_run.c |  2 ++
 tools/include/uapi/linux/bpf.h |  2 ++
 tools/lib/bpf/libbpf.c |  2 ++
 10 files changed, 88 insertions(+), 6 deletions(-)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index d536640aef41..c401b308a325 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -2116,6 +2116,11 @@ void bpf_prog_disassoc_struct_ops(struct bpf_prog *prog);
 void *bpf_prog_get_assoc_struct_ops(const struct bpf_prog_aux *aux);
 u32 bpf_struct_ops_id(const void *kdata);
 
+static inline bool is_tracing_multi(enum bpf_attach_type type)
+{
+   return type == BPF_TRACE_FENTRY_MULTI || type == BPF_TRACE_FEXIT_MULTI;
+}
+
 #ifdef CONFIG_NET
 /* Define it here to avoid the use of forward declaration */
 struct bpf_dummy_ops_state {
diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h
index 139bdececdcf..eb2c4432856d 100644
--- a/include/linux/btf_ids.h
+++ b/include/linux/btf_ids.h
@@ -284,5 +284,6 @@ extern u32 bpf_cgroup_btf_id[];
 extern u32 bpf_local_storage_map_btf_id[];
 extern u32 btf_bpf_map_id[];
 extern u32 bpf_kmem_cache_btf_id[];
+extern u32 bpf_multi_func_btf_id[];
 
 #endif
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index c8d400b7680a..68600972a778 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1154,6 +1154,8 @@ enum bpf_attach_type {
BPF_TRACE_KPROBE_SESSION,
BPF_TRACE_UPROBE_SESSION,
BPF_TRACE_FSESSION,
+   BPF_TRACE_FENTRY_MULTI,
+   BPF_TRACE_FEXIT_MULTI,
__MAX_BPF_ATTACH_TYPE
 };
 
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 09fcbb125155..c8738834bbc9 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -6221,6 +6221,8 @@ static int btf_validate_prog_ctx_type(struct 
bpf_verifier_log *log, const struct
case BPF_TRACE_FEXIT:
case BPF_MODIFY_RETURN:
case BPF_TRACE_FSESSION:
+   case BPF_TRACE_FENTRY_MULTI:
+   case BPF_TRACE_FEXIT_MULTI:
/* allow u64* as ctx */
if (btf_is_int(t) && t->size == 8)
return 0;
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 003ad95940c9..2680740e9c09 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -41,6 +41,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -2653,7 +2654,8 @@ static int
 bpf_prog_load_check_attach(enum bpf_prog_type prog_type,
   enum bpf_attach_type expected_attach_type,
   struct btf *attach_btf, u32 btf_id,
-  struct bpf_prog *dst_prog)
+  struct bpf_prog *dst_prog,
+  bool multi_func)
 {
if (btf_id) {
if (btf_id > BTF_MAX_TYPE)
@@ -2673,6 +2675,14 @@ bpf_prog_load_check_attach(enum bpf_prog_type prog_type,
}
}
 
+   if (multi_func) {
+   if (prog_type != BPF_PROG_TYPE_TRACING)
+   return -EINVAL;
+   if (!attach_btf || btf_id)
+   return -EINVAL;
+   return 0;
+   }
+
if (attach_btf && (!btf_id || dst_prog))
return -EINVAL;
 
@@ -2865,6 +2875,16 @@ static int bpf_prog_mark_insn_arrays_ready(struct 
bpf_prog *prog)
return 0;
 }
 
+#define DEFINE_BPF_MULTI_FUNC(args...) \
+   extern int bpf_multi_func(args);\
+   int __init bpf_multi_func(args) { return 0; }
+
+DEFINE_BPF_MULTI_FUNC(unsigned long a1, unsigned long a2,
+ unsigned long a3, unsigned long a4,
+ unsigned long a5, unsigned long a6)
+
+BTF_ID_LIST_GLOBAL_SINGLE(bpf_multi_func_btf_id, func, bpf_multi_func)
+
 /* last field in 'union bpf_attr' used by this command */
 #define