m68k, bpf: Add initial BPF JIT compiler support
Subsystems (3)
PATCH v12 1/1 m68k, bpf: Add initial BPF JIT compiler support
Add a BPF JIT compiler for the m68k architecture.
The JIT generates m68k machine code targeting m68020+ processors and coldfire parts with an mmu (ISA_B/ISA_C). It excludes plain 68000/68010 and non-mmu coldfire processors, as it relies on 32-bit branch displacements (b<cc>.l) to handle large bpf programs.
Tested with bpf selftests jit_insns and jit_insns_blinded, excluding 64 bit, kfunc, and bpf subprogram call subtests:
Summary: 2/41 PASSED, 0 SKIPPED, 0/0 FAILED
---
Changes in v12:
- Fix short branch offset comments in emit_jmp().
.../features/core/eBPF-JIT/arch-support.txt | 2 +- MAINTAINERS | 6 + arch/m68k/Kbuild | 2 +- arch/m68k/Kconfig | 1 + arch/m68k/net/Makefile | 2 + arch/m68k/net/bpf_jit_comp.c | 1752 +++++++++++++++++ 6 files changed, 1763 insertions(+), 2 deletions(-) create mode 100644 arch/m68k/net/Makefile create mode 100644 arch/m68k/net/bpf_jit_comp.c
Documentation/features/core/eBPF-JIT/arch-support.txt +1 -1
@@ -13,7 +13,7 @@ | csky: | TODO | | hexagon: | TODO | | loongarch: | ok | - | m68k: | TODO | + | m68k: | ok | | microblaze: | TODO | | mips: | ok | | nios2: | TODO |
MAINTAINERS +6 -0
@@ -4997,6 +4997,12 @@ L: [email protected] S: Maintained F: arch/loongarch/net/ +BPF JIT for M68K +M: Kuan-Wei Chiu <[email protected]> +L: [email protected] +S: Maintained +F: arch/m68k/net/ + BPF JIT for MIPS (32-BIT AND 64-BIT) M: Johan Almbladh <[email protected]> M: Paul Burton <[email protected]>
arch/m68k/Kbuild +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y += kernel/ mm/ +obj-y += kernel/ mm/ net/ obj-$(CONFIG_Q40) += q40/ obj-$(CONFIG_AMIGA) += amiga/ obj-$(CONFIG_ATARI) += atari/
arch/m68k/Kconfig +1 -0
@@ -32,6 +32,7 @@ config M68K select HAVE_ARCH_TLB_REMOVE_TABLE if MMU_MOTOROLA select HAVE_ASM_MODVERSIONS select HAVE_DEBUG_BUGVERBOSE + select HAVE_EBPF_JIT if MMU select HAVE_EFFICIENT_UNALIGNED_ACCESS if !CPU_HAS_NO_UNALIGNED select HAVE_LD_DEAD_CODE_DATA_ELIMINATION select HAVE_MOD_ARCH_SPECIFIC
arch/m68k/net/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_BPF_JIT) += bpf_jit_comp.o
arch/m68k/net/bpf_jit_comp.c new file +1752 -0
1,752 lines not on this page · raw message
Signature · 1 line
2.56.1.839.g22a8290db9-goog
[email protected]
AI reviewTL;DR: Nits only, no bug found: the m68k JIT hardcodes the tail-call limit (0x7021) and the 44/48-byte prologue jump offset; suggests named constants and a check so later edits don't quietly break…
Quoted 1 line
m68k, bpf: Add initial BPF JIT compiler support
TL;DR: Nits only, no bug found: the m68k JIT hardcodes the tail-call limit (0x7021) and the 44/48-byte prologue jump offset; suggests named constants and a check so later edits don't quietly break tail calls.
Quoted 5 lines
arch/m68k/net/bpf_jit_comp.c new file +0
-0
[ ... ]
Quoted 8 lines
arch/m68k/net/bpf_jit_comp.c new file +8
-0+emit_16 (ctx, (u16 )STACK_OFFSET (BPF_TC_LO )); + +emit_16 (ctx,0x2068 );/* movea.l d16(%a0), %a0 */ +emit_16 (ctx, offsetof(struct bpf_prog , bpf_func)); + +emit_16 (ctx,0x4ee8 );/* jmp d16(%a0) */ +emit_16 (ctx,CPU_IS_COLDFIRE ?48 :44 ); +
[ ... ]
arch/m68k/net/bpf_jit_comp.c line 1405
Quoted 6 lines
arch/m68k/net/bpf_jit_comp.c new file +6
-0+static void build_prologue (struct jit_ctx *ctx) +{ +int total_stack =SCRATCH_SIZE +MAX_BPF_STACK +8 ; + +emit_16 (ctx,0x7021 );/* moveq #33, %d0 */ +
this isn't a bug, but could the tail-call counter be emitted as 0x7000 | MAX_TAIL_CALL_CNT instead of the literal 0x7021, so that a grep for MAX_TAIL_CALL_CNT finds this place if the limit ever changes?
Similarly, emit_tail_call() jumps to bpf_func + (CPU_IS_COLDFIRE ? 48 : 44), which only holds while build_prologue() emits exactly 44 or 48 bytes. Could that offset be a named constant that is checked against ctx->idx at the end of build_prologue(), so a later edit to the prologue cannot quietly break tail calls?
---
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/45866130532
Quoted 5 lines · On Thu, Nov 26, 2026 at 05:45:05PM +0000, [email protected] wrote:
Quoted 1 line
m68k, bpf: Add initial BPF JIT compiler support
TL;DR: Nits only, no bug found: the m68k JIT hardcodes the tail-call limit (
0x7021) and the 44/48-byte prologue jump offset; suggests named constants and a check so later edits don't quietly break tail calls.
I'll hold off on respinning just for these nits and fold them in if a v13 is needed.
Regards,
Kuan-Wei