History

bpf: Introducte bpf_this_cpu_ptr()

Add bpf_this_cpu_ptr() to help access percpu var on this cpu. This helper always returns a valid pointer, therefore no need to check returned value for NULL. Also note that all programs run with preemption disabled, which means that the returned pointer is stable during all the execution of the program.

Hao Luo committed 6 years ago

Commit 63d9b801 parent eaa6bcb6 files · +52 −3Browse files

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

Unified · Split

include/uapi/linux/bpf.h+13−0
@@ -3703,6 +3703,18 @@ union bpf_attr { · 3702 unmodified lines
37033703 * Return
37043704 * A pointer pointing to the kernel percpu variable on *cpu*, or
37053705 * NULL, if *cpu* is invalid.
3706+ *
3707+ * void *bpf_this_cpu_ptr(const void *percpu_ptr)
3708+ * Description
3709+ * Take a pointer to a percpu ksym, *percpu_ptr*, and return a
3710+ * pointer to the percpu kernel variable on this cpu. See the
3711+ * description of 'ksym' in **bpf_per_cpu_ptr**\ ().
3712+ *
3713+ * bpf_this_cpu_ptr() has the same semantic as this_cpu_ptr() in
3714+ * the kernel. Different from **bpf_per_cpu_ptr**\ (), it would
3715+ * never return NULL.
3716+ * Return
3717+ * A pointer pointing to the kernel percpu variable on this cpu.
37063718 */
37073719 #define __BPF_FUNC_MAPPER(FN) \
37083720 FN(unspec), \
@@ -3859,6 +3871,7 @@ union bpf_attr { · 150 unmodified lines
38593871 FN(skb_cgroup_classid), \
38603872 FN(redirect_neigh), \
38613873 FN(bpf_per_cpu_ptr), \
3874+ FN(bpf_this_cpu_ptr), \
38623875 /* */
38633876
38643877 /* integer value in 'imm' field of BPF_CALL instruction selects which helper