Skip to contentSkip to conversation

net: bpf jit: ppc: optimize choose_load_func error path

PATCH In review Vladimir Murzin 5 participants 11 messages Oct 8, 2013 – Oct 14, 2013 1 message not in the archive

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

PATCH 1/3 net: bpf jit: ppc: optimize choose_load_func error path

Macro CHOOSE_LOAD_FUNC returns handler for "any offset" if checks for K were not passed. At the same time handlers for "any offset" cases make the same checks against r_addr at run-time, that will always lead to bpf_error.

Run-time checks are still necessary for indirect load operations, but error path for absolute and mesh loads are worth to optimize during bpf compile time.

Cc Jan Seiffert <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc Matt Evans <[email protected]>
---
 arch/powerpc/net/bpf_jit_comp.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/powerpc/net/bpf_jit_comp.c +6 -1
index bf56e33..754320a 100644
@@ -132,7 +132,7 @@ static void bpf_jit_build_epilogue(u32 *image, struct codegen_context *ctx)
 }
 
 #define CHOOSE_LOAD_FUNC(K, func) \
-	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
+	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : NULL) : func##_positive_offset)
 
 /* Assemble the body code between the prologue & epilogue. */
 static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
@@ -427,6 +427,11 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
 		case BPF_S_LD_B_ABS:
 			func = CHOOSE_LOAD_FUNC(K, sk_load_byte);
 		common_load:
+			if (!func) {
+				PPC_LI(r_ret, 0);
+				PPC_JMP(exit_addr);
+				break;
+			}
 			/* Load from [K]. */
 			ctx->seen |= SEEN_DATAREF;
 			PPC_LI64(r_scratch1, func);
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 5 lines · Vladimir Murzin

Macro CHOOSE_LOAD_FUNC returns handler for "any offset" if checks for K were not passed. At the same time handlers for "any offset" cases make the same checks against r_addr at run-time, that will always lead to bpf_error.

Hmmm, if i only would remember why i wrote it that way....
I memory serves me right the idea was to always have a solid fall back, no matter what, to the generic load function which works more like the load_pointer from filter.c.
This way the COOSE-macro may could have been used at more places, but that never played out.

And since all i wanted was to get the negative indirect load fixed, optimizing the constant error case was not on my plate.
That you can get your negative K filter JITed in the first place, even if the constant error case was slower than necessary, was good enough ;)

The ARM JIT is broken till this date...

You can have my
I'm-OK-with-this: Jan Seiffert <[email protected]>

for all three patches, -ENOTIME for a full review ATM.

Quoted 42 lines

Run-time checks are still necessary for indirect load operations, but error path for absolute and mesh loads are worth to optimize during bpf compile time.

Cc Jan Seiffert <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc Matt Evans <[email protected]>
---
 arch/powerpc/net/bpf_jit_comp.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/powerpc/net/bpf_jit_comp.c +6 -1
index bf56e33..754320a 100644
@@ -132,7 +132,7 @@ static void bpf_jit_build_epilogue(u32 *image, struct codegen_context *ctx)
 }
 
 #define CHOOSE_LOAD_FUNC(K, func) \
-	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
+	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : NULL) : func##_positive_offset)
 
 /* Assemble the body code between the prologue & epilogue. */
 static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
@@ -427,6 +427,11 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
 		case BPF_S_LD_B_ABS:
 			func = CHOOSE_LOAD_FUNC(K, sk_load_byte);
 		common_load:
+			if (!func) {
+				PPC_LI(r_ret, 0);
+				PPC_JMP(exit_addr);
+				break;
+			}
 			/* Load from [K]. */
 			ctx->seen |= SEEN_DATAREF;
 			PPC_LI64(r_scratch1, func);
Signature · 1 line
An UDP packet walks into a
#2 lore raw
Quoted 14 lines · Jan Seiffert
Quoted 5 lines · Vladimir Murzin

Macro CHOOSE_LOAD_FUNC returns handler for "any offset" if checks for K were not passed. At the same time handlers for "any offset" cases make the same checks against r_addr at run-time, that will always lead to bpf_error.

Hmmm, if i only would remember why i wrote it that way....
I memory serves me right the idea was to always have a solid fall back, no matter what, to the generic load function which works more like the load_pointer from filter.c.
This way the COOSE-macro may could have been used at more places, but that never played out.

Quoted 6 lines

And since all i wanted was to get the negative indirect load fixed, optimizing the constant error case was not on my plate.
That you can get your negative K filter JITed in the first place, even if the constant error case was slower than necessary, was good enough ;)

The ARM JIT is broken till this date...

... and s390 too.

Quoted 6 lines

You can have my
I'm-OK-with-this: Jan Seiffert <[email protected]>

for all three patches, -ENOTIME for a full review ATM.

Thanks for feedback, Jan!

Quoted 46 lines
Quoted 42 lines

Run-time checks are still necessary for indirect load operations, but error path for absolute and mesh loads are worth to optimize during bpf compile time.

Cc Jan Seiffert <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc Matt Evans <[email protected]>
---
 arch/powerpc/net/bpf_jit_comp.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/powerpc/net/bpf_jit_comp.c +6 -1
index bf56e33..754320a 100644
@@ -132,7 +132,7 @@ static void bpf_jit_build_epilogue(u32 *image, struct codegen_context *ctx)
 }
 
 #define CHOOSE_LOAD_FUNC(K, func) \
-	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
+	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : NULL) : func##_positive_offset)
 
 /* Assemble the body code between the prologue & epilogue. */
 static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
@@ -427,6 +427,11 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
 		case BPF_S_LD_B_ABS:
 			func = CHOOSE_LOAD_FUNC(K, sk_load_byte);
 		common_load:
+			if (!func) {
+				PPC_LI(r_ret, 0);
+				PPC_JMP(exit_addr);
+				break;
+			}
 			/* Load from [K]. */
 			ctx->seen |= SEEN_DATAREF;
 			PPC_LI64(r_scratch1, func);
Signature · 1 line
An UDP packet walks into a

A message that is not in the archive (sent off-list or not yet received): [email protected]

maintainer
#4 lore raw

Re: [PATCH 2/3] net: bpf jit: x86: optimize choose_load_func error path

From: Vladimir Murzin <[email protected]>
Date: Tue, 8 Oct 2013 20:31:49 +0400

Quoted 51 lines

Macro CHOOSE_LOAD_FUNC returns handler for "any offset" if checks for K were not passed. At the same time handlers for "any offset" cases make the same checks against r_addr at run-time, that will always lead to bpf_error.

Run-time checks are still necessary for indirect load operations, but error path for absolute and mesh loads are worth to optimize during bpf compile time.

Cc Jan Seiffert <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc "David S. Miller" <[email protected]
Cc "H. Peter Anvin" <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/net/bpf_jit_comp.c |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
arch/x86/net/bpf_jit_comp.c +8 -2
index 79c216a..28ac17f 100644
@@ -123,7 +123,7 @@ static inline void bpf_flush_icache(void *start, void *end)
 }
 
 #define CHOOSE_LOAD_FUNC(K, func) \
-	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
+	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : NULL) : func##_positive_offset)
 
 /* Helper to find the offset of pkt_type in sk_buff
  * We want to make sure its still a 3bit field starting at a byte boundary.
@@ -611,7 +611,13 @@ void bpf_jit_compile(struct sk_filter *fp)
 			}
 			case BPF_S_LD_W_ABS:
 				func = CHOOSE_LOAD_FUNC(K, sk_load_word);
-common_load:			seen |= SEEN_DATAREF;
+common_load:
+				if (!func) {
+					CLEAR_A();
+					EMIT_JMP(cleanup_addr - addrs[i]);
+					break;
+				}
+				seen |= SEEN_DATAREF;
 				t_offset = func - (image + addrs[i]);
 				EMIT1_off32(0xbe, K); /* mov imm32,%esi */
 				EMIT1_off32(0xe8, t_offset); /* call */

arch/x86/net/bpf_jit_comp.c common_load: seen |= SEEN_DATAREF; · line 634

Quoted 8 lines
arch/x86/net/bpf_jit_comp.c +1 -4
@@ -625,10 +631,7 @@ common_load:			seen |= SEEN_DATAREF;
 			case BPF_S_LDX_B_MSH:
 				func = CHOOSE_LOAD_FUNC(K, sk_load_byte_msh);
 				seen |= SEEN_DATAREF | SEEN_XREG;
-				t_offset = func - (image + addrs[i]);
-				EMIT1_off32(0xbe, K);	/* mov imm32,%esi */
-				EMIT1_off32(0xe8, t_offset); /* call sk_load_byte_msh */
-				break;
+				goto common_load;

This second hunk will set SEEN_DATAREF even if common_load takes the !func path, that is not the intention at all here.

There's a reason why these two code blocks aren't shared.

#5 lore raw

Re: [PATCH 2/3] net: bpf jit: x86: optimize choose_load_func error path

Quoted 66 lines · David Miller

From: Vladimir Murzin <[email protected]>
Date: Tue, 8 Oct 2013 20:31:49 +0400

Quoted 51 lines

Macro CHOOSE_LOAD_FUNC returns handler for "any offset" if checks for K were not passed. At the same time handlers for "any offset" cases make the same checks against r_addr at run-time, that will always lead to bpf_error.

Run-time checks are still necessary for indirect load operations, but error path for absolute and mesh loads are worth to optimize during bpf compile time.

Cc Jan Seiffert <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc "David S. Miller" <[email protected]
Cc "H. Peter Anvin" <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/net/bpf_jit_comp.c |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
arch/x86/net/bpf_jit_comp.c +8 -2
index 79c216a..28ac17f 100644
@@ -123,7 +123,7 @@ static inline void bpf_flush_icache(void *start, void *end)
 }
 
 #define CHOOSE_LOAD_FUNC(K, func) \
-	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
+	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : NULL) : func##_positive_offset)
 
 /* Helper to find the offset of pkt_type in sk_buff
  * We want to make sure its still a 3bit field starting at a byte boundary.
@@ -611,7 +611,13 @@ void bpf_jit_compile(struct sk_filter *fp)
 			}
 			case BPF_S_LD_W_ABS:
 				func = CHOOSE_LOAD_FUNC(K, sk_load_word);
-common_load:			seen |= SEEN_DATAREF;
+common_load:
+				if (!func) {
+					CLEAR_A();
+					EMIT_JMP(cleanup_addr - addrs[i]);
+					break;
+				}
+				seen |= SEEN_DATAREF;
 				t_offset = func - (image + addrs[i]);
 				EMIT1_off32(0xbe, K); /* mov imm32,%esi */
 				EMIT1_off32(0xe8, t_offset); /* call */

arch/x86/net/bpf_jit_comp.c common_load: seen |= SEEN_DATAREF; · line 634

Quoted 8 lines
arch/x86/net/bpf_jit_comp.c +1 -4
@@ -625,10 +631,7 @@ common_load:			seen |= SEEN_DATAREF;
 			case BPF_S_LDX_B_MSH:
 				func = CHOOSE_LOAD_FUNC(K, sk_load_byte_msh);
 				seen |= SEEN_DATAREF | SEEN_XREG;
-				t_offset = func - (image + addrs[i]);
-				EMIT1_off32(0xbe, K);	/* mov imm32,%esi */
-				EMIT1_off32(0xe8, t_offset); /* call sk_load_byte_msh */
-				break;
+				goto common_load;

This second hunk will set SEEN_DATAREF even if common_load takes the !func path, that is not the intention at all here.

Quoted 1 line

There's a reason why these two code blocks aren't shared.

Thanks for review, David!

What about patch bellow?

---
 arch/x86/net/bpf_jit_comp.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
arch/x86/net/bpf_jit_comp.c +16 -2
index 79c216a..92128fe 100644
@@ -123,7 +123,7 @@ static inline void bpf_flush_icache(void *start, void *end)
 }
 
 #define CHOOSE_LOAD_FUNC(K, func) \
