linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/6] bpf: verifier: stop emitting zext for LDX
@ 2023-09-12 22:46 Puranjay Mohan
  2023-09-12 22:46 ` [PATCH bpf-next 1/6] bpf, riscv32: Always zero extend for LDX with B/W/H Puranjay Mohan
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Puranjay Mohan @ 2023-09-12 22:46 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Shubham Bansal,
	Russell King, James E.J. Bottomley, Helge Deller, Naveen N. Rao,
	Michael Ellerman, Nicholas Piggin, Christophe Leroy, Luke Nelson,
	Xi Wang, Paul Walmsley, Palmer Dabbelt, Albert Ou, Wang YanQing,
	bpf, linux-arm-kernel, linux-kernel, linux-parisc, linuxppc-dev,
	linux-riscv, netdev
  Cc: puranjay12

All 64-bit architectures that support the BPF JIT do LDX + zero extension
with a single CPU instruction. Some 64-bit architectures like riscv64,
s390, mips64, etc. have bpf_jit_needs_zext() -> true. This means although
these architectures do LDX + zero extension with a single CPU instruction,
the verifier emits extra zero extension instructions after LDX | B/H/W.

After a discussion about this in [1], it was decided that the verifier
should not emit zext instructions for LDX and all JITs that can't do a LDX
+ zero extension with a single instruction should emit two instructions by
default for LDX.

All 32 bit JITs checked for ctx->prog->aux->verifier_zext and did not do
explicit zero extension after LDX if this is set by the verifier.

This patch series changes all applicable 32-bit JITs to always do a zero
extension after LDX without checking ctx->prog->aux->verifier_zext.

The last patch modifies the verifier to always mark the destination of LDX
as 64 bit which in turn stops the verifier from emitting zext after LDX.

These changes have not been tested because I don't have the hardware to do
so, I would request the JIT maintainers to help me test this. Especially,
the powerpc32 JTI where amount of code change is more.

[1] https://lore.kernel.org/all/CANk7y0j2f-gPgZwd+YfTL71-6wfvky+f=kBC_ccqsS0EHAysyA@mail.gmail.com/

Puranjay Mohan (6):
  bpf, riscv32: Always zero extend for LDX with B/W/H
  bpf, x86-32: Always zero extend for LDX with B/W/H
  bpf, parisc32: Always zero extend for LDX with B/W/H
  bpf, powerpc32: Always zero extend for LDX
  bpf, arm32: Always zero extend for LDX with B/H/W
  bpf, verifier: always mark destination of LDX as 64-bit

 arch/arm/net/bpf_jit_32.c         |  9 +++------
 arch/parisc/net/bpf_jit_comp32.c  |  9 +++------
 arch/powerpc/net/bpf_jit_comp32.c | 25 ++++++++-----------------
 arch/riscv/net/bpf_jit_comp32.c   |  9 +++------
 arch/x86/net/bpf_jit_comp32.c     |  2 --
 kernel/bpf/verifier.c             |  4 +---
 6 files changed, 18 insertions(+), 40 deletions(-)

-- 
2.39.2


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

end of thread, other threads:[~2023-09-13  0:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-12 22:46 [PATCH bpf-next 0/6] bpf: verifier: stop emitting zext for LDX Puranjay Mohan
2023-09-12 22:46 ` [PATCH bpf-next 1/6] bpf, riscv32: Always zero extend for LDX with B/W/H Puranjay Mohan
2023-09-12 22:46 ` [PATCH bpf-next 2/6] bpf, x86-32: " Puranjay Mohan
2023-09-12 22:46 ` [PATCH bpf-next 3/6] bpf, parisc32: " Puranjay Mohan
2023-09-12 22:46 ` [PATCH bpf-next 4/6] bpf, powerpc32: Always zero extend for LDX Puranjay Mohan
2023-09-12 22:46 ` [PATCH bpf-next 5/6] bpf, arm32: Always zero extend for LDX with B/H/W Puranjay Mohan
2023-09-12 23:03   ` Russell King (Oracle)
2023-09-12 23:16     ` Puranjay Mohan
2023-09-13  0:10       ` Alexei Starovoitov
2023-09-12 22:46 ` [PATCH bpf-next 6/6] bpf, verifier: always mark destination of LDX as 64-bit Puranjay Mohan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).