On Thu, 2 Feb 2017 20:27:15 -0800
Alexei Starovoitov <[email protected]> wrote:

> On Thu, Feb 02, 2017 at 06:00:09PM +0100, Jesper Dangaard Brouer wrote:
> > 
> > [PATCH] doc: how interacting with eBPF maps works
> > 
> > Documented by reading the code.  
> 
> looks great!
> please submit the patch to net-next and cc Jonathan ?

Good idea, but I'll take this round of review first, before pushing it
to the kernel tree. 

I also want a build-env section.

Also considering splitting the "Types of maps"[1] section into a
separate file, as this avoids a too long HTML page being generated.

[1] 
http://prototype-kernel.readthedocs.io/en/latest/bpf/ebpf_maps.html#types-of-maps

> Comments below:
> 
> > I hope someone more knowledgeable will review this and
> > correct me where I misunderstood things.
> > 
> > Signed-off-by: Jesper Dangaard Brouer <[email protected]>
> > ---
> >  kernel/Documentation/bpf/ebpf_maps.rst |  126 
> > ++++++++++++++++++++++++++++++--
> >  1 file changed, 120 insertions(+), 6 deletions(-)
> > 
> > diff --git a/kernel/Documentation/bpf/ebpf_maps.rst 
> > b/kernel/Documentation/bpf/ebpf_maps.rst
> > index 562edd566e0b..55068c7f3dab 100644
> > --- a/kernel/Documentation/bpf/ebpf_maps.rst
> > +++ b/kernel/Documentation/bpf/ebpf_maps.rst
> > @@ -23,13 +23,128 @@ and accessed by multiple programs (from man-page 
> > `bpf(2)`_):
> >   up to the user process and eBPF program to decide what they store
> >   inside maps.
> >  
> > +Creating a map
> > +==============
> > +
> > +A maps is created based on a request from userspace, via the `bpf`_
> > +syscall (`bpf_cmd`_ BPF_MAP_CREATE), and returns a new file descriptor
> > +that refers to the map. These are the setup arguments when creating a
> > +map.
> > +
> > +.. code-block:: c
> > +
> > +  struct { /* anonymous struct used by BPF_MAP_CREATE command */
> > +         __u32   map_type;       /* one of enum bpf_map_type */
> > +         __u32   key_size;       /* size of key in bytes */
> > +         __u32   value_size;     /* size of value in bytes */
> > +         __u32   max_entries;    /* max number of entries in a map */
> > +         __u32   map_flags;      /* prealloc or not */
> > +  };
> > +
> > +For programs under samples/bpf/ the ``load_bpf_file()`` call (from
> > +`samples/bpf/bpf_load`_) takes care of parsing elf file compiled by
                                                    ^^^      

> > +LLVM, pickup 'maps' section and creates maps via BPF syscall.  This is
                  ^^^^^^^^^^^^^^             ^^^^^^^^^^^^^^^^^^^^^

> > +done by defining a ``struct bpf_map_def`` with an elf section
> > +__attribute__ ``SEC("maps")``, in the xxx_kern.c file.  The maps file
> > +descriptor is available in the userspace xxx_user.c file, via global
> > +array variable ``map_fd[]``, and the array map index correspons to the
> > +order the maps sections were defined in elf file of xxx_kern.c file.
> > +
> > +.. code-block:: c
> > +
> > +  struct bpf_map_def {
> > +   unsigned int type;
> > +   unsigned int key_size;
> > +   unsigned int value_size;
> > +   unsigned int max_entries;
> > +   unsigned int map_flags;
> > +  };  
> 
> As Daniel said please mention that this is C program <-> elf loader
> convention. It's not a kernel abi.

I feel I did mention the ELF part above, but I guess should try to make
it more clear, as you missed this.


> perf map defitions are different from tc and from samples/bpf/

I didn't know about TC maps.  Can you or Daniel please point me to some
TC-eBFP-code that setup a map?  So, I can wrap my head around how it
does it... I think it would be valuable to have a section here
describing how TC manage maps.

See what I figured out myself in this commit:
 https://github.com/netoptimizer/prototype-kernel/commit/3640a48df52c

And the new TC section:
 
http://prototype-kernel.readthedocs.io/en/latest/bpf/ebpf_maps.html#qdisc-traffic-control-convention

> iovisor/bcc is not using elf at all.

True (I do know that bcc doesn't use elf).
 
> > +
> > +  struct bpf_map_def SEC("maps") my_map = {
> > +   .type        = BPF_MAP_TYPE_XXX,
> > +   .key_size    = sizeof(u32),
> > +   .value_size  = sizeof(u64),
> > +   .max_entries = 42,
> > +   .map_flags   = 0
> > +  };
> > +
> > +.. _samples/bpf/bpf_load:
> > +   
> > https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/samples/bpf/bpf_load.c
> > +
> > +
> > +Interacting with maps
> > +=====================

I'll use another email and commit change to address this "Interacting
with maps" section...


-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer
_______________________________________________
iovisor-dev mailing list
[email protected]
https://lists.iovisor.org/mailman/listinfo/iovisor-dev

Reply via email to