Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:bpf_prog_load

Proto:static int bpf_prog_load(union bpf_attr *attr, union bpf_attr __user *uattr)

Type:int

Parameter:

TypeParameterName
union bpf_attr *attr
union bpf_attr __user *uattr
1704  type = one of enum bpf_prog_type
1710  If helper macro to check that unused fields 'union bpf_attr' are zero (BPF_PROG_LOAD) Then Return -EINVAL
1713  If prog_flags & ~( If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the* verifier will perform strict alignment checking as if the kernel* has been built with CONFIG_EFFICIENT_UNALIGNED_ACCESS not set,* and NET_IP_ALIGN defined to 2. | If BPF_F_ANY_ALIGNMENT is used in BPF_PROF_LOAD command, the* verifier will allow any alignment whatsoever. On platforms* with strict alignment requirements for loads ands stores (such* as sparc and mips) the verifier validates that all loads and | The verifier internal test flag. Behavior is undefined | BPF_F_TEST_RND_HI32 is used in BPF_PROG_LOAD command for testing purpose.* Verifier does sub-register def/use analysis and identifies instructions whose* def only matters for low 32-bit, high 32-bit is never referenced later) Then Return -EINVAL
1719  If Not IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',* 0 otherwise.(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && prog_flags & If BPF_F_ANY_ALIGNMENT is used in BPF_PROF_LOAD command, the* verifier will allow any alignment whatsoever. On platforms* with strict alignment requirements for loads ands stores (such* as sparc and mips) the verifier validates that all loads and && Not Check operation authority Then Return -EPERM
1725  If Copy a NUL terminated string from userspace < 0 Then Return -EFAULT
1728  license[ size of license - 1] = 0
1731  is_gpl = license_is_gpl_compatible(license)
1733  If insn_cnt == 0 || insn_cnt > If Check operation authority Then yes. 1M insns Else BPF_MAXINSNS Then Return -E2BIG
1736  If type != BPF_PROG_TYPE_SOCKET_FILTER && type != BPF_PROG_TYPE_CGROUP_SKB && Not Check operation authority Then Return -EPERM
1741  Initially all BPF programs could be loaded w/o specifying* expected_attach_type
1742  If bpf_prog_load_check_attach(type, For some prog types expected attach type must be known at * load time to verify attach type specific parts of prog * (context accesses, allowed helpers, etc)., in-kernel BTF type id to attach to , 0 to attach to vmlinux ) Then Return -EINVAL
1748  prog = bpf_prog_alloc(bpf_prog_size(insn_cnt), GFP_USER)
1749  If Not prog Then Return -ENOMEM
1752  For some prog types = For some prog types expected attach type must be known at * load time to verify attach type specific parts of prog * (context accesses, allowed helpers, etc).
1753  in-kernel BTF type id to attach to = in-kernel BTF type id to attach to
1754  If 0 to attach to vmlinux Then
1757  tgt_prog = bpf_prog_get( 0 to attach to vmlinux )
1758  If IS_ERR(tgt_prog) Then
1759  err = PTR_ERR(tgt_prog)
1760  Go to free_prog_nouncharge
1762  linked_prog = tgt_prog
1765  offload_requested = Not Not ifindex of netdev to prep for
1767  err = security_bpf_prog_alloc( Auxiliary fields )
1768  If err Then Go to free_prog_nouncharge
1771  err = bpf_prog_charge_memlock(prog)
1772  If err Then Go to free_prog_sec
1775  Number of filter blocks = insn_cnt
1777  err = -EFAULT
1778  If copy_from_user(insns, u64_to_user_ptr(insns), bpf_prog_insn_size(prog)) != 0 Then Go to free_prog
1782  Original BPF program = NULL
1783  Is our filter JIT'ed? = 0
1785  atomic64_set( & refcnt, 1)
1786  Is filter GPL compatible? = If is_gpl Then 1 Else 0
1788  If bpf_prog_is_dev_bound( Auxiliary fields ) Then
1789  err = bpf_prog_offload_init(prog, attr)
1790  If err Then Go to free_prog
1795  err = find_prog_type(type, prog)
1796  If err < 0 Then Go to free_prog
1799  ns since boottime = ktime_get_boottime_ns()
1800  err = dst and src must have at least BPF_OBJ_NAME_LEN number of bytes.* Return 0 on success and < 0 on error.
1801  If err Then Go to free_prog
1805  err = bpf_check( & prog, attr, uattr)
1806  If err < 0 Then Go to free_used_maps
1809  prog = pf_prog_select_runtime - select exec runtime for BPF program*@fp: bpf_prog populated with internal BPF program*@err: pointer to error variable* Try to JIT eBPF program, if JIT is not available, use interpreter.
1810  If err < 0 Then Go to free_used_maps
1813  err = bpf_prog_alloc_id(prog)
1814  If err Then Go to free_used_maps
1831  bpf_prog_kallsyms_add(prog)
1832  perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_LOAD, 0)
1834  err = bpf_prog_new_fd(prog)
1835  If err < 0 Then bpf_prog_put(prog)
1837  Return err
1839  free_used_maps :
1844  __bpf_prog_put_noref(prog, used by non-func prog as the number of func progs )
1845  Return err
1846  free_prog :
1847  bpf_prog_uncharge_memlock(prog)
1848  free_prog_sec :
1849  security_bpf_prog_free( Auxiliary fields )
1850  free_prog_nouncharge :
1851  Free internal BPF program
1852  Return err