mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 20:51:03 +02:00
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. Signed-off-by: Hao Luo <haoluo@google.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Andrii Nakryiko <andriin@fb.com> Link: https://lore.kernel.org/bpf/20200929235049.2533242-6-haoluo@google.com
This commit is contained in:
committed by
Alexei Starovoitov
parent
eaa6bcb71e
commit
63d9b80dcf
@@ -3703,6 +3703,18 @@ union bpf_attr {
|
||||
* Return
|
||||
* A pointer pointing to the kernel percpu variable on *cpu*, or
|
||||
* NULL, if *cpu* is invalid.
|
||||
*
|
||||
* void *bpf_this_cpu_ptr(const void *percpu_ptr)
|
||||
* Description
|
||||
* Take a pointer to a percpu ksym, *percpu_ptr*, and return a
|
||||
* pointer to the percpu kernel variable on this cpu. See the
|
||||
* description of 'ksym' in **bpf_per_cpu_ptr**\ ().
|
||||
*
|
||||
* bpf_this_cpu_ptr() has the same semantic as this_cpu_ptr() in
|
||||
* the kernel. Different from **bpf_per_cpu_ptr**\ (), it would
|
||||
* never return NULL.
|
||||
* Return
|
||||
* A pointer pointing to the kernel percpu variable on this cpu.
|
||||
*/
|
||||
#define __BPF_FUNC_MAPPER(FN) \
|
||||
FN(unspec), \
|
||||
@@ -3859,6 +3871,7 @@ union bpf_attr {
|
||||
FN(skb_cgroup_classid), \
|
||||
FN(redirect_neigh), \
|
||||
FN(bpf_per_cpu_ptr), \
|
||||
FN(bpf_this_cpu_ptr), \
|
||||
/* */
|
||||
|
||||
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
|
||||
|
Reference in New Issue
Block a user