History

bpf: Add bpf_xdp_output() helper

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.

Eelco Chaudron committed 6 years ago

Commit d831ee81 parent 4823b727 files · +148 −4Browse files

Showing the changes to include/uapi/linux (1 of 7 files). Show all

Unified · Split

include/uapi/linux/bpf.h+25−1
@@ -2927,6 +2927,29 @@ union bpf_attr { · 2926 unmodified lines
29272927 *
29282928 * **-ENOENT** if pidns does not exists for the current task.
29292929 *
2930+ * int bpf_xdp_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
2931+ * Description
2932+ * Write raw *data* blob into a special BPF perf event held by
2933+ * *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
2934+ * event must have the following attributes: **PERF_SAMPLE_RAW**
2935+ * as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
2936+ * **PERF_COUNT_SW_BPF_OUTPUT** as **config**.
2937+ *
2938+ * The *flags* are used to indicate the index in *map* for which
2939+ * the value must be put, masked with **BPF_F_INDEX_MASK**.
2940+ * Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
2941+ * to indicate that the index of the current CPU core should be
2942+ * used.
2943+ *
2944+ * The value to write, of *size*, is passed through eBPF stack and
2945+ * pointed by *data*.
2946+ *
2947+ * *ctx* is a pointer to in-kernel struct xdp_buff.
2948+ *
2949+ * This helper is similar to **bpf_perf_eventoutput**\ () but
2950+ * restricted to raw_tracepoint bpf programs.
2951+ * Return
2952+ * 0 on success, or a negative error in case of failure.
29302953 */
29312954 #define __BPF_FUNC_MAPPER(FN) \
29322955 FN(unspec), \
@@ -3049,7 +3072,8 @@ union bpf_attr { · 116 unmodified lines
30493072 FN(send_signal_thread), \
30503073 FN(jiffies64), \
30513074 FN(read_branch_records), \
3052− FN(get_ns_current_pid_tgid),
3075+ FN(get_ns_current_pid_tgid), \
3076+ FN(xdp_output),
30533077
30543078 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
30553079 * function eBPF program intends to call