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

Eugene Syromiatnikov esyr at redhat.com
Sun Mar 8 22:11:55 UTC 2020


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.
> 
> Signed-off-by: Paul Chaignon <paul.chaignon at gmail.com>
> ---
> Changelogs:
>   Changes in v2:
>   - Add ATTRIBUTE_ALIGNED(8) to uint64_t attributes.
>   - Rebase on master.
> 
>  NEWS                 |  3 +++
>  bpf.c                | 23 +++++++++++++++++++++++
>  bpf_attr.h           | 24 ++++++++++++++++++++++++
>  tests/bpf.c          | 27 +++++++++++++++++++++++++++
>  xlat/bpf_commands.in |  4 ++++
>  5 files changed, 81 insertions(+)
> 
> diff --git a/NEWS b/NEWS
> index 8c2ddfda..bbf03cc6 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -13,6 +13,9 @@ Noteworthy changes in release ?.? (????-??-??)
>     * Ability to set precision for the absolute timestamp, relative timestamp,
>       and syscall time output (using --absolute-timestamps,
>       --relative-timestamps, and --syscall-times options, respectively).
> +  * Implemented decoding of BPF_MAP_LOOKUP_BATCH,
> +    BPF_MAP_LOOKUP_AND_DELETE_BATCH, BPF_MAP_UPDATE_BATCH, and
> +    BPF_MAP_DELETE_BATCH bpf syscall commands.
>    * Enhanced decoding of BPF_MAP_CREATE and BPF_PROG_ATTACH bpf syscall
>      commands.
>    * Updated lists of BPF_* constants.
> diff --git a/bpf.c b/bpf.c
> index c432181c..4ed034e9 100644
> --- a/bpf.c
> +++ b/bpf.c
> @@ -954,6 +954,25 @@ BEGIN_BPF_CMD_DECODER(BPF_TASK_FD_QUERY)

> +	PRINT_FIELD_ADDR64("{", attr, in_batch);
> +	PRINT_FIELD_ADDR64(", ", attr, out_batch);

These fields are ignored in BPF_MAP_UPDATE_BATCH/BPF_MAP_DELETE_BATCH.

> +	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.

> +	PRINT_FIELD_U64(", ", attr, flags);

Why PRINT_FIELD_U64? Is the -1ULL value special here?

Also, PRINT_FIELD_X makes more sense here.

> --- a/tests/bpf.c
> +++ b/tests/bpf.c

> +		CHK(BPF_MAP_LOOKUP_BATCH),

What about the rest of the commands?



More information about the Strace-devel mailing list