[PATCH v2] bpf: support new commands BPF_MAP_*_BATCH

Paul Chaignon paul.chaignon at gmail.com
Mon Mar 23 06:42:56 UTC 2020


On Sun, Mar 08, 2020 at 11:11:55PM +0100, Eugene Syromiatnikov wrote:
> On Sun, Mar 08, 2020 at 06:33:54PM +0100, Paul Chaignon wrote:
> > * xlat/bpf_commands.in (BPF_MAP_LOOKUP_BATCH): New constant introduced
> > by Linux commit v5.6-rc1~151^2~46^2~23^2~7.
> > (BPF_MAP_LOOKUP_AND_DELETE_BATCH): New constant introduced by Linux
> > commit v5.6-rc1~151^2~46^2~23^2~4.
> > (BPF_MAP_UPDATE_BATCH, BPF_MAP_DELETE_BATCH): New constants introduced
> > by Linux commit v5.6-rc1~151^2~46^2~23^2~6.
> > * bpf.c (BEGIN_BPF_CMD_DECODER(BPF_MAP_LOOKUP_BATCH),
> > BEGIN_BPF_CMD_DECODER(BPF_MAP_LOOKUP_AND_DELETE_BATCH),
> > BEGIN_BPF_CMD_DECODER(BPF_MAP_UPDATE_BATCH),
> > BEGIN_BPF_CMD_DECODER(BPF_MAP_DELETE_BATCH)): Decode the new commands.
> > * bpf_attr.h (BPF_MAP_LOOKUP_BATCH_struct,
> > BPF_MAP_LOOKUP_AND_DELETE_BATCH_struct, BPF_MAP_UPDATE_BATCH_struct,
> > BPF_MAP_DELETE_BATCH_struct): New structs introduced by Linux commit
> > v5.6-rc1~151^2~46^2~23^2~7.
> > * NEWS: Mention this.
> > * tests/bpf.c (BPF_MAP_LOOKUP_BATCH_checks): Tests for the new commands.

[...]

> > +	PRINT_FIELD_ADDR64(", ", attr, keys);
> > +	PRINT_FIELD_ADDR64(", ", attr, values);
> 
> > +	PRINT_FIELD_U(", ", attr, count);
> 
> This is in/out field for BPF_MAP_*_BATCH, so it has to be printed
> both on entering and exiting.

What's the best way to handle this?  It looks like for accept(2), you
only print the last two arguments (addr and addrlen) on exiting.  Should
I do the same here?  In that case, should I simply add an exception to
SYS_FUNC(bpf)?

> 
> > +	PRINT_FIELD_U64(", ", attr, flags);
> 
> Why PRINT_FIELD_U64? Is the -1ULL value special here?
> 
> Also, PRINT_FIELD_X makes more sense here.

As far as I can see, the flags field is reserved for now and must
currently be 0.  I've switched this to PRINT_FIELD_X.

> 
> > --- a/tests/bpf.c
> > +++ b/tests/bpf.c
> 
> > +		CHK(BPF_MAP_LOOKUP_BATCH),
> 
> What about the rest of the commands?

I thought they were identical so I only added LOOKUP_BATCH.  I've now
added UPDATE_BATCH and DELETE_BATCH as well.

Paul


More information about the Strace-devel mailing list