Skip to content

Commit b238e18

Browse files
eddyz87Alexei Starovoitov
authored andcommitted
bpf: refactor bpf_helper_changes_pkt_data to use helper number
Use BPF helper number instead of function pointer in bpf_helper_changes_pkt_data(). This would simplify usage of this function in verifier.c:check_cfg() (in a follow-up patch), where only helper number is easily available and there is no real need to lookup helper proto. Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://lore.kernel.org/r/20241210041100.1898468-3-eddyz87@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 27e88bc commit b238e18

File tree

4 files changed

+31
-38
lines changed

4 files changed

+31
-38
lines changed

include/linux/filter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena);
11221122
bool bpf_jit_supports_private_stack(void);
11231123
u64 bpf_arch_uaddress_limit(void);
11241124
void arch_bpf_stack_walk(bool (*consume_fn)(void *cookie, u64 ip, u64 sp, u64 bp), void *cookie);
1125-
bool bpf_helper_changes_pkt_data(void *func);
1125+
bool bpf_helper_changes_pkt_data(enum bpf_func_id func_id);
11261126

11271127
static inline bool bpf_dump_raw_ok(const struct cred *cred)
11281128
{

kernel/bpf/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2936,7 +2936,7 @@ void __weak bpf_jit_compile(struct bpf_prog *prog)
29362936
{
29372937
}
29382938

2939-
bool __weak bpf_helper_changes_pkt_data(void *func)
2939+
bool __weak bpf_helper_changes_pkt_data(enum bpf_func_id func_id)
29402940
{
29412941
return false;
29422942
}

kernel/bpf/verifier.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10728,7 +10728,7 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
1072810728
}
1072910729

1073010730
/* With LD_ABS/IND some JITs save/restore skb from r1. */
10731-
changes_data = bpf_helper_changes_pkt_data(fn->func);
10731+
changes_data = bpf_helper_changes_pkt_data(func_id);
1073210732
if (changes_data && fn->arg1_type != ARG_PTR_TO_CTX) {
1073310733
verbose(env, "kernel subsystem misconfigured func %s#%d: r1 != ctx\n",
1073410734
func_id_name(func_id), func_id);

net/core/filter.c

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7899,42 +7899,35 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv6_proto = {
78997899

79007900
#endif /* CONFIG_INET */
79017901

7902-
bool bpf_helper_changes_pkt_data(void *func)
7903-
{
7904-
if (func == bpf_skb_vlan_push ||
7905-
func == bpf_skb_vlan_pop ||
7906-
func == bpf_skb_store_bytes ||
7907-
func == bpf_skb_change_proto ||
7908-
func == bpf_skb_change_head ||
7909-
func == sk_skb_change_head ||
7910-
func == bpf_skb_change_tail ||
7911-
func == sk_skb_change_tail ||
7912-
func == bpf_skb_adjust_room ||
7913-
func == sk_skb_adjust_room ||
7914-
func == bpf_skb_pull_data ||
7915-
func == sk_skb_pull_data ||
7916-
func == bpf_clone_redirect ||
7917-
func == bpf_l3_csum_replace ||
7918-
func == bpf_l4_csum_replace ||
7919-
func == bpf_xdp_adjust_head ||
7920-
func == bpf_xdp_adjust_meta ||
7921-
func == bpf_msg_pull_data ||
7922-
func == bpf_msg_push_data ||
7923-
func == bpf_msg_pop_data ||
7924-
func == bpf_xdp_adjust_tail ||
7925-
#if IS_ENABLED(CONFIG_IPV6_SEG6_BPF)
7926-
func == bpf_lwt_seg6_store_bytes ||
7927-
func == bpf_lwt_seg6_adjust_srh ||
7928-
func == bpf_lwt_seg6_action ||
7929-
#endif
7930-
#ifdef CONFIG_INET
7931-
func == bpf_sock_ops_store_hdr_opt ||
7932-
#endif
7933-
func == bpf_lwt_in_push_encap ||
7934-
func == bpf_lwt_xmit_push_encap)
7902+
bool bpf_helper_changes_pkt_data(enum bpf_func_id func_id)
7903+
{
7904+
switch (func_id) {
7905+
case BPF_FUNC_clone_redirect:
7906+
case BPF_FUNC_l3_csum_replace:
7907+
case BPF_FUNC_l4_csum_replace:
7908+
case BPF_FUNC_lwt_push_encap:
7909+
case BPF_FUNC_lwt_seg6_action:
7910+
case BPF_FUNC_lwt_seg6_adjust_srh:
7911+
case BPF_FUNC_lwt_seg6_store_bytes:
7912+
case BPF_FUNC_msg_pop_data:
7913+
case BPF_FUNC_msg_pull_data:
7914+
case BPF_FUNC_msg_push_data:
7915+
case BPF_FUNC_skb_adjust_room:
7916+
case BPF_FUNC_skb_change_head:
7917+
case BPF_FUNC_skb_change_proto:
7918+
case BPF_FUNC_skb_change_tail:
7919+
case BPF_FUNC_skb_pull_data:
7920+
case BPF_FUNC_skb_store_bytes:
7921+
case BPF_FUNC_skb_vlan_pop:
7922+
case BPF_FUNC_skb_vlan_push:
7923+
case BPF_FUNC_store_hdr_opt:
7924+
case BPF_FUNC_xdp_adjust_head:
7925+
case BPF_FUNC_xdp_adjust_meta:
7926+
case BPF_FUNC_xdp_adjust_tail:
79357927
return true;
7936-
7937-
return false;
7928+
default:
7929+
return false;
7930+
}
79387931
}
79397932

79407933
const struct bpf_func_proto bpf_event_output_data_proto __weak;

0 commit comments

Comments
 (0)