Skip to content

Commit 80b48c4

Browse files
borkmanndavem330
authored andcommitted
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 <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6816a7f commit 80b48c4

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

kernel/bpf/helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const struct bpf_func_proto bpf_get_prandom_u32_proto = {
101101

102102
static u64 bpf_get_smp_processor_id(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
103103
{
104-
return raw_smp_processor_id();
104+
return smp_processor_id();
105105
}
106106

107107
const struct bpf_func_proto bpf_get_smp_processor_id_proto = {

net/core/filter.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ static u64 __get_raw_cpu_id(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
150150
return raw_smp_processor_id();
151151
}
152152

153+
static 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+
153159
static u32 convert_skb_access(int skb_field, int dst_reg, int src_reg,
154160
struct bpf_insn *insn_buf)
155161
{
@@ -2037,7 +2043,7 @@ sk_filter_func_proto(enum bpf_func_id func_id)
20372043
case BPF_FUNC_get_prandom_u32:
20382044
return &bpf_get_prandom_u32_proto;
20392045
case BPF_FUNC_get_smp_processor_id:
2040-
return &bpf_get_smp_processor_id_proto;
2046+
return &bpf_get_raw_smp_processor_id_proto;
20412047
case BPF_FUNC_tail_call:
20422048
return &bpf_tail_call_proto;
20432049
case BPF_FUNC_ktime_get_ns:
@@ -2086,6 +2092,8 @@ tc_cls_act_func_proto(enum bpf_func_id func_id)
20862092
return &bpf_get_route_realm_proto;
20872093
case BPF_FUNC_perf_event_output:
20882094
return bpf_get_event_output_proto();
2095+
case BPF_FUNC_get_smp_processor_id:
2096+
return &bpf_get_smp_processor_id_proto;
20892097
default:
20902098
return sk_filter_func_proto(func_id);
20912099
}

0 commit comments

Comments
 (0)