Skip to contentSkip to conversation

bpf: avoid unnecessary IPI in bpf_flush_icache

PATCH In review Yanfei Xu 3 participants 7 messages Jun 1, 2021 – Jun 3, 2021

Subsystems (5)
Networking Network drivers BPF arm64 +1 more subsystems
lore
Share & tools
lore

Yanfei Xu

author
#0 lore raw

cover bpf: avoid unnecessary IPI in bpf_flush_icache

Hi,

When looking at the IPI counts in /proc/interrupts, there are always IPI1 happened on isolated cpus, even if the cpus had been idle with nohz. However, we should bother these cpus as less as possible.

The IPI1 were raised by flush_icache_range in bpf_int_jit_compile(). Futher, the calling of it was introduced in 3b8c9f1cdfc5("arm64:
IPI each CPU after invalidating the I-cache for kernel mappings"), then I found the bpf case seems no need this operation. But I'm not sure, and still learning the JIT codes meanwhile. If I am wrong, please fix me, many thanks!

Yanfei Xu (1):
bpf: avoid unnecessary IPI in bpf_flush_icache

 arch/arm64/net/bpf_jit_comp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 1 line
2.27.0
author
#1 lore raw

PATCH 1/1 bpf: avoid unnecessary IPI in bpf_flush_icache

It's no need to trigger IPI for keeping pipeline fresh in bpf case.

---
 arch/arm64/net/bpf_jit_comp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/net/bpf_jit_comp.c +1 -1
index f7b194878a99..5311f8be4ba4 100644
@@ -974,7 +974,7 @@ static int validate_code(struct jit_ctx *ctx)
 
 static inline void bpf_flush_icache(void *start, void *end)
 {
-	flush_icache_range((unsigned long)start, (unsigned long)end);
+	__flush_icache_range((unsigned long)start, (unsigned long)end);
 }
 
 struct arm64_jit_data {
Signature · 1 line
2.27.0
maintainer
#2 lore raw
Quoted 1 line · Yanfei Xu

It's no need to trigger IPI for keeping pipeline fresh in bpf case.

This needs a more concrete explanation/analysis on "why it is safe" to do so rather than just saying that it is not needed.

Quoted 19 lines
---
  arch/arm64/net/bpf_jit_comp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/net/bpf_jit_comp.c +1 -1
index f7b194878a99..5311f8be4ba4 100644
@@ -974,7 +974,7 @@ static int validate_code(struct jit_ctx *ctx)
 
  static inline void bpf_flush_icache(void *start, void *end)
  {
-	flush_icache_range((unsigned long)start, (unsigned long)end);
+	__flush_icache_range((unsigned long)start, (unsigned long)end);
  }
 
  struct arm64_jit_data {
maintainer
#3 lore raw
Quoted 5 lines · Daniel Borkmann
Quoted 1 line · Yanfei Xu

It's no need to trigger IPI for keeping pipeline fresh in bpf case.

This needs a more concrete explanation/analysis on "why it is safe" to do so rather than just saying that it is not needed.

Agreed. You need to show how the executing thread ends up going through a context synchronizing operation before jumping to the generated code if the IPI here is removed.

Will

author
#4 lore raw
Quoted 4 lines · Will Deacon

[Please note: This e-mail is from an EXTERNAL e-mail address]

Quoted 1 line · Daniel Borkmann

On 6/1/21 5:06 PM, Yanfei Xu wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

It's no need to trigger IPI for keeping pipeline fresh in bpf case.

This needs a more concrete explanation/analysis on "why it is safe" to do so rather than just saying that it is not needed.

Agreed. You need to show how the executing thread ends up going through a context synchronizing operation before jumping to the generated code if the IPI here is removed.

This patch came out with I looked through ftrace codes. Ftrace modify the text code and don't send IPI in aarch64_insn_patch_text_nosync(). I mistakenly thought the bpf is same with ftrace.

But now I'm still not sure why the ftrace don't need the IPI to go through context synchronizing, maybe the worst situation is omit a tracing event?

Thanks,
Yanfei

Quoted 3 lines

Will

maintainer
#5 lore raw
Quoted 16 lines · Yanfei
Quoted 4 lines · Will Deacon

[Please note: This e-mail is from an EXTERNAL e-mail address]

Quoted 1 line · Daniel Borkmann

On 6/1/21 5:06 PM, Yanfei Xu wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

It's no need to trigger IPI for keeping pipeline fresh in bpf case.

This needs a more concrete explanation/analysis on "why it is safe" to do so rather than just saying that it is not needed.

Agreed. You need to show how the executing thread ends up going through a context synchronizing operation before jumping to the generated code if the IPI here is removed.

Quoted 7 lines

This patch came out with I looked through ftrace codes. Ftrace modify the text code and don't send IPI in aarch64_insn_patch_text_nosync(). I mistakenly thought the bpf is same with ftrace.

But now I'm still not sure why the ftrace don't need the IPI to go through context synchronizing, maybe the worst situation is omit a tracing event?

I think ftrace handles this itself via ftrace_sync_ipi, no?

Will

author
#6 lore raw
Quoted 23 lines · Will Deacon

[Please note: This e-mail is from an EXTERNAL e-mail address]

Quoted 20 lines · Yanfei
Quoted 4 lines · Will Deacon

[Please note: This e-mail is from an EXTERNAL e-mail address]

Quoted 1 line · Daniel Borkmann

On 6/1/21 5:06 PM, Yanfei Xu wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

It's no need to trigger IPI for keeping pipeline fresh in bpf case.

This needs a more concrete explanation/analysis on "why it is safe" to do so rather than just saying that it is not needed.

Agreed. You need to show how the executing thread ends up going through a context synchronizing operation before jumping to the generated code if the IPI here is removed.

This patch came out with I looked through ftrace codes. Ftrace modify the text code and don't send IPI in aarch64_insn_patch_text_nosync(). I mistakenly thought the bpf is same with ftrace.

Quoted 5 lines
Quoted 3 lines

But now I'm still not sure why the ftrace don't need the IPI to go through context synchronizing, maybe the worst situation is omit a tracing event?

I think ftrace handles this itself via ftrace_sync_ipi, no?

Ah, Yes! I missed this...

Anyway, thanks for your reminding and very sorry for my noise.

Regards,
Yanfei

Quoted 3 lines

Will