On Wed, May 22, 2024 at 11:42 PM Alexei Starovoitov <alexei.starovoitov@xxxxxxxxx> wrote: > > From: Alexei Starovoitov <ast@xxxxxxxxxx> > > v1->v2: > - Replaced copy precision logic with faster and more accurate alternative. > See find_precision(). ... > +static void find_precise_reg(struct bpf_reg_state *cur_reg) > +{ > + struct bpf_reg_state *reg; > + > + reg = cur_reg->parent; > + while (reg && reg->type == SCALAR_VALUE) { > + /* > + * propagate_liveness() might not have happened for this states yet. > + * Intermediate reg missing LIVE_READ mark is not an issue. > + */ > + if (reg->precise && (reg->live & REG_LIVE_READ)) { > + cur_reg->precise = true; > + break; > + } > + reg = reg->parent; > + } > +} > + > +static void find_precision(struct bpf_verifier_state *cur_state) > +{ > + struct bpf_func_state *state; > + struct bpf_reg_state *reg; > + > + if (!get_loop_entry(cur_state)) > + return; > + bpf_for_each_reg_in_vstate(cur_state, state, reg, ({ > + if (reg->type != SCALAR_VALUE || reg->precise) > + continue; > + find_precise_reg(reg); > + })); > +} This turned out to be an ok idea for a good case and horrible idea when loop doesn't converge, since walking parentage chain is very expensive when loop is reaching million of iterations. There will be a v3 with fixes. pw-bot: cr