1958cf2e2SKumar Kartikeya Dwivedi #ifndef __BPF_EXPERIMENTAL__ 2958cf2e2SKumar Kartikeya Dwivedi #define __BPF_EXPERIMENTAL__ 3958cf2e2SKumar Kartikeya Dwivedi 4958cf2e2SKumar Kartikeya Dwivedi #include <vmlinux.h> 5958cf2e2SKumar Kartikeya Dwivedi #include <bpf/bpf_tracing.h> 6958cf2e2SKumar Kartikeya Dwivedi #include <bpf/bpf_helpers.h> 7958cf2e2SKumar Kartikeya Dwivedi #include <bpf/bpf_core_read.h> 8958cf2e2SKumar Kartikeya Dwivedi 964069c72SKumar Kartikeya Dwivedi #define __contains(name, node) __attribute__((btf_decl_tag("contains:" #name ":" #node))) 1064069c72SKumar Kartikeya Dwivedi 11958cf2e2SKumar Kartikeya Dwivedi /* Description 12958cf2e2SKumar Kartikeya Dwivedi * Allocates an object of the type represented by 'local_type_id' in 13958cf2e2SKumar Kartikeya Dwivedi * program BTF. User may use the bpf_core_type_id_local macro to pass the 14958cf2e2SKumar Kartikeya Dwivedi * type ID of a struct in program BTF. 15958cf2e2SKumar Kartikeya Dwivedi * 16958cf2e2SKumar Kartikeya Dwivedi * The 'local_type_id' parameter must be a known constant. 17d2dcc67dSDave Marchevsky * The 'meta' parameter is rewritten by the verifier, no need for BPF 18d2dcc67dSDave Marchevsky * program to set it. 19958cf2e2SKumar Kartikeya Dwivedi * Returns 20958cf2e2SKumar Kartikeya Dwivedi * A pointer to an object of the type corresponding to the passed in 21958cf2e2SKumar Kartikeya Dwivedi * 'local_type_id', or NULL on failure. 22958cf2e2SKumar Kartikeya Dwivedi */ 23958cf2e2SKumar Kartikeya Dwivedi extern void *bpf_obj_new_impl(__u64 local_type_id, void *meta) __ksym; 24958cf2e2SKumar Kartikeya Dwivedi 25958cf2e2SKumar Kartikeya Dwivedi /* Convenience macro to wrap over bpf_obj_new_impl */ 26958cf2e2SKumar Kartikeya Dwivedi #define bpf_obj_new(type) ((type *)bpf_obj_new_impl(bpf_core_type_id_local(type), NULL)) 27958cf2e2SKumar Kartikeya Dwivedi 28ac9f0605SKumar Kartikeya Dwivedi /* Description 29ac9f0605SKumar Kartikeya Dwivedi * Free an allocated object. All fields of the object that require 30ac9f0605SKumar Kartikeya Dwivedi * destruction will be destructed before the storage is freed. 31ac9f0605SKumar Kartikeya Dwivedi * 32d2dcc67dSDave Marchevsky * The 'meta' parameter is rewritten by the verifier, no need for BPF 33d2dcc67dSDave Marchevsky * program to set it. 34ac9f0605SKumar Kartikeya Dwivedi * Returns 35ac9f0605SKumar Kartikeya Dwivedi * Void. 36ac9f0605SKumar Kartikeya Dwivedi */ 37ac9f0605SKumar Kartikeya Dwivedi extern void bpf_obj_drop_impl(void *kptr, void *meta) __ksym; 38ac9f0605SKumar Kartikeya Dwivedi 39ac9f0605SKumar Kartikeya Dwivedi /* Convenience macro to wrap over bpf_obj_drop_impl */ 40ac9f0605SKumar Kartikeya Dwivedi #define bpf_obj_drop(kptr) bpf_obj_drop_impl(kptr, NULL) 41ac9f0605SKumar Kartikeya Dwivedi 428cab76ecSKumar Kartikeya Dwivedi /* Description 437c50b1cbSDave Marchevsky * Increment the refcount on a refcounted local kptr, turning the 447c50b1cbSDave Marchevsky * non-owning reference input into an owning reference in the process. 457c50b1cbSDave Marchevsky * 46d2dcc67dSDave Marchevsky * The 'meta' parameter is rewritten by the verifier, no need for BPF 47d2dcc67dSDave Marchevsky * program to set it. 487c50b1cbSDave Marchevsky * Returns 497c50b1cbSDave Marchevsky * An owning reference to the object pointed to by 'kptr' 507c50b1cbSDave Marchevsky */ 517c50b1cbSDave Marchevsky extern void *bpf_refcount_acquire_impl(void *kptr, void *meta) __ksym; 527c50b1cbSDave Marchevsky 537c50b1cbSDave Marchevsky /* Convenience macro to wrap over bpf_refcount_acquire_impl */ 547c50b1cbSDave Marchevsky #define bpf_refcount_acquire(kptr) bpf_refcount_acquire_impl(kptr, NULL) 557c50b1cbSDave Marchevsky 567c50b1cbSDave Marchevsky /* Description 578cab76ecSKumar Kartikeya Dwivedi * Add a new entry to the beginning of the BPF linked list. 58d2dcc67dSDave Marchevsky * 59d2dcc67dSDave Marchevsky * The 'meta' and 'off' parameters are rewritten by the verifier, no need 60d2dcc67dSDave Marchevsky * for BPF programs to set them 618cab76ecSKumar Kartikeya Dwivedi * Returns 62d2dcc67dSDave Marchevsky * 0 if the node was successfully added 63d2dcc67dSDave Marchevsky * -EINVAL if the node wasn't added because it's already in a list 648cab76ecSKumar Kartikeya Dwivedi */ 65d2dcc67dSDave Marchevsky extern int bpf_list_push_front_impl(struct bpf_list_head *head, 66d2dcc67dSDave Marchevsky struct bpf_list_node *node, 67d2dcc67dSDave Marchevsky void *meta, __u64 off) __ksym; 68d2dcc67dSDave Marchevsky 69d2dcc67dSDave Marchevsky /* Convenience macro to wrap over bpf_list_push_front_impl */ 70d2dcc67dSDave Marchevsky #define bpf_list_push_front(head, node) bpf_list_push_front_impl(head, node, NULL, 0) 718cab76ecSKumar Kartikeya Dwivedi 728cab76ecSKumar Kartikeya Dwivedi /* Description 738cab76ecSKumar Kartikeya Dwivedi * Add a new entry to the end of the BPF linked list. 74d2dcc67dSDave Marchevsky * 75d2dcc67dSDave Marchevsky * The 'meta' and 'off' parameters are rewritten by the verifier, no need 76d2dcc67dSDave Marchevsky * for BPF programs to set them 778cab76ecSKumar Kartikeya Dwivedi * Returns 78d2dcc67dSDave Marchevsky * 0 if the node was successfully added 79d2dcc67dSDave Marchevsky * -EINVAL if the node wasn't added because it's already in a list 808cab76ecSKumar Kartikeya Dwivedi */ 81d2dcc67dSDave Marchevsky extern int bpf_list_push_back_impl(struct bpf_list_head *head, 82d2dcc67dSDave Marchevsky struct bpf_list_node *node, 83d2dcc67dSDave Marchevsky void *meta, __u64 off) __ksym; 84d2dcc67dSDave Marchevsky 85d2dcc67dSDave Marchevsky /* Convenience macro to wrap over bpf_list_push_back_impl */ 86d2dcc67dSDave Marchevsky #define bpf_list_push_back(head, node) bpf_list_push_back_impl(head, node, NULL, 0) 878cab76ecSKumar Kartikeya Dwivedi 888cab76ecSKumar Kartikeya Dwivedi /* Description 898cab76ecSKumar Kartikeya Dwivedi * Remove the entry at the beginning of the BPF linked list. 908cab76ecSKumar Kartikeya Dwivedi * Returns 918cab76ecSKumar Kartikeya Dwivedi * Pointer to bpf_list_node of deleted entry, or NULL if list is empty. 928cab76ecSKumar Kartikeya Dwivedi */ 938cab76ecSKumar Kartikeya Dwivedi extern struct bpf_list_node *bpf_list_pop_front(struct bpf_list_head *head) __ksym; 948cab76ecSKumar Kartikeya Dwivedi 958cab76ecSKumar Kartikeya Dwivedi /* Description 968cab76ecSKumar Kartikeya Dwivedi * Remove the entry at the end of the BPF linked list. 978cab76ecSKumar Kartikeya Dwivedi * Returns 988cab76ecSKumar Kartikeya Dwivedi * Pointer to bpf_list_node of deleted entry, or NULL if list is empty. 998cab76ecSKumar Kartikeya Dwivedi */ 1008cab76ecSKumar Kartikeya Dwivedi extern struct bpf_list_node *bpf_list_pop_back(struct bpf_list_head *head) __ksym; 1018cab76ecSKumar Kartikeya Dwivedi 102c834df84SDave Marchevsky /* Description 103c834df84SDave Marchevsky * Remove 'node' from rbtree with root 'root' 104c834df84SDave Marchevsky * Returns 105c834df84SDave Marchevsky * Pointer to the removed node, or NULL if 'root' didn't contain 'node' 106c834df84SDave Marchevsky */ 107c834df84SDave Marchevsky extern struct bpf_rb_node *bpf_rbtree_remove(struct bpf_rb_root *root, 108c834df84SDave Marchevsky struct bpf_rb_node *node) __ksym; 109c834df84SDave Marchevsky 110c834df84SDave Marchevsky /* Description 111c834df84SDave Marchevsky * Add 'node' to rbtree with root 'root' using comparator 'less' 112d2dcc67dSDave Marchevsky * 113d2dcc67dSDave Marchevsky * The 'meta' and 'off' parameters are rewritten by the verifier, no need 114d2dcc67dSDave Marchevsky * for BPF programs to set them 115c834df84SDave Marchevsky * Returns 116d2dcc67dSDave Marchevsky * 0 if the node was successfully added 117d2dcc67dSDave Marchevsky * -EINVAL if the node wasn't added because it's already in a tree 118c834df84SDave Marchevsky */ 119d2dcc67dSDave Marchevsky extern int bpf_rbtree_add_impl(struct bpf_rb_root *root, struct bpf_rb_node *node, 120d2dcc67dSDave Marchevsky bool (less)(struct bpf_rb_node *a, const struct bpf_rb_node *b), 121d2dcc67dSDave Marchevsky void *meta, __u64 off) __ksym; 122d2dcc67dSDave Marchevsky 123d2dcc67dSDave Marchevsky /* Convenience macro to wrap over bpf_rbtree_add_impl */ 124d2dcc67dSDave Marchevsky #define bpf_rbtree_add(head, node, less) bpf_rbtree_add_impl(head, node, less, NULL, 0) 125c834df84SDave Marchevsky 126c834df84SDave Marchevsky /* Description 127c834df84SDave Marchevsky * Return the first (leftmost) node in input tree 128c834df84SDave Marchevsky * Returns 129c834df84SDave Marchevsky * Pointer to the node, which is _not_ removed from the tree. If the tree 130c834df84SDave Marchevsky * contains no nodes, returns NULL. 131c834df84SDave Marchevsky */ 132c834df84SDave Marchevsky extern struct bpf_rb_node *bpf_rbtree_first(struct bpf_rb_root *root) __ksym; 133c834df84SDave Marchevsky 134*bef1f6beSYonghong Song /* Description 135*bef1f6beSYonghong Song * Allocates a percpu object of the type represented by 'local_type_id' in 136*bef1f6beSYonghong Song * program BTF. User may use the bpf_core_type_id_local macro to pass the 137*bef1f6beSYonghong Song * type ID of a struct in program BTF. 138*bef1f6beSYonghong Song * 139*bef1f6beSYonghong Song * The 'local_type_id' parameter must be a known constant. 140*bef1f6beSYonghong Song * The 'meta' parameter is rewritten by the verifier, no need for BPF 141*bef1f6beSYonghong Song * program to set it. 142*bef1f6beSYonghong Song * Returns 143*bef1f6beSYonghong Song * A pointer to a percpu object of the type corresponding to the passed in 144*bef1f6beSYonghong Song * 'local_type_id', or NULL on failure. 145*bef1f6beSYonghong Song */ 146*bef1f6beSYonghong Song extern void *bpf_percpu_obj_new_impl(__u64 local_type_id, void *meta) __ksym; 147*bef1f6beSYonghong Song 148*bef1f6beSYonghong Song /* Convenience macro to wrap over bpf_percpu_obj_new_impl */ 149*bef1f6beSYonghong Song #define bpf_percpu_obj_new(type) ((type __percpu_kptr *)bpf_percpu_obj_new_impl(bpf_core_type_id_local(type), NULL)) 150*bef1f6beSYonghong Song 151*bef1f6beSYonghong Song /* Description 152*bef1f6beSYonghong Song * Free an allocated percpu object. All fields of the object that require 153*bef1f6beSYonghong Song * destruction will be destructed before the storage is freed. 154*bef1f6beSYonghong Song * 155*bef1f6beSYonghong Song * The 'meta' parameter is rewritten by the verifier, no need for BPF 156*bef1f6beSYonghong Song * program to set it. 157*bef1f6beSYonghong Song * Returns 158*bef1f6beSYonghong Song * Void. 159*bef1f6beSYonghong Song */ 160*bef1f6beSYonghong Song extern void bpf_percpu_obj_drop_impl(void *kptr, void *meta) __ksym; 161*bef1f6beSYonghong Song 162*bef1f6beSYonghong Song /* Convenience macro to wrap over bpf_obj_drop_impl */ 163*bef1f6beSYonghong Song #define bpf_percpu_obj_drop(kptr) bpf_percpu_obj_drop_impl(kptr, NULL) 164*bef1f6beSYonghong Song 165958cf2e2SKumar Kartikeya Dwivedi #endif 166