Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:kernel\bpf\syscall.c Create Date:2022-07-28 12:52:28
Last Modify:2022-05-19 18:06:12 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:map_lookup_elem

Proto:static int map_lookup_elem(union bpf_attr *attr)

Type:int

Parameter:

TypeParameterName
union bpf_attr *attr
814  __user * ukey = u64_to_user_ptr(key)
815  __user * uvalue = u64_to_user_ptr(value)
816  ufd = anonymous struct used by BPF_MAP_*_ELEM commands
823  If helper macro to check that unused fields 'union bpf_attr' are zero (BPF_MAP_LOOKUP_ELEM) Then Return -EINVAL
826  If flags & ~spin_lock-ed map_lookup/map_update Then Return -EINVAL
829  f = fdget(ufd)
830  map = error is returned, fd is released.* On success caller should complete fd access with matching fdput()
831  If IS_ERR(map) Then Return PTR_ERR(map)
833  If Not (map_get_sys_perms(map, f) & Has read method(s) ) Then
834  err = -EPERM
835  Go to err_put
838  If flags & spin_lock-ed map_lookup/map_update && Not map_value_has_spin_lock(map) Then
840  err = -EINVAL
841  Go to err_put
844  key = __bpf_copy_key(ukey, key_size)
845  If IS_ERR(key) Then
846  err = PTR_ERR(key)
847  Go to err_put
850  If map_type == BPF_MAP_TYPE_PERCPU_HASH || map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH || map_type == BPF_MAP_TYPE_PERCPU_ARRAY || map_type == BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE Then value_size = und_up - round up to next specified power of 2*@x: the value to round*@y: multiple to round up to (must be a power of 2)* Rounds @x up to next multiple of @y (which must be a power of 2).* To perform arbitrary rounding up, use roundup() below.(value_size, 8) * num_possible_cpus()
855  Else if IS_FD_MAP(map) Then value_size = sizeof(u32)
857  Else value_size = value_size
860  err = -ENOMEM
861  value = Allocation memory
862  If Not value Then Go to free_key
865  If bpf_map_is_dev_bound(map) Then
866  err = bpf_map_offload_lookup_elem(map, key, value)
867  Go to done
870  Even if we don't have any preemption, we need preempt disable/enable* to be barriers, so that we don't have things like get_user/put_user* that can cause faults and scheduling migrate into our preempt-protected* region.()
871  this_cpu_inc(bpf_prog_active)
872  If map_type == BPF_MAP_TYPE_PERCPU_HASH || map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH Then
874  err = bpf_percpu_hash_copy(map, key, value)
875  Else if map_type == BPF_MAP_TYPE_PERCPU_ARRAY Then
876  err = bpf_percpu_array_copy(map, key, value)
877  Else if map_type == BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE Then
878  err = bpf_percpu_cgroup_storage_copy(map, key, value)
879  Else if map_type == BPF_MAP_TYPE_STACK_TRACE Then
880  err = bpf_stackmap_copy(map, key, value)
881  Else if IS_FD_ARRAY(map) || IS_FD_PROG_ARRAY(map) Then
882  err = ly called from syscall
883  Else if IS_FD_HASH(map) Then
884  err = ly called from syscall
885  Else if map_type == BPF_MAP_TYPE_REUSEPORT_SOCKARRAY Then
886  err = bpf_fd_reuseport_array_lookup_elem(map, key, value)
887  Else if map_type == BPF_MAP_TYPE_QUEUE || map_type == BPF_MAP_TYPE_STACK Then
889  err = map_peek_elem(map, value)
890  Else
891  _read_lock() - mark the beginning of an RCU read-side critical section* When synchronize_rcu() is invoked on one CPU while other CPUs* are within RCU read-side critical sections, then the* synchronize_rcu() is guaranteed to block until after all the other
892  If map_lookup_elem_sys_only Then ptr = map_lookup_elem_sys_only(map, key)
894  Else ptr = map_lookup_elem(map, key)
896  If IS_ERR(ptr) Then
897  err = PTR_ERR(ptr)
898  Else if Not ptr Then
899  err = -ENOENT
900  Else
901  err = 0
910  _read_unlock() - marks the end of an RCU read-side critical section.* In most situations, rcu_read_unlock() is immune from deadlock.* However, in kernels built with CONFIG_RCU_BOOST, rcu_read_unlock()
912  this_cpu_dec(bpf_prog_active)
913  preempt_enable()
915  done :
916  If err Then Go to free_value
919  err = -EFAULT
920  If copy_to_user(uvalue, value, value_size) != 0 Then Go to free_value
923  err = 0
925  free_value :
926  kfree(value)
927  free_key :
928  kfree(key)
929  err_put :
930  fdput(f)
931  Return err