On Tue, Jan 17, 2023 at 11:06 AM Martin KaFai Lau <martin.lau@xxxxxxxxx> wrote: > > On 1/13/23 5:05 PM, Daniel Rosenberg wrote: > > I think the first question is related to the refcnt of the struct_ops. Whenever > a new tcp connection is established, it also needs to bump the refcnt of a (bpf) > tcp_congestion_ops. The tcp subsystem currently does a bpf_try_module_get() > which then calls bpf_struct_ops_get() if 'owner == BPF_MODULE_OWNER'. > bpf_struct_ops_get() will inc the refcnt of the struct_ops. > Thanks! I hadn't noticed the 'owner == BPF_MODULE_OWNER' case. That fits what I need exactly. The only issue there is that those functions aren't exported for module use, which is easy enough to change. > > I think the next set of question is about when FUSE itself is built as a module. > The first is how to register 'struct bpf_struct_ops bpf_fuse_struct_ops'. You > are correct that right now it is done during compile time in > bpf_struct_ops_types.h. To make FUSE itself built as a module and > bpf_fuse_struct_ops defined in the FUSE module, some work is needed in > bpf_struct_ops.c to allow registering struct_ops in runtime during module_init. > For module reference counting, I think the bpf_fuse_struct_ops should be able to > hold one refcnt of the fuse module. Not sure how bpf_fuse_struct_ops looks like > and I also don't know how grabbing the map fd will help. It seems you already > have something working, so it may be easier to discuss base on that. For the moment, I'm just building the verification side into the kernel and exporting a function to register the reg/unreg functions. Adjusting bpf_struct_ops.c for registering struct_ops at runtime is probably a better path. I'll look into that after I've got more working under the new system. I still need to figure out how to get dynptrs working with struct_ops, which I think is going to involve a new dynptr type... Something like DYNPTR_TYPE_KERN, where the memory is managed by the kernel, and only fully initialized dynptrs are passed in. It's possible that BPF_DYNPTR_TYPE_RINGBUF might mostly cover that already, but I imagine there's some ringbuf specific things to it... At the moment, I've just got a toy setup for bpf_fuse_struct_ops to figure out the verification I need, so there's not all that much to see there yet.