All of lore.kernel.org
 help / color / mirror / Atom feed
From: Donald Hunter <donald.hunter@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH bpf-next v1] bpf, docs: document BPF_MAP_TYPE_ARRAY_OF_MAPS and *_HASH_OF_MAPS
Date: Mon, 07 Nov 2022 11:41:49 +0000	[thread overview]
Message-ID: <m2r0yfrnya.fsf@gmail.com> (raw)
In-Reply-To: <CAEf4BzYiSyps09esMH407WnzPvND+c56EQHeooLUF9RKcs-Y3Q@mail.gmail.com> (Andrii Nakryiko's message of "Fri, 4 Nov 2022 14:26:33 -0700")

Andrii Nakryiko <andrii.nakryiko@gmail.com> writes:

> On Mon, Oct 10, 2022 at 4:32 AM Donald Hunter <donald.hunter@gmail.com> wrote:
>>
>> Add documentation for the ARRAY_OF_MAPS and HASH_OF_MAPS map types,
>> including usage and examples.
>>
>> Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
>> ---
>
> subject suggestion (as it's pretty long):
>
> bpf, docs: document BPF_MAP_TYPE_{ARRAY,HASH}_OF_MAPS

Thanks for the tip. Hopefully already resolved well enough in v2+.

>> +Examples
>> +========
>> +
>> +Kernel BPF
>> +----------
>> +
>> +This snippet shows how to create an array of devmaps in a BPF program. Note that
>> +the outer array can only be modified from user space using the syscall API.
>> +
>> +.. code-block:: c
>> +
>> +    struct redirect_map {
>> +            __uint(type, BPF_MAP_TYPE_DEVMAP);
>> +            __uint(max_entries, 32);
>> +            __type(key, enum skb_drop_reason);
>> +            __type(value, __u64);
>> +    } redirect_map SEC(".maps");
>> +
>> +    struct {
>> +            __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
>> +            __uint(max_entries, 2);
>> +            __uint(key_size, sizeof(int));
>> +            __uint(value_size, sizeof(int));
>> +            __array(values, struct redirect_map);
>> +    } outer_map SEC(".maps");
>> +
>
> Let's also demonstrate libbpf's declarative way to initialize entries
> in outer map? See progs/test_btf_map_in_map.c under selftests/bpf for
> various examples.

Will do, thanks!

>> +This snippet shows how to lookup an outer map to retrieve an inner map.
>> +
>> +.. code-block:: c
>> +
>> +    SEC("xdp")
>> +    int redirect_by_priority(struct xdp_md *ctx) {
>> +            struct bpf_map *devmap;
>> +            int action = XDP_PASS;
>> +            int index = 0;
>> +
>> +            devmap = bpf_map_lookup_elem(&outer_arr, &index);
>> +            if (!devmap)
>> +                    return XDP_PASS;
>> +
>> +            /* use inner devmap here */
>> +
>> +            return action;
>> +    }
>> +
>> +User Space
>> +----------
>> +
>> +This snippet shows how to create an array based outer map:
>> +
>> +.. code-block:: c
>> +
>> +    int create_outer_array(int inner_fd) {
>> +            int fd;
>> +            LIBBPF_OPTS(bpf_map_create_opts, opts);
>> +            opts.inner_map_fd = inner_fd;
>
> LIBBPF_OPTS(bpf_map_create_opts, opts, .inner_map_fd = inner_fd);

+1, thanks.

      reply	other threads:[~2022-11-07 12:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-10 11:21 [PATCH bpf-next v1] bpf, docs: document BPF_MAP_TYPE_ARRAY_OF_MAPS and *_HASH_OF_MAPS Donald Hunter
2022-11-01 11:00 ` Maryam Tahhan
2022-11-04 21:26 ` Andrii Nakryiko
2022-11-07 11:41   ` Donald Hunter [this message]

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=m2r0yfrnya.fsf@gmail.com \
    --to=donald.hunter@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    /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.