BPF List
 help / color / mirror / Atom feed
From: Hou Tao <houtao@huaweicloud.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Hao Luo <haoluo@google.com>,
	Yonghong Song <yonghong.song@linux.dev>,
	Daniel Borkmann <daniel@iogearbox.net>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Jiri Olsa <jolsa@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	Hou Tao <houtao1@huawei.com>, Xu Kuohai <xukuohai@huawei.com>
Subject: Re: [PATCH bpf-next 03/16] bpf: Parse bpf_dynptr in map key
Date: Mon, 21 Oct 2024 22:02:41 +0800	[thread overview]
Message-ID: <b2ceb4b4-e9bf-dc07-86ac-c7c3edbd4d04@huaweicloud.com> (raw)
In-Reply-To: <CAADnVQKmkaYJixBrJpWPDpHM9R9jq91meY9bERCVaC11CN4G_w@mail.gmail.com>

Hi,

On 10/12/2024 12:29 AM, Alexei Starovoitov wrote:
> On Tue, Oct 8, 2024 at 2:02 AM Hou Tao <houtao@huaweicloud.com> wrote:
>> +#define MAX_DYNPTR_CNT_IN_MAP_KEY 4
>> +
>>  static int map_check_btf(struct bpf_map *map, struct bpf_token *token,
>>                          const struct btf *btf, u32 btf_key_id, u32 btf_value_id)
>>  {
>> @@ -1103,6 +1113,40 @@ static int map_check_btf(struct bpf_map *map, struct bpf_token *token,
>>         if (!value_type || value_size != map->value_size)
>>                 return -EINVAL;
>>
>> +       if (btf_type_is_dynptr(btf, key_type))
>> +               map->key_record = btf_new_bpf_dynptr_record();
>> +       else
>> +               map->key_record = btf_parse_fields(btf, key_type, BPF_DYNPTR, map->key_size);
>> +       if (!IS_ERR_OR_NULL(map->key_record)) {
>> +               if (map->key_record->cnt > MAX_DYNPTR_CNT_IN_MAP_KEY) {
>> +                       ret = -E2BIG;
>> +                       goto free_map_tab;
> Took me a while to grasp that map->key_record is only for dynptr fields
> and map->record is for the rest except dynptr fields.
>
> Maybe rename key_record to dynptr_fields ?
> Or at least add a comment to struct bpf_map to explain
> what each btf_record is for.

I was trying to rename map->record to map->value_record, however, I was
afraid that it may introduce too much churn, so I didn't do that. But I
think it is a good idea to add comments for both btf_record. And
considering that only bpf_dynptr is enabled for map key, renaming it to
dynptr_fields seems reasonable as well.
>
> It's kinda arbitrary decision to support multiple dynptr-s per key
> while other fields are not.
> Maybe worth looking at generalizing it a bit so single btf_record
> can have multiple of certain field kinds?
> In addition to btf_record->cnt you'd need btf_record->dynptr_cnt
> but that would be easier to extend in the future ?

Map value has already supported multiple kptrs or bpf_list_node. And in
the discussion [1], I thought multiple dynptr support in map key is
necessary, so I enabled it.

[1]:
https://lore.kernel.org/bpf/CAADnVQJWaBRB=P-ZNkppwm=0tZaT3qP8PKLLJ2S5SSA2-S8mxg@mail.gmail.com/


  reply	other threads:[~2024-10-21 14:02 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-08  9:14 [PATCH bpf-next 00/16] Support dynptr key for hash map Hou Tao
2024-10-08  9:14 ` [PATCH bpf-next 01/16] bpf: Introduce map flag BPF_F_DYNPTR_IN_KEY Hou Tao
2024-10-10  2:21   ` Alexei Starovoitov
2024-10-21 13:45     ` Hou Tao
2024-10-22  3:53       ` Alexei Starovoitov
2024-10-22  4:22         ` Hou Tao
2024-10-08  9:14 ` [PATCH bpf-next 02/16] bpf: Add two helpers to facilitate the btf parsing of bpf_dynptr Hou Tao
2024-10-08  9:14 ` [PATCH bpf-next 03/16] bpf: Parse bpf_dynptr in map key Hou Tao
2024-10-10 18:02   ` Eduard Zingerman
2024-10-21 13:48     ` Hou Tao
2024-10-11 16:29   ` Alexei Starovoitov
2024-10-21 14:02     ` Hou Tao [this message]
2024-10-22  3:59       ` Alexei Starovoitov
2024-10-22  7:20         ` Hou Tao
2024-10-22 18:44           ` Alexei Starovoitov
2024-10-08  9:14 ` [PATCH bpf-next 04/16] bpf: Pass flags instead of bool to check_helper_mem_access() Hou Tao
2024-10-08  9:14 ` [PATCH bpf-next 05/16] bpf: Support map key with dynptr in verifier Hou Tao
2024-10-10 20:30   ` Eduard Zingerman
2024-10-10 20:57     ` Eduard Zingerman
2024-10-21 13:50       ` Hou Tao
2024-10-13 13:07   ` Dan Carpenter
2024-10-31  2:39     ` Hou Tao
2024-10-08  9:14 ` [PATCH bpf-next 06/16] bpf: Introduce bpf_dynptr_user Hou Tao
2024-10-10 21:50   ` Andrii Nakryiko
2024-10-10 22:12     ` Alexei Starovoitov
2024-10-21 13:51     ` Hou Tao
2024-10-08  9:14 ` [PATCH bpf-next 07/16] libbpf: Add helpers for bpf_dynptr_user Hou Tao
2024-10-10 21:50   ` Andrii Nakryiko
2024-10-21 13:51     ` Hou Tao
2024-10-08  9:14 ` [PATCH bpf-next 08/16] bpf: Handle bpf_dynptr_user in bpf syscall when it is used as input Hou Tao
2024-10-13 13:08   ` Dan Carpenter
2024-10-31  2:44     ` Hou Tao
2024-10-08  9:14 ` [PATCH bpf-next 09/16] bpf: Handle bpf_dynptr_user in bpf syscall when it is used as output Hou Tao
2024-10-08  9:14 ` [PATCH bpf-next 10/16] bpf: Disable unsupported functionalities for map with dynptr key Hou Tao
2024-10-08  9:14 ` [PATCH bpf-next 11/16] bpf: Add bpf_mem_alloc_check_size() helper Hou Tao
2024-10-08  9:14 ` [PATCH bpf-next 12/16] bpf: Support basic operations for dynptr key in hash map Hou Tao
2024-10-11 16:47   ` Alexei Starovoitov
2024-10-30 10:02     ` Hou Tao
2024-11-02 18:31       ` Alexei Starovoitov
2024-10-08  9:14 ` [PATCH bpf-next 13/16] bpf: Export bpf_dynptr_set_size Hou Tao
2024-10-08  9:14 ` [PATCH bpf-next 14/16] bpf: Support get_next_key operation for dynptr key in hash map Hou Tao
2024-10-08  9:15 ` [PATCH bpf-next 15/16] bpf: Enable BPF_F_DYNPTR_IN_KEY for " Hou Tao
2024-10-08  9:15 ` [PATCH bpf-next 16/16] selftests/bpf: Add test cases for hash map with dynptr key Hou Tao
2024-10-11 18:23   ` Alexei Starovoitov
2024-10-21 14:05     ` Hou Tao
2024-10-11 22:11 ` [PATCH bpf-next 00/16] Support dynptr key for hash map Eduard Zingerman
2024-10-21 14:09   ` Hou Tao

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=b2ceb4b4-e9bf-dc07-86ac-c7c3edbd4d04@huaweicloud.com \
    --to=houtao@huaweicloud.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=houtao1@huawei.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=xukuohai@huawei.com \
    --cc=yonghong.song@linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox