1*c86216bcSAlexei Starovoitov=============
2*c86216bcSAlexei StarovoitovBPF licensing
3*c86216bcSAlexei Starovoitov=============
4*c86216bcSAlexei Starovoitov
5*c86216bcSAlexei StarovoitovBackground
6*c86216bcSAlexei Starovoitov==========
7*c86216bcSAlexei Starovoitov
8*c86216bcSAlexei Starovoitov* Classic BPF was BSD licensed
9*c86216bcSAlexei Starovoitov
10*c86216bcSAlexei Starovoitov"BPF" was originally introduced as BSD Packet Filter in
11*c86216bcSAlexei Starovoitovhttp://www.tcpdump.org/papers/bpf-usenix93.pdf. The corresponding instruction
12*c86216bcSAlexei Starovoitovset and its implementation came from BSD with BSD license. That original
13*c86216bcSAlexei Starovoitovinstruction set is now known as "classic BPF".
14*c86216bcSAlexei Starovoitov
15*c86216bcSAlexei StarovoitovHowever an instruction set is a specification for machine-language interaction,
16*c86216bcSAlexei Starovoitovsimilar to a programming language.  It is not a code. Therefore, the
17*c86216bcSAlexei Starovoitovapplication of a BSD license may be misleading in a certain context, as the
18*c86216bcSAlexei Starovoitovinstruction set may enjoy no copyright protection.
19*c86216bcSAlexei Starovoitov
20*c86216bcSAlexei Starovoitov* eBPF (extended BPF) instruction set continues to be BSD
21*c86216bcSAlexei Starovoitov
22*c86216bcSAlexei StarovoitovIn 2014, the classic BPF instruction set was significantly extended. We
23*c86216bcSAlexei Starovoitovtypically refer to this instruction set as eBPF to disambiguate it from cBPF.
24*c86216bcSAlexei StarovoitovThe eBPF instruction set is still BSD licensed.
25*c86216bcSAlexei Starovoitov
26*c86216bcSAlexei StarovoitovImplementations of eBPF
27*c86216bcSAlexei Starovoitov=======================
28*c86216bcSAlexei Starovoitov
29*c86216bcSAlexei StarovoitovUsing the eBPF instruction set requires implementing code in both kernel space
30*c86216bcSAlexei Starovoitovand user space.
31*c86216bcSAlexei Starovoitov
32*c86216bcSAlexei StarovoitovIn Linux Kernel
33*c86216bcSAlexei Starovoitov---------------
34*c86216bcSAlexei Starovoitov
35*c86216bcSAlexei StarovoitovThe reference implementations of the eBPF interpreter and various just-in-time
36*c86216bcSAlexei Starovoitovcompilers are part of Linux and are GPLv2 licensed. The implementation of
37*c86216bcSAlexei StarovoitoveBPF helper functions is also GPLv2 licensed. Interpreters, JITs, helpers,
38*c86216bcSAlexei Starovoitovand verifiers are called eBPF runtime.
39*c86216bcSAlexei Starovoitov
40*c86216bcSAlexei StarovoitovIn User Space
41*c86216bcSAlexei Starovoitov-------------
42*c86216bcSAlexei Starovoitov
43*c86216bcSAlexei StarovoitovThere are also implementations of eBPF runtime (interpreter, JITs, helper
44*c86216bcSAlexei Starovoitovfunctions) under
45*c86216bcSAlexei StarovoitovApache2 (https://github.com/iovisor/ubpf),
46*c86216bcSAlexei StarovoitovMIT (https://github.com/qmonnet/rbpf), and
47*c86216bcSAlexei StarovoitovBSD (https://github.com/DPDK/dpdk/blob/main/lib/librte_bpf).
48*c86216bcSAlexei Starovoitov
49*c86216bcSAlexei StarovoitovIn HW
50*c86216bcSAlexei Starovoitov-----
51*c86216bcSAlexei Starovoitov
52*c86216bcSAlexei StarovoitovThe HW can choose to execute eBPF instruction natively and provide eBPF runtime
53*c86216bcSAlexei Starovoitovin HW or via the use of implementing firmware with a proprietary license.
54*c86216bcSAlexei Starovoitov
55*c86216bcSAlexei StarovoitovIn other operating systems
56*c86216bcSAlexei Starovoitov--------------------------
57*c86216bcSAlexei Starovoitov
58*c86216bcSAlexei StarovoitovOther kernels or user space implementations of eBPF instruction set and runtime
59*c86216bcSAlexei Starovoitovcan have proprietary licenses.
60*c86216bcSAlexei Starovoitov
61*c86216bcSAlexei StarovoitovUsing BPF programs in the Linux kernel
62*c86216bcSAlexei Starovoitov======================================
63*c86216bcSAlexei Starovoitov
64*c86216bcSAlexei StarovoitovLinux Kernel (while being GPLv2) allows linking of proprietary kernel modules
65*c86216bcSAlexei Starovoitovunder these rules:
66*c86216bcSAlexei StarovoitovDocumentation/process/license-rules.rst
67*c86216bcSAlexei Starovoitov
68*c86216bcSAlexei StarovoitovWhen a kernel module is loaded, the linux kernel checks which functions it
69*c86216bcSAlexei Starovoitovintends to use. If any function is marked as "GPL only," the corresponding
70*c86216bcSAlexei Starovoitovmodule or program has to have GPL compatible license.
71*c86216bcSAlexei Starovoitov
72*c86216bcSAlexei StarovoitovLoading BPF program into the Linux kernel is similar to loading a kernel
73*c86216bcSAlexei Starovoitovmodule. BPF is loaded at run time and not statically linked to the Linux
74*c86216bcSAlexei Starovoitovkernel. BPF program loading follows the same license checking rules as kernel
75*c86216bcSAlexei Starovoitovmodules. BPF programs can be proprietary if they don't use "GPL only" BPF
76*c86216bcSAlexei Starovoitovhelper functions.
77*c86216bcSAlexei Starovoitov
78*c86216bcSAlexei StarovoitovFurther, some BPF program types - Linux Security Modules (LSM) and TCP
79*c86216bcSAlexei StarovoitovCongestion Control (struct_ops), as of Aug 2021 - are required to be GPL
80*c86216bcSAlexei Starovoitovcompatible even if they don't use "GPL only" helper functions directly. The
81*c86216bcSAlexei Starovoitovregistration step of LSM and TCP congestion control modules of the Linux
82*c86216bcSAlexei Starovoitovkernel is done through EXPORT_SYMBOL_GPL kernel functions. In that sense LSM
83*c86216bcSAlexei Starovoitovand struct_ops BPF programs are implicitly calling "GPL only" functions.
84*c86216bcSAlexei StarovoitovThe same restriction applies to BPF programs that call kernel functions
85*c86216bcSAlexei Starovoitovdirectly via unstable interface also known as "kfunc".
86*c86216bcSAlexei Starovoitov
87*c86216bcSAlexei StarovoitovPackaging BPF programs with user space applications
88*c86216bcSAlexei Starovoitov====================================================
89*c86216bcSAlexei Starovoitov
90*c86216bcSAlexei StarovoitovGenerally, proprietary-licensed applications and GPL licensed BPF programs
91*c86216bcSAlexei Starovoitovwritten for the Linux kernel in the same package can co-exist because they are
92*c86216bcSAlexei Starovoitovseparate executable processes. This applies to both cBPF and eBPF programs.
93