Skip to contentSkip to conversation

bpf, x86: No bpf_arch_text_poke() for kernel text

PATCH In review Vincent Li 2 participants 4 messages Sep 19, 2025 – Sep 20, 2025

Subsystems (3)
lore
Share & tools
lore

Vincent Li

author
#0 lore raw

PATCH 1/1 bpf, x86: No bpf_arch_text_poke() for kernel text

kernel function replies on ftrace to poke kernel functions.

---
 arch/x86/net/bpf_jit_comp.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/x86/net/bpf_jit_comp.c +6 -4
index 8d34a9400a5e..63b9c8717bf3 100644
@@ -643,10 +643,12 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
 int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
 		       void *old_addr, void *new_addr)
 {
-	if (!is_kernel_text((long)ip) &&
-	    !is_bpf_text_address((long)ip))
-		/* BPF poking in modules is not supported */
-		return -EINVAL;
+	if (!is_bpf_text_address((long)ip))
+		/* Only poking bpf text is supported. Since kernel function
+		 * entry is set up by ftrace, we reply on ftrace to poke kernel
+		 * functions. BPF poking in modules is not supported.
+		 */
+		return -ENOTSUPP;
 
 	/*
 	 * See emit_prologue(), for IBT builds the trampoline hook is preceded
Signature · 1 line
2.34.1
#1 lore raw
Quoted 15 lines · Vincent Li

kernel function replies on ftrace to poke kernel functions.

---
 arch/x86/net/bpf_jit_comp.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/x86/net/bpf_jit_comp.c +0 -0
index 8d34a9400a5e..63b9c8717bf3 100644
@@ -643,10 +643,12 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
 int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
                       void *old_addr, void *new_addr)

arch/x86/net/bpf_jit_comp.c static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t, · line 650

Quoted 10 lines
arch/x86/net/bpf_jit_comp.c +5 -4
 {
-       if (!is_kernel_text((long)ip) &&
-           !is_bpf_text_address((long)ip))
-               /* BPF poking in modules is not supported */
-               return -EINVAL;
+       if (!is_bpf_text_address((long)ip))
+               /* Only poking bpf text is supported. Since kernel function
+                * entry is set up by ftrace, we reply on ftrace to poke kernel
+                * functions. BPF poking in modules is not supported.
+                */

Not true. Pls study kernel/bpf/trampoline.c and how it's used.

pw-bot: cr

author
#2 lore raw
Quoted 21 lines · Alexei Starovoitov
Quoted 19 lines · Vincent Li

kernel function replies on ftrace to poke kernel functions.

---
 arch/x86/net/bpf_jit_comp.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/x86/net/bpf_jit_comp.c +0 -3
index 8d34a9400a5e..63b9c8717bf3 100644
@@ -643,10 +643,12 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
 int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
                       void *old_addr, void *new_addr)
 {
-       if (!is_kernel_text((long)ip) &&
-           !is_bpf_text_address((long)ip))
-               /* BPF poking in modules is not supported */
Quoted 9 lines

arch/x86/net/bpf_jit_comp.c static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t, · line 650

Quoted 6 lines
arch/x86/net/bpf_jit_comp.c +5 -1
-               return -EINVAL;
+       if (!is_bpf_text_address((long)ip))
+               /* Only poking bpf text is supported. Since kernel function
+                * entry is set up by ftrace, we reply on ftrace to poke kernel
+                * functions. BPF poking in modules is not supported.
+                */

Not true. Pls study kernel/bpf/trampoline.c and how it's used.

oops :). I copied and pasted from arm64 arch/arm64/net/bpf_jit_comp.c and thought it applies to x86 too, sorry about that.

if (!__bpf_address_lookup((unsigned long)ip, &size, &offset, namebuf))
/* Only poking bpf text is supported. Since kernel function
* entry is set up by ftrace, we reply on ftrace to poke kernel
* functions.
*/
return -ENOTSUPP;

Quoted 1 line

pw-bot: cr

#3 lore raw
Quoted 33 lines · Vincent Li
Quoted 21 lines · Alexei Starovoitov
Quoted 19 lines · Vincent Li

kernel function replies on ftrace to poke kernel functions.

---
 arch/x86/net/bpf_jit_comp.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/x86/net/bpf_jit_comp.c +0 -3
index 8d34a9400a5e..63b9c8717bf3 100644
@@ -643,10 +643,12 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
 int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
                       void *old_addr, void *new_addr)
 {
-       if (!is_kernel_text((long)ip) &&
-           !is_bpf_text_address((long)ip))
-               /* BPF poking in modules is not supported */
Quoted 9 lines

arch/x86/net/bpf_jit_comp.c static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t, · line 650

Quoted 6 lines
arch/x86/net/bpf_jit_comp.c +5 -1
-               return -EINVAL;
+       if (!is_bpf_text_address((long)ip))
+               /* Only poking bpf text is supported. Since kernel function
+                * entry is set up by ftrace, we reply on ftrace to poke kernel
+                * functions. BPF poking in modules is not supported.
+                */

Not true. Pls study kernel/bpf/trampoline.c and how it's used.

Quoted 3 lines

oops :). I copied and pasted from arm64 arch/arm64/net/bpf_jit_comp.c and thought it applies to x86 too, sorry about that.

arm64 is different, since it has hw restriction on how far the jump can reach. It has to do a very special dance.