mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
bpf: Print 32-bit SCEV bounds as 32-bit numbers
- Print large 32-bit bounds without sign extension. - Omit 32-bit bounds when they coincide with 64-bit bounds. Before: loop header at ..., widening r0 to 0x80000000..0xffffffff (s32 0xffffffff80000000..-1) step 1 loop header at ..., widening r0 to 0..3 (s32 0..3) step 1 After: loop header at ..., widening r0 to 0x80000000..0xffffffff (s32 0x80000000..-1) step 1 loop header at ..., widening r0 to 0..3 step 1 Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261026-scev-simpler-clamp-v2-6-f373aec9825f@gmail.com
This commit is contained in:
parent
abc9a76a88
commit
899cbaae6e
|
|
@ -1280,6 +1280,7 @@ __printf(3, 4) void verbose_linfo(struct bpf_verifier_env *env,
|
|||
u32 insn_off,
|
||||
const char *prefix_fmt, ...);
|
||||
void bpf_verbose_snum(struct bpf_verifier_env *env, s64 num);
|
||||
void bpf_verbose_snum32(struct bpf_verifier_env *env, s32 num);
|
||||
|
||||
#define verifier_bug_if(cond, env, fmt, args...) \
|
||||
({ \
|
||||
|
|
|
|||
|
|
@ -535,6 +535,14 @@ void bpf_verbose_snum(struct bpf_verifier_env *env, s64 num)
|
|||
verbose(env, "%#llx", num);
|
||||
}
|
||||
|
||||
void bpf_verbose_snum32(struct bpf_verifier_env *env, s32 num)
|
||||
{
|
||||
if (is_snum_decimal(num))
|
||||
verbose(env, "%d", num);
|
||||
else
|
||||
verbose(env, "%#x", (u32)num);
|
||||
}
|
||||
|
||||
int tnum_strn(char *str, size_t size, struct tnum a)
|
||||
{
|
||||
/* print as a constant, if tnum is fully known */
|
||||
|
|
|
|||
|
|
@ -2456,11 +2456,13 @@ static void log_bounds(struct bpf_verifier_env *env, const struct bounds *bounds
|
|||
bpf_verbose_snum(env, cnum64_smin(bounds->r64));
|
||||
bpf_log(log, "..");
|
||||
bpf_verbose_snum(env, cnum64_smax(bounds->r64));
|
||||
if (bounds->r32.size < U32_MAX) {
|
||||
if (bounds->r32.size < U32_MAX &&
|
||||
(cnum32_smin(bounds->r32) != cnum64_smin(bounds->r64) ||
|
||||
cnum32_smax(bounds->r32) != cnum64_smax(bounds->r64))) {
|
||||
bpf_log(log, " (s32 ");
|
||||
bpf_verbose_snum(env, cnum32_smin(bounds->r32));
|
||||
bpf_verbose_snum32(env, cnum32_smin(bounds->r32));
|
||||
bpf_log(log, "..");
|
||||
bpf_verbose_snum(env, cnum32_smax(bounds->r32));
|
||||
bpf_verbose_snum32(env, cnum32_smax(bounds->r32));
|
||||
bpf_log(log, ")");
|
||||
}
|
||||
bpf_log(log, " step %u", bounds->step);
|
||||
|
|
|
|||
|
|
@ -1771,7 +1771,7 @@ __success
|
|||
__log_level(2)
|
||||
__flag(BPF_F_TEST_STATE_FREQ)
|
||||
__msg("loop header at 1, header_count is 4")
|
||||
__msg("loop header at 1, widening r0 to 0..3 (s32 0..3) step 1")
|
||||
__msg("loop header at 1, widening r0 to 0..3 step 1")
|
||||
__msg("loop header at 1, clamping r0")
|
||||
__msg("4: R0=3")
|
||||
__naked void pre_cond_je32(void)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user