bpf_licensing.rst 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. =============
  2. BPF licensing
  3. =============
  4. Background
  5. ==========
  6. * Classic BPF was BSD licensed
  7. "BPF" was originally introduced as BSD Packet Filter in
  8. http://www.tcpdump.org/papers/bpf-usenix93.pdf. The corresponding instruction
  9. set and its implementation came from BSD with BSD license. That original
  10. instruction set is now known as "classic BPF".
  11. However an instruction set is a specification for machine-language interaction,
  12. similar to a programming language. It is not a code. Therefore, the
  13. application of a BSD license may be misleading in a certain context, as the
  14. instruction set may enjoy no copyright protection.
  15. * eBPF (extended BPF) instruction set continues to be BSD
  16. In 2014, the classic BPF instruction set was significantly extended. We
  17. typically refer to this instruction set as eBPF to disambiguate it from cBPF.
  18. The eBPF instruction set is still BSD licensed.
  19. Implementations of eBPF
  20. =======================
  21. Using the eBPF instruction set requires implementing code in both kernel space
  22. and user space.
  23. In Linux Kernel
  24. ---------------
  25. The reference implementations of the eBPF interpreter and various just-in-time
  26. compilers are part of Linux and are GPLv2 licensed. The implementation of
  27. eBPF helper functions is also GPLv2 licensed. Interpreters, JITs, helpers,
  28. and verifiers are called eBPF runtime.
  29. In User Space
  30. -------------
  31. There are also implementations of eBPF runtime (interpreter, JITs, helper
  32. functions) under
  33. Apache2 (https://github.com/iovisor/ubpf),
  34. MIT (https://github.com/qmonnet/rbpf), and
  35. BSD (https://github.com/DPDK/dpdk/blob/main/lib/librte_bpf).
  36. In HW
  37. -----
  38. The HW can choose to execute eBPF instruction natively and provide eBPF runtime
  39. in HW or via the use of implementing firmware with a proprietary license.
  40. In other operating systems
  41. --------------------------
  42. Other kernels or user space implementations of eBPF instruction set and runtime
  43. can have proprietary licenses.
  44. Using BPF programs in the Linux kernel
  45. ======================================
  46. Linux Kernel (while being GPLv2) allows linking of proprietary kernel modules
  47. under these rules:
  48. Documentation/process/license-rules.rst
  49. When a kernel module is loaded, the linux kernel checks which functions it
  50. intends to use. If any function is marked as "GPL only," the corresponding
  51. module or program has to have GPL compatible license.
  52. Loading BPF program into the Linux kernel is similar to loading a kernel
  53. module. BPF is loaded at run time and not statically linked to the Linux
  54. kernel. BPF program loading follows the same license checking rules as kernel
  55. modules. BPF programs can be proprietary if they don't use "GPL only" BPF
  56. helper functions.
  57. Further, some BPF program types - Linux Security Modules (LSM) and TCP
  58. Congestion Control (struct_ops), as of Aug 2021 - are required to be GPL
  59. compatible even if they don't use "GPL only" helper functions directly. The
  60. registration step of LSM and TCP congestion control modules of the Linux
  61. kernel is done through EXPORT_SYMBOL_GPL kernel functions. In that sense LSM
  62. and struct_ops BPF programs are implicitly calling "GPL only" functions.
  63. The same restriction applies to BPF programs that call kernel functions
  64. directly via unstable interface also known as "kfunc".
  65. Packaging BPF programs with user space applications
  66. ====================================================
  67. Generally, proprietary-licensed applications and GPL licensed BPF programs
  68. written for the Linux kernel in the same package can co-exist because they are
  69. separate executable processes. This applies to both cBPF and eBPF programs.