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
5178 * Dynamically cast a *sk* pointer to a *mptcp_sock* pointer.5178 * Dynamically cast a *sk* pointer to a *mptcp_sock* pointer.
5179 * Return5179 * Return
5180 * *sk* if casting is valid, or **NULL** otherwise.5180 * *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.
5181 */5192 */
5182#define __BPF_FUNC_MAPPER(FN) \5193#define __BPF_FUNC_MAPPER(FN) \
5183 FN(unspec), \5194 FN(unspec), \
@@ -5377,6 +5388,7 @@ union bpf_attr { · 193 unmodified lines
5377 FN(kptr_xchg), \5388 FN(kptr_xchg), \
5378 FN(map_lookup_percpu_elem), \5389 FN(map_lookup_percpu_elem), \
5379 FN(skc_to_mptcp_sock), \5390 FN(skc_to_mptcp_sock), \
5391 FN(dynptr_from_mem), \
5380 /* */5392 /* */
5381 5393
5382/* integer value in 'imm' field of BPF_CALL instruction selects which helper5394/* integer value in 'imm' field of BPF_CALL instruction selects which helper