* [PATCH] x86/bpf: make arch_bpf_trampoline_size allocate from EXECMEM_MODULE_DATA
@ 2026-08-18 13:05 Mike Rapoport
2026-08-18 14:07 ` bot+bpf-ci
2026-08-18 20:51 ` Jiri Olsa
0 siblings, 2 replies; 5+ messages in thread
From: Mike Rapoport @ 2026-08-18 13:05 UTC (permalink / raw)
To: Alexei Starovoitov, Andrii Nakryiko, Borislav Petkov,
Daniel Borkmann, Dave Hansen, Eduard Zingerman, Ingo Molnar,
Kumar Kartikeya Dwivedi, Song Liu, Thomas Gleixner
Cc: Emil Tsalapatis, H. Peter Anvin, Jiri Olsa, John Fastabend,
Martin KaFai Lau, Mike Rapoport, Yonghong Song, bpf, linux-kernel,
x86, Jiri Olsa
From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
Jiri Olsa reports slowdown of tracing_multi benchmark that allocates huge
number of trampolines [1].
The slowdown caused by extra protection changes in execmem_alloc_rw() and
execmem_free().
With ROX caches enabled, all execmem allocations except EXECMEM_MODULE_DATA
are ROX after the allocation. execmem_alloc_rw() temporarily sets them to
W+NX and execmem_free() resets them back to ROX.
The only user of bpf_jit_alloc_exec_rw() is x86::arch_bpf_trampoline_size()
that only needs a temporary writable buffer in the modules address space.
On x86 executable memory and module data are constrained to the same
address range, so x86::arch_bpf_trampoline_size() can directly use
execmem_alloc(EXECMEM_MODULE_DATA)
Replace the call to bpf_jit_alloc_exec_rw() with a call to
execmem_alloc(EXECMEM_MODULE_DATA) in x86::arch_bpf_trampoline_size() and
drop bpf_jit_alloc_exec_rw() helper.
Reported-by: Jiri Olsa <olsajiri@gmail.com>
Link: https://lore.kernel.org/all/an8r7EODLIL-bZM3@krava
Fixes: f0334294a428 ("bpf, x86: make sure allocation in arch_bpf_trampoline_size() is writable")
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
arch/x86/net/bpf_jit_comp.c | 8 +++++---
include/linux/filter.h | 1 -
kernel/bpf/core.c | 5 -----
3 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index b2feec81e231..7d064d3e2788 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -13,6 +13,7 @@
#include <linux/bpf_verifier.h>
#include <linux/memory.h>
#include <linux/sort.h>
+#include <linux/execmem.h>
#include <asm/extable.h>
#include <asm/ftrace.h>
#include <asm/set_memory.h>
@@ -3706,15 +3707,16 @@ int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
*
* We cannot use kvmalloc here, because we need image to be in
* module memory range.
- * Since it must be writable use bpf_jit_alloc_exec_rw().
+ * Since it must be writable use execmem_alloc(EXECMEM_MODULE_DATA)
+ * that returns writable memory in the module address space.
*/
- image = bpf_jit_alloc_exec_rw(PAGE_SIZE);
+ image = execmem_alloc(EXECMEM_MODULE_DATA, PAGE_SIZE);
if (!image)
return -ENOMEM;
ret = __arch_prepare_bpf_trampoline(&im, image, image + PAGE_SIZE, image,
m, flags, tnodes, func_addr);
- bpf_jit_free_exec(image);
+ execmem_free(image);
return ret;
}
diff --git a/include/linux/filter.h b/include/linux/filter.h
index 32d5297c557e..14acb2455746 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -1333,7 +1333,6 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
void bpf_jit_binary_free(struct bpf_binary_header *hdr);
u64 bpf_jit_alloc_exec_limit(void);
void *bpf_jit_alloc_exec(unsigned long size);
-void *bpf_jit_alloc_exec_rw(unsigned long size);
void bpf_jit_free_exec(void *addr);
void bpf_jit_free(struct bpf_prog *fp);
struct bpf_binary_header *
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index e2076667b245..1b89c18cf246 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -1128,11 +1128,6 @@ void *bpf_jit_alloc_exec(unsigned long size)
return execmem_alloc(EXECMEM_BPF, size);
}
-void *bpf_jit_alloc_exec_rw(unsigned long size)
-{
- return execmem_alloc_rw(EXECMEM_BPF, size);
-}
-
void bpf_jit_free_exec(void *addr)
{
execmem_free(addr);
base-commit: 07edbd8fe6416f45e9ba6b0edcd3e40770601ebc
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] x86/bpf: make arch_bpf_trampoline_size allocate from EXECMEM_MODULE_DATA
2026-08-18 13:05 [PATCH] x86/bpf: make arch_bpf_trampoline_size allocate from EXECMEM_MODULE_DATA Mike Rapoport
@ 2026-08-18 14:07 ` bot+bpf-ci
2026-08-19 6:42 ` Mike Rapoport
2026-08-18 20:51 ` Jiri Olsa
1 sibling, 1 reply; 5+ messages in thread
From: bot+bpf-ci @ 2026-08-18 14:07 UTC (permalink / raw)
To: rppt, ast, andrii, bp, daniel, dave.hansen, eddyz87, mingo,
memxor, song, tglx
Cc: emil, hpa, jolsa, john.fastabend, martin.lau, rppt, yonghong.song,
bpf, linux-kernel, x86, olsajiri, ast, andrii, daniel, martin.lau,
eddyz87, yonghong.song, clm, ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 1847 bytes --]
> x86/bpf: make arch_bpf_trampoline_size allocate from EXECMEM_MODULE_DATA
>
> Jiri Olsa reports slowdown of tracing_multi benchmark that allocates huge
> number of trampolines [1].
>
> The slowdown caused by extra protection changes in execmem_alloc_rw() and
> execmem_free().
>
> With ROX caches enabled, all execmem allocations except EXECMEM_MODULE_DATA
> are ROX after the allocation. execmem_alloc_rw() temporarily sets them to
> W+NX and execmem_free() resets them back to ROX.
>
> The only user of bpf_jit_alloc_exec_rw() is x86::arch_bpf_trampoline_size()
> that only needs a temporary writable buffer in the modules address space.
>
> On x86 executable memory and module data are constrained to the same
> address range, so x86::arch_bpf_trampoline_size() can directly use
> execmem_alloc(EXECMEM_MODULE_DATA)
>
> Replace the call to bpf_jit_alloc_exec_rw() with a call to
> execmem_alloc(EXECMEM_MODULE_DATA) in x86::arch_bpf_trampoline_size() and
> drop bpf_jit_alloc_exec_rw() helper.
>
> Reported-by: Jiri Olsa <olsajiri@gmail.com>
> Link: https://lore.kernel.org/all/an8r7EODLIL-bZM3@krava
> Fixes: f0334294a428 ("bpf, x86: make sure allocation in arch_bpf_trampoline_size() is writable")
^^^^^^^^^^^^
The Fixes tag references commit f0334294a428, which does not exist in
this repository. Should this be:
Fixes: 5bf02dbf39fa ("bpf, x86: Make sure allocation in arch_bpf_trampoline_size() is writable")
That commit introduced bpf_jit_alloc_exec_rw() and the performance issue
being addressed here.
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/32142507111
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] x86/bpf: make arch_bpf_trampoline_size allocate from EXECMEM_MODULE_DATA
2026-08-18 14:07 ` bot+bpf-ci
@ 2026-08-19 6:42 ` Mike Rapoport
2026-08-19 7:34 ` Daniel Borkmann
0 siblings, 1 reply; 5+ messages in thread
From: Mike Rapoport @ 2026-08-19 6:42 UTC (permalink / raw)
To: bot+bpf-ci
Cc: ast, andrii, bp, daniel, dave.hansen, eddyz87, mingo, memxor,
song, tglx, emil, hpa, jolsa, john.fastabend, martin.lau,
yonghong.song, bpf, linux-kernel, x86, olsajiri, martin.lau, clm,
ihor.solodrai
On Tue, Aug 18, 2026 at 02:07:23PM +0000, bot+bpf-ci@kernel.org wrote:
> > x86/bpf: make arch_bpf_trampoline_size allocate from EXECMEM_MODULE_DATA
> >
> > Jiri Olsa reports slowdown of tracing_multi benchmark that allocates huge
> > number of trampolines [1].
> >
> > The slowdown caused by extra protection changes in execmem_alloc_rw() and
> > execmem_free().
> >
> > With ROX caches enabled, all execmem allocations except EXECMEM_MODULE_DATA
> > are ROX after the allocation. execmem_alloc_rw() temporarily sets them to
> > W+NX and execmem_free() resets them back to ROX.
> >
> > The only user of bpf_jit_alloc_exec_rw() is x86::arch_bpf_trampoline_size()
> > that only needs a temporary writable buffer in the modules address space.
> >
> > On x86 executable memory and module data are constrained to the same
> > address range, so x86::arch_bpf_trampoline_size() can directly use
> > execmem_alloc(EXECMEM_MODULE_DATA)
> >
> > Replace the call to bpf_jit_alloc_exec_rw() with a call to
> > execmem_alloc(EXECMEM_MODULE_DATA) in x86::arch_bpf_trampoline_size() and
> > drop bpf_jit_alloc_exec_rw() helper.
> >
> > Reported-by: Jiri Olsa <olsajiri@gmail.com>
> > Link: https://lore.kernel.org/all/an8r7EODLIL-bZM3@krava
> > Fixes: f0334294a428 ("bpf, x86: make sure allocation in arch_bpf_trampoline_size() is writable")
> ^^^^^^^^^^^^
>
> The Fixes tag references commit f0334294a428, which does not exist in
> this repository. Should this be:
>
> Fixes: 5bf02dbf39fa ("bpf, x86: Make sure allocation in arch_bpf_trampoline_size() is writable")
Argh, checked the log on a wrong branch.
Can you folks fix it up when applying or you'd need v3?
> That commit introduced bpf_jit_alloc_exec_rw() and the performance issue
> being addressed here.
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] x86/bpf: make arch_bpf_trampoline_size allocate from EXECMEM_MODULE_DATA
2026-08-19 6:42 ` Mike Rapoport
@ 2026-08-19 7:34 ` Daniel Borkmann
0 siblings, 0 replies; 5+ messages in thread
From: Daniel Borkmann @ 2026-08-19 7:34 UTC (permalink / raw)
To: Mike Rapoport, bot+bpf-ci
Cc: ast, andrii, bp, dave.hansen, eddyz87, mingo, memxor, song, tglx,
emil, hpa, jolsa, john.fastabend, martin.lau, yonghong.song, bpf,
linux-kernel, x86, olsajiri, martin.lau, clm, ihor.solodrai
On 8/19/26 8:42 AM, Mike Rapoport wrote:
> On Tue, Aug 18, 2026 at 02:07:23PM +0000, bot+bpf-ci@kernel.org wrote:
>>> x86/bpf: make arch_bpf_trampoline_size allocate from EXECMEM_MODULE_DATA
>>>
>>> Jiri Olsa reports slowdown of tracing_multi benchmark that allocates huge
>>> number of trampolines [1].
>>>
>>> The slowdown caused by extra protection changes in execmem_alloc_rw() and
>>> execmem_free().
>>>
>>> With ROX caches enabled, all execmem allocations except EXECMEM_MODULE_DATA
>>> are ROX after the allocation. execmem_alloc_rw() temporarily sets them to
>>> W+NX and execmem_free() resets them back to ROX.
>>>
>>> The only user of bpf_jit_alloc_exec_rw() is x86::arch_bpf_trampoline_size()
>>> that only needs a temporary writable buffer in the modules address space.
>>>
>>> On x86 executable memory and module data are constrained to the same
>>> address range, so x86::arch_bpf_trampoline_size() can directly use
>>> execmem_alloc(EXECMEM_MODULE_DATA)
>>>
>>> Replace the call to bpf_jit_alloc_exec_rw() with a call to
>>> execmem_alloc(EXECMEM_MODULE_DATA) in x86::arch_bpf_trampoline_size() and
>>> drop bpf_jit_alloc_exec_rw() helper.
>>>
>>> Reported-by: Jiri Olsa <olsajiri@gmail.com>
>>> Link: https://lore.kernel.org/all/an8r7EODLIL-bZM3@krava
>>> Fixes: f0334294a428 ("bpf, x86: make sure allocation in arch_bpf_trampoline_size() is writable")
>> ^^^^^^^^^^^^
>>
>> The Fixes tag references commit f0334294a428, which does not exist in
>> this repository. Should this be:
>>
>> Fixes: 5bf02dbf39fa ("bpf, x86: Make sure allocation in arch_bpf_trampoline_size() is writable")
>
> Argh, checked the log on a wrong branch.
>
> Can you folks fix it up when applying or you'd need v3?
Yeap, we'll do, np.
>> That commit introduced bpf_jit_alloc_exec_rw() and the performance issue
>> being addressed here.
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/bpf: make arch_bpf_trampoline_size allocate from EXECMEM_MODULE_DATA
2026-08-18 13:05 [PATCH] x86/bpf: make arch_bpf_trampoline_size allocate from EXECMEM_MODULE_DATA Mike Rapoport
2026-08-18 14:07 ` bot+bpf-ci
@ 2026-08-18 20:51 ` Jiri Olsa
1 sibling, 0 replies; 5+ messages in thread
From: Jiri Olsa @ 2026-08-18 20:51 UTC (permalink / raw)
To: Mike Rapoport
Cc: Alexei Starovoitov, Andrii Nakryiko, Borislav Petkov,
Daniel Borkmann, Dave Hansen, Eduard Zingerman, Ingo Molnar,
Kumar Kartikeya Dwivedi, Song Liu, Thomas Gleixner,
Emil Tsalapatis, H. Peter Anvin, John Fastabend, Martin KaFai Lau,
Yonghong Song, bpf, linux-kernel, x86, Jiri Olsa
On Tue, Aug 18, 2026 at 04:05:10PM +0300, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
>
> Jiri Olsa reports slowdown of tracing_multi benchmark that allocates huge
> number of trampolines [1].
>
> The slowdown caused by extra protection changes in execmem_alloc_rw() and
> execmem_free().
>
> With ROX caches enabled, all execmem allocations except EXECMEM_MODULE_DATA
> are ROX after the allocation. execmem_alloc_rw() temporarily sets them to
> W+NX and execmem_free() resets them back to ROX.
>
> The only user of bpf_jit_alloc_exec_rw() is x86::arch_bpf_trampoline_size()
> that only needs a temporary writable buffer in the modules address space.
>
> On x86 executable memory and module data are constrained to the same
> address range, so x86::arch_bpf_trampoline_size() can directly use
> execmem_alloc(EXECMEM_MODULE_DATA)
>
> Replace the call to bpf_jit_alloc_exec_rw() with a call to
> execmem_alloc(EXECMEM_MODULE_DATA) in x86::arch_bpf_trampoline_size() and
> drop bpf_jit_alloc_exec_rw() helper.
>
> Reported-by: Jiri Olsa <olsajiri@gmail.com>
> Link: https://lore.kernel.org/all/an8r7EODLIL-bZM3@krava
> Fixes: f0334294a428 ("bpf, x86: make sure allocation in arch_bpf_trampoline_size() is writable")
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Tested-by: Jiri Olsa <jolsa@kernel.org>
thanks,
jirak
> ---
> arch/x86/net/bpf_jit_comp.c | 8 +++++---
> include/linux/filter.h | 1 -
> kernel/bpf/core.c | 5 -----
> 3 files changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
> index b2feec81e231..7d064d3e2788 100644
> --- a/arch/x86/net/bpf_jit_comp.c
> +++ b/arch/x86/net/bpf_jit_comp.c
> @@ -13,6 +13,7 @@
> #include <linux/bpf_verifier.h>
> #include <linux/memory.h>
> #include <linux/sort.h>
> +#include <linux/execmem.h>
> #include <asm/extable.h>
> #include <asm/ftrace.h>
> #include <asm/set_memory.h>
> @@ -3706,15 +3707,16 @@ int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
> *
> * We cannot use kvmalloc here, because we need image to be in
> * module memory range.
> - * Since it must be writable use bpf_jit_alloc_exec_rw().
> + * Since it must be writable use execmem_alloc(EXECMEM_MODULE_DATA)
> + * that returns writable memory in the module address space.
> */
> - image = bpf_jit_alloc_exec_rw(PAGE_SIZE);
> + image = execmem_alloc(EXECMEM_MODULE_DATA, PAGE_SIZE);
> if (!image)
> return -ENOMEM;
>
> ret = __arch_prepare_bpf_trampoline(&im, image, image + PAGE_SIZE, image,
> m, flags, tnodes, func_addr);
> - bpf_jit_free_exec(image);
> + execmem_free(image);
> return ret;
> }
>
> diff --git a/include/linux/filter.h b/include/linux/filter.h
> index 32d5297c557e..14acb2455746 100644
> --- a/include/linux/filter.h
> +++ b/include/linux/filter.h
> @@ -1333,7 +1333,6 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
> void bpf_jit_binary_free(struct bpf_binary_header *hdr);
> u64 bpf_jit_alloc_exec_limit(void);
> void *bpf_jit_alloc_exec(unsigned long size);
> -void *bpf_jit_alloc_exec_rw(unsigned long size);
> void bpf_jit_free_exec(void *addr);
> void bpf_jit_free(struct bpf_prog *fp);
> struct bpf_binary_header *
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index e2076667b245..1b89c18cf246 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -1128,11 +1128,6 @@ void *bpf_jit_alloc_exec(unsigned long size)
> return execmem_alloc(EXECMEM_BPF, size);
> }
>
> -void *bpf_jit_alloc_exec_rw(unsigned long size)
> -{
> - return execmem_alloc_rw(EXECMEM_BPF, size);
> -}
> -
> void bpf_jit_free_exec(void *addr)
> {
> execmem_free(addr);
>
> base-commit: 07edbd8fe6416f45e9ba6b0edcd3e40770601ebc
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-08-19 7:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-18 13:05 [PATCH] x86/bpf: make arch_bpf_trampoline_size allocate from EXECMEM_MODULE_DATA Mike Rapoport
2026-08-18 14:07 ` bot+bpf-ci
2026-08-19 6:42 ` Mike Rapoport
2026-08-19 7:34 ` Daniel Borkmann
2026-08-18 20:51 ` Jiri Olsa
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.