1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */ 3 4 #ifndef __BPF_DIAGNOSTICS_H 5 #define __BPF_DIAGNOSTICS_H 6 7 #include <linux/compiler_attributes.h> 8 #include <linux/stdarg.h> 9 #include <linux/types.h> 10 11 struct bpf_func_state; 12 struct bpf_reg_state; 13 struct bpf_verifier_env; 14 struct btf; 15 16 enum bpf_diag_mod_reason { 17 BPF_DIAG_MOD_WRITE, 18 BPF_DIAG_MOD_SPILL, 19 BPF_DIAG_MOD_VAR_WRITE, 20 BPF_DIAG_MOD_REF_RELEASE, 21 BPF_DIAG_MOD_PKT_DATA_CHANGE, 22 BPF_DIAG_MOD_NON_OWN_REF, 23 BPF_DIAG_MOD_CALLER_SAVED, 24 }; 25 26 bool bpf_diag_enabled(const struct bpf_verifier_env *env); 27 int bpf_diag_init(struct bpf_verifier_env *env); 28 void bpf_diag_init_frame(struct bpf_verifier_env *env, struct bpf_func_state *state); 29 char *bpf_diag_fmt_buf(struct bpf_verifier_env *env, size_t size); 30 const char *bpf_diag_vfmt(struct bpf_verifier_env *env, const char *fmt, va_list args) 31 __printf(2, 0); 32 const char *bpf_diag_fmt(struct bpf_verifier_env *env, const char *fmt, ...) __printf(2, 3); 33 const char *bpf_diag_fmt_btf_type(struct bpf_verifier_env *env, const struct btf *btf, u32 type_id); 34 u64 bpf_diag_event_log_save(struct bpf_verifier_env *env); 35 void bpf_diag_event_log_restore(struct bpf_verifier_env *env, u64 log_pos); 36 void bpf_diag_free(struct bpf_verifier_env *env); 37 void bpf_diag_record_branch(struct bpf_verifier_env *env, u32 insn_idx, bool cond_true); 38 void bpf_diag_mod_begin(struct bpf_verifier_env *env, const struct bpf_reg_state *reg, 39 const struct bpf_reg_state *origin, enum bpf_diag_mod_reason reason); 40 void bpf_diag_mod_end(struct bpf_verifier_env *env); 41 void bpf_diag_record_scrub(struct bpf_verifier_env *env, const struct bpf_reg_state *reg, 42 enum bpf_diag_mod_reason reason); 43 void bpf_diag_record_scrub_stack(struct bpf_verifier_env *env, 44 const struct bpf_func_state *state, s16 min_off, s16 max_off, 45 enum bpf_diag_mod_reason reason); 46 void bpf_diag_record_ref_acquire(struct bpf_verifier_env *env, u32 insn_idx, u32 ref_id); 47 void bpf_diag_record_ref_release(struct bpf_verifier_env *env, u32 insn_idx, u32 ref_id); 48 49 #endif /* __BPF_DIAGNOSTICS_H */ 50