]> www.infradead.org Git - users/jedix/linux-maple.git/commit
bpf: Refactor active lock management
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Sat, 9 Nov 2024 23:14:29 +0000 (15:14 -0800)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 11 Nov 2024 16:18:51 +0000 (08:18 -0800)
commitf6b9a69a9e56b2083aca8a925fc1a28eb698e3ed
tree8b2ca0fbb9af8bf263c9a161715643cf81e4b0b2
parent937a1c29a287e8f48c4cea714c76a13e14d989ac
bpf: Refactor active lock management

When bpf_spin_lock was introduced originally, there was deliberation on
whether to use an array of lock IDs, but since bpf_spin_lock is limited
to holding a single lock at any given time, we've been using a single ID
to identify the held lock.

In preparation for introducing spin locks that can be taken multiple
times, introduce support for acquiring multiple lock IDs. For this
purpose, reuse the acquired_refs array and store both lock and pointer
references. We tag the entry with REF_TYPE_PTR or REF_TYPE_LOCK to
disambiguate and find the relevant entry. The ptr field is used to track
the map_ptr or btf (for bpf_obj_new allocations) to ensure locks can be
matched with protected fields within the same "allocation", i.e.
bpf_obj_new object or map value.

The struct active_lock is changed to an int as the state is part of the
acquired_refs array, and we only need active_lock as a cheap way of
detecting lock presence.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20241109231430.2475236-2-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
include/linux/bpf_verifier.h
kernel/bpf/verifier.c