Macro DEFINE_BPF_ITER_FUNC is implemented so target can define an init function to capture the BTF type which represents the target. The bpf_iter_meta is a structure holding meta data, common to all targets in the bpf program. Additional marker functions are called before or after bpf_seq_read() show()/next()/stop() callback functions to help calculate precise seq_num and whether call bpf_prog inside stop(). Two functions, bpf_iter_get_info() and bpf_iter_run_prog(), are implemented so target can get needed information from bpf_iter infrastructure and can run the program.
Showing the changes to include/linux (1 of 2 files). Show all
Unified · Split
| @@ -1129,6 +1129,9 @@ int bpf_obj_pin_user(u32 ufd, const char __user *pathname); · 1128 unmodified lines | |||
| 1129 | int bpf_obj_get_user(const char __user *pathname, int flags); | 1129 | int bpf_obj_get_user(const char __user *pathname, int flags); |
| 1130 | 1130 | ||
| 1131 | #define BPF_ITER_FUNC_PREFIX "__bpf_iter__" | 1131 | #define BPF_ITER_FUNC_PREFIX "__bpf_iter__" |
| 1132 | #define DEFINE_BPF_ITER_FUNC(target, args...) \ | ||
| 1133 | extern int __bpf_iter__ ## target(args); \ | ||
| 1134 | int __init __bpf_iter__ ## target(args) { return 0; } | ||
| 1132 | 1135 | ||
| 1133 | typedef int (*bpf_iter_init_seq_priv_t)(void *private_data); | 1136 | typedef int (*bpf_iter_init_seq_priv_t)(void *private_data); |
| 1134 | typedef void (*bpf_iter_fini_seq_priv_t)(void *private_data); | 1137 | typedef void (*bpf_iter_fini_seq_priv_t)(void *private_data); |
| @@ -1141,12 +1144,20 @@ struct bpf_iter_reg { · 6 unmodified lines | |||
| 1141 | u32 seq_priv_size; | 1144 | u32 seq_priv_size; |
| 1142 | }; | 1145 | }; |
| 1143 | 1146 | ||
| 1147 | struct bpf_iter_meta { | ||
| 1148 | __bpf_md_ptr(struct seq_file *, seq); | ||
| 1149 | u64 session_id; | ||
| 1150 | u64 seq_num; | ||
| 1151 | }; | ||
| 1152 | |||
| 1144 | int bpf_iter_reg_target(struct bpf_iter_reg *reg_info); | 1153 | int bpf_iter_reg_target(struct bpf_iter_reg *reg_info); |
| 1145 | void bpf_iter_unreg_target(const char *target); | 1154 | void bpf_iter_unreg_target(const char *target); |
| 1146 | bool bpf_iter_prog_supported(struct bpf_prog *prog); | 1155 | bool bpf_iter_prog_supported(struct bpf_prog *prog); |
| 1147 | int bpf_iter_link_attach(const union bpf_attr *attr, struct bpf_prog *prog); | 1156 | int bpf_iter_link_attach(const union bpf_attr *attr, struct bpf_prog *prog); |
| 1148 | int bpf_iter_new_fd(struct bpf_link *link); | 1157 | int bpf_iter_new_fd(struct bpf_link *link); |
| 1149 | bool bpf_link_is_iter(struct bpf_link *link); | 1158 | bool bpf_link_is_iter(struct bpf_link *link); |
| 1159 | struct bpf_prog *bpf_iter_get_info(struct bpf_iter_meta *meta, bool in_stop); | ||
| 1160 | int bpf_iter_run_prog(struct bpf_prog *prog, void *ctx); | ||
| 1150 | 1161 | ||
| 1151 | int bpf_percpu_hash_copy(struct bpf_map *map, void *key, void *value); | 1162 | int bpf_percpu_hash_copy(struct bpf_map *map, void *key, void *value); |
| 1152 | int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value); | 1163 | int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value); |