From: Martin KaFai Lau <martin.lau@linux.dev>
To: Amery Hung <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
yangpeihao@sjtu.edu.cn, daniel@iogearbox.net, andrii@kernel.org,
alexei.starovoitov@gmail.com, martin.lau@kernel.org,
sinquersw@gmail.com, toke@redhat.com, jhs@mojatatu.com,
jiri@resnulli.us, sdf@google.com, xiyou.wangcong@gmail.com,
yepeilin.cs@gmail.com
Subject: Re: [RFC PATCH v9 05/11] bpf: net_sched: Support implementation of Qdisc_ops in bpf
Date: Thu, 25 Jul 2024 14:24:59 -0700 [thread overview]
Message-ID: <d0ff81d2-3297-4b13-855b-810c11390dc9@linux.dev> (raw)
In-Reply-To: <20240714175130.4051012-6-amery.hung@bytedance.com>
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.
> + 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.
> + }
> + }
> +
> + 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.
> + 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.
> + .name = "Qdisc_ops",
> + .cfi_stubs = &__bpf_ops_qdisc_ops,
> + .owner = THIS_MODULE,
> +};
next prev parent reply other threads:[~2024-07-25 21:25 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-14 17:51 [RFC PATCH v9 00/11] bpf qdisc Amery Hung
2024-07-14 17:51 ` [RFC PATCH v9 01/11] bpf: Support getting referenced kptr from struct_ops argument Amery Hung
2024-07-24 0:32 ` Martin KaFai Lau
2024-07-24 17:00 ` Amery Hung
2024-07-25 1:28 ` Martin KaFai Lau
2024-07-14 17:51 ` [RFC PATCH v9 02/11] selftests/bpf: Test referenced kptr arguments of struct_ops programs Amery Hung
2024-07-14 17:51 ` [RFC PATCH v9 03/11] bpf: Allow struct_ops prog to return referenced kptr Amery Hung
2024-07-24 5:36 ` Kui-Feng Lee
2024-07-24 18:27 ` Kui-Feng Lee
2024-07-24 20:44 ` Amery Hung
2024-07-26 18:22 ` Kui-Feng Lee
2024-07-26 22:45 ` Amery Hung
2024-07-24 23:57 ` Martin KaFai Lau
2024-07-14 17:51 ` [RFC PATCH v9 04/11] selftests/bpf: Test returning referenced kptr from struct_ops programs Amery Hung
2024-07-14 17:51 ` [RFC PATCH v9 05/11] bpf: net_sched: Support implementation of Qdisc_ops in bpf Amery Hung
2024-07-15 5:55 ` kernel test robot
2024-07-18 0:00 ` Amery Hung
2024-07-25 21:24 ` Martin KaFai Lau [this message]
2024-07-31 4:09 ` Amery Hung
2024-07-14 17:51 ` [RFC PATCH v9 06/11] bpf: net_sched: Add bpf qdisc kfuncs Amery Hung
2024-07-25 22:38 ` Martin KaFai Lau
2024-07-31 4:08 ` Amery Hung
2024-07-14 17:51 ` [RFC PATCH v9 07/11] bpf: net_sched: Allow more optional operators in Qdisc_ops Amery Hung
2024-07-18 0:01 ` Amery Hung
2024-07-26 1:15 ` Martin KaFai Lau
2024-07-26 18:30 ` Martin KaFai Lau
2024-07-26 22:30 ` Amery Hung
2024-07-30 0:20 ` Martin KaFai Lau
2024-07-14 17:51 ` [RFC PATCH v9 08/11] libbpf: Support creating and destroying qdisc Amery Hung
2024-07-14 17:51 ` [RFC PATCH v9 09/11] selftests: Add a basic fifo qdisc test Amery Hung
2024-07-14 17:51 ` [RFC PATCH v9 10/11] selftests: Add a bpf fq qdisc to selftest Amery Hung
2024-07-19 1:54 ` Martin KaFai Lau
2024-07-19 18:20 ` Amery Hung
2024-07-14 17:51 ` [RFC PATCH v9 11/11] selftests: Add a bpf netem " Amery Hung
2024-07-17 10:13 ` [RFC PATCH v9 00/11] bpf qdisc Donald Hunter
2024-07-17 22:04 ` Amery Hung
2024-07-19 17:21 ` [OFFLIST RFC 1/4] bpf: Search for kptrs in prog BTF structs Amery Hung
2024-07-19 17:21 ` [OFFLIST RFC 2/4] bpf: Rename ARG_PTR_TO_KPTR -> ARG_KPTR_XCHG_DEST Amery Hung
2024-07-19 17:21 ` [OFFLIST RFC 3/4] bpf: Support bpf_kptr_xchg into local kptr Amery Hung
2024-07-23 0:18 ` Alexei Starovoitov
2024-07-24 0:08 ` Amery Hung
2024-07-19 17:21 ` [OFFLIST RFC 4/4] selftests/bpf: Test bpf_kptr_xchg stashing " Amery Hung
2024-07-23 0:19 ` [RFC PATCH v9 00/11] bpf qdisc Alexei Starovoitov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d0ff81d2-3297-4b13-855b-810c11390dc9@linux.dev \
--to=martin.lau@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=martin.lau@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sdf@google.com \
--cc=sinquersw@gmail.com \
--cc=toke@redhat.com \
--cc=xiyou.wangcong@gmail.com \
--cc=yangpeihao@sjtu.edu.cn \
--cc=yepeilin.cs@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.