diff options
| author | Alexei Starovoitov <ast@kernel.org> | 2019-01-24 04:35:33 +0300 |
|---|---|---|
| committer | Alexei Starovoitov <ast@kernel.org> | 2019-01-24 04:35:33 +0300 |
| commit | 923cefe3f90148b5da26433f6affbce7908e528d (patch) | |
| tree | 28a991a3a4afc3b0116f559f139c94e473044499 /include | |
| parent | bbebce8eb9a54091b9a66121fd26b7caabd76895 (diff) | |
| parent | 9a06927e778bc4e805acc8fa03573bbf7e597cc5 (diff) | |
| download | linux-923cefe3f90148b5da26433f6affbce7908e528d.tar.xz | |
Merge branch 'dead-code-elimination'
Jakub Kicinski says:
====================
This set adds support for complete removal of dead code.
Patch 3 contains all the code removal logic, patches 2 and 4
additionally optimize branches around and to dead code.
Patches 6 and 7 allow offload JITs to take advantage of the
optimization. After a few small clean ups (8, 9, 10) nfp
support is added (11, 12).
Removing code directly in the verifier makes it easy to adjust
the relevant metadata (line info, subprogram info). JITs for
code store constrained architectures would have hard time
performing such adjustments at JIT level. Removing subprograms
or line info is very hard once BPF core finished the verification.
For user space to perform dead code removal it would have to perform
the execution simulation/analysis similar to what the verifier does.
v3:
- fix uninitilized var warning in GCC 6 (buildbot).
v4:
- simplify the linfo-keeping logic (Yonghong). Instead of
trying to figure out that we are removing first instruction
of a subprogram, just always keep last dead line info, if
first live instruction doesn't have one.
v5:
- improve comments (Martin Lau).
====================
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/linux/bpf.h | 7 | ||||
| -rw-r--r-- | include/linux/bpf_verifier.h | 6 | ||||
| -rw-r--r-- | include/linux/filter.h | 1 |
3 files changed, 14 insertions, 0 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h index e734f163bd0b..3851529062ec 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -268,9 +268,15 @@ struct bpf_verifier_ops { }; struct bpf_prog_offload_ops { + /* verifier basic callbacks */ int (*insn_hook)(struct bpf_verifier_env *env, int insn_idx, int prev_insn_idx); int (*finalize)(struct bpf_verifier_env *env); + /* verifier optimization callbacks (called after .finalize) */ + int (*replace_insn)(struct bpf_verifier_env *env, u32 off, + struct bpf_insn *insn); + int (*remove_insns)(struct bpf_verifier_env *env, u32 off, u32 cnt); + /* program management callbacks */ int (*prepare)(struct bpf_prog *prog); int (*translate)(struct bpf_prog *prog); void (*destroy)(struct bpf_prog *prog); @@ -283,6 +289,7 @@ struct bpf_prog_offload { void *dev_priv; struct list_head offloads; bool dev_state; + bool opt_failed; void *jited_image; u32 jited_len; }; diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h index 573cca00a0e6..0620e418dde5 100644 --- a/include/linux/bpf_verifier.h +++ b/include/linux/bpf_verifier.h @@ -187,6 +187,7 @@ struct bpf_insn_aux_data { int sanitize_stack_off; /* stack slot to be cleared */ bool seen; /* this insn was processed by the verifier */ u8 alu_state; /* used in combination with alu_limit */ + unsigned int orig_idx; /* original instruction index */ }; #define MAX_USED_MAPS 64 /* max number of maps accessed by one eBPF program */ @@ -265,5 +266,10 @@ int bpf_prog_offload_verifier_prep(struct bpf_prog *prog); int bpf_prog_offload_verify_insn(struct bpf_verifier_env *env, int insn_idx, int prev_insn_idx); int bpf_prog_offload_finalize(struct bpf_verifier_env *env); +void +bpf_prog_offload_replace_insn(struct bpf_verifier_env *env, u32 off, + struct bpf_insn *insn); +void +bpf_prog_offload_remove_insns(struct bpf_verifier_env *env, u32 off, u32 cnt); #endif /* _LINUX_BPF_VERIFIER_H */ diff --git a/include/linux/filter.h b/include/linux/filter.h index ad106d845b22..be9af6b4a9e4 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -778,6 +778,7 @@ static inline bool bpf_dump_raw_ok(void) struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off, const struct bpf_insn *patch, u32 len); +int bpf_remove_insns(struct bpf_prog *prog, u32 off, u32 cnt); void bpf_clear_redirect_map(struct bpf_map *map); |
