BPF List
 help / color / mirror / Atom feed
* [PATCH v1 0/3] Add tnum_scast helper
@ 2025-11-25 12:56 Dimitar Kanaliev
  2025-11-25 12:56 ` [PATCH v1 1/3] bpf: Introduce tnum_scast as a tnum native sign extension helper Dimitar Kanaliev
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Dimitar Kanaliev @ 2025-11-25 12:56 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
	Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
	Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Mykola Lysenko, Shung-Hsi Yu, Dimitar Kanaliev

Hello,

This patch series introduces a new tnum helper function called tnum_scast
which can perform sign extension on tnums. 

The goal of this patch is to help simplify (and unify) sign extension
operations performed on tnums inside the verifier. Additionally,
the changes also improve the precision with which boundaries are tracked
for s64/u64, since we can more accurately deduce said ranges. The patch
removes assignments to worst case {S,U}64_{MIN,MAX}.

There are a bunch of other places in which existing sign extensions can
be replaced with the new primitive, but I thought I'd start off with
register coercion as a minimal self contained example.

The first patch in the series introduces tnum_scast. The second patch
makes use of tnum_scast to simplify the logic in coerce_reg_to_size_sx
and coerce_subreg_to_size_sx. The last patch introduces some more tests
related to sign extension.

Changelog:
	v0 -> v1:
	- Simplified tnum_scast() implementation to use native s64
	arithmetic shifts for sign extension instead of manual bit masking.
	- Refactored coerce_{reg,subreg}_to_size_sx in verifier to rely
	on __update_reg_bounds() instead of the previously introduced
	manual logic. Removed some dead code for set_sext{32,64} values.
	- Removed irrelevant tests, added one that fails at base without
	our changes.

Dimitar Kanaliev (3):
  bpf: Introduce tnum_scast as a tnum native sign extension helper
  bpf: verifier: Simplify register sign extension with tnum_scast
  selftests/bpf: Add verifier bounds checks for sign extension

 include/linux/tnum.h                          |   3 +
 kernel/bpf/tnum.c                             |  13 ++
 kernel/bpf/verifier.c                         | 150 ++++--------------
 .../selftests/bpf/progs/verifier_movsx.c      |  19 +++
 4 files changed, 65 insertions(+), 120 deletions(-)

-- 
2.43.0


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

end of thread, other threads:[~2025-12-15  2:41 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-25 12:56 [PATCH v1 0/3] Add tnum_scast helper Dimitar Kanaliev
2025-11-25 12:56 ` [PATCH v1 1/3] bpf: Introduce tnum_scast as a tnum native sign extension helper Dimitar Kanaliev
2025-11-25 13:22   ` bot+bpf-ci
2025-11-26  8:56     ` Shung-Hsi Yu
2025-12-01  7:43       ` Dimitar Kanaliev
2025-12-15  2:40         ` Shung-Hsi Yu
2025-11-25 12:56 ` [PATCH v1 2/3] bpf: verifier: Simplify register sign extension with tnum_scast Dimitar Kanaliev
2025-11-25 13:22   ` bot+bpf-ci
2025-11-26 10:32     ` Dimitar Kanaliev
2025-12-01 23:49   ` Eduard Zingerman
2025-12-02 10:53     ` Dimitar Kanaliev
2025-12-02 18:03       ` Eduard Zingerman
2025-12-04  6:50       ` Shung-Hsi Yu
2025-11-25 12:56 ` [PATCH v1 3/3] selftests/bpf: Add verifier bounds checks for sign extension Dimitar Kanaliev
2025-11-26  9:04 ` [PATCH v1 0/3] Add tnum_scast helper Shung-Hsi Yu

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