Skip to content

LoongArch: BPF: arena instruction gating, private stack and exceptions

George Guo bpf linux-kselftest lkml loongarch 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest5 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5LoongArch: BPF: Gate unsupported arena instructions via bpf_jit_supports_insn()arch/loongarch/net/bpf_jit.c+20 -00 replies
2/5LoongArch: BPF: Add private stack supportarch/loongarch/net/bpf_jit.c arch/loongarch/net/bpf_jit.h+109 -30 replies
3/5LoongArch: BPF: Add exceptions (bpf_throw) supportarch/loongarch/kernel/stacktrace.c arch/loongarch/net/bpf_jit.c+90 -30 replies
4/5selftests/bpf: Add LoongArch deny listtools/testing/selftests/bpf/DENYLIST.loongarch+2 -00 replies
5/5selftests/bpf: Enable struct_ops private stack test for LoongArchtools/testing/selftests/bpf/prog_tests/struct_ops_private_stack.c+1 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/5] LoongArch: BPF: arena instruction gating, private stack and exceptions

From: George Guo <[email protected]>

This series adds three LoongArch BPF JIT features, plus the accompanying selftest changes:

1. Gate the arena instructions the JIT does not implement (atomics and sign-extending loads on arena pointers) via bpf_jit_supports_insn(), so the verifier rejects such programs early with a clear message instead of letting them fail late in the JIT.
2. Per-program private stack (bpf_jit_supports_private_stack()): the BPF stack of deep/recursive tracing programs is moved off the kernel stack into a per-CPU allocation bracketed by overflow/underflow guards that are checked on teardown.
3. Exceptions / bpf_throw (bpf_jit_supports_exceptions()): unwind to the exception boundary program via arch_bpf_stack_walk() (built on the ORC unwinder) and reuse its frame in the exception callback. Gated on CONFIG_UNWINDER_ORC.

Patches 4-5 are the selftests side: a LoongArch deny list (arena_atomics, which patch 1 deliberately rejects) and enabling the struct_ops private stack test on LoongArch. They touch tools/testing/selftests/bpf, hence the bpf@vger / linux-kselftest Cc.

The series is independent of the earlier "LoongArch: BPF: Support internal-only MOV to resolve per-CPU addrs" / "Add timed may_goto support" patches [1] (no functional or apply dependency) and targets the LoongArch tree.

Testing on a LoongArch board (test_progs):
- exceptions: 117 subtests, 0 failed
- struct_ops_private_stack: private_stack / _fail / _recur, 0 failed
- arena list/htab/strsearch and verifier_arena*: pass
- arena_atomics: rejected by the verifier as expected ("BPF_ATOMIC stores into Rn arena is not allowed"), hence the deny-list entry in patch 4

[1] <https://lore.kernel.org/all/[email protected]/>

George Guo (5):
LoongArch: BPF: Gate unsupported arena instructions via
bpf_jit_supports_insn()
LoongArch: BPF: Add private stack support
LoongArch: BPF: Add exceptions (bpf_throw) support selftests/bpf: Add LoongArch deny list
selftests/bpf: Enable struct_ops private stack test for LoongArch

 arch/loongarch/kernel/stacktrace.c            |  52 ++++++
 arch/loongarch/net/bpf_jit.c                  | 172 +++++++++++++++++-
 arch/loongarch/net/bpf_jit.h                  |   1 +
 .../testing/selftests/bpf/DENYLIST.loongarch  |   2 +
 .../bpf/prog_tests/struct_ops_private_stack.c |   2 +-
 5 files changed, 222 insertions(+), 7 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/DENYLIST.loongarch

base-commit: 186d3c4e92242351afc24d9784f31cb4cd08a4b7

Signature · 1 line
2.25.1