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
3703 * Return3703 * Return
3704 * A pointer pointing to the kernel percpu variable on *cpu*, or3704 * A pointer pointing to the kernel percpu variable on *cpu*, or
3705 * NULL, if *cpu* is invalid.3705 * 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.
3706 */3718 */
3707#define __BPF_FUNC_MAPPER(FN) \3719#define __BPF_FUNC_MAPPER(FN) \
3708 FN(unspec), \3720 FN(unspec), \
@@ -3859,6 +3871,7 @@ union bpf_attr { · 150 unmodified lines
3859 FN(skb_cgroup_classid), \3871 FN(skb_cgroup_classid), \
3860 FN(redirect_neigh), \3872 FN(redirect_neigh), \
3861 FN(bpf_per_cpu_ptr), \3873 FN(bpf_per_cpu_ptr), \
3874 FN(bpf_this_cpu_ptr), \
3862 /* */3875 /* */
3863 3876
3864/* integer value in 'imm' field of BPF_CALL instruction selects which helper3877/* integer value in 'imm' field of BPF_CALL instruction selects which helper