bpf: mostly decouple jump history management from is_state_visited()
authorAndrii Nakryiko <andrii@kernel.org>
Tue, 6 Dec 2022 23:33:44 +0000 (15:33 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 7 Dec 2022 03:14:38 +0000 (19:14 -0800)
commita095f421057e22853022cb644b1589d0dd0e756e
treec33f61ef1b9eb4bb28e81e0c4abca9ae4b6ad831
parentbffdeaa8a5af7200b0e74c9d5a41167f86626a36
bpf: mostly decouple jump history management from is_state_visited()

Jump history updating and state equivalence checks are conceptually
independent, so move push_jmp_history() out of is_state_visited(). Also
make a decision whether to perform state equivalence checks or not one
layer higher in do_check(), keeping is_state_visited() unconditionally
performing state checks.

push_jmp_history() should be performed after state checks. There is just
one small non-uniformity. When is_state_visited() finds already
validated equivalent state, it propagates precision marks to current
state's parent chain. For this to work correctly, jump history has to be
updated, so is_state_visited() is doing that internally.

But if no equivalent verified state is found, jump history has to be
updated in a newly cloned child state, so is_jmp_point()
+ push_jmp_history() is performed after is_state_visited() exited with
zero result, which means "proceed with validation".

This change has no functional changes. It's not strictly necessary, but
feels right to decouple these two processes.

Acked-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20221206233345.438540-3-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c