Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: Update kfuncs using btf_struct_meta to new variants

Update selftests to use the new non-_impl kfuncs marked with
KF_IMPLICIT_ARGS by removing redundant declarations and macros from
bpf_experimental.h (the new kfuncs are present in the vmlinux.h) and
updating relevant callsites.

Fix spin_lock verifier-log matching for lock_id_kptr_preserve by
accepting variable instruction numbers. The calls to kfuncs with
implicit arguments do not have register moves (e.g. r5 = 0)
corresponding to dummy arguments anymore, so the order of instructions
has shifted.

Acked-by: Mykyta Yatsenko <yatsenko@meta.com>
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20260327203241.3365046-2-ihor.solodrai@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Ihor Solodrai and committed by
Alexei Starovoitov
101a9d9d d4570725

+9 -156
+4 -152
tools/testing/selftests/bpf/bpf_experimental.h
··· 8 8 9 9 #define __contains(name, node) __attribute__((btf_decl_tag("contains:" #name ":" #node))) 10 10 11 - /* Description 12 - * Allocates an object of the type represented by 'local_type_id' in 13 - * program BTF. User may use the bpf_core_type_id_local macro to pass the 14 - * type ID of a struct in program BTF. 15 - * 16 - * The 'local_type_id' parameter must be a known constant. 17 - * The 'meta' parameter is rewritten by the verifier, no need for BPF 18 - * program to set it. 19 - * Returns 20 - * A pointer to an object of the type corresponding to the passed in 21 - * 'local_type_id', or NULL on failure. 22 - */ 23 - extern void *bpf_obj_new_impl(__u64 local_type_id, void *meta) __ksym; 11 + /* Convenience macro to wrap over bpf_obj_new */ 12 + #define bpf_obj_new(type) ((type *)bpf_obj_new(bpf_core_type_id_local(type))) 24 13 25 - /* Convenience macro to wrap over bpf_obj_new_impl */ 26 - #define bpf_obj_new(type) ((type *)bpf_obj_new_impl(bpf_core_type_id_local(type), NULL)) 27 - 28 - /* Description 29 - * Free an allocated object. All fields of the object that require 30 - * destruction will be destructed before the storage is freed. 31 - * 32 - * The 'meta' parameter is rewritten by the verifier, no need for BPF 33 - * program to set it. 34 - * Returns 35 - * Void. 36 - */ 37 - extern void bpf_obj_drop_impl(void *kptr, void *meta) __ksym; 38 - 39 - /* Convenience macro to wrap over bpf_obj_drop_impl */ 40 - #define bpf_obj_drop(kptr) bpf_obj_drop_impl(kptr, NULL) 41 - 42 - /* Description 43 - * Increment the refcount on a refcounted local kptr, turning the 44 - * non-owning reference input into an owning reference in the process. 45 - * 46 - * The 'meta' parameter is rewritten by the verifier, no need for BPF 47 - * program to set it. 48 - * Returns 49 - * An owning reference to the object pointed to by 'kptr' 50 - */ 51 - extern void *bpf_refcount_acquire_impl(void *kptr, void *meta) __ksym; 52 - 53 - /* Convenience macro to wrap over bpf_refcount_acquire_impl */ 54 - #define bpf_refcount_acquire(kptr) bpf_refcount_acquire_impl(kptr, NULL) 55 - 56 - /* Description 57 - * Add a new entry to the beginning of the BPF linked list. 58 - * 59 - * The 'meta' and 'off' parameters are rewritten by the verifier, no need 60 - * for BPF programs to set them 61 - * Returns 62 - * 0 if the node was successfully added 63 - * -EINVAL if the node wasn't added because it's already in a list 64 - */ 65 - extern int bpf_list_push_front_impl(struct bpf_list_head *head, 66 - struct bpf_list_node *node, 67 - void *meta, __u64 off) __ksym; 68 - 69 - /* Convenience macro to wrap over bpf_list_push_front_impl */ 70 - #define bpf_list_push_front(head, node) bpf_list_push_front_impl(head, node, NULL, 0) 71 - 72 - /* Description 73 - * Add a new entry to the end of the BPF linked list. 74 - * 75 - * The 'meta' and 'off' parameters are rewritten by the verifier, no need 76 - * for BPF programs to set them 77 - * Returns 78 - * 0 if the node was successfully added 79 - * -EINVAL if the node wasn't added because it's already in a list 80 - */ 81 - extern int bpf_list_push_back_impl(struct bpf_list_head *head, 82 - struct bpf_list_node *node, 83 - void *meta, __u64 off) __ksym; 84 - 85 - /* Convenience macro to wrap over bpf_list_push_back_impl */ 86 - #define bpf_list_push_back(head, node) bpf_list_push_back_impl(head, node, NULL, 0) 87 - 88 - /* Description 89 - * Remove the entry at the beginning of the BPF linked list. 90 - * Returns 91 - * Pointer to bpf_list_node of deleted entry, or NULL if list is empty. 92 - */ 93 - extern struct bpf_list_node *bpf_list_pop_front(struct bpf_list_head *head) __ksym; 94 - 95 - /* Description 96 - * Remove the entry at the end of the BPF linked list. 97 - * Returns 98 - * Pointer to bpf_list_node of deleted entry, or NULL if list is empty. 99 - */ 100 - extern struct bpf_list_node *bpf_list_pop_back(struct bpf_list_head *head) __ksym; 101 - 102 - /* Description 103 - * Remove 'node' from rbtree with root 'root' 104 - * Returns 105 - * Pointer to the removed node, or NULL if 'root' didn't contain 'node' 106 - */ 107 - extern struct bpf_rb_node *bpf_rbtree_remove(struct bpf_rb_root *root, 108 - struct bpf_rb_node *node) __ksym; 109 - 110 - /* Description 111 - * Add 'node' to rbtree with root 'root' using comparator 'less' 112 - * 113 - * The 'meta' and 'off' parameters are rewritten by the verifier, no need 114 - * for BPF programs to set them 115 - * Returns 116 - * 0 if the node was successfully added 117 - * -EINVAL if the node wasn't added because it's already in a tree 118 - */ 119 - extern int bpf_rbtree_add_impl(struct bpf_rb_root *root, struct bpf_rb_node *node, 120 - bool (less)(struct bpf_rb_node *a, const struct bpf_rb_node *b), 121 - void *meta, __u64 off) __ksym; 122 - 123 - /* Convenience macro to wrap over bpf_rbtree_add_impl */ 124 - #define bpf_rbtree_add(head, node, less) bpf_rbtree_add_impl(head, node, less, NULL, 0) 125 - 126 - /* Description 127 - * Return the first (leftmost) node in input tree 128 - * Returns 129 - * Pointer to the node, which is _not_ removed from the tree. If the tree 130 - * contains no nodes, returns NULL. 131 - */ 132 - extern struct bpf_rb_node *bpf_rbtree_first(struct bpf_rb_root *root) __ksym; 133 - 134 - /* Description 135 - * Allocates a percpu object of the type represented by 'local_type_id' in 136 - * program BTF. User may use the bpf_core_type_id_local macro to pass the 137 - * type ID of a struct in program BTF. 138 - * 139 - * The 'local_type_id' parameter must be a known constant. 140 - * The 'meta' parameter is rewritten by the verifier, no need for BPF 141 - * program to set it. 142 - * Returns 143 - * A pointer to a percpu object of the type corresponding to the passed in 144 - * 'local_type_id', or NULL on failure. 145 - */ 146 - extern void *bpf_percpu_obj_new_impl(__u64 local_type_id, void *meta) __ksym; 147 - 148 - /* Convenience macro to wrap over bpf_percpu_obj_new_impl */ 149 - #define bpf_percpu_obj_new(type) ((type __percpu_kptr *)bpf_percpu_obj_new_impl(bpf_core_type_id_local(type), NULL)) 150 - 151 - /* Description 152 - * Free an allocated percpu object. All fields of the object that require 153 - * destruction will be destructed before the storage is freed. 154 - * 155 - * The 'meta' parameter is rewritten by the verifier, no need for BPF 156 - * program to set it. 157 - * Returns 158 - * Void. 159 - */ 160 - extern void bpf_percpu_obj_drop_impl(void *kptr, void *meta) __ksym; 14 + /* Convenience macro to wrap over bpf_percpu_obj_new */ 15 + #define bpf_percpu_obj_new(type) ((type __percpu_kptr *)bpf_percpu_obj_new(bpf_core_type_id_local(type))) 161 16 162 17 struct bpf_iter_task_vma; 163 18 ··· 21 166 __u64 addr) __ksym; 22 167 extern struct vm_area_struct *bpf_iter_task_vma_next(struct bpf_iter_task_vma *it) __ksym; 23 168 extern void bpf_iter_task_vma_destroy(struct bpf_iter_task_vma *it) __ksym; 24 - 25 - /* Convenience macro to wrap over bpf_obj_drop_impl */ 26 - #define bpf_percpu_obj_drop(kptr) bpf_percpu_obj_drop_impl(kptr, NULL) 27 169 28 170 /* Description 29 171 * Throw a BPF exception from the program, immediately terminating its
+3 -2
tools/testing/selftests/bpf/prog_tests/spin_lock.c
··· 13 13 const char *err_msg; 14 14 } spin_lock_fail_tests[] = { 15 15 { "lock_id_kptr_preserve", 16 - "5: (bf) r1 = r0 ; R0=ptr_foo(id=2,ref_obj_id=2) " 17 - "R1=ptr_foo(id=2,ref_obj_id=2) refs=2\n6: (85) call bpf_this_cpu_ptr#154\n" 16 + "[0-9]\\+: (bf) r1 = r0 ; R0=ptr_foo(id=2,ref_obj_id=2)" 17 + " R1=ptr_foo(id=2,ref_obj_id=2) refs=2\n" 18 + "[0-9]\\+: (85) call bpf_this_cpu_ptr#154\n" 18 19 "R1 type=ptr_ expected=percpu_ptr_" }, 19 20 { "lock_id_global_zero", 20 21 "; R1=map_value(map=.data.A,ks=4,vs=4)\n2: (85) call bpf_this_cpu_ptr#154\n"
+2 -2
tools/testing/selftests/bpf/progs/kptr_xchg_inline.c
··· 25 25 "if r0 == 0 goto 1f;" 26 26 "r1 = r0;" 27 27 "r2 = 0;" 28 - "call %[bpf_obj_drop_impl];" 28 + "call %[bpf_obj_drop];" 29 29 "1:" 30 30 "r0 = 0;" 31 31 "exit;" 32 32 : 33 33 : __imm_addr(ptr), 34 34 __imm(bpf_kptr_xchg), 35 - __imm(bpf_obj_drop_impl) 35 + __imm(bpf_obj_drop) 36 36 : __clobber_all 37 37 ); 38 38 }