History

bpf: Add bpf_dynptr_read and bpf_dynptr_write

This patch adds two helper functions, bpf_dynptr_read and bpf_dynptr_write: long bpf_dynptr_read(void *dst, u32 len, struct bpf_dynptr *src, u32 offset); long bpf_dynptr_write(struct bpf_dynptr *dst, u32 offset, void *src, u32 len); The dynptr passed into these functions must be valid dynptrs that have been initialized.

Joanne Koong committed 4 years ago

Commit 13bbbfb1 parent bc34dee3 files · +116 −0Browse files

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

Unified · Split

tools/include/uapi/linux/bpf.h+19−0
@@ -5221,6 +5221,23 @@ union bpf_attr { · 5220 unmodified lines
52215221 * 'bpf_ringbuf_discard'.
52225222 * Return
52235223 * Nothing. Always succeeds.
5224+ *
5225+ * long bpf_dynptr_read(void *dst, u32 len, struct bpf_dynptr *src, u32 offset)
5226+ * Description
5227+ * Read *len* bytes from *src* into *dst*, starting from *offset*
5228+ * into *src*.
5229+ * Return
5230+ * 0 on success, -E2BIG if *offset* + *len* exceeds the length
5231+ * of *src*'s data, -EINVAL if *src* is an invalid dynptr.
5232+ *
5233+ * long bpf_dynptr_write(struct bpf_dynptr *dst, u32 offset, void *src, u32 len)
5234+ * Description
5235+ * Write *len* bytes from *src* into *dst*, starting from *offset*
5236+ * into *dst*.
5237+ * Return
5238+ * 0 on success, -E2BIG if *offset* + *len* exceeds the length
5239+ * of *dst*'s data, -EINVAL if *dst* is an invalid dynptr or if *dst*
5240+ * is a read-only dynptr.
52245241 */
52255242 #define __BPF_FUNC_MAPPER(FN) \
52265243 FN(unspec), \
@@ -5424,6 +5441,8 @@ union bpf_attr { · 197 unmodified lines
54245441 FN(ringbuf_reserve_dynptr), \
54255442 FN(ringbuf_submit_dynptr), \
54265443 FN(ringbuf_discard_dynptr), \
5444+ FN(dynptr_read), \
5445+ FN(dynptr_write), \
54275446 /* */
54285447
54295448 /* integer value in 'imm' field of BPF_CALL instruction selects which helper