History

bpf: Add bpf_dynptr_from_mem for local dynptrs

This patch adds a new api bpf_dynptr_from_mem: long bpf_dynptr_from_mem(void *data, u32 size, u64 flags, struct bpf_dynptr *ptr); which initializes a dynptr to point to a bpf program's local memory. For now only local memory that is of reg type PTR_TO_MAP_VALUE is supported.

Joanne Koong committed 4 years ago

Commit 263ae151 parent 97e03f54 files · +95 −0Browse files

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

Unified · Split

include/uapi/linux/bpf.h+12−0
@@ -5178,6 +5178,17 @@ union bpf_attr { · 5177 unmodified lines
51785178 * Dynamically cast a *sk* pointer to a *mptcp_sock* pointer.
51795179 * Return
51805180 * *sk* if casting is valid, or **NULL** otherwise.
5181+ *
5182+ * long bpf_dynptr_from_mem(void *data, u32 size, u64 flags, struct bpf_dynptr *ptr)
5183+ * Description
5184+ * Get a dynptr to local memory *data*.
5185+ *
5186+ * *data* must be a ptr to a map value.
5187+ * The maximum *size* supported is DYNPTR_MAX_SIZE.
5188+ * *flags* is currently unused.
5189+ * Return
5190+ * 0 on success, -E2BIG if the size exceeds DYNPTR_MAX_SIZE,
5191+ * -EINVAL if flags is not 0.
51815192 */
51825193 #define __BPF_FUNC_MAPPER(FN) \
51835194 FN(unspec), \
@@ -5377,6 +5388,7 @@ union bpf_attr { · 193 unmodified lines
53775388 FN(kptr_xchg), \
53785389 FN(map_lookup_percpu_elem), \
53795390 FN(skc_to_mptcp_sock), \
5391+ FN(dynptr_from_mem), \
53805392 /* */
53815393
53825394 /* integer value in 'imm' field of BPF_CALL instruction selects which helper