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

Dmitry V. Levin ldv at altlinux.org
Sat Apr 4 17:30:34 UTC 2020


On Sat, Apr 04, 2020 at 07:03:17PM +0200, 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_UPDATE_BATCH),
> BEGIN_BPF_CMD_DECODER(BPF_MAP_DELETE_BATCH)): Decode the new commands.
> (decode_BPF_MAP_LOOKUP_AND_DELETE_BATCH): New macro.
> (SYS_FUNC(bpf)): 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.
> (BPF_MAP_LOOKUP_BATCH_struct_size,
> BPF_MAP_LOOKUP_AND_DELETE_BATCH_struct_size,
> BPF_MAP_UPDATE_BATCH_struct_size, BPF_MAP_DELETE_BATCH_struct_size): New
> macros.
> * NEWS: Mention this.
> * tests/bpf.c (BPF_MAP_LOOKUP_BATCH_checks, BPF_MAP_UPDATE_BATCH_checks,
> BPF_MAP_DELETE_BATCH_checks): Tests for the new commands.
> 
> Signed-off-by: Paul Chaignon <paul.chaignon at gmail.com>
> ---
> Changelogs:
>   Changes in v4:
>   - Fix printing of extra data and closing brackets.
>   - Print name of "batch" structure.
>   Changes in v3:
>   - Add tests for BPF_MAP_UPDATE_BATCH and BPF_MAP_DELETE_BATCH.
>   - Do not print unused fields in_batch and out_batch.
>   - Print count on entering and exiting.
>   - Fix printing of flags.
>   Changes in v2:
>   - Add ATTRIBUTE_ALIGNED(8) to uint64_t attributes.
>   - Rebase on master.
> 
>  NEWS                 |  3 ++
>  bpf.c                | 88 ++++++++++++++++++++++++++++++++++++++++++++
>  bpf_attr.h           | 24 ++++++++++++
>  tests/bpf.c          | 75 +++++++++++++++++++++++++++++++++++++
>  xlat/bpf_commands.in |  4 ++
>  5 files changed, 194 insertions(+)
> 
> diff --git a/NEWS b/NEWS
> index 6e6dda34..b667bd04 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -30,6 +30,9 @@ Noteworthy changes in release ?.? (????-??-??)
>    * Implemented decoding of openat2 and pidfd_getfd syscalls.
>    * Enhanced io_uring_register, prctl, sched_getattr, and sched_setattr syscall
>      decoding.
> +  * 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.
>    * Enhanced decoding of RTC_VL_READ ioctl command.
> diff --git a/bpf.c b/bpf.c
> index d666a423..97d102c6 100644
> --- a/bpf.c
> +++ b/bpf.c
> @@ -954,6 +954,90 @@ BEGIN_BPF_CMD_DECODER(BPF_TASK_FD_QUERY)
>  }
>  END_BPF_CMD_DECODER(RVAL_DECODED)
>  
> +BEGIN_BPF_CMD_DECODER(BPF_MAP_LOOKUP_BATCH)
> +{
> +	unsigned long count;
> +
> +	if (entering(tcp)) {
> +		set_tcb_priv_ulong(tcp, attr.count);
> +
> +		PRINT_FIELD_ADDR64("{batch={", attr, in_batch);
> +		PRINT_FIELD_ADDR64(", ", attr, out_batch);
> +		PRINT_FIELD_ADDR64(", ", attr, keys);
> +		PRINT_FIELD_ADDR64(", ", attr, values);
> +		PRINT_FIELD_U(", ", attr, count);
> +		PRINT_FIELD_FD(", ", attr, map_fd, tcp);
> +		PRINT_FIELD_FLAGS(", ", attr, elem_flags,
> +				  bpf_map_lookup_elem_flags, "BPF_???");
> +		PRINT_FIELD_X(", ", attr, flags);
> +
> +		tprintf("}");
> +	} else {
> +		count = get_tcb_priv_ulong(tcp);
> +		if (count != attr.count) {
> +			PRINT_FIELD_U("=> {", attr, count);
> +			tprintf("}");
> +		}
> +		return RVAL_DECODED;
> +	}
> +}
> +END_BPF_CMD_DECODER(0)

Shouldn't the name "batch" be printed on exiting as well?


-- 
ldv


More information about the Strace-devel mailing list