函数逻辑报告

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:kernel\bpf\syscall.c Create Date:2022-07-27 14:05:03
Last Modify:2022-05-19 18:06:12 Copyright©Brick
首页 函数Tree
注解内核,赢得工具下载SCCTEnglish

函数名称:map_lookup_elem

函数原型:static int map_lookup_elem(union bpf_attr *attr)

返回类型:int

参数:

类型参数名称
union bpf_attr *attr
814  __userukey等于u64_to_user_ptr(key)
815  __useruvalue等于u64_to_user_ptr(value)
816  ufd等于 anonymous struct used by BPF_MAP_*_ELEM commands
823  如果helper macro to check that unused fields 'union bpf_attr' are zero (BPF_MAP_LOOKUP_ELEM)则返回:负EINVAL
826  如果flags按位与spin_lock-ed map_lookup/map_update 的反则返回:负EINVAL
829  f等于fdget(ufd)
830  map等于 error is returned, fd is released.* On success caller should complete fd access with matching fdput()
831  如果是错误则返回:错误
833  如果非map_get_sys_perms(map, f)按位与Has read method(s) 的值则
834  err等于负EPERM
835  转到:err_put
838  如果flags按位与spin_lock-ed map_lookup/map_update 且非map_value_has_spin_lock(map)则
840  err等于负EINVAL
841  转到:err_put
844  key等于__bpf_copy_key(ukey, key_size)
845  如果是错误
846  err等于错误
847  转到:err_put
850  如果map_type恒等于BPF_MAP_TYPE_PERCPU_HASHmap_type恒等于BPF_MAP_TYPE_LRU_PERCPU_HASHmap_type恒等于BPF_MAP_TYPE_PERCPU_ARRAYmap_type恒等于BPF_MAP_TYPE_PERCPU_CGROUP_STORAGEvalue_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  否则如果IS_FD_MAP(map)则value_size等于sizeof(u32)
857  否则value_size等于value_size
860  err等于负ENOMEM
861  value等于开辟内存
862  如果非value则转到:free_key
865  如果bpf_map_is_dev_bound(map)则
866  err等于bpf_map_offload_lookup_elem(map, key, value)
867  转到:done
870  禁止抢占()
871  this_cpu_inc(bpf_prog_active)
872  如果map_type恒等于BPF_MAP_TYPE_PERCPU_HASHmap_type恒等于BPF_MAP_TYPE_LRU_PERCPU_HASH
874  err等于bpf_percpu_hash_copy(map, key, value)
875  否则如果map_type恒等于BPF_MAP_TYPE_PERCPU_ARRAY
876  err等于bpf_percpu_array_copy(map, key, value)
877  否则如果map_type恒等于BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE
878  err等于bpf_percpu_cgroup_storage_copy(map, key, value)
879  否则如果map_type恒等于BPF_MAP_TYPE_STACK_TRACE
880  err等于bpf_stackmap_copy(map, key, value)
881  否则如果IS_FD_ARRAY(map)或IS_FD_PROG_ARRAY(map)则
882  err等于ly called from syscall
883  否则如果IS_FD_HASH(map)则
884  err等于ly called from syscall
885  否则如果map_type恒等于BPF_MAP_TYPE_REUSEPORT_SOCKARRAY
886  err等于bpf_fd_reuseport_array_lookup_elem(map, key, value)
887  否则如果map_type恒等于BPF_MAP_TYPE_QUEUEmap_type恒等于BPF_MAP_TYPE_STACK
889  err等于map_peek_elem(map, value)
890  否则
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  如果map_lookup_elem_sys_onlyptr等于map_lookup_elem_sys_only(map, key)
894  否则ptr等于map_lookup_elem(map, key)
896  如果是错误
897  err等于错误
898  否则如果非ptr
899  err等于负ENOENT
900  否则
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  禁用抢占和中断()
915  done :
916  如果err则转到:free_value
919  err等于负EFAULT
920  如果copy_to_user(uvalue, value, value_size)不等于0则转到:free_value
923  err等于0
925  free_value :
926  kfree(value)
927  free_key :
928  kfree(key)
929  err_put :
930  fdput(f)
931  返回:err