Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/8] bpf: Add UHMUL and SHMUL instructions
@ 2026-10-21  5:40 tangyazhou
  2026-10-21  5:40 ` [PATCH bpf-next v2 1/8] " tangyazhou
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: tangyazhou @ 2026-10-21  5:40 UTC (permalink / raw)
  To: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, David Vernet, bpf
  Cc: John Fastabend, Martin KaFai Lau, Song Liu, Yonghong Song,
	Jiri Olsa, Emil Tsalapatis, Ihor Solodrai, Quentin Monnet,
	Puranjay Mohan, Xu Kuohai, Björn Töpel, Pu Lehui,
	Catalin Marinas, Will Deacon, Mark Rutland, linux-arm-kernel,
	linux-riscv, Shahab Vahedi, Russell King, Tiezhu Yang,
	Hengqi Chen, Johan Almbladh, Paul Burton, James E.J. Bottomley,
	Helge Deller, Hari Bathini, Christophe Leroy (CS GROUP),
	Naveen N Rao, Luke Nelson, Xi Wang, Ilya Leoshkevich,
	Heiko Carstens, Vasily Gorbik, David S. Miller, Wang YanQing,
	Jakub Kicinski, Jonathan Corbet, linux-doc, Tianci Cao,
	Yazhou Tang, Shenghao Yuan, Alexei Starovoitov

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


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

end of thread, other threads:[~2026-10-21 17:12 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-21  5:40 [PATCH bpf-next v2 0/8] bpf: Add UHMUL and SHMUL instructions tangyazhou
2026-10-21  5:40 ` [PATCH bpf-next v2 1/8] " tangyazhou
2026-10-21  6:15   ` bot+bpf-ci
2026-10-21 17:11   ` Alexei Starovoitov
2026-10-21  5:52 ` [PATCH bpf-next v2 2/8] bpf, x86: JIT UHMUL and SHMUL on x86-64 tangyazhou
2026-10-21  8:23 ` [PATCH bpf-next v2 3/8] bpf, arm64: JIT UHMUL and SHMUL tangyazhou
2026-10-21  8:23 ` [PATCH bpf-next v2 4/8] bpf, riscv: JIT UHMUL and SHMUL on RV64 tangyazhou
2026-10-21  8:23 ` [PATCH bpf-next v2 5/8] bpf: Reject UHMUL/SHMUL in unsupported backends tangyazhou
2026-10-21  8:23 ` [PATCH bpf-next v2 6/8] bpf: Refactor ALU instruction variant validation tangyazhou
2026-10-21  8:24 ` [PATCH bpf-next v2 7/8] bpf: Add verifier support for UHMUL and SHMUL tangyazhou
2026-10-21  8:24 ` [PATCH bpf-next v2 8/8] selftests/bpf: Add bytecode tests " tangyazhou

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