Skip to content

Commit 8e095f0

Browse files
bpf: Refactor mark_{dynptr,iter}_read
JIRA: https://issues.redhat.com/browse/RHEL-78201 commit b79f5f5 Author: Kumar Kartikeya Dwivedi <memxor@gmail.com> Date: Tue Dec 3 19:03:56 2024 -0800 bpf: Refactor mark_{dynptr,iter}_read There is possibility of sharing code between mark_dynptr_read and mark_iter_read for updating liveness information of their stack slots. Consolidate common logic into mark_stack_slot_obj_read function in preparation for the next patch which needs the same logic for its own stack slots. Acked-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/r/20241204030400.208005-4-memxor@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
1 parent 079313e commit 8e095f0

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

kernel/bpf/verifier.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3195,10 +3195,27 @@ static int mark_reg_read(struct bpf_verifier_env *env,
31953195
return 0;
31963196
}
31973197

3198-
static int mark_dynptr_read(struct bpf_verifier_env *env, struct bpf_reg_state *reg)
3198+
static int mark_stack_slot_obj_read(struct bpf_verifier_env *env, struct bpf_reg_state *reg,
3199+
int spi, int nr_slots)
31993200
{
32003201
struct bpf_func_state *state = func(env, reg);
3201-
int spi, ret;
3202+
int err, i;
3203+
3204+
for (i = 0; i < nr_slots; i++) {
3205+
struct bpf_reg_state *st = &state->stack[spi - i].spilled_ptr;
3206+
3207+
err = mark_reg_read(env, st, st->parent, REG_LIVE_READ64);
3208+
if (err)
3209+
return err;
3210+
3211+
mark_stack_slot_scratched(env, spi - i);
3212+
}
3213+
return 0;
3214+
}
3215+
3216+
static int mark_dynptr_read(struct bpf_verifier_env *env, struct bpf_reg_state *reg)
3217+
{
3218+
int spi;
32023219

32033220
/* For CONST_PTR_TO_DYNPTR, it must have already been done by
32043221
* check_reg_arg in check_helper_call and mark_btf_func_reg_size in
@@ -3213,31 +3230,13 @@ static int mark_dynptr_read(struct bpf_verifier_env *env, struct bpf_reg_state *
32133230
* bounds and spi is the first dynptr slot. Simply mark stack slot as
32143231
* read.
32153232
*/
3216-
ret = mark_reg_read(env, &state->stack[spi].spilled_ptr,
3217-
state->stack[spi].spilled_ptr.parent, REG_LIVE_READ64);
3218-
if (ret)
3219-
return ret;
3220-
return mark_reg_read(env, &state->stack[spi - 1].spilled_ptr,
3221-
state->stack[spi - 1].spilled_ptr.parent, REG_LIVE_READ64);
3233+
return mark_stack_slot_obj_read(env, reg, spi, BPF_DYNPTR_NR_SLOTS);
32223234
}
32233235

32243236
static int mark_iter_read(struct bpf_verifier_env *env, struct bpf_reg_state *reg,
32253237
int spi, int nr_slots)
32263238
{
3227-
struct bpf_func_state *state = func(env, reg);
3228-
int err, i;
3229-
3230-
for (i = 0; i < nr_slots; i++) {
3231-
struct bpf_reg_state *st = &state->stack[spi - i].spilled_ptr;
3232-
3233-
err = mark_reg_read(env, st, st->parent, REG_LIVE_READ64);
3234-
if (err)
3235-
return err;
3236-
3237-
mark_stack_slot_scratched(env, spi - i);
3238-
}
3239-
3240-
return 0;
3239+
return mark_stack_slot_obj_read(env, reg, spi, nr_slots);
32413240
}
32423241

32433242
/* This function is supposed to be used by the following 32-bit optimization

0 commit comments

Comments
 (0)