Skip to contentSkip to conversation

bpf: Remove the unnecessary insn buffer comparison

PATCH Applied Haiyue Wang 3 participants 4 messages Jan 8, 2023 – Jan 10, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: Remove the unnecessary insn buffer comparison

The variable 'insn' is initialized to 'insn_buf' without being changed, only some helper macros are defined, so the insn buffer comparison is unnecessary, just remove it.

---
 net/core/filter.c | 6 ------
 1 file changed, 6 deletions(-)
net/core/filter.c +0 -6
index ab811293ae5d..d9befa6ba04e 100644
@@ -6847,9 +6847,6 @@ u32 bpf_tcp_sock_convert_ctx_access(enum bpf_access_type type,
 					FIELD));			\
 	} while (0)
 
-	if (insn > insn_buf)
-		return insn - insn_buf;
-
 	switch (si->off) {
 	case offsetof(struct bpf_tcp_sock, rtt_min):
 		BUILD_BUG_ON(sizeof_field(struct tcp_sock, rtt_min) !=
@@ -10147,9 +10144,6 @@ static u32 sock_ops_convert_ctx_access(enum bpf_access_type type,
 			SOCK_OPS_GET_FIELD(BPF_FIELD, OBJ_FIELD, OBJ);	      \
 	} while (0)
 
-	if (insn > insn_buf)
-		return insn - insn_buf;
-
 	switch (si->off) {
 	case offsetof(struct bpf_sock_ops, op):
 		*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct bpf_sock_ops_kern,
Signature · 1 line
2.39.0
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Haiyue Wang

The variable 'insn' is initialized to 'insn_buf' without being changed, only some helper macros are defined, so the insn buffer comparison is unnecessary, just remove it.

Looks like these should have been removed as part of commit 2377b81de527 ("bpf: split shared bpf_tcp_sock and bpf_sock_ops implementation").

Quoted 32 lines
---
  net/core/filter.c | 6 ------
  1 file changed, 6 deletions(-)
net/core/filter.c +0 -3
index ab811293ae5d..d9befa6ba04e 100644
@@ -6847,9 +6847,6 @@ u32 bpf_tcp_sock_convert_ctx_access(enum  
 bpf_access_type type,
  					FIELD));			\
  	} while (0)
 
-	if (insn > insn_buf)
-		return insn - insn_buf;
-
  	switch (si->off) {
  	case offsetof(struct bpf_tcp_sock, rtt_min):

BUILD_BUG_ON(sizeof_field(struct tcp_sock, rtt_min) !=

net/core/filter.c +0 -3
@@ -10147,9 +10144,6 @@ static u32 sock_ops_convert_ctx_access(enum  
 bpf_access_type type,
  			SOCK_OPS_GET_FIELD(BPF_FIELD, OBJ_FIELD, OBJ);	      \
  	} while (0)
 
-	if (insn > insn_buf)
-		return insn - insn_buf;
-
  	switch (si->off) {
  	case offsetof(struct bpf_sock_ops, op):

*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct bpf_sock_ops_kern,
--
2.39.0

#2 lore raw
Quoted 17 lines

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Tuesday, January 10, 2023 01:39
To: Wang, Haiyue <[email protected]>
Cc: [email protected]; Alexei Starovoitov <[email protected]>; Daniel Borkmann <[email protected]>; Andrii Nakryiko <[email protected]>; Martin KaFai Lau <[email protected]>; Song Liu <[email protected]>; Yonghong Song <[email protected]>; John Fastabend <[email protected]>; KP Singh <[email protected]>; Hao Luo <[email protected]>; Jiri Olsa <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH bpf-next v1] bpf: Remove the unnecessary insn buffer comparison

Quoted 3 lines · Haiyue Wang

The variable 'insn' is initialized to 'insn_buf' without being changed, only some helper macros are defined, so the insn buffer comparison is unnecessary, just remove it.

Quoted 7 lines
Quoted 1 line

Looks like these should have been removed as part of commit 2377b81de527 ("bpf: split shared bpf_tcp_sock and bpf_sock_ops implementation").

Thanks for the information, yes, it was missed. ;-)

Quoted 8 lines
Quoted 8 lines
---
  net/core/filter.c | 6 ------
  1 file changed, 6 deletions(-)

--
2.39.0

#3 lore raw
In reply to Haiyue Wang
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Quoted 8 lines · On Sun, 8 Jan 2023 23:12:57 +0800 you wrote:

The variable 'insn' is initialized to 'insn_buf' without being changed, only some helper macros are defined, so the insn buffer comparison is unnecessary, just remove it.

---
 net/core/filter.c | 6 ------
 1 file changed, 6 deletions(-)

Here is the summary with links:
- [bpf-next,v1] bpf: Remove the unnecessary insn buffer comparison

    https://git.kernel.org/bpf/bpf-next/c/66cf99b55e58

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html