aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2016-06-28 06:18:26 -0400
committerDavid S. Miller <davem@davemloft.net>2016-06-30 05:54:40 -0400
commit80b48c445797a634d869c7e5a53e182ba2688931 (patch)
tree18b46e8be4b541b966929a478c26c184e2ac3862
parent6816a7ffce32e999601825ddfd887f36d3052932 (diff)
bpf: don't use raw processor id in generic helper
Use smp_processor_id() for the generic helper bpf_get_smp_processor_id() instead of the raw variant. This allows for preemption checks when we have DEBUG_PREEMPT, and otherwise uses the raw variant anyway. We only need to keep the raw variant for socket filters, but we can reuse the helper that is already there from cBPF side. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--kernel/bpf/helpers.c2
-rw-r--r--net/core/filter.c10
2 files changed, 10 insertions, 2 deletions
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index ad7a0573f71b..1ea3afba1a4f 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -101,7 +101,7 @@ const struct bpf_func_proto bpf_get_prandom_u32_proto = {
101 101
102static u64 bpf_get_smp_processor_id(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5) 102static u64 bpf_get_smp_processor_id(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
103{ 103{
104 return raw_smp_processor_id(); 104 return smp_processor_id();
105} 105}
106 106
107const struct bpf_func_proto bpf_get_smp_processor_id_proto = { 107const struct bpf_func_proto bpf_get_smp_processor_id_proto = {
diff --git a/net/core/filter.c b/net/core/filter.c
index cb9fc16cac46..46c88d9cec5c 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -150,6 +150,12 @@ static u64 __get_raw_cpu_id(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
150 return raw_smp_processor_id(); 150 return raw_smp_processor_id();
151} 151}
152 152
153static const struct bpf_func_proto bpf_get_raw_smp_processor_id_proto = {
154 .func = __get_raw_cpu_id,
155 .gpl_only = false,
156 .ret_type = RET_INTEGER,
157};
158
153static u32 convert_skb_access(int skb_field, int dst_reg, int src_reg, 159static u32 convert_skb_access(int skb_field, int dst_reg, int src_reg,
154 struct bpf_insn *insn_buf) 160 struct bpf_insn *insn_buf)
155{ 161{
@@ -2037,7 +2043,7 @@ sk_filter_func_proto(enum bpf_func_id func_id)
2037 case BPF_FUNC_get_prandom_u32: 2043 case BPF_FUNC_get_prandom_u32:
2038 return &bpf_get_prandom_u32_proto; 2044 return &bpf_get_prandom_u32_proto;
2039 case BPF_FUNC_get_smp_processor_id: 2045 case BPF_FUNC_get_smp_processor_id:
2040 return &bpf_get_smp_processor_id_proto; 2046 return &bpf_get_raw_smp_processor_id_proto;
2041 case BPF_FUNC_tail_call: 2047 case BPF_FUNC_tail_call:
2042 return &bpf_tail_call_proto; 2048 return &bpf_tail_call_proto;
2043 case BPF_FUNC_ktime_get_ns: 2049 case BPF_FUNC_ktime_get_ns:
@@ -2086,6 +2092,8 @@ tc_cls_act_func_proto(enum bpf_func_id func_id)
2086 return &bpf_get_route_realm_proto; 2092 return &bpf_get_route_realm_proto;
2087 case BPF_FUNC_perf_event_output: 2093 case BPF_FUNC_perf_event_output:
2088 return bpf_get_event_output_proto(); 2094 return bpf_get_event_output_proto();
2095 case BPF_FUNC_get_smp_processor_id:
2096 return &bpf_get_smp_processor_id_proto;
2089 default: 2097 default:
2090 return sk_filter_func_proto(func_id); 2098 return sk_filter_func_proto(func_id);
2091 } 2099 }