bpf: Move prog->aux->linked_prog and trampoline into bpf_link on attach
authorToke Høiland-Jørgensen <toke@redhat.com>
Tue, 29 Sep 2020 12:45:50 +0000 (14:45 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 29 Sep 2020 20:09:23 +0000 (13:09 -0700)
commit3aac1ead5eb6b76f3d2b8d111e6de1c2de23fb34
treefb66fb0f2de431275e8c5a09d896a97f9641dacb
parent85e3f318506ece12714535821d0b3186f7121b5b
bpf: Move prog->aux->linked_prog and trampoline into bpf_link on attach

In preparation for allowing multiple attachments of freplace programs, move
the references to the target program and trampoline into the
bpf_tracing_link structure when that is created. To do this atomically,
introduce a new mutex in prog->aux to protect writing to the two pointers
to target prog and trampoline, and rename the members to make it clear that
they are related.

With this change, it is no longer possible to attach the same tracing
program multiple times (detaching in-between), since the reference from the
tracing program to the target disappears on the first attach. However,
since the next patch will let the caller supply an attach target, that will
also make it possible to attach to the same place multiple times.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/160138355059.48470.2503076992210324984.stgit@toke.dk
include/linux/bpf.h
kernel/bpf/btf.c
kernel/bpf/core.c
kernel/bpf/preload/iterators/iterators.bpf.c
kernel/bpf/preload/iterators/iterators.skel.h
kernel/bpf/syscall.c
kernel/bpf/trampoline.c
kernel/bpf/verifier.c