-	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
+	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : NULL) : func##_positive_offset)
 
 /* Helper to find the offset of pkt_type in sk_buff
  * We want to make sure its still a 3bit field starting at a byte boundary.
@@ -611,7 +611,14 @@ void bpf_jit_compile(struct sk_filter *fp)
 			}
 			case BPF_S_LD_W_ABS:
 				func = CHOOSE_LOAD_FUNC(K, sk_load_word);
-common_load:			seen |= SEEN_DATAREF;
+common_load:
+				if (!func) {
+					CLEAR_A();
+					EIT_JMP(cleanup_addr - addrs[i]);
+					break;
+				}
+
+				seen |= SEEN_DATAREF;
 				t_offset = func - (image + addrs[i]);
 				EMIT1_off32(0xbe, K); /* mov imm32,%esi */
 				EMIT1_off32(0xe8, t_offset); /* call */
@@ -624,6 +631,13 @@ common_load:			seen |= SEEN_DATAREF;
 				goto common_load;
 			case BPF_S_LDX_B_MSH:
 				func = CHOOSE_LOAD_FUNC(K, sk_load_byte_msh);
+
+				if (!func) {
+					CLEAR_A();
+					EIT_JMP(cleanup_addr - addrs[i]);
+					break;
+				}
+
 				seen |= SEEN_DATAREF | SEEN_XREG;
 				t_offset = func - (image + addrs[i]);
 				EMIT1_off32(0xbe, K);	/* mov imm32,%esi */
Signature · 3 lines
1.8.1.5

Vladimir
#6 lore raw

Re: [PATCH 2/3] net: bpf jit: x86: optimize choose_load_func error path

Quoted 4 lines · Vladimir Murzin
Quoted 3 lines · David Miller

From: Vladimir Murzin <[email protected]>
Date: Tue, 8 Oct 2013 20:31:49 +0400

[..snip..]

arch/x86/net/bpf_jit_comp.c void bpf_jit_compile(struct sk_filter *fp) · line 617

Quoted 5 lines
arch/x86/net/bpf_jit_comp.c +4 -1
-common_load:			seen |= SEEN_DATAREF;
+common_load:
+				if (!func) {
+					CLEAR_A();
+					EIT_JMP(cleanup_addr - addrs[i]);

EMIT? (likewise elsewhere)

Quoted 22 lines
arch/x86/net/bpf_jit_comp.c +11 -0
+					break;
+				}
+
+				seen |= SEEN_DATAREF;
 				t_offset = func - (image + addrs[i]);
 				EMIT1_off32(0xbe, K); /* mov imm32,%esi */
 				EMIT1_off32(0xe8, t_offset); /* call */
@@ -624,6 +631,13 @@ common_load:			seen |= SEEN_DATAREF;
 				goto common_load;
 			case BPF_S_LDX_B_MSH:
 				func = CHOOSE_LOAD_FUNC(K, sk_load_byte_msh);
+
+				if (!func) {
+					CLEAR_A();
+					EIT_JMP(cleanup_addr - addrs[i]);
+					break;
+				}
+
 				seen |= SEEN_DATAREF | SEEN_XREG;
 				t_offset = func - (image + addrs[i]);
 				EMIT1_off32(0xbe, K);	/* mov imm32,%esi */
Signature · 1 line
mailto:[email protected]
#7 lore raw

Re: [PATCH 2/3] net: bpf jit: x86: optimize choose_load_func error path

Quoted 9 lines · malc
Quoted 4 lines · Vladimir Murzin
Quoted 3 lines · David Miller

From: Vladimir Murzin <[email protected]>
Date: Tue, 8 Oct 2013 20:31:49 +0400

[..snip..]

Quoted 7 lines

arch/x86/net/bpf_jit_comp.c void bpf_jit_compile(struct sk_filter *fp) · line 617

Quoted 5 lines
arch/x86/net/bpf_jit_comp.c +4 -1
-common_load:			seen |= SEEN_DATAREF;
+common_load:
+				if (!func) {
+					CLEAR_A();
+					EIT_JMP(cleanup_addr - addrs[i]);

EMIT? (likewise elsewhere)

Oops... Thanks for quick response!

I'd better send the patch as a separate message.

Quoted 26 lines
Quoted 23 lines
arch/x86/net/bpf_jit_comp.c +11 -0
+					break;
+				}
+
+				seen |= SEEN_DATAREF;
 				t_offset = func - (image + addrs[i]);
 				EMIT1_off32(0xbe, K); /* mov imm32,%esi */
 				EMIT1_off32(0xe8, t_offset); /* call */
@@ -624,6 +631,13 @@ common_load:			seen |= SEEN_DATAREF;
 				goto common_load;
 			case BPF_S_LDX_B_MSH:
 				func = CHOOSE_LOAD_FUNC(K, sk_load_byte_msh);
+
+				if (!func) {
+					CLEAR_A();
+					EIT_JMP(cleanup_addr - addrs[i]);
+					break;
+				}
+
 				seen |= SEEN_DATAREF | SEEN_XREG;
 				t_offset = func - (image + addrs[i]);
 				EMIT1_off32(0xbe, K);	/* mov imm32,%esi */
Signature · 1 line
mailto:[email protected]
#8 lore raw

PATCH 2/3 net: bpf jit: x86: optimize choose_load_func error path

In reply to a message not in the archive

Macro CHOOSE_LOAD_FUNC returns handler for "any offset" if checks for K were not passed. At the same time handlers for "any offset" cases make the same checks against r_addr at run-time, that will always lead to bpf_error.

Run-time checks are still necessary for indirect load operations, but error path for absolute and mesh loads are worth to optimize during bpf compile time.

---

David pointed at inability to merge mesh load with common load code. This patch is updated according to this note.

 arch/x86/net/bpf_jit_comp.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
arch/x86/net/bpf_jit_comp.c +16 -2
index 79c216a..92128fe 100644
@@ -123,7 +123,7 @@ static inline void bpf_flush_icache(void *start, void *end)
 }
 
 #define CHOOSE_LOAD_FUNC(K, func) \
-	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
+	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : NULL) : func##_positive_offset)
 
 /* Helper to find the offset of pkt_type in sk_buff
  * We want to make sure its still a 3bit field starting at a byte boundary.
@@ -611,7 +611,14 @@ void bpf_jit_compile(struct sk_filter *fp)
 			}
 			case BPF_S_LD_W_ABS:
 				func = CHOOSE_LOAD_FUNC(K, sk_load_word);
-common_load:			seen |= SEEN_DATAREF;
+common_load:
+				if (!func) {
+					CLEAR_A();
+					EMIT_JMP(cleanup_addr - addrs[i]);
+					break;
+				}
+
+				seen |= SEEN_DATAREF;
 				t_offset = func - (image + addrs[i]);
 				EMIT1_off32(0xbe, K); /* mov imm32,%esi */
 				EMIT1_off32(0xe8, t_offset); /* call */
@@ -624,6 +631,13 @@ common_load:			seen |= SEEN_DATAREF;
 				goto common_load;
 			case BPF_S_LDX_B_MSH:
 				func = CHOOSE_LOAD_FUNC(K, sk_load_byte_msh);
+
+				if (!func) {
+					CLEAR_A();
+					EMIT_JMP(cleanup_addr - addrs[i]);
+					break;
+				}
+
 				seen |= SEEN_DATAREF | SEEN_XREG;
 				t_offset = func - (image + addrs[i]);
 				EMIT1_off32(0xbe, K);	/* mov imm32,%esi */
Signature · 1 line
1.8.1.5
#9 lore raw

PATCH 2/3 net: bpf jit: x86: optimize choose_load_func error path

Macro CHOOSE_LOAD_FUNC returns handler for "any offset" if checks for K were not passed. At the same time handlers for "any offset" cases make the same checks against r_addr at run-time, that will always lead to bpf_error.

Run-time checks are still necessary for indirect load operations, but error path for absolute and mesh loads are worth to optimize during bpf compile time.

---

David pointed at inability to merge mesh load with common load code. This patch is updated according to this note.

 arch/x86/net/bpf_jit_comp.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
arch/x86/net/bpf_jit_comp.c +16 -2
index 79c216a..92128fe 100644
@@ -123,7 +123,7 @@ static inline void bpf_flush_icache(void *start, void *end)
 }
 
 #define CHOOSE_LOAD_FUNC(K, func) \
-	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
+	((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : NULL) : func##_positive_offset)
 
 /* Helper to find the offset of pkt_type in sk_buff
  * We want to make sure its still a 3bit field starting at a byte boundary.
@@ -611,7 +611,14 @@ void bpf_jit_compile(struct sk_filter *fp)
 			}
 			case BPF_S_LD_W_ABS:
 				func = CHOOSE_LOAD_FUNC(K, sk_load_word);
-common_load:			seen |= SEEN_DATAREF;
+common_load:
+				if (!func) {
+					CLEAR_A();
+					EMIT_JMP(cleanup_addr - addrs[i]);
+					break;
+				}
+
+				seen |= SEEN_DATAREF;
 				t_offset = func - (image + addrs[i]);
 				EMIT1_off32(0xbe, K); /* mov imm32,%esi */
 				EMIT1_off32(0xe8, t_offset); /* call */
@@ -624,6 +631,13 @@ common_load:			seen |= SEEN_DATAREF;
 				goto common_load;
 			case BPF_S_LDX_B_MSH:
 				func = CHOOSE_LOAD_FUNC(K, sk_load_byte_msh);
+
+				if (!func) {
+					CLEAR_A();
+					EMIT_JMP(cleanup_addr - addrs[i]);
+					break;
+				}
+
 				seen |= SEEN_DATAREF | SEEN_XREG;
 				t_offset = func - (image + addrs[i]);
 				EMIT1_off32(0xbe, K);	/* mov imm32,%esi */
Signature · 1 line
1.8.1.5
#10 lore raw

Re: [PATCH 2/3] net: bpf jit: x86: optimize choose_load_func error path

Quoted 8 lines · Vladimir Murzin

Macro CHOOSE_LOAD_FUNC returns handler for "any offset" if checks for K were not passed. At the same time handlers for "any offset" cases make the same checks against r_addr at run-time, that will always lead to bpf_error.

Run-time checks are still necessary for indirect load operations, but error path for absolute and mesh loads are worth to optimize during bpf compile time.

I don't get the point.

What real world use case or problem are you trying to handle ?

bpf_error returns 0, so it seems your patch does the same.

A buggy BPF program should not expect us to 'save' a few cycles.

#11 lore raw

Re: [PATCH 2/3] net: bpf jit: x86: optimize choose_load_func error path

Quoted 10 lines · Eric Dumazet
Quoted 8 lines · Vladimir Murzin

Macro CHOOSE_LOAD_FUNC returns handler for "any offset" if checks for K were not passed. At the same time handlers for "any offset" cases make the same checks against r_addr at run-time, that will always lead to bpf_error.

Run-time checks are still necessary for indirect load operations, but error path for absolute and mesh loads are worth to optimize during bpf compile time.

Quoted 10 lines

I don't get the point.

What real world use case or problem are you trying to handle ?

bpf_error returns 0, so it seems your patch does the same.

A buggy BPF program should not expect us to 'save' a few cycles.

Hi Eric!

There is no real world use case for me - it was eliminated by plain code reading. The patch is not supposed to change behavior of BPF program - only optimization of the error path.
I agree with, you there is no significant reason for optimizations of rarely used pice of code. However, it is not only saving pipeline cycles and I-cache lines for usually "never taken" branch. In case this "never taken" branch is a buggy part of BPF program, we can avoid extra instructions and save space for the rest of BPF program - there is no need to care about seen flags of buggy part anymore.

Anyway, if you still think it's not good enough - just throw it away ;)

Thanks
Vladimir