RE: [PATCH bpf-next] bpf: add bpf_xdp_output() helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Eelco Chaudron wrote:
> Introduce new helper that reuses existing xdp perf_event output
> implementation, but can be called from raw_tracepoint programs
> that receive 'struct xdp_buff *' as a tracepoint argument.
> 
> Signed-off-by: Eelco Chaudron <echaudro@xxxxxxxxxx>
> ---
>  include/uapi/linux/bpf.h                           |   27 ++++++++++
>  kernel/bpf/verifier.c                              |    4 +-
>  kernel/trace/bpf_trace.c                           |    3 +
>  net/core/filter.c                                  |   16 ++++++
>  tools/include/uapi/linux/bpf.h                     |   27 ++++++++++
>  .../testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c |   53 ++++++++++++++++++++
>  .../testing/selftests/bpf/progs/test_xdp_bpf2bpf.c |   24 +++++++++
>  7 files changed, 150 insertions(+), 4 deletions(-)
> 
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index 40b2d9476268..41a90e2d5821 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -2914,6 +2914,30 @@ union bpf_attr {
>   *		of sizeof(struct perf_branch_entry).
>   *
>   *		**-ENOENT** if architecture does not support branch records.
> + *
> + * int bpf_xdp_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
> + *	Description

feels a bit odd to have flags in the middle of a signature but it follows
bpf_perf_event_output() so I guess its better to have the two use the
same signature vs break it here.

> + *		Write raw *data* blob into a special BPF perf event held by
> + *		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
> + *		event must have the following attributes: **PERF_SAMPLE_RAW**
> + *		as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
> + *		**PERF_COUNT_SW_BPF_OUTPUT** as **config**.
> + *
> + *		The *flags* are used to indicate the index in *map* for which
> + *		the value must be put, masked with **BPF_F_INDEX_MASK**.
> + *		Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
> + *		to indicate that the index of the current CPU core should be
> + *		used.
> + *
> + *		The value to write, of *size*, is passed through eBPF stack and
> + *		pointed by *data*.
> + *
> + *		*ctx* is a pointer to in-kernel struct xdp_buff.
> + *
> + *		This helper is similar to **bpf_perf_eventoutput**\ () but
> + *		restricted to raw_tracepoint bpf programs.
> + *	Return
> + *		0 on success, or a negative error in case of failure.
>   */

Otherwise,

Acked-by: John Fastabend <john.fastabend@xxxxxxxxx>



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux