On Mon, 15 Aug 2022 at 07:34, Yonghong Song <yhs@xxxxxx> wrote: > > On 8/10/22 2:46 PM, Kumar Kartikeya Dwivedi wrote: > > On Tue, 2 Aug 2022 at 00:23, Alexei Starovoitov <ast@xxxxxx> wrote: > [...] > > > > Just to continue brainstorming: Comments on this? > > > > Instead of a rbtree map, you have a struct bpf_rbtree global variable > > which works like a rbtree. To associate a lock with multiple > > bpf_rbtree, you do clang style thread safety annotation in the bpf > > program: > > > > #define __guarded_by(lock) __attribute__((btf_type_tag("guarded_by:" #lock)) > > > > struct bpf_spin_lock shared_lock; > > struct bpf_rbtree rbtree1 __guarded_by(shared_lock); > > struct bpf_rbtree rbtree2 __guarded_by(shared_lock); > > For the above __guarded_by macro, we should use > btf_decl_tag instead of btf_type_tag > > #define __guarded_by(lock) __attribute__((btf_decl_tag("guarded_by:" #lock)) > > Currently, in llvm implementation, btf_type_tag only applies > to pointee type's. btf_decl_tag can apply to global variable, > function argument, function return value and struct/union members. > So btf_decl_tag shoul work for the above global variable case or > below struct rbtree_set member case. > Yep, I actually wrote a prototype list implementation (it's very close so I can probably post it very soon as an RFC, at this point) which is using declaration tags like this. For now only one bpf_spin_lock is there in a map value or globally, so I didn't add guarded_by, but if you look in [0] it can be used to tag e.g. value_type of a specific bpf_list_head, which node in that value type can be linked, etc. [0]: https://github.com/kkdwivedi/linux/commits/bpf-list