[PATCH bpf-next v2 0/8] bpf: Add UHMUL and SHMUL instructions

tangyazhou at zju.edu.cn tangyazhou at zju.edu.cn
Tue Oct 20 22:40:34 PDT 2026


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, and documentation
support, along with JIT support for x86-64, arm64 and riscv64. 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 8/8 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. The corresponding LLVM patch
is available for review at:

  https://github.com/llvm/llvm-project/pull/234076

The instruction design is inspired by the UHMUL and SHMUL operations in
sBPF (Solana's BPF variant). Patch 1/8 describes the encoding and
immediate-semantics differences.

Apologies for the delay in sending v2. I was tied up with other commitments
over the past month.

---
Changes in v2:
- Introduce a new conformance group "divmul64v2" for UHMUL/SHMUL. (bot+bpf-ci)
- Shorten the name of bpf_mul_variant. (Alexei)
- Remove redundant validation for off field in interpreter. (Alexei)
- Split arena test to two separate files.
- Link to v1: https://patch.msgid.link/20260917041712.1860722-1-tangyazhou@zju.edu.cn

Changes in v1:
- Add JIT support on arm64 and riscv64. (Alexei)
- Fix the HMUL check on PowerPC JIT backend. (Sashiko AI reviewer)
- Link to RFC: https://lore.kernel.org/bpf/20260902070534.2141812-1-tangyazhou@zju.edu.cn/

To: bpf at vger.kernel.org
To: Alexei Starovoitov <ast at kernel.org>
To: Daniel Borkmann <daniel at iogearbox.net>
To: Andrii Nakryiko <andrii at kernel.org>
To: Eduard Zingerman <eddyz87 at gmail.com>
To: Kumar Kartikeya Dwivedi <memxor at gmail.com>
To: David Vernet <void at manifault.com>
To: bpf at ietf.org
Cc: John Fastabend <john.fastabend at gmail.com>
Cc: Martin KaFai Lau <martin.lau at linux.dev>
Cc: Song Liu <song at kernel.org>
Cc: Yonghong Song <yonghong.song at linux.dev>
Cc: Jiri Olsa <jolsa at kernel.org>
Cc: Emil Tsalapatis <emil at etsalapatis.com>
Cc: Ihor Solodrai <ihor.solodrai at linux.dev>
Cc: Quentin Monnet <qmo at kernel.org>
Cc: Puranjay Mohan <puranjay at kernel.org>
Cc: Xu Kuohai <xukuohai at huaweicloud.com>
Cc: Björn Töpel <bjorn at kernel.org>
Cc: Pu Lehui <pulehui at huawei.com>
Cc: Catalin Marinas <catalin.marinas at arm.com>
Cc: Will Deacon <will at kernel.org>
Cc: Mark Rutland <mark.rutland at arm.com>
Cc: linux-arm-kernel at lists.infradead.org
Cc: linux-riscv at lists.infradead.org
Cc: Shahab Vahedi <list+bpf at vahedi.org>
Cc: Russell King <linux at armlinux.org.uk>
Cc: Tiezhu Yang <yangtiezhu at loongson.cn>
Cc: Hengqi Chen <hengqi.chen at gmail.com>
Cc: Johan Almbladh <johan.almbladh at anyfinetworks.com>
Cc: Paul Burton <paulburton at kernel.org>
Cc: "James E.J. Bottomley" <James.Bottomley at HansenPartnership.com>
Cc: Helge Deller <deller at gmx.de>
Cc: Hari Bathini <hbathini at linux.ibm.com>
Cc: Christophe Leroy (CS GROUP) <chleroy at kernel.org>
Cc: Naveen N Rao <naveen at kernel.org>
Cc: Luke Nelson <luke.r.nels at gmail.com>
Cc: Xi Wang <xi.wang at gmail.com>
Cc: Ilya Leoshkevich <iii at linux.ibm.com>
Cc: Heiko Carstens <hca at linux.ibm.com>
Cc: Vasily Gorbik <gor at linux.ibm.com>
Cc: David S. Miller <davem at davemloft.net>
Cc: Wang YanQing <udknight at gmail.com>
Cc: Jakub Kicinski <kuba at kernel.org>
Cc: Jonathan Corbet <corbet at lwn.net>
Cc: linux-doc at vger.kernel.org

---
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 (5):
      bpf, arm64: JIT UHMUL and SHMUL
      bpf, riscv: JIT UHMUL and SHMUL on RV64
      bpf: Reject UHMUL/SHMUL in unsupported backends
      bpf: Refactor ALU instruction variant validation
      selftests/bpf: Add bytecode tests for UHMUL and SHMUL

 .../bpf/standardization/instruction-set.rst        |  37 +++-
 arch/arc/net/bpf_jit_core.c                        |   3 +
 arch/arm/net/bpf_jit_32.c                          |   3 +
 arch/arm64/include/asm/insn.h                      |   4 +
 arch/arm64/lib/insn.c                              |   6 +
 arch/arm64/net/bpf_jit.h                           |   6 +
 arch/arm64/net/bpf_jit_comp.c                      |  15 +-
 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.h                           |   5 +
 arch/riscv/net/bpf_jit_comp32.c                    |   3 +
 arch/riscv/net/bpf_jit_comp64.c                    |  18 +-
 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 +
 drivers/net/ethernet/netronome/nfp/bpf/verifier.c  |   6 +
 include/linux/filter.h                             |  38 ++++
 include/uapi/linux/bpf.h                           |   6 +
 kernel/bpf/core.c                                  |  41 +++-
 kernel/bpf/disasm.c                                |  18 ++
 kernel/bpf/verifier.c                              |  68 +++++-
 tools/include/uapi/linux/bpf.h                     |   6 +
 tools/testing/selftests/bpf/prog_tests/verifier.c  |   2 +
 .../selftests/bpf/prog_tests/verifier_hmul_arena.c |  19 ++
 tools/testing/selftests/bpf/progs/verifier_hmul.c  | 235 +++++++++++++++++++++
 .../selftests/bpf/progs/verifier_hmul_arena.c      |  70 ++++++
 .../bpf/progs/verifier_value_illegal_alu.c         |   7 +-
 33 files changed, 671 insertions(+), 23 deletions(-)
---
base-commit: 3a65f38d928a2699ebcec72a2d60bdb8fcde8284
change-id: 20261021-bpf-hmul-40deb6203548

Best regards,
--  
Yazhou Tang <tangyazhou518 at outlook.com>




More information about the linux-riscv mailing list