Skip to contentSkip to conversation

bpf: Remove bpf_get_smp_processor_id_proto

PATCH In review Feng Yang 2 participants 4 messages Apr 18, 2025 – Apr 22, 2025

Subsystems (8)
lore
Share & tools
lore

Feng Yang

author
#0 lore raw

PATCH 1/1 bpf: Remove bpf_get_smp_processor_id_proto

From: Feng Yang <[email protected]>

All BPF programs either disable CPU preemption or CPU migration,
so the bpf_get_smp_processor_id_proto can be safely removed,
and the bpf_get_raw_smp_processor_id_proto in bpf_base_func_proto works perfectly.

---
 include/linux/bpf.h      |  1 -
 kernel/bpf/core.c        |  1 -
 kernel/bpf/helpers.c     | 12 ------------
 kernel/trace/bpf_trace.c |  2 --
 net/core/filter.c        |  6 ------
 5 files changed, 22 deletions(-)
include/linux/bpf.h +0 -1
index 3f0cc89c0622..36e525141556 100644
@@ -3316,7 +3316,6 @@ extern const struct bpf_func_proto bpf_map_peek_elem_proto;
 extern const struct bpf_func_proto bpf_map_lookup_percpu_elem_proto;
 
 extern const struct bpf_func_proto bpf_get_prandom_u32_proto;
-extern const struct bpf_func_proto bpf_get_smp_processor_id_proto;
 extern const struct bpf_func_proto bpf_get_numa_node_id_proto;
 extern const struct bpf_func_proto bpf_tail_call_proto;
 extern const struct bpf_func_proto bpf_ktime_get_ns_proto;
kernel/bpf/core.c +0 -1
index ba6b6118cf50..1ad41a16b86e 100644
@@ -2943,7 +2943,6 @@ const struct bpf_func_proto bpf_spin_unlock_proto __weak;
 const struct bpf_func_proto bpf_jiffies64_proto __weak;
 
 const struct bpf_func_proto bpf_get_prandom_u32_proto __weak;
-const struct bpf_func_proto bpf_get_smp_processor_id_proto __weak;
 const struct bpf_func_proto bpf_get_numa_node_id_proto __weak;
 const struct bpf_func_proto bpf_ktime_get_ns_proto __weak;
 const struct bpf_func_proto bpf_ktime_get_boot_ns_proto __weak;
kernel/bpf/helpers.c +0 -12
index e3a2662f4e33..2d2bfb2911f8 100644
@@ -149,18 +149,6 @@ const struct bpf_func_proto bpf_get_prandom_u32_proto = {
 	.ret_type	= RET_INTEGER,
 };
 
-BPF_CALL_0(bpf_get_smp_processor_id)
-{
-	return smp_processor_id();
-}
-
-const struct bpf_func_proto bpf_get_smp_processor_id_proto = {
-	.func		= bpf_get_smp_processor_id,
-	.gpl_only	= false,
-	.ret_type	= RET_INTEGER,
-	.allow_fastcall	= true,
-};
-
 BPF_CALL_0(bpf_get_numa_node_id)
 {
 	return numa_node_id();
kernel/trace/bpf_trace.c +0 -2
index 0f5906f43d7c..39360cd6baf1 100644
@@ -1462,8 +1462,6 @@ bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 		return &bpf_get_current_comm_proto;
 	case BPF_FUNC_trace_printk:
 		return bpf_get_trace_printk_proto();
-	case BPF_FUNC_get_smp_processor_id:
-		return &bpf_get_smp_processor_id_proto;
 	case BPF_FUNC_get_numa_node_id:
 		return &bpf_get_numa_node_id_proto;
 	case BPF_FUNC_perf_event_read:
net/core/filter.c +0 -6
index bc6828761a47..7f7ec913ddbc 100644
@@ -8264,8 +8264,6 @@ tc_cls_act_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 		return &bpf_set_hash_proto;
 	case BPF_FUNC_perf_event_output:
 		return &bpf_skb_event_output_proto;
-	case BPF_FUNC_get_smp_processor_id:
-		return &bpf_get_smp_processor_id_proto;
 	case BPF_FUNC_skb_under_cgroup:
 		return &bpf_skb_under_cgroup_proto;
 	case BPF_FUNC_get_socket_cookie:
@@ -8343,8 +8341,6 @@ xdp_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 	switch (func_id) {
 	case BPF_FUNC_perf_event_output:
 		return &bpf_xdp_event_output_proto;
-	case BPF_FUNC_get_smp_processor_id:
-		return &bpf_get_smp_processor_id_proto;
 	case BPF_FUNC_csum_diff:
 		return &bpf_csum_diff_proto;
 	case BPF_FUNC_xdp_adjust_head:
@@ -8570,8 +8566,6 @@ lwt_out_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 		return &bpf_get_hash_recalc_proto;
 	case BPF_FUNC_perf_event_output:
 		return &bpf_skb_event_output_proto;
-	case BPF_FUNC_get_smp_processor_id:
-		return &bpf_get_smp_processor_id_proto;
 	case BPF_FUNC_skb_under_cgroup:
 		return &bpf_skb_under_cgroup_proto;
 	default:
Signature · 1 line
2.39.0.windows.2
#1 lore raw
Quoted 51 lines · Feng Yang

From: Feng Yang <[email protected]>

All BPF programs either disable CPU preemption or CPU migration,
so the bpf_get_smp_processor_id_proto can be safely removed,
and the bpf_get_raw_smp_processor_id_proto in bpf_base_func_proto works perfectly.

---
 include/linux/bpf.h      |  1 -
 kernel/bpf/core.c        |  1 -
 kernel/bpf/helpers.c     | 12 ------------
 kernel/trace/bpf_trace.c |  2 --
 net/core/filter.c        |  6 ------
 5 files changed, 22 deletions(-)
include/linux/bpf.h +0 -1
index 3f0cc89c0622..36e525141556 100644
@@ -3316,7 +3316,6 @@ extern const struct bpf_func_proto bpf_map_peek_elem_proto;
 extern const struct bpf_func_proto bpf_map_lookup_percpu_elem_proto;
 
 extern const struct bpf_func_proto bpf_get_prandom_u32_proto;
-extern const struct bpf_func_proto bpf_get_smp_processor_id_proto;
 extern const struct bpf_func_proto bpf_get_numa_node_id_proto;
 extern const struct bpf_func_proto bpf_tail_call_proto;
 extern const struct bpf_func_proto bpf_ktime_get_ns_proto;
kernel/bpf/core.c +0 -1
index ba6b6118cf50..1ad41a16b86e 100644
@@ -2943,7 +2943,6 @@ const struct bpf_func_proto bpf_spin_unlock_proto __weak;
 const struct bpf_func_proto bpf_jiffies64_proto __weak;
 
 const struct bpf_func_proto bpf_get_prandom_u32_proto __weak;
-const struct bpf_func_proto bpf_get_smp_processor_id_proto __weak;
 const struct bpf_func_proto bpf_get_numa_node_id_proto __weak;
 const struct bpf_func_proto bpf_ktime_get_ns_proto __weak;
 const struct bpf_func_proto bpf_ktime_get_boot_ns_proto __weak;
kernel/bpf/helpers.c +0 -2
index e3a2662f4e33..2d2bfb2911f8 100644
@@ -149,18 +149,6 @@ const struct bpf_func_proto bpf_get_prandom_u32_proto = {
        .ret_type       = RET_INTEGER,
 };
 
-BPF_CALL_0(bpf_get_smp_processor_id)
-{

kernel/bpf/helpers.c const struct bpf_func_proto bpf_get_prandom_u32_proto = { · line 163

Quoted 10 lines
kernel/bpf/helpers.c +0 -10
-       return smp_processor_id();
-}
-
-const struct bpf_func_proto bpf_get_smp_processor_id_proto = {
-       .func           = bpf_get_smp_processor_id,
-       .gpl_only       = false,
-       .ret_type       = RET_INTEGER,
-       .allow_fastcall = true,
-};
-

bpf_get_raw_smp_processor_id_proto doesn't have allow_fastcall = true

so this breaks tests.

Instead of removing BPF_CALL_0(bpf_get_smp_processor_id) we should probably remove BPF_CALL_0(bpf_get_raw_cpu_id) and adjust SKF_AD_OFF + SKF_AD_CPU case.
I don't recall why raw_ version was used back in 2014.

pw-bot: cr

author
#2 lore raw

Subject: Re: [PATCH bpf-next] bpf: Remove bpf_get_smp_processor_id_proto

Quoted 66 lines · On Mon, 21 Apr 2025 18:53:07 -0700 Alexei Starovoitov…
Quoted 51 lines · Feng Yang

From: Feng Yang <[email protected]>

All BPF programs either disable CPU preemption or CPU migration,
so the bpf_get_smp_processor_id_proto can be safely removed,
and the bpf_get_raw_smp_processor_id_proto in bpf_base_func_proto works perfectly.

---
 include/linux/bpf.h      |  1 -
 kernel/bpf/core.c        |  1 -
 kernel/bpf/helpers.c     | 12 ------------
 kernel/trace/bpf_trace.c |  2 --
 net/core/filter.c        |  6 ------
 5 files changed, 22 deletions(-)
include/linux/bpf.h +0 -1
index 3f0cc89c0622..36e525141556 100644
@@ -3316,7 +3316,6 @@ extern const struct bpf_func_proto bpf_map_peek_elem_proto;
 extern const struct bpf_func_proto bpf_map_lookup_percpu_elem_proto;
 
 extern const struct bpf_func_proto bpf_get_prandom_u32_proto;
-extern const struct bpf_func_proto bpf_get_smp_processor_id_proto;
 extern const struct bpf_func_proto bpf_get_numa_node_id_proto;
 extern const struct bpf_func_proto bpf_tail_call_proto;
 extern const struct bpf_func_proto bpf_ktime_get_ns_proto;
kernel/bpf/core.c +0 -1
index ba6b6118cf50..1ad41a16b86e 100644
@@ -2943,7 +2943,6 @@ const struct bpf_func_proto bpf_spin_unlock_proto __weak;
 const struct bpf_func_proto bpf_jiffies64_proto __weak;
 
 const struct bpf_func_proto bpf_get_prandom_u32_proto __weak;
-const struct bpf_func_proto bpf_get_smp_processor_id_proto __weak;
 const struct bpf_func_proto bpf_get_numa_node_id_proto __weak;
 const struct bpf_func_proto bpf_ktime_get_ns_proto __weak;
 const struct bpf_func_proto bpf_ktime_get_boot_ns_proto __weak;
kernel/bpf/helpers.c +0 -2
index e3a2662f4e33..2d2bfb2911f8 100644
@@ -149,18 +149,6 @@ const struct bpf_func_proto bpf_get_prandom_u32_proto = {
        .ret_type       = RET_INTEGER,
 };
 
-BPF_CALL_0(bpf_get_smp_processor_id)
-{

kernel/bpf/helpers.c const struct bpf_func_proto bpf_get_prandom_u32_proto = { · line 163

Quoted 10 lines
kernel/bpf/helpers.c +0 -10
-       return smp_processor_id();
-}
-
-const struct bpf_func_proto bpf_get_smp_processor_id_proto = {
-       .func           = bpf_get_smp_processor_id,
-       .gpl_only       = false,
-       .ret_type       = RET_INTEGER,
-       .allow_fastcall = true,
-};
-

bpf_get_raw_smp_processor_id_proto doesn't have allow_fastcall = true

Quoted 7 lines

so this breaks tests.

Instead of removing BPF_CALL_0(bpf_get_smp_processor_id) we should probably remove BPF_CALL_0(bpf_get_raw_cpu_id) and adjust SKF_AD_OFF + SKF_AD_CPU case.
I don't recall why raw_ version was used back in 2014.

The following two seem to explain the reason:
https://lore.kernel.org/all/7103e2085afa29c006cd5b94a6e4a2ac83efc30d.1467106475.git.daniel@iogearbox.net/
https://lore.kernel.org/all/02fa71ebe1c560cad489967aa29c653b48932596.1474586162.git.daniel@iogearbox.net/

#3 lore raw

Re:

Quoted 79 lines · Feng Yang

Subject: Re: [PATCH bpf-next] bpf: Remove bpf_get_smp_processor_id_proto

Quoted 66 lines · On Mon, 21 Apr 2025 18:53:07 -0700 Alexei Starovoitov…
Quoted 51 lines · Feng Yang

From: Feng Yang <[email protected]>

All BPF programs either disable CPU preemption or CPU migration,
so the bpf_get_smp_processor_id_proto can be safely removed,
and the bpf_get_raw_smp_processor_id_proto in bpf_base_func_proto works perfectly.

---
 include/linux/bpf.h      |  1 -
 kernel/bpf/core.c        |  1 -
 kernel/bpf/helpers.c     | 12 ------------
 kernel/trace/bpf_trace.c |  2 --
 net/core/filter.c        |  6 ------
 5 files changed, 22 deletions(-)
include/linux/bpf.h +0 -1
index 3f0cc89c0622..36e525141556 100644
@@ -3316,7 +3316,6 @@ extern const struct bpf_func_proto bpf_map_peek_elem_proto;
 extern const struct bpf_func_proto bpf_map_lookup_percpu_elem_proto;
 
 extern const struct bpf_func_proto bpf_get_prandom_u32_proto;
-extern const struct bpf_func_proto bpf_get_smp_processor_id_proto;
 extern const struct bpf_func_proto bpf_get_numa_node_id_proto;
 extern const struct bpf_func_proto bpf_tail_call_proto;
 extern const struct bpf_func_proto bpf_ktime_get_ns_proto;
kernel/bpf/core.c +0 -1
index ba6b6118cf50..1ad41a16b86e 100644
@@ -2943,7 +2943,6 @@ const struct bpf_func_proto bpf_spin_unlock_proto __weak;
 const struct bpf_func_proto bpf_jiffies64_proto __weak;
 
 const struct bpf_func_proto bpf_get_prandom_u32_proto __weak;
-const struct bpf_func_proto bpf_get_smp_processor_id_proto __weak;
 const struct bpf_func_proto bpf_get_numa_node_id_proto __weak;
 const struct bpf_func_proto bpf_ktime_get_ns_proto __weak;
 const struct bpf_func_proto bpf_ktime_get_boot_ns_proto __weak;
kernel/bpf/helpers.c +0 -2
index e3a2662f4e33..2d2bfb2911f8 100644
@@ -149,18 +149,6 @@ const struct bpf_func_proto bpf_get_prandom_u32_proto = {
        .ret_type       = RET_INTEGER,
 };
 
-BPF_CALL_0(bpf_get_smp_processor_id)
-{

kernel/bpf/helpers.c const struct bpf_func_proto bpf_get_prandom_u32_proto = { · line 163

Quoted 10 lines
kernel/bpf/helpers.c +0 -10
-       return smp_processor_id();
-}
-
-const struct bpf_func_proto bpf_get_smp_processor_id_proto = {
-       .func           = bpf_get_smp_processor_id,
-       .gpl_only       = false,
-       .ret_type       = RET_INTEGER,
-       .allow_fastcall = true,
-};
-

bpf_get_raw_smp_processor_id_proto doesn't have allow_fastcall = true

Quoted 7 lines

so this breaks tests.

Instead of removing BPF_CALL_0(bpf_get_smp_processor_id) we should probably remove BPF_CALL_0(bpf_get_raw_cpu_id) and adjust SKF_AD_OFF + SKF_AD_CPU case.
I don't recall why raw_ version was used back in 2014.

Quoted 4 lines

The following two seem to explain the reason:
https://lore.kernel.org/all/7103e2085afa29c006cd5b94a6e4a2ac83efc30d.1467106475.git.daniel@iogearbox.net/
https://lore.kernel.org/all/02fa71ebe1c560cad489967aa29c653b48932596.1474586162.git.daniel@iogearbox.net/

Ahh. socket filters run in RCU CS. They don't disable preemption or migration. Then let's keep things as-is.
We still want debugging provided by smp_processor_id().
If we switch everything to raw_ may miss things. Like this example with socket filters.