On Tue, Jul 11, 2023 at 11:00 AM Dave Marchevsky <davemarchevsky@xxxxxx> wrote: > > Structs bpf_rb_node and bpf_list_node are opaquely defined in > uapi/linux/bpf.h, as BPF program writers are not expected to touch their > fields - nor does the verifier allow them to do so. > > Currently these structs are simple wrappers around structs rb_node and > list_head and linked_list / rbtree implementation just casts and passes > to library functions for those data structures. Later patches in this > series, though, will add an "owner" field to bpf_{rb,list}_node, such > that they're not just wrapping an underlying node type. Moreover, the > bpf linked_list and rbtree implementations will deal with these owner > pointers directly in a few different places. > > To avoid having to do > > void *owner = (void*)bpf_list_node + sizeof(struct list_head) > > with opaque UAPI node types, add bpf_{list,rb}_node_internal struct > definitions to internal headers and modify linked_list and rbtree to use > the internal types where appropriate. > > Signed-off-by: Dave Marchevsky <davemarchevsky@xxxxxx> > --- > include/linux/bpf.h | 10 ++++++++++ > kernel/bpf/helpers.c | 23 +++++++++++++---------- > 2 files changed, 23 insertions(+), 10 deletions(-) > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > index 360433f14496..d5841059fd2f 100644 > --- a/include/linux/bpf.h > +++ b/include/linux/bpf.h > @@ -228,6 +228,16 @@ struct btf_record { > struct btf_field fields[]; > }; > > +/* Non-opaque version of bpf_rb_node in uapi/linux/bpf.h */ > +struct bpf_rb_node_internal { > + struct rb_node rb_node; > +} __attribute__((aligned(8))); > + > +/* Non-opaque version of bpf_list_node in uapi/linux/bpf.h */ > +struct bpf_list_node_internal { > + struct list_head list_head; > +} __attribute__((aligned(8))); We typically use _kern suffix for data structs that mirror bpf.h structs. Let's use it here as well instead of _internal.