6sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget%/translations/zh_CN/bpf/bpf_design_QAmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget%/translations/zh_TW/bpf/bpf_design_QAmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget%/translations/it_IT/bpf/bpf_design_QAmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget%/translations/ja_JP/bpf/bpf_design_QAmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget%/translations/ko_KR/bpf/bpf_design_QAmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget%/translations/sp_SP/bpf/bpf_design_QAmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(hBPF Design Q&Ah]hBPF Design Q&A}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhh?/var/lib/git/docbuild/linux/Documentation/bpf/bpf_design_QA.rsthKubh paragraph)}(hX:BPF extensibility and applicability to networking, tracing, security in the linux kernel and several user space implementations of BPF virtual machine led to a number of misunderstanding on what BPF actually is. This short QA is an attempt to address that and outline a direction of where BPF is heading long term.h]hX:BPF extensibility and applicability to networking, tracing, security in the linux kernel and several user space implementations of BPF virtual machine led to a number of misunderstanding on what BPF actually is. This short QA is an attempt to address that and outline a direction of where BPF is heading long term.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubhtopic)}(hhh]h bullet_list)}(hhh]h list_item)}(hhh](h)}(hhh]h reference)}(hhh]hQuestions and Answers}(hhhhhNhNubah}(h]id1ah ]h"]h$]h&]refidquestions-and-answersuh1hhhubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh](h)}(hhh]h)}(hhh]h)}(hhh]h=Q: Is BPF a generic instruction set similar to x64 and arm64?}(hhhhhNhNubah}(h]id2ah ]h"]h$]h&]refid;q-is-bpf-a-generic-instruction-set-similar-to-x64-and-arm64uh1hhhubah}(h]h ]h"]h$]h&]uh1hhhubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]h%Q: Is BPF a generic virtual machine ?}(hjhhhNhNubah}(h]id3ah ]h"]h$]h&]refid"q-is-bpf-a-generic-virtual-machineuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh](h)}(hhh]h)}(hhh](hBPF is generic instruction set }(hj>hhhNhNubhemphasis)}(h*with*h]hwith}(hjGhhhNhNubah}(h]h ]h"]h$]h&]uh1jEhNhNhj>ubh C calling convention.}(hj>hhhNhNubeh}(h]id4ah ]h"]h$]h&]refid8bpf-is-generic-instruction-set-with-c-calling-conventionuh1hhj;ubah}(h]h ]h"]h$]h&]uh1hhj8ubh)}(hhh](h)}(hhh]h)}(hhh]h)}(hhh]h'Q: Why C calling convention was chosen?}(hjqhhhNhNubah}(h]id5ah ]h"]h$]h&]refid%q-why-c-calling-convention-was-chosenuh1hhjnubah}(h]h ]h"]h$]h&]uh1hhjkubah}(h]h ]h"]h$]h&]uh1hhjhubh)}(hhh]h)}(hhh]h)}(hhh]h9Q: Can multiple return values be supported in the future?}(hjhhhNhNubah}(h]id6ah ]h"]h$]h&]refid7q-can-multiple-return-values-be-supported-in-the-futureuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhjhubh)}(hhh]h)}(hhh]h)}(hhh]hAQ: Can more than 5 function arguments be supported in the future?}(hjhhhNhNubah}(h]id7ah ]h"]h$]h&]refid?q-can-more-than-5-function-arguments-be-supported-in-the-futureuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhjhubeh}(h]h ]h"]h$]h&]uh1hhj8ubeh}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]hAQ: Can BPF programs access instruction pointer or return address?}(hjhhhNhNubah}(h]id8ah ]h"]h$]h&]refid?q-can-bpf-programs-access-instruction-pointer-or-return-addressuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]h*Q: Can BPF programs access stack pointer ?}(hjhhhNhNubah}(h]id9ah ]h"]h$]h&]refid'q-can-bpf-programs-access-stack-pointeruh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]h;Q: Does C-calling convention diminishes possible use cases?}(hj'hhhNhNubah}(h]id10ah ]h"]h$]h&]refid9q-does-c-calling-convention-diminishes-possible-use-casesuh1hhj$ubah}(h]h ]h"]h$]h&]uh1hhj!ubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]hLQ: Does it mean that ‘innovative’ extensions to BPF code are disallowed?}(hjIhhhNhNubah}(h]id11ah ]h"]h$]h&]refidDq-does-it-mean-that-innovative-extensions-to-bpf-code-are-disalloweduh1hhjFubah}(h]h ]h"]h$]h&]uh1hhjCubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]h(Q: Can loops be supported in a safe way?}(hjkhhhNhNubah}(h]id12ah ]h"]h$]h&]refid&q-can-loops-be-supported-in-a-safe-wayuh1hhjhubah}(h]h ]h"]h$]h&]uh1hhjeubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]h Q: What are the verifier limits?}(hjhhhNhNubah}(h]id13ah ]h"]h$]h&]refidq-what-are-the-verifier-limitsuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh](h)}(hhh]h)}(hhh]hInstruction level questions}(hjhhhNhNubah}(h]id14ah ]h"]h$]h&]refidinstruction-level-questionsuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hhh](h)}(hhh]h)}(hhh]h)}(hhh]h+Q: LD_ABS and LD_IND instructions vs C code}(hjhhhNhNubah}(h]id15ah ]h"]h$]h&]refid*q-ld-abs-and-ld-ind-instructions-vs-c-codeuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hhh]h)}(hhh]h)}(hhh]h8Q: BPF instructions mapping not one-to-one to native CPU}(hjhhhNhNubah}(h]id16ah ]h"]h$]h&]refid7q-bpf-instructions-mapping-not-one-to-one-to-native-cpuuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hhh]h)}(hhh]h)}(hhh]h4Q: Why BPF_DIV instruction doesn’t map to x64 div?}(hjhhhNhNubah}(h]id17ah ]h"]h$]h&]refid0q-why-bpf-div-instruction-doesn-t-map-to-x64-divuh1hhjubah}(h]h ]h"]h$]h&]uh1hhj ubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hhh]h)}(hhh]h)}(hhh]h.Q: Why BPF has implicit prologue and epilogue?}(hj4hhhNhNubah}(h]id18ah ]h"]h$]h&]refid,q-why-bpf-has-implicit-prologue-and-epilogueuh1hhj1ubah}(h]h ]h"]h$]h&]uh1hhj.ubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hhh]h)}(hhh]h)}(hhh]hMQ: Why BPF_JLT and BPF_JLE instructions were not introduced in the beginning?}(hjVhhhNhNubah}(h]id19ah ]h"]h$]h&]refidKq-why-bpf-jlt-and-bpf-jle-instructions-were-not-introduced-in-the-beginninguh1hhjSubah}(h]h ]h"]h$]h&]uh1hhjPubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hhh]h)}(hhh]h)}(hhh]h&Q: BPF 32-bit subregister requirements}(hjxhhhNhNubah}(h]id20ah ]h"]h$]h&]refid%q-bpf-32-bit-subregister-requirementsuh1hhjuubah}(h]h ]h"]h$]h&]uh1hhjrubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]hQ: Does BPF have a stable ABI?}(hjhhhNhNubah}(h]id21ah ]h"]h$]h&]refidq-does-bpf-have-a-stable-abiuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]h*Q: Are tracepoints part of the stable ABI?}(hjhhhNhNubah}(h]id22ah ]h"]h$]h&]refid(q-are-tracepoints-part-of-the-stable-abiuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]h>Q: Are places where kprobes can attach part of the stable ABI?}(hjhhhNhNubah}(h]id23ah ]h"]h$]h&]refidhhhNhNubah}(h]id33ah ]h"]h$]h&]refid;q-marking-a-function-with-btf-id-makes-that-function-an-abiuh1hhj;ubah}(h]h ]h"]h$]h&]uh1hhj8ubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]hGQ: What is the compatibility story for special BPF types in map values?}(hj`hhhNhNubah}(h]id34ah ]h"]h$]h&]refidEq-what-is-the-compatibility-story-for-special-bpf-types-in-map-valuesuh1hhj]ubah}(h]h ]h"]h$]h&]uh1hhjZubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]hNQ: What is the compatibility story for special BPF types in allocated objects?}(hjhhhNhNubah}(h]id35ah ]h"]h$]h&]refidLq-what-is-the-compatibility-story-for-special-bpf-types-in-allocated-objectsuh1hhjubah}(h]h ]h"]h$]h&]uh1hhj|ubah}(h]h ]h"]h$]h&]uh1hhhubeh}(h]h ]h"]h$]h&]uh1hhhubeh}(h]h ]h"]h$]h&]uh1hhhubah}(h]h ]h"]h$]h&]uh1hhhhhhNhNubah}(h]contentsah ](contentslocaleh"]contentsah$]h&]uh1hhhhK hhhhubh)}(hhh](h)}(hQuestions and Answersh]hQuestions and Answers}(hjhhhNhNubah}(h]h ]h"]h$]h&]refidhuh1hhjhhhhhKubh)}(hhh](h)}(h=Q: Is BPF a generic instruction set similar to x64 and arm64?h]h=Q: Is BPF a generic instruction set similar to x64 and arm64?}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjhhhhhKubh)}(hA: NO.h]hA: NO.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]j ah ]h"]=q: is bpf a generic instruction set similar to x64 and arm64?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h%Q: Is BPF a generic virtual machine ?h]h%Q: Is BPF a generic virtual machine ?}(hjhhhNhNubah}(h]h ]h"]h$]h&]jj%uh1hhjhhhhhKubh)}(hA: NO.h]hA: NO.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]j+ah ]h"]%q: is bpf a generic virtual machine ?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h;BPF is generic instruction set *with* C calling convention.h](hBPF is generic instruction set }(hjhhhNhNubjF)}(hjIh]hwith}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jEhjubh C calling convention.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]jj[uh1hhjhhhhhKubh)}(hhh](h)}(h'Q: Why C calling convention was chosen?h]h'Q: Why C calling convention was chosen?}(hj=hhhNhNubah}(h]h ]h"]h$]h&]jjzuh1hhj:hhhhhKubh)}(hXqA: Because BPF programs are designed to run in the linux kernel which is written in C, hence BPF defines instruction set compatible with two most used architectures x64 and arm64 (and takes into consideration important quirks of other architectures) and defines calling convention that is compatible with C calling convention of the linux kernel on those architectures.h]hXqA: Because BPF programs are designed to run in the linux kernel which is written in C, hence BPF defines instruction set compatible with two most used architectures x64 and arm64 (and takes into consideration important quirks of other architectures) and defines calling convention that is compatible with C calling convention of the linux kernel on those architectures.}(hjKhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hj:hhubeh}(h]jah ]h"]'q: why c calling convention was chosen?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h9Q: Can multiple return values be supported in the future?h]h9Q: Can multiple return values be supported in the future?}(hjchhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhj`hhhhhK(ubh)}(h>A: NO. BPF allows only register R0 to be used as return value.h]h>A: NO. BPF allows only register R0 to be used as return value.}(hjqhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK)hj`hhubeh}(h]jah ]h"]9q: can multiple return values be supported in the future?ah$]h&]uh1hhjhhhhhK(ubh)}(hhh](h)}(hAQ: Can more than 5 function arguments be supported in the future?h]hAQ: Can more than 5 function arguments be supported in the future?}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjhhhhhK,ubh)}(hA: NO. BPF calling convention only allows registers R1-R5 to be used as arguments. BPF is not a standalone instruction set. (unlike x64 ISA that allows msft, cdecl and other conventions)h]hA: NO. BPF calling convention only allows registers R1-R5 to be used as arguments. BPF is not a standalone instruction set. (unlike x64 ISA that allows msft, cdecl and other conventions)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK-hjhhubeh}(h]jah ]h"]Aq: can more than 5 function arguments be supported in the future?ah$]h&]uh1hhjhhhhhK,ubeh}(h]jaah ]h"]9bpf is generic instruction set with c calling convention.ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(hAQ: Can BPF programs access instruction pointer or return address?h]hAQ: Can BPF programs access instruction pointer or return address?}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjhhhhhK2ubh)}(hA: NO.h]hA: NO.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK3hjhhubeh}(h]jah ]h"]Aq: can bpf programs access instruction pointer or return address?ah$]h&]uh1hhjhhhhhK2ubh)}(hhh](h)}(h*Q: Can BPF programs access stack pointer ?h]h*Q: Can BPF programs access stack pointer ?}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjhhhhhK6ubh)}(hA: NO.h]hA: NO.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK7hjhhubh)}(hOnly frame pointer (register R10) is accessible. From compiler point of view it's necessary to have stack pointer. For example, LLVM defines register R11 as stack pointer in its BPF backend, but it makes sure that generated code never uses it.h]hOnly frame pointer (register R10) is accessible. From compiler point of view it’s necessary to have stack pointer. For example, LLVM defines register R11 as stack pointer in its BPF backend, but it makes sure that generated code never uses it.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK9hjhhubeh}(h]jah ]h"]*q: can bpf programs access stack pointer ?ah$]h&]uh1hhjhhhhhK6ubh)}(hhh](h)}(h;Q: Does C-calling convention diminishes possible use cases?h]h;Q: Does C-calling convention diminishes possible use cases?}(hjhhhNhNubah}(h]h ]h"]h$]h&]jj0uh1hhj hhhhhK?ubh)}(hA: YES.h]hA: YES.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK@hj hhubh)}(hXBPF design forces addition of major functionality in the form of kernel helper functions and kernel objects like BPF maps with seamless interoperability between them. It lets kernel call into BPF programs and programs call kernel helpers with zero overhead, as all of them were native C code. That is particularly the case for JITed BPF programs that are indistinguishable from native kernel C code.h]hXBPF design forces addition of major functionality in the form of kernel helper functions and kernel objects like BPF maps with seamless interoperability between them. It lets kernel call into BPF programs and programs call kernel helpers with zero overhead, as all of them were native C code. That is particularly the case for JITed BPF programs that are indistinguishable from native kernel C code.}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKBhj hhubeh}(h]j6ah ]h"];q: does c-calling convention diminishes possible use cases?ah$]h&]uh1hhjhhhhhK?ubh)}(hhh](h)}(hHQ: Does it mean that 'innovative' extensions to BPF code are disallowed?h]hLQ: Does it mean that ‘innovative’ extensions to BPF code are disallowed?}(hjDhhhNhNubah}(h]h ]h"]h$]h&]jjRuh1hhjAhhhhhKKubh)}(h A: Soft yes.h]h A: Soft yes.}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKLhjAhhubh)}(hAt least for now, until BPF core has support for bpf-to-bpf calls, indirect calls, loops, global variables, jump tables, read-only sections, and all other normal constructs that C code can produce.h]hAt least for now, until BPF core has support for bpf-to-bpf calls, indirect calls, loops, global variables, jump tables, read-only sections, and all other normal constructs that C code can produce.}(hj`hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKNhjAhhubeh}(h]jXah ]h"]Hq: does it mean that 'innovative' extensions to bpf code are disallowed?ah$]h&]uh1hhjhhhhhKKubh)}(hhh](h)}(h(Q: Can loops be supported in a safe way?h]h(Q: Can loops be supported in a safe way?}(hjxhhhNhNubah}(h]h ]h"]h$]h&]jjtuh1hhjuhhhhhKTubh)}(hA: It's not clear yet.h]hA: It’s not clear yet.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKUhjuhhubh)}(hABPF developers are trying to find a way to support bounded loops.h]hABPF developers are trying to find a way to support bounded loops.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKWhjuhhubeh}(h]jzah ]h"](q: can loops be supported in a safe way?ah$]h&]uh1hhjhhhhhKTubh)}(hhh](h)}(h Q: What are the verifier limits?h]h Q: What are the verifier limits?}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjhhhhhK[ubh)}(hXAA: The only limit known to the user space is BPF_MAXINSNS (4096). It's the maximum number of instructions that the unprivileged bpf program can have. The verifier has various internal limits. Like the maximum number of instructions that can be explored during program analysis. Currently, that limit is set to 1 million. Which essentially means that the largest program can consist of 1 million NOP instructions. There is a limit to the maximum number of subsequent branches, a limit to the number of nested bpf-to-bpf calls, a limit to the number of the verifier states per instruction, a limit to the number of maps used by the program. All these limits can be hit with a sufficiently complex program. There are also non-numerical limits that can cause the program to be rejected. The verifier used to recognize only pointer + constant expressions. Now it can recognize pointer + bounded_register. bpf_lookup_map_elem(key) had a requirement that 'key' must be a pointer to the stack. Now, 'key' can be a pointer to map value. The verifier is steadily getting 'smarter'. The limits are being removed. The only way to know that the program is going to be accepted by the verifier is to try to load it. The bpf development process guarantees that the future kernel versions will accept all bpf programs that were accepted by the earlier versions.h]hXOA: The only limit known to the user space is BPF_MAXINSNS (4096). It’s the maximum number of instructions that the unprivileged bpf program can have. The verifier has various internal limits. Like the maximum number of instructions that can be explored during program analysis. Currently, that limit is set to 1 million. Which essentially means that the largest program can consist of 1 million NOP instructions. There is a limit to the maximum number of subsequent branches, a limit to the number of nested bpf-to-bpf calls, a limit to the number of the verifier states per instruction, a limit to the number of maps used by the program. All these limits can be hit with a sufficiently complex program. There are also non-numerical limits that can cause the program to be rejected. The verifier used to recognize only pointer + constant expressions. Now it can recognize pointer + bounded_register. bpf_lookup_map_elem(key) had a requirement that ‘key’ must be a pointer to the stack. Now, ‘key’ can be a pointer to map value. The verifier is steadily getting ‘smarter’. The limits are being removed. The only way to know that the program is going to be accepted by the verifier is to try to load it. The bpf development process guarantees that the future kernel versions will accept all bpf programs that were accepted by the earlier versions.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK\hjhhubeh}(h]jah ]h"] q: what are the verifier limits?ah$]h&]uh1hhjhhhhhK[ubh)}(hhh](h)}(hInstruction level questionsh]hInstruction level questions}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjhhhhhKuubh)}(hhh](h)}(h+Q: LD_ABS and LD_IND instructions vs C codeh]h+Q: LD_ABS and LD_IND instructions vs C code}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjhhhhhKxubh)}(hQ: How come LD_ABS and LD_IND instruction are present in BPF whereas C code cannot express them and has to use builtin intrinsics?h]hQ: How come LD_ABS and LD_IND instruction are present in BPF whereas C code cannot express them and has to use builtin intrinsics?}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKzhjhhubh)}(hA: This is artifact of compatibility with classic BPF. Modern networking code in BPF performs better without them. See 'direct packet access'.h]hA: This is artifact of compatibility with classic BPF. Modern networking code in BPF performs better without them. See ‘direct packet access’.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK}hjhhubeh}(h]jah ]h"]+q: ld_abs and ld_ind instructions vs c codeah$]h&]uh1hhjhhhhhKxubh)}(hhh](h)}(h8Q: BPF instructions mapping not one-to-one to native CPUh]h8Q: BPF instructions mapping not one-to-one to native CPU}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjhhhhhKubh)}(hQ: It seems not all BPF instructions are one-to-one to native CPU. For example why BPF_JNE and other compare and jumps are not cpu-like?h]hQ: It seems not all BPF instructions are one-to-one to native CPU. For example why BPF_JNE and other compare and jumps are not cpu-like?}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hA: This was necessary to avoid introducing flags into ISA which are impossible to make generic and efficient across CPU architectures.h]hA: This was necessary to avoid introducing flags into ISA which are impossible to make generic and efficient across CPU architectures.}(hj3hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]jah ]h"]8q: bpf instructions mapping not one-to-one to native cpuah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h2Q: Why BPF_DIV instruction doesn't map to x64 div?h]h4Q: Why BPF_DIV instruction doesn’t map to x64 div?}(hjKhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjHhhhhhKubh)}(hA: Because if we picked one-to-one relationship to x64 it would have made it more complicated to support on arm64 and other archs. Also it needs div-by-zero runtime check.h]hA: Because if we picked one-to-one relationship to x64 it would have made it more complicated to support on arm64 and other archs. Also it needs div-by-zero runtime check.}(hjYhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjHhhubeh}(h]j!ah ]h"]2q: why bpf_div instruction doesn't map to x64 div?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h.Q: Why BPF has implicit prologue and epilogue?h]h.Q: Why BPF has implicit prologue and epilogue?}(hjqhhhNhNubah}(h]h ]h"]h$]h&]jj=uh1hhjnhhhhhKubh)}(hXaA: Because architectures like sparc have register windows and in general there are enough subtle differences between architectures, so naive store return address into stack won't work. Another reason is BPF has to be safe from division by zero (and legacy exception path of LD_ABS insn). Those instructions need to invoke epilogue and return implicitly.h]hXcA: Because architectures like sparc have register windows and in general there are enough subtle differences between architectures, so naive store return address into stack won’t work. Another reason is BPF has to be safe from division by zero (and legacy exception path of LD_ABS insn). Those instructions need to invoke epilogue and return implicitly.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjnhhubeh}(h]jCah ]h"].q: why bpf has implicit prologue and epilogue?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(hMQ: Why BPF_JLT and BPF_JLE instructions were not introduced in the beginning?h]hMQ: Why BPF_JLT and BPF_JLE instructions were not introduced in the beginning?}(hjhhhNhNubah}(h]h ]h"]h$]h&]jj_uh1hhjhhhhhKubh)}(hXA: Because classic BPF didn't have them and BPF authors felt that compiler workaround would be acceptable. Turned out that programs lose performance due to lack of these compare instructions and they were added. These two instructions is a perfect example what kind of new BPF instructions are acceptable and can be added in the future. These two already had equivalent instructions in native CPUs. New instructions that don't have one-to-one mapping to HW instructions will not be accepted.h]hXA: Because classic BPF didn’t have them and BPF authors felt that compiler workaround would be acceptable. Turned out that programs lose performance due to lack of these compare instructions and they were added. These two instructions is a perfect example what kind of new BPF instructions are acceptable and can be added in the future. These two already had equivalent instructions in native CPUs. New instructions that don’t have one-to-one mapping to HW instructions will not be accepted.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]jeah ]h"]Mq: why bpf_jlt and bpf_jle instructions were not introduced in the beginning?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h&Q: BPF 32-bit subregister requirementsh]h&Q: BPF 32-bit subregister requirements}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjhhhhhKubh)}(hQ: BPF 32-bit subregisters have a requirement to zero upper 32-bits of BPF registers which makes BPF inefficient virtual machine for 32-bit CPU architectures and 32-bit HW accelerators. Can true 32-bit registers be added to BPF in the future?h]hQ: BPF 32-bit subregisters have a requirement to zero upper 32-bits of BPF registers which makes BPF inefficient virtual machine for 32-bit CPU architectures and 32-bit HW accelerators. Can true 32-bit registers be added to BPF in the future?}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hA: NO.h]hA: NO.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hBut some optimizations on zero-ing the upper 32 bits for BPF registers are available, and can be leveraged to improve the performance of JITed BPF programs for 32-bit architectures.h]hBut some optimizations on zero-ing the upper 32 bits for BPF registers are available, and can be leveraged to improve the performance of JITed BPF programs for 32-bit architectures.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXStarting with version 7, LLVM is able to generate instructions that operate on 32-bit subregisters, provided the option -mattr=+alu32 is passed for compiling a program. Furthermore, the verifier can now mark the instructions for which zero-ing the upper bits of the destination register is required, and insert an explicit zero-extension (zext) instruction (a mov32 variant). This means that for architectures without zext hardware support, the JIT back-ends do not need to clear the upper bits for subregisters written by alu32 instructions or narrow loads. Instead, the back-ends simply need to support code generation for that mov32 variant, and to overwrite bpf_jit_needs_zext() to make it return "true" (in order to enable zext insertion in the verifier).h]hXStarting with version 7, LLVM is able to generate instructions that operate on 32-bit subregisters, provided the option -mattr=+alu32 is passed for compiling a program. Furthermore, the verifier can now mark the instructions for which zero-ing the upper bits of the destination register is required, and insert an explicit zero-extension (zext) instruction (a mov32 variant). This means that for architectures without zext hardware support, the JIT back-ends do not need to clear the upper bits for subregisters written by alu32 instructions or narrow loads. Instead, the back-ends simply need to support code generation for that mov32 variant, and to overwrite bpf_jit_needs_zext() to make it return “true” (in order to enable zext insertion in the verifier).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXNote that it is possible for a JIT back-end to have partial hardware support for zext. In that case, if verifier zext insertion is enabled, it could lead to the insertion of unnecessary zext instructions. Such instructions could be removed by creating a simple peephole inside the JIT back-end: if one instruction has hardware support for zext and if the next instruction is an explicit zext, then the latter can be skipped when doing the code generation.h]hXNote that it is possible for a JIT back-end to have partial hardware support for zext. In that case, if verifier zext insertion is enabled, it could lead to the insertion of unnecessary zext instructions. Such instructions could be removed by creating a simple peephole inside the JIT back-end: if one instruction has hardware support for zext and if the next instruction is an explicit zext, then the latter can be skipped when doing the code generation.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]jah ]h"]&q: bpf 32-bit subregister requirementsah$]h&]uh1hhjhhhhhKubeh}(h]jah ]h"]instruction level questionsah$]h&]uh1hhjhhhhhKuubh)}(hhh](h)}(hQ: Does BPF have a stable ABI?h]hQ: Does BPF have a stable ABI?}(hj" hhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhj hhhhhKubh)}(hXA: YES. BPF instructions, arguments to BPF programs, set of helper functions and their arguments, recognized return codes are all part of ABI. However there is one specific exception to tracing programs which are using helpers like bpf_probe_read() to walk kernel internal data structures and compile with kernel internal headers. Both of these kernel internals are subject to change and can break with newer kernels such that the program needs to be adapted accordingly.h]hXA: YES. BPF instructions, arguments to BPF programs, set of helper functions and their arguments, recognized return codes are all part of ABI. However there is one specific exception to tracing programs which are using helpers like bpf_probe_read() to walk kernel internal data structures and compile with kernel internal headers. Both of these kernel internals are subject to change and can break with newer kernels such that the program needs to be adapted accordingly.}(hj0 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj hhubh)}(hNew BPF functionality is generally added through the use of kfuncs instead of new helpers. Kfuncs are not considered part of the stable API, and have their own lifecycle expectations as described in :ref:`BPF_kfunc_lifecycle_expectations`.h](hNew BPF functionality is generally added through the use of kfuncs instead of new helpers. Kfuncs are not considered part of the stable API, and have their own lifecycle expectations as described in }(hj> hhhNhNubh)}(h':ref:`BPF_kfunc_lifecycle_expectations`h]hinline)}(hjH h]h BPF_kfunc_lifecycle_expectations}(hjL hhhNhNubah}(h]h ](xrefstdstd-refeh"]h$]h&]uh1jJ hjF ubah}(h]h ]h"]h$]h&]refdocbpf/bpf_design_QA refdomainjW reftyperef refexplicitrefwarn reftarget bpf_kfunc_lifecycle_expectationsuh1hhhhKhj> ubh.}(hj> hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj hhubeh}(h]jah ]h"]q: does bpf have a stable abi?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h*Q: Are tracepoints part of the stable ABI?h]h*Q: Are tracepoints part of the stable ABI?}(hj hhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhj| hhhhhKubh)}(hA: NO. Tracepoints are tied to internal implementation details hence they are subject to change and can break with newer kernels. BPF programs need to change accordingly when this happens.h]hA: NO. Tracepoints are tied to internal implementation details hence they are subject to change and can break with newer kernels. BPF programs need to change accordingly when this happens.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj| hhubeh}(h]jah ]h"]*q: are tracepoints part of the stable abi?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h>Q: Are places where kprobes can attach part of the stable ABI?h]h>Q: Are places where kprobes can attach part of the stable ABI?}(hj hhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhj hhhhhKubh)}(hA: NO. The places to which kprobes can attach are internal implementation details, which means that they are subject to change and can break with newer kernels. BPF programs need to change accordingly when this happens.h]hA: NO. The places to which kprobes can attach are internal implementation details, which means that they are subject to change and can break with newer kernels. BPF programs need to change accordingly when this happens.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj hhubeh}(h]jah ]h"]>q: are places where kprobes can attach part of the stable abi?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h+Q: How much stack space a BPF program uses?h]h+Q: How much stack space a BPF program uses?}(hj hhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhj hhhhhKubh)}(hA: Currently all program types are limited to 512 bytes of stack space, but the verifier computes the actual amount of stack used and both interpreter and most JITed code consume necessary amount.h]hA: Currently all program types are limited to 512 bytes of stack space, but the verifier computes the actual amount of stack used and both interpreter and most JITed code consume necessary amount.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj hhubeh}(h]jah ]h"]+q: how much stack space a bpf program uses?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(hQ: Can BPF be offloaded to HW?h]hQ: Can BPF be offloaded to HW?}(hj hhhNhNubah}(h]h ]h"]h$]h&]jj7uh1hhj hhhhhKubh)}(h2A: YES. BPF HW offload is supported by NFP driver.h]h2A: YES. BPF HW offload is supported by NFP driver.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj hhubeh}(h]j=ah ]h"]q: can bpf be offloaded to hw?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h,Q: Does classic BPF interpreter still exist?h]h,Q: Does classic BPF interpreter still exist?}(hj hhhNhNubah}(h]h ]h"]h$]h&]jjYuh1hhj hhhhhKubh)}(hGA: NO. Classic BPF programs are converted into extend BPF instructions.h]hGA: NO. Classic BPF programs are converted into extend BPF instructions.}(hj% hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj hhubeh}(h]j_ah ]h"],q: does classic bpf interpreter still exist?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h+Q: Can BPF call arbitrary kernel functions?h]h+Q: Can BPF call arbitrary kernel functions?}(hj= hhhNhNubah}(h]h ]h"]h$]h&]jj{uh1hhj: hhhhhKubh)}(hA: NO. BPF programs can only call specific functions exposed as BPF helpers or kfuncs. The set of available functions is defined for every program type.h]hA: NO. BPF programs can only call specific functions exposed as BPF helpers or kfuncs. The set of available functions is defined for every program type.}(hjK hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj: hhubeh}(h]jah ]h"]+q: can bpf call arbitrary kernel functions?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h-Q: Can BPF overwrite arbitrary kernel memory?h]h-Q: Can BPF overwrite arbitrary kernel memory?}(hjc hhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhj` hhhhhKubh)}(hA: NO.h]hA: NO.}(hjq hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj` hhubh)}(hXTracing bpf programs can *read* arbitrary memory with bpf_probe_read() and bpf_probe_read_str() helpers. Networking programs cannot read arbitrary memory, since they don't have access to these helpers. Programs can never read or write arbitrary memory directly.h](hTracing bpf programs can }(hj hhhNhNubjF)}(h*read*h]hread}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jEhj ubh arbitrary memory with bpf_probe_read() and bpf_probe_read_str() helpers. Networking programs cannot read arbitrary memory, since they don’t have access to these helpers. Programs can never read or write arbitrary memory directly.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj` hhubeh}(h]jah ]h"]-q: can bpf overwrite arbitrary kernel memory?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h+Q: Can BPF overwrite arbitrary user memory?h]h+Q: Can BPF overwrite arbitrary user memory?}(hj hhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhj hhhhhKubh)}(h A: Sort-of.h]h A: Sort-of.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj hhubh)}(hXTracing BPF programs can overwrite the user memory of the current task with bpf_probe_write_user(). Every time such program is loaded the kernel will print warning message, so this helper is only useful for experiments and prototypes. Tracing BPF programs are root only.h]hXTracing BPF programs can overwrite the user memory of the current task with bpf_probe_write_user(). Every time such program is loaded the kernel will print warning message, so this helper is only useful for experiments and prototypes. Tracing BPF programs are root only.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj hhubeh}(h]jah ]h"]+q: can bpf overwrite arbitrary user memory?ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h(Q: New functionality via kernel modules?h]h(Q: New functionality via kernel modules?}(hj hhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhj hhhhhMubh)}(hoQ: Can BPF functionality such as new program or map types, new helpers, etc be added out of kernel module code?h]hoQ: Can BPF functionality such as new program or map types, new helpers, etc be added out of kernel module code?}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(h A: Yes, through kfuncs and kptrsh]h A: Yes, through kfuncs and kptrs}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj hhubh)}(hThe core BPF functionality such as program types, maps and helpers cannot be added to by modules. However, modules can expose functionality to BPF programs by exporting kfuncs (which may return pointers to module-internal data structures as kptrs).h]hThe core BPF functionality such as program types, maps and helpers cannot be added to by modules. However, modules can expose functionality to BPF programs by exporting kfuncs (which may return pointers to module-internal data structures as kptrs).}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj hhubeh}(h]jah ]h"](q: new functionality via kernel modules?ah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h.Q: Directly calling kernel function is an ABI?h]h.Q: Directly calling kernel function is an ABI?}(hj hhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhj hhhhhMubh)}(hwQ: Some kernel functions (e.g. tcp_slow_start) can be called by BPF programs. Do these kernel functions become an ABI?h]hwQ: Some kernel functions (e.g. tcp_slow_start) can be called by BPF programs. Do these kernel functions become an ABI?}(hj- hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hA: NO.h]hA: NO.}(hj; hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hXThe kernel function protos will change and the bpf programs will be rejected by the verifier. Also, for example, some of the bpf-callable kernel functions have already been used by other kernel tcp cc (congestion-control) implementations. If any of these kernel functions has changed, both the in-tree and out-of-tree kernel tcp cc implementations have to be changed. The same goes for the bpf programs and they have to be adjusted accordingly. See :ref:`BPF_kfunc_lifecycle_expectations` for details.h](hXThe kernel function protos will change and the bpf programs will be rejected by the verifier. Also, for example, some of the bpf-callable kernel functions have already been used by other kernel tcp cc (congestion-control) implementations. If any of these kernel functions has changed, both the in-tree and out-of-tree kernel tcp cc implementations have to be changed. The same goes for the bpf programs and they have to be adjusted accordingly. See }(hjI hhhNhNubh)}(h':ref:`BPF_kfunc_lifecycle_expectations`h]jK )}(hjS h]h BPF_kfunc_lifecycle_expectations}(hjU hhhNhNubah}(h]h ](jV stdstd-refeh"]h$]h&]uh1jJ hjQ ubah}(h]h ]h"]h$]h&]refdocjc refdomainj_ reftyperef refexplicitrefwarnji bpf_kfunc_lifecycle_expectationsuh1hhhhMhjI ubh for details.}(hjI hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj hhubeh}(h]j ah ]h"].q: directly calling kernel function is an abi?ah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h5Q: Attaching to arbitrary kernel functions is an ABI?h]h5Q: Attaching to arbitrary kernel functions is an ABI?}(hj hhhNhNubah}(h]h ]h"]h$]h&]jj%uh1hhj hhhhhM!ubh)}(hlQ: BPF programs can be attached to many kernel functions. Do these kernel functions become part of the ABI?h]hlQ: BPF programs can be attached to many kernel functions. Do these kernel functions become part of the ABI?}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM"hj hhubh)}(hA: NO.h]hA: NO.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM%hj hhubh)}(hThe kernel function prototypes will change, and BPF programs attaching to them will need to change. The BPF compile-once-run-everywhere (CO-RE) should be used in order to make it easier to adapt your BPF programs to different versions of the kernel.h]hThe kernel function prototypes will change, and BPF programs attaching to them will need to change. The BPF compile-once-run-everywhere (CO-RE) should be used in order to make it easier to adapt your BPF programs to different versions of the kernel.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM'hj hhubeh}(h]j+ah ]h"]5q: attaching to arbitrary kernel functions is an abi?ah$]h&]uh1hhjhhhhhM!ubh)}(hhh](h)}(h=Q: Marking a function with BTF_ID makes that function an ABI?h]h=Q: Marking a function with BTF_ID makes that function an ABI?}(hj hhhNhNubah}(h]h ]h"]h$]h&]jjGuh1hhj hhhhhM-ubh)}(hA: NO.h]hA: NO.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM.hj hhubh)}(htThe BTF_ID macro does not cause a function to become part of the ABI any more than does the EXPORT_SYMBOL_GPL macro.h]htThe BTF_ID macro does not cause a function to become part of the ABI any more than does the EXPORT_SYMBOL_GPL macro.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM0hj hhubeh}(h]jMah ]h"]=q: marking a function with btf_id makes that function an abi?ah$]h&]uh1hhjhhhhhM-ubh)}(hhh](h)}(hGQ: What is the compatibility story for special BPF types in map values?h]hGQ: What is the compatibility story for special BPF types in map values?}(hj hhhNhNubah}(h]h ]h"]h$]h&]jjiuh1hhj hhhhhM4ubh)}(hX{Q: Users are allowed to embed bpf_spin_lock, bpf_timer fields in their BPF map values (when using BTF support for BPF maps). This allows to use helpers for such objects on these fields inside map values. Users are also allowed to embed pointers to some kernel types (with __kptr_untrusted and __kptr BTF tags). Will the kernel preserve backwards compatibility for these features?h]hX{Q: Users are allowed to embed bpf_spin_lock, bpf_timer fields in their BPF map values (when using BTF support for BPF maps). This allows to use helpers for such objects on these fields inside map values. Users are also allowed to embed pointers to some kernel types (with __kptr_untrusted and __kptr BTF tags). Will the kernel preserve backwards compatibility for these features?}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM5hj hhubh)}(hbA: It depends. For bpf_spin_lock, bpf_timer: YES, for kptr and everything else: NO, but see below.h]hbA: It depends. For bpf_spin_lock, bpf_timer: YES, for kptr and everything else: NO, but see below.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM;hj hhubh)}(hFor struct types that have been added already, like bpf_spin_lock and bpf_timer, the kernel will preserve backwards compatibility, as they are part of UAPI.h]hFor struct types that have been added already, like bpf_spin_lock and bpf_timer, the kernel will preserve backwards compatibility, as they are part of UAPI.}(hj% hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM>hj hhubh)}(hXFor kptrs, they are also part of UAPI, but only with respect to the kptr mechanism. The types that you can use with a __kptr_untrusted and __kptr tagged pointer in your struct are NOT part of the UAPI contract. The supported types can and will change across kernel releases. However, operations like accessing kptr fields and bpf_kptr_xchg() helper will continue to be supported across kernel releases for the supported types.h]hXFor kptrs, they are also part of UAPI, but only with respect to the kptr mechanism. The types that you can use with a __kptr_untrusted and __kptr tagged pointer in your struct are NOT part of the UAPI contract. The supported types can and will change across kernel releases. However, operations like accessing kptr fields and bpf_kptr_xchg() helper will continue to be supported across kernel releases for the supported types.}(hj3 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMAhj hhubh)}(hXFor any other supported struct type, unless explicitly stated in this document and added to bpf.h UAPI header, such types can and will arbitrarily change their size, type, and alignment, or any other user visible API or ABI detail across kernel releases. The users must adapt their BPF programs to the new changes and update them to make sure their programs continue to work correctly.h]hXFor any other supported struct type, unless explicitly stated in this document and added to bpf.h UAPI header, such types can and will arbitrarily change their size, type, and alignment, or any other user visible API or ABI detail across kernel releases. The users must adapt their BPF programs to the new changes and update them to make sure their programs continue to work correctly.}(hjA hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMHhj hhubh)}(hXSNOTE: BPF subsystem specially reserves the 'bpf\_' prefix for type names, in order to introduce more special fields in the future. Hence, user programs must avoid defining types with 'bpf\_' prefix to not be broken in future releases. In other words, no backwards compatibility is guaranteed if one using a type in BTF with 'bpf\_' prefix.h]hX_NOTE: BPF subsystem specially reserves the ‘bpf_’ prefix for type names, in order to introduce more special fields in the future. Hence, user programs must avoid defining types with ‘bpf_’ prefix to not be broken in future releases. In other words, no backwards compatibility is guaranteed if one using a type in BTF with ‘bpf_’ prefix.}(hjO hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMNhj hhubeh}(h]joah ]h"]Gq: what is the compatibility story for special bpf types in map values?ah$]h&]uh1hhjhhhhhM4ubh)}(hhh](h)}(hNQ: What is the compatibility story for special BPF types in allocated objects?h]hNQ: What is the compatibility story for special BPF types in allocated objects?}(hjg hhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjd hhhhhMUubh)}(hQ: Same as above, but for allocated objects (i.e. objects allocated using bpf_obj_new for user defined types). Will the kernel preserve backwards compatibility for these features?h]hQ: Same as above, but for allocated objects (i.e. objects allocated using bpf_obj_new for user defined types). Will the kernel preserve backwards compatibility for these features?}(hju hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMVhjd hhubh)}(hA: NO.h]hA: NO.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMZhjd hhubh)}(hXUnlike map value types, the API to work with allocated objects and any support for special fields inside them is exposed through kfuncs, and thus has the same lifecycle expectations as the kfuncs themselves. See :ref:`BPF_kfunc_lifecycle_expectations` for details.h](hUnlike map value types, the API to work with allocated objects and any support for special fields inside them is exposed through kfuncs, and thus has the same lifecycle expectations as the kfuncs themselves. See }(hj hhhNhNubh)}(h':ref:`BPF_kfunc_lifecycle_expectations`h]jK )}(hj h]h BPF_kfunc_lifecycle_expectations}(hj hhhNhNubah}(h]h ](jV stdstd-refeh"]h$]h&]uh1jJ hj ubah}(h]h ]h"]h$]h&]refdocjc refdomainj reftyperef refexplicitrefwarnji bpf_kfunc_lifecycle_expectationsuh1hhhhM\hj ubh for details.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM\hjd hhubeh}(h]jah ]h"]Nq: what is the compatibility story for special bpf types in allocated objects?ah$]h&]uh1hhjhhhhhMUubeh}(h]hah ]h"]questions and answersah$]h&]uh1hhhhhhhhKubeh}(h]bpf-design-q-aah ]h"]bpf design q&aah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerj error_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(j j jjj hjj jj+jjaj]jjjjjjjj jj>j6jrjXjjzjjj jjjjEjjkj!jjCjjej jjy jj jj jj jj j=j7 j_j] jj jj jj jj j j j+j jMja joj ju nametypes}(j jj jjjj]jjjj j>jrjjj jjEjkjjj jy j j j j j7 j] j j j j j j ja j uh}(j hjhhjj jj+jjajjj:jj`jjjjjjj6j jXjAjzjujjjjjjjjj!jHjCjnjejjjjj jj| jj jj j=j j_j jj: jj` jj jj j j j+j jMj joj jjd hhjhj%jj[j>jzjqjjjjjjjjj0j'jRjIjtjkjjjjjjjjjjj=j4j_jVjjxjjjjjjjj j7j.jYjPj{jrjjjjjjjjj%jjGj>jij`jju footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}j K#sRparse_messages]transform_messages] transformerN include_log] decorationNhhub.