mirror of
https://github.com/torvalds/linux.git
synced 2024-11-12 07:01:57 +00:00
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>
This commit is contained in:
parent
6816a7ffce
commit
80b48c4457
@ -101,7 +101,7 @@ const struct bpf_func_proto bpf_get_prandom_u32_proto = {
|
|||||||
|
|
||||||
static u64 bpf_get_smp_processor_id(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
|
static u64 bpf_get_smp_processor_id(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
|
||||||
{
|
{
|
||||||
return raw_smp_processor_id();
|
return smp_processor_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct bpf_func_proto bpf_get_smp_processor_id_proto = {
|
const struct bpf_func_proto bpf_get_smp_processor_id_proto = {
|
||||||
|
@ -150,6 +150,12 @@ static u64 __get_raw_cpu_id(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
|
|||||||
return raw_smp_processor_id();
|
return raw_smp_processor_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct bpf_func_proto bpf_get_raw_smp_processor_id_proto = {
|
||||||
|
.func = __get_raw_cpu_id,
|
||||||
|
.gpl_only = false,
|
||||||
|
.ret_type = RET_INTEGER,
|
||||||
|
};
|
||||||
|
|
||||||
static u32 convert_skb_access(int skb_field, int dst_reg, int src_reg,
|
static u32 convert_skb_access(int skb_field, int dst_reg, int src_reg,
|
||||||
struct bpf_insn *insn_buf)
|
struct bpf_insn *insn_buf)
|
||||||
{
|
{
|
||||||
@ -2037,7 +2043,7 @@ sk_filter_func_proto(enum bpf_func_id func_id)
|
|||||||
case BPF_FUNC_get_prandom_u32:
|
case BPF_FUNC_get_prandom_u32:
|
||||||
return &bpf_get_prandom_u32_proto;
|
return &bpf_get_prandom_u32_proto;
|
||||||
case BPF_FUNC_get_smp_processor_id:
|
case BPF_FUNC_get_smp_processor_id:
|
||||||
return &bpf_get_smp_processor_id_proto;
|
return &bpf_get_raw_smp_processor_id_proto;
|
||||||
case BPF_FUNC_tail_call:
|
case BPF_FUNC_tail_call:
|
||||||
return &bpf_tail_call_proto;
|
return &bpf_tail_call_proto;
|
||||||
case BPF_FUNC_ktime_get_ns:
|
case BPF_FUNC_ktime_get_ns:
|
||||||
@ -2086,6 +2092,8 @@ tc_cls_act_func_proto(enum bpf_func_id func_id)
|
|||||||
return &bpf_get_route_realm_proto;
|
return &bpf_get_route_realm_proto;
|
||||||
case BPF_FUNC_perf_event_output:
|
case BPF_FUNC_perf_event_output:
|
||||||
return bpf_get_event_output_proto();
|
return bpf_get_event_output_proto();
|
||||||
|
case BPF_FUNC_get_smp_processor_id:
|
||||||
|
return &bpf_get_smp_processor_id_proto;
|
||||||
default:
|
default:
|
||||||
return sk_filter_func_proto(func_id);
|
return sk_filter_func_proto(func_id);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user