[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAMB2axOSLmnrdDDfjzToBd+st2M5Ri8GpUmy-WgmCwG_pCEiRg@mail.gmail.com>
Date: Tue, 30 Jul 2024 21:09:21 -0700
From: Amery Hung <ameryhung@...il.com>
To: Martin KaFai Lau <martin.lau@...ux.dev>
Cc: bpf@...r.kernel.org, netdev@...r.kernel.org, yangpeihao@...u.edu.cn,
daniel@...earbox.net, andrii@...nel.org, alexei.starovoitov@...il.com,
martin.lau@...nel.org, sinquersw@...il.com, toke@...hat.com, jhs@...atatu.com,
jiri@...nulli.us, sdf@...gle.com, xiyou.wangcong@...il.com,
yepeilin.cs@...il.com
Subject: Re: [RFC PATCH v9 05/11] bpf: net_sched: Support implementation of
Qdisc_ops in bpf
On Thu, Jul 25, 2024 at 2:25 PM Martin KaFai Lau <martin.lau@...ux.dev> wrote:
>
> On 7/14/24 10:51 AM, Amery Hung wrote:
> > +static const struct bpf_func_proto *
> > +bpf_qdisc_get_func_proto(enum bpf_func_id func_id,
> > + const struct bpf_prog *prog)
> > +{
> > + switch (func_id) {
>
> Instead of an empty switch, it should be useful to provide the skb->data related
> helper. It can start with read only dynptr first, the BPF_FUNC_dynptr_read
> helper here.
>
> Also, the kfuncs: bpf_dynptr_slice and bpf_dynptr_from_skb_rdonly.
>
I will add the helper and kfuncs and try them out.
> > + default:
> > + return bpf_base_func_proto(func_id, prog);
>
> [ ... ]
>
> > + }
> > +}
> > +
> > +BTF_ID_LIST_SINGLE(bpf_sk_buff_ids, struct, sk_buff)
> > +BTF_ID_LIST_SINGLE(bpf_sk_buff_ptr_ids, struct, bpf_sk_buff_ptr)
> > +
> > +static bool bpf_qdisc_is_valid_access(int off, int size,
> > + enum bpf_access_type type,
> > + const struct bpf_prog *prog,
> > + struct bpf_insn_access_aux *info)
> > +{
> > + struct btf *btf = prog->aux->attach_btf;
> > + u32 arg;
> > +
> > + arg = get_ctx_arg_idx(btf, prog->aux->attach_func_proto, off);
> > + if (!strcmp(prog->aux->attach_func_name, "enqueue")) {
> > + if (arg == 2) {
> > + info->reg_type = PTR_TO_BTF_ID | PTR_TRUSTED;
> > + info->btf = btf;
> > + info->btf_id = bpf_sk_buff_ptr_ids[0];
> > + return true;
>
> This will allow type == BPF_WRITE to ctx which should be rejected. The below
> bpf_tracing_btf_ctx_access() could have rejected it.
>
Right. I will check the access type of the "to_free" argument in .enqueue.
> > + }
> > + }
> > +
> > + return bpf_tracing_btf_ctx_access(off, size, type, prog, info);
> > +}
> > +
>
> [ ... ]
>
> > +
> > +static bool is_unsupported(u32 member_offset)
> > +{
> > + unsigned int i;
> > +
> > + for (i = 0; i < ARRAY_SIZE(unsupported_ops); i++) {
> > + if (member_offset == unsupported_ops[i])
> > + return true;
> > + }
> > +
> > + return false;
> > +}
> > +
> > +static int bpf_qdisc_check_member(const struct btf_type *t,
> > + const struct btf_member *member,
> > + const struct bpf_prog *prog)
> > +{
> > + if (is_unsupported(__btf_member_bit_offset(t, member) / 8))
>
> Note that the ".check_member" and the "is_unsupported" can be removed as you
> also noticed on the recent unsupported ops cleanup patches.
Thanks for looping me in. I removed them when testing the series.
>
> > + return -ENOTSUPP;
> > + return 0;
> > +}
>
> [ ... ]
>
> > +static struct Qdisc_ops __bpf_ops_qdisc_ops = {
> > + .enqueue = Qdisc_ops__enqueue,
> > + .dequeue = Qdisc_ops__dequeue,
> > + .peek = Qdisc_ops__peek,
> > + .init = Qdisc_ops__init,
> > + .reset = Qdisc_ops__reset,
> > + .destroy = Qdisc_ops__destroy,
> > + .change = Qdisc_ops__change,
> > + .attach = Qdisc_ops__attach,
> > + .change_tx_queue_len = Qdisc_ops__change_tx_queue_len,
> > + .change_real_num_tx = Qdisc_ops__change_real_num_tx,
> > + .dump = Qdisc_ops__dump,
> > + .dump_stats = Qdisc_ops__dump_stats,
>
> Similar to the above is_unsupported comment. The unsupported ops should be
> removed from the cfi_stubs.
>
> > + .ingress_block_set = Qdisc_ops__ingress_block_set,
> > + .egress_block_set = Qdisc_ops__egress_block_set,
> > + .ingress_block_get = Qdisc_ops__ingress_block_get,
> > + .egress_block_get = Qdisc_ops__egress_block_get,
> > +};
> > +
> > +static struct bpf_struct_ops bpf_Qdisc_ops = {
> > + .verifier_ops = &bpf_qdisc_verifier_ops,
> > + .reg = bpf_qdisc_reg,
> > + .unreg = bpf_qdisc_unreg,
> > + .check_member = bpf_qdisc_check_member,
> > + .init_member = bpf_qdisc_init_member,
> > + .init = bpf_qdisc_init,
> > + .validate = bpf_qdisc_validate,
>
> ".validate" is optional. The empty "bpf_qdisc_validate" can be removed.
>
Got it.
> > + .name = "Qdisc_ops",
> > + .cfi_stubs = &__bpf_ops_qdisc_ops,
> > + .owner = THIS_MODULE,
> > +};
>
>
Powered by blists - more mailing lists