Re: [PATCH bpf-next v5 04/13] bpf: net_sched: Add basic bpf qdisc kfuncs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Mar 14, 2025 at 1:14 PM Alexei Starovoitov
<alexei.starovoitov@xxxxxxxxx> wrote:
>
> On Thu, Mar 13, 2025 at 12:03 PM Amery Hung <ameryhung@xxxxxxxxx> wrote:
> >
> > From: Amery Hung <amery.hung@xxxxxxxxxxxxx>
> >
> > Add basic kfuncs for working on skb in qdisc.
> >
> > Both bpf_qdisc_skb_drop() and bpf_kfree_skb() can be used to release
> > a reference to an skb. However, bpf_qdisc_skb_drop() can only be called
> > in .enqueue where a to_free skb list is available from kernel to defer
> > the release. bpf_kfree_skb() should be used elsewhere. It is also used
> > in bpf_obj_free_fields() when cleaning up skb in maps and collections.
> >
> > bpf_skb_get_hash() returns the flow hash of an skb, which can be used
> > to build flow-based queueing algorithms.
> >
> > Finally, allow users to create read-only dynptr via bpf_dynptr_from_skb().
> >
> > Signed-off-by: Amery Hung <amery.hung@xxxxxxxxxxxxx>
> > ---
> >  include/linux/bpf.h         |  1 +
> >  kernel/bpf/bpf_struct_ops.c |  2 +
> >  net/sched/bpf_qdisc.c       | 93 ++++++++++++++++++++++++++++++++++++-
> >  3 files changed, 95 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> > index 463e922cb0f5..d3b0c4ccaebf 100644
> > --- a/include/linux/bpf.h
> > +++ b/include/linux/bpf.h
> > @@ -1826,6 +1826,7 @@ struct bpf_struct_ops {
> >         void *cfi_stubs;
> >         struct module *owner;
> >         const char *name;
> > +       const struct btf_type *type;
> >         struct btf_func_model func_models[BPF_STRUCT_OPS_MAX_NR_MEMBERS];
> >  };
>
> there is an alternative to this...
>
> > +static int bpf_qdisc_kfunc_filter(const struct bpf_prog *prog, u32 kfunc_id)
> > +{
> > +       if (bpf_Qdisc_ops.type != btf_type_by_id(prog->aux->attach_btf,
> > +                                                prog->aux->attach_btf_id))
> > +               return 0;
> > +
> > +       /* Skip the check when prog->attach_func_name is not yet available
> > +        * during check_cfg().
> > +        */
> > +       if (!btf_id_set8_contains(&qdisc_kfunc_ids, kfunc_id) ||
> > +           !prog->aux->attach_func_name)
> > +               return 0;
> > +
> > +       if (bpf_struct_ops_prog_moff(prog) == offsetof(struct Qdisc_ops, enqueue)) {
> > +               if (btf_id_set_contains(&qdisc_enqueue_kfunc_set, kfunc_id))
> > +                       return 0;
> > +       }
>
> Instead of logic in this patch and patch 2,
> I think it's cleaner to do:
> https://lore.kernel.org/all/AM6PR03MB50804BE76B752350307B6B4C99C22@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
>
> then in this patch it will be
>
> if (prog->aux->st_ops != &bpf_Qdisc_ops)
>
> and instead of unchecked array accesses in bpf_struct_ops_prog_moff()
> it will be prog->aux->attach_st_ops_member_off
>
> Also see flag based approach in Juntong's patch 3+4.
> imo it looks cleaner (more extensible with more checks per st_ops hook)
> than offsetof() approach above.

Thanks for the pointer! I will drop patch 2 and adopt the flag-based
kfunc filter.





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux