The previous patch created the inner oracle maps, this patch simply populates them by copying the information on verifier states from aux->oracle_states to the inner array maps. After this, aux->oracle_states isn't required anymore and can be freed. Signed-off-by: Paul Chaignon --- kernel/bpf/oracle.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/kernel/bpf/oracle.c b/kernel/bpf/oracle.c index 66ee840a35eb..404c641cb3f6 100644 --- a/kernel/bpf/oracle.c +++ b/kernel/bpf/oracle.c @@ -109,6 +109,33 @@ static struct bpf_map *create_inner_oracle_map(size_t size) return ERR_PTR(err); } +static int populate_oracle_inner_map(struct list_head *head, struct bpf_map *inner_map) +{ + struct bpf_oracle_state_list *sl; + struct list_head *pos, *tmp; + int i = 0; + + list_for_each_safe(pos, tmp, head) { + sl = container_of(pos, struct bpf_oracle_state_list, node); + inner_map->ops->map_update_elem(inner_map, &i, &sl->state, 0); + i++; + } + + return 0; +} + +static void free_oracle_states(struct list_head *oracle_states) +{ + struct bpf_oracle_state_list *sl; + struct list_head *pos, *tmp; + + list_for_each_safe(pos, tmp, oracle_states) { + sl = container_of(pos, struct bpf_oracle_state_list, node); + kfree(sl); + } + kvfree(oracle_states); +} + struct bpf_prog *patch_oracle_check_insn(struct bpf_verifier_env *env, struct bpf_insn *insn, int i, int *cnt) { @@ -141,6 +168,10 @@ struct bpf_prog *patch_oracle_check_insn(struct bpf_verifier_env *env, struct bp insn_buf[2] = *insn; *cnt = 3; + populate_oracle_inner_map(head, inner_map); + free_oracle_states(aux->oracle_states); + aux->oracle_states = NULL; + new_prog = bpf_patch_insn_data(env, i, insn_buf, *cnt); if (!new_prog) return ERR_PTR(-ENOMEM); -- 2.43.0