mbox series

[v0,0/3] Add tnum_scast helper

Message ID 20250130112342.69843-1-dimitar.kanaliev@siteground.com (mailing list archive)
Headers show
Series Add tnum_scast helper | expand

Message

Dimitar Kanaliev Jan. 30, 2025, 11:23 a.m. UTC
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.

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: Extend tests with more coverage for sign extension

 include/linux/tnum.h                          |   3 +
 kernel/bpf/tnum.c                             |  29 ++++
 kernel/bpf/verifier.c                         | 124 ++++++------------
 .../selftests/bpf/progs/verifier_movsx.c      |  73 +++++++++++
 4 files changed, 144 insertions(+), 85 deletions(-)