aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@kernel.org>2017-12-12 12:16:22 -0500
committerAlexei Starovoitov <ast@kernel.org>2017-12-12 12:16:56 -0500
commit553a8f2f42dffc5414a82fffe55d9b8c0fbd383f (patch)
tree39d63df8a9c2794258d6d4328c7b18d10a2ecc29 /tools
parenta23967c181cae80becb451b38ff2a1e01c05c37b (diff)
parent023f46c5b807ae5fff83b57d918727a5b9dbee55 (diff)
Merge branch 'bpf-override-return'
Josef Bacik says: ==================== This is the same as v8, just rebased onto the bpf tree. v8->v9: - rebased onto the bpf tree. v7->v8: - removed the _ASM_KPROBE_ERROR_INJECT since it was not needed. v6->v7: - moved the opt-in macro to bpf.h out of kprobes.h. v5->v6: - add BPF_ALLOW_ERROR_INJECTION() tagging for functions that will support this feature. This way only functions that opt-in will be allowed to be overridden. - added a btrfs patch to allow error injection for open_ctree() so that the bpf sample actually works. v4->v5: - disallow kprobe_override programs from being put in the prog map array so we don't tail call into something we didn't check. This allows us to make the normal path still fast without a bunch of percpu operations. v3->v4: - fix a build error found by kbuild test bot (I didn't wait long enough apparently.) - Added a warning message as per Daniels suggestion. v2->v3: - added a ->kprobe_override flag to bpf_prog. - added some sanity checks to disallow attaching bpf progs that have ->kprobe_override set that aren't for ftrace kprobes. - added the trace_kprobe_ftrace helper to check if the trace_event_call is a ftrace kprobe. - renamed bpf_kprobe_state to bpf_kprobe_override, fixed it so we only read this value in the kprobe path, and thus only write to it if we're overriding or clearing the override. v1->v2: - moved things around to make sure that bpf_override_return could really only be used for an ftrace kprobe. - killed the special return values from trace_call_bpf. - renamed pc_modified to bpf_kprobe_state so bpf_override_return could tell if it was being called from an ftrace kprobe context. - reworked the logic in kprobe_perf_func to take advantage of bpf_kprobe_state. - updated the test as per Alexei's review. - Original message - A lot of our error paths are not well tested because we have no good way of injecting errors generically. Some subystems (block, memory) have ways to inject errors, but they are random so it's hard to get reproduceable results. With BPF we can add determinism to our error injection. We can use kprobes and other things to verify we are injecting errors at the exact case we are trying to test. This patch gives us the tool to actual do the error injection part. It is very simple, we just set the return value of the pt_regs we're given to whatever we provide, and then override the PC with a dummy function that simply returns. Right now this only works on x86, but it would be simple enough to expand to other architectures. Thanks, Josef ==================== In patch "bpf: add a bpf_override_function helper" Alexei moved "ifdef CONFIG_BPF_KPROBE_OVERRIDE" few lines to fail program loading when kprobe_override is not available instead of failing at run-time. Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/include/uapi/linux/bpf.h7
-rw-r--r--tools/testing/selftests/bpf/bpf_helpers.h3
2 files changed, 8 insertions, 2 deletions
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 4c223ab30293..cf446c25c0ec 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -677,6 +677,10 @@ union bpf_attr {
677 * @buf: buf to fill 677 * @buf: buf to fill
678 * @buf_size: size of the buf 678 * @buf_size: size of the buf
679 * Return : 0 on success or negative error code 679 * Return : 0 on success or negative error code
680 *
681 * int bpf_override_return(pt_regs, rc)
682 * @pt_regs: pointer to struct pt_regs
683 * @rc: the return value to set
680 */ 684 */
681#define __BPF_FUNC_MAPPER(FN) \ 685#define __BPF_FUNC_MAPPER(FN) \
682 FN(unspec), \ 686 FN(unspec), \
@@ -736,7 +740,8 @@ union bpf_attr {
736 FN(xdp_adjust_meta), \ 740 FN(xdp_adjust_meta), \
737 FN(perf_event_read_value), \ 741 FN(perf_event_read_value), \
738 FN(perf_prog_read_value), \ 742 FN(perf_prog_read_value), \
739 FN(getsockopt), 743 FN(getsockopt), \
744 FN(override_return),
740 745
741/* integer value in 'imm' field of BPF_CALL instruction selects which helper 746/* integer value in 'imm' field of BPF_CALL instruction selects which helper
742 * function eBPF program intends to call 747 * function eBPF program intends to call
diff --git a/tools/testing/selftests/bpf/bpf_helpers.h b/tools/testing/selftests/bpf/bpf_helpers.h
index fd9a17fa8a8b..33cb00e46c49 100644
--- a/tools/testing/selftests/bpf/bpf_helpers.h
+++ b/tools/testing/selftests/bpf/bpf_helpers.h
@@ -82,7 +82,8 @@ static int (*bpf_perf_event_read_value)(void *map, unsigned long long flags,
82static int (*bpf_perf_prog_read_value)(void *ctx, void *buf, 82static int (*bpf_perf_prog_read_value)(void *ctx, void *buf,
83 unsigned int buf_size) = 83 unsigned int buf_size) =
84 (void *) BPF_FUNC_perf_prog_read_value; 84 (void *) BPF_FUNC_perf_prog_read_value;
85 85static int (*bpf_override_return)(void *ctx, unsigned long rc) =
86 (void *) BPF_FUNC_override_return;
86 87
87/* llvm builtin functions that eBPF C program may use to 88/* llvm builtin functions that eBPF C program may use to
88 * emit BPF_LD_ABS and BPF_LD_IND instructions 89 * emit BPF_LD_ABS and BPF_LD_IND instructions