BPF List
 help / color / mirror / Atom feed
* [RFC PATCH bpf-next 0/6] bpf: Add UHMUL and SHMUL instructions
@ 2026-09-02  7:05 Yazhou Tang
  2026-09-02  7:05 ` [RFC PATCH bpf-next 1/6] " Yazhou Tang
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: Yazhou Tang @ 2026-09-02  7:05 UTC (permalink / raw)
  To: bpf, ast, eddyz87
  Cc: daniel, john.fastabend, andrii, martin.lau, song, yonghong.song,
	kpsingh, sdf, haoluo, jolsa, tangyazhou518, shenghaoyuan0928,
	ziye

From: Yazhou Tang <tangyazhou518@outlook.com>

This patchset adds unsigned and signed high-half multiplication to the BPF
ISA. UHMUL returns the high 64 bits of an unsigned 64-by-64-bit product,
while SHMUL does the same for a signed product.

Both operations are BPF_ALU64 BPF_MUL variants selected by insn->off.
off == 0 remains the existing low-half multiplication, while off == 1
and off == 2 select UHMUL and SHMUL, respectively. The immediate forms
use the usual sign-extended 32-bit BPF immediate.

The patchset adds interpreter, disassembler, verifier, documentation, and
x86-64 JIT support. Unsupported JIT and hardware offload backends reject
the variants to avoid compiling them as ordinary multiplication. For
now, the verifier computes exact results for constant operands and
otherwise conservatively marks the destination unknown.

Patch 6/6 uses raw bytecode for UHMUL and SHMUL because LLVM support has
not been merged yet. Once it is available, the raw encodings can be
replaced with the uh*= and sh*= mnemonics. A draft LLVM implementation
is available at:

  https://github.com/ADSWT518/llvm-project/tree/bpf-hmul-insn

We plan to finalize and submit it as an LLVM pull request after the
kernel-side ISA changes are merged.

The instruction design is inspired by the UHMUL and SHMUL operations in
Solana sBPF. Patch 1/6 describes the encoding and immediate-semantics
differences.

Feedback on the encoding, immediate semantics, and initial verifier
model would be appreciated.

Tianci Cao (3):
  bpf: Add UHMUL and SHMUL instructions
  bpf, x86: JIT UHMUL and SHMUL on x86-64
  bpf: Add verifier support for UHMUL and SHMUL

Yazhou Tang (3):
  bpf: Reject UHMUL/SHMUL in unsupported JITs
  bpf: Refactor ALU instruction variant validation
  selftests/bpf: Add bytecode tests for UHMUL and SHMUL

 .../bpf/standardization/instruction-set.rst   |  26 +-
 arch/arc/net/bpf_jit_core.c                   |   3 +
 arch/arm/net/bpf_jit_32.c                     |   3 +
 arch/arm64/net/bpf_jit_comp.c                 |   3 +
 arch/loongarch/net/bpf_jit.c                  |   3 +
 arch/mips/net/bpf_jit_comp32.c                |   3 +
 arch/mips/net/bpf_jit_comp64.c                |   3 +
 arch/parisc/net/bpf_jit_comp32.c              |   3 +
 arch/parisc/net/bpf_jit_comp64.c              |   3 +
 arch/powerpc/net/bpf_jit_comp32.c             |   3 +
 arch/powerpc/net/bpf_jit_comp64.c             |   3 +
 arch/riscv/net/bpf_jit_comp32.c               |   3 +
 arch/riscv/net/bpf_jit_comp64.c               |   3 +
 arch/s390/net/bpf_jit_comp.c                  |   3 +
 arch/sparc/net/bpf_jit_comp_64.c              |   3 +
 arch/x86/net/bpf_jit_comp.c                   |  48 +++
 arch/x86/net/bpf_jit_comp32.c                 |   3 +
 .../net/ethernet/netronome/nfp/bpf/verifier.c |   6 +
 include/linux/filter.h                        |  39 +++
 include/uapi/linux/bpf.h                      |  10 +
 kernel/bpf/core.c                             |  45 ++-
 kernel/bpf/disasm.c                           |  18 ++
 kernel/bpf/verifier.c                         |  69 ++++-
 tools/include/uapi/linux/bpf.h                |  10 +
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/verifier_hmul.c       | 284 ++++++++++++++++++
 .../bpf/progs/verifier_value_illegal_alu.c    |   9 +-
 27 files changed, 598 insertions(+), 13 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_hmul.c

-- 
2.43.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2026-09-12  3:40 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-02  7:05 [RFC PATCH bpf-next 0/6] bpf: Add UHMUL and SHMUL instructions Yazhou Tang
2026-09-02  7:05 ` [RFC PATCH bpf-next 1/6] " Yazhou Tang
2026-09-07 19:51   ` Alexei Starovoitov
2026-09-08  8:30     ` Yazhou Tang
2026-09-12  3:40       ` Alexei Starovoitov
2026-09-02  7:05 ` [RFC PATCH bpf-next 2/6] bpf, x86: JIT UHMUL and SHMUL on x86-64 Yazhou Tang
2026-09-02  7:05 ` [RFC PATCH bpf-next 3/6] bpf: Reject UHMUL/SHMUL in unsupported JITs Yazhou Tang
2026-09-02  7:21   ` sashiko-bot
2026-09-02  8:09     ` Yazhou Tang
2026-09-07 19:53   ` Alexei Starovoitov
2026-09-08  8:32     ` Yazhou Tang
2026-09-02  7:05 ` [RFC PATCH bpf-next 4/6] bpf: Refactor ALU instruction variant validation Yazhou Tang
2026-09-02  7:05 ` [RFC PATCH bpf-next 5/6] bpf: Add verifier support for UHMUL and SHMUL Yazhou Tang
2026-09-02  7:05 ` [RFC PATCH bpf-next 6/6] selftests/bpf: Add bytecode tests " Yazhou Tang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox