aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2016-09-08 20:45:29 -0400
committerDavid S. Miller <davem@davemloft.net>2016-09-09 22:36:04 -0400
commitf035a51536af9802f55d8c79bd87f184ebffb093 (patch)
treeb10ca650031a03f3752a1ea9f7178282e8eb0a75 /kernel
parent6088b5823b4cb132a838878747384cbfb5ce6646 (diff)
bpf: add BPF_SIZEOF and BPF_FIELD_SIZEOF macros
Add BPF_SIZEOF() and BPF_FIELD_SIZEOF() macros to improve the code a bit which otherwise often result in overly long bytes_to_bpf_size(sizeof()) and bytes_to_bpf_size(FIELD_SIZEOF()) lines. So place them into a macro helper instead. Moreover, we currently have a BUILD_BUG_ON(BPF_FIELD_SIZEOF()) check in convert_bpf_extensions(), but we should rather make that generic as well and add a BUILD_BUG_ON() test in all BPF_SIZEOF()/BPF_FIELD_SIZEOF() users to detect any rewriter size issues at compile time. Note, there are currently none, but we want to assert that it stays this way. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/trace/bpf_trace.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index d3869b03d9fe..e63d7d435796 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -583,18 +583,18 @@ static u32 pe_prog_convert_ctx_access(enum bpf_access_type type, int dst_reg,
583 switch (ctx_off) { 583 switch (ctx_off) {
584 case offsetof(struct bpf_perf_event_data, sample_period): 584 case offsetof(struct bpf_perf_event_data, sample_period):
585 BUILD_BUG_ON(FIELD_SIZEOF(struct perf_sample_data, period) != sizeof(u64)); 585 BUILD_BUG_ON(FIELD_SIZEOF(struct perf_sample_data, period) != sizeof(u64));
586 *insn++ = BPF_LDX_MEM(bytes_to_bpf_size(FIELD_SIZEOF(struct bpf_perf_event_data_kern, data)), 586
587 dst_reg, src_reg, 587 *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct bpf_perf_event_data_kern,
588 data), dst_reg, src_reg,
588 offsetof(struct bpf_perf_event_data_kern, data)); 589 offsetof(struct bpf_perf_event_data_kern, data));
589 *insn++ = BPF_LDX_MEM(BPF_DW, dst_reg, dst_reg, 590 *insn++ = BPF_LDX_MEM(BPF_DW, dst_reg, dst_reg,
590 offsetof(struct perf_sample_data, period)); 591 offsetof(struct perf_sample_data, period));
591 break; 592 break;
592 default: 593 default:
593 *insn++ = BPF_LDX_MEM(bytes_to_bpf_size(FIELD_SIZEOF(struct bpf_perf_event_data_kern, regs)), 594 *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct bpf_perf_event_data_kern,
594 dst_reg, src_reg, 595 regs), dst_reg, src_reg,
595 offsetof(struct bpf_perf_event_data_kern, regs)); 596 offsetof(struct bpf_perf_event_data_kern, regs));
596 *insn++ = BPF_LDX_MEM(bytes_to_bpf_size(sizeof(long)), 597 *insn++ = BPF_LDX_MEM(BPF_SIZEOF(long), dst_reg, dst_reg, ctx_off);
597 dst_reg, dst_reg, ctx_off);
598 break; 598 break;
599 } 599 }
600 600