Qsphinx.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/linux-notesmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget#/translations/zh_TW/bpf/linux-notesmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget#/translations/it_IT/bpf/linux-notesmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget#/translations/ja_JP/bpf/linux-notesmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget#/translations/ko_KR/bpf/linux-notesmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget#/translations/sp_SP/bpf/linux-notesmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhtopic)}(h Contents h](htitle)}(hContentsh]hContents}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhh=/var/lib/git/docbuild/linux/Documentation/bpf/linux-notes.rsthKubh bullet_list)}(hhh]h list_item)}(hhh](h paragraph)}(hhh]h reference)}(hhh](h generated)}(hhh]h1   }(hhhhhNhNubah}(h]h ]sectnumah"]h$]h&]uh1hhNhNhhubhLinux implementation notes}(hhhhhNhNubeh}(h]id1ah ]h"]h$]h&]refidlinux-implementation-notesuh1hhhubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh](h)}(hhh]h)}(hhh]h)}(hhh](h)}(hhh]h 1.1   }(hhhhhNhNubah}(h]h ]hah"]h$]h&]uh1hhNhNhhubhByte swap instructions}(hhhhhNhNubeh}(h]id2ah ]h"]h$]h&]refidbyte-swap-instructionsuh1hhhubah}(h]h ]h"]h$]h&]uh1hhhubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh](h)}(hhh]h 1.2   }(hj*hhhNhNubah}(h]h ]hah"]h$]h&]uh1hhNhNhj'ubhJump instructions}(hj'hhhNhNubeh}(h]id3ah ]h"]h$]h&]refidjump-instructionsuh1hhj$ubah}(h]h ]h"]h$]h&]uh1hhj!ubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh](h)}(hhh]h 1.3   }(hjYhhhNhNubah}(h]h ]hah"]h$]h&]uh1hhNhNhjVubhMaps}(hjVhhhNhNubeh}(h]id4ah ]h"]h$]h&]refidmapsuh1hhjSubah}(h]h ]h"]h$]h&]uh1hhjPubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh](h)}(hhh]h 1.4   }(hjhhhNhNubah}(h]h ]hah"]h$]h&]uh1hhNhNhjubh Variables}(hjhhhNhNubeh}(h]id5ah ]h"]h$]h&]refid variablesuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh](h)}(hhh]h 1.5   }(hjhhhNhNubah}(h]h ]hah"]h$]h&]uh1hhNhNhjubh%Legacy BPF Packet access instructions}(hjhhhNhNubeh}(h]id6ah ]h"]h$]h&]refid%legacy-bpf-packet-access-instructionsuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhhubeh}(h]h ]auto-tocah"]h$]h&]uh1hhhubeh}(h]h ]h"]h$]h&]uh1hhhubah}(h]h ]jah"]h$]h&]uh1hhhhhhNhNubeh}(h]contentsah ]contentsah"]contentsah$]h&]uh1hhhhKhhhhubhsection)}(hhh](h)}(hLinux implementation notesh](h)}(hhh]h1   }(hjhhhNhNubah}(h]h ]hah"]h$]h&]uh1hhjhhhNhNubhLinux implementation notes}(hjhhhNhNubeh}(h]h ]h"]h$]h&]autoKrefidhuh1hhjhhhhhKubh)}(hlThis document provides more details specific to the Linux kernel implementation of the eBPF instruction set.h]hlThis document provides more details specific to the Linux kernel implementation of the eBPF instruction set.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hhh](h)}(hByte swap instructionsh](h)}(hhh]h 1.1   }(hj0hhhNhNubah}(h]h ]hah"]h$]h&]uh1hhj,hhhNhNubhByte swap instructions}(hj,hhhNhNubeh}(h]h ]h"]h$]h&]jKjjuh1hhj)hhhhhK ubh)}(hf``BPF_FROM_LE`` and ``BPF_FROM_BE`` exist as aliases for ``BPF_TO_LE`` and ``BPF_TO_BE`` respectively.h](hliteral)}(h``BPF_FROM_LE``h]h BPF_FROM_LE}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjGubh and }(hjGhhhNhNubjL)}(h``BPF_FROM_BE``h]h BPF_FROM_BE}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjGubh exist as aliases for }(hjGhhhNhNubjL)}(h ``BPF_TO_LE``h]h BPF_TO_LE}(hjqhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjGubh and }hjGsbjL)}(h ``BPF_TO_BE``h]h BPF_TO_BE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjGubh respectively.}(hjGhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK hj)hhubeh}(h]jah ]h"]byte swap instructionsah$]h&]uh1jhjhhhhhK ubj)}(hhh](h)}(hJump instructionsh](h)}(hhh]h 1.2   }(hjhhhNhNubah}(h]h ]hah"]h$]h&]uh1hhjhhhNhNubhJump instructions}(hjhhhNhNubeh}(h]h ]h"]h$]h&]jKjj=uh1hhjhhhhhKubh)}(h``BPF_CALL | BPF_X | BPF_JMP`` (0x8d), where the helper function integer would be read from a specified register, is not currently supported by the verifier. Any programs with this instruction will fail to load until such support is added.h](jL)}(h``BPF_CALL | BPF_X | BPF_JMP``h]hBPF_CALL | BPF_X | BPF_JMP}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh (0x8d), where the helper function integer would be read from a specified register, is not currently supported by the verifier. Any programs with this instruction will fail to load until such support is added.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]jCah ]h"]jump instructionsah$]h&]uh1jhjhhhhhKubj)}(hhh](h)}(hMapsh](h)}(hhh]h 1.3   }(hjhhhNhNubah}(h]h ]hah"]h$]h&]uh1hhjhhhNhNubhMaps}(hjhhhNhNubeh}(h]h ]h"]h$]h&]jKjjluh1hhjhhhhhKubh)}(hULinux only supports the 'map_val(map)' operation on array maps with a single element.h]hYLinux only supports the ‘map_val(map)’ operation on array maps with a single element.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hLinux uses an fd_array to store maps associated with a BPF program. Thus, map_by_idx(imm) uses the fd at that index in the array.h]hLinux uses an fd_array to store maps associated with a BPF program. Thus, map_by_idx(imm) uses the fd at that index in the array.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]jrah ]h"]mapsah$]h&]uh1jhjhhhhhKubj)}(hhh](h)}(h Variablesh](h)}(hhh]h 1.4   }(hj+hhhNhNubah}(h]h ]hah"]h$]h&]uh1hhj'hhhNhNubh Variables}(hj'hhhNhNubeh}(h]h ]h"]h$]h&]jKjjuh1hhj$hhhhhK ubh)}(hThe following 64-bit immediate instruction specifies that a variable address, which corresponds to some integer stored in the 'imm' field, should be loaded:h]hThe following 64-bit immediate instruction specifies that a variable address, which corresponds to some integer stored in the ‘imm’ field, should be loaded:}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK"hj$hhubhtable)}(hhh]htgroup)}(hhh](hcolspec)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jZhjWubj[)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jZhjWubj[)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jZhjWubj[)}(hhh]h}(h]h ]h"]h$]h&]colwidthK)uh1jZhjWubj[)}(hhh]h}(h]h ]h"]h$]h&]colwidthK uh1jZhjWubj[)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jZhjWubhthead)}(hhh]hrow)}(hhh](hentry)}(hhh]h)}(hopcode constructionh]hopcode construction}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK&hjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hopcodeh]hopcode}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK&hjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hsrch]hsrc}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK&hjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h pseudocodeh]h pseudocode}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK&hjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(himm typeh]himm type}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK&hjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hdst typeh]hdst type}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK&hjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjWubhtbody)}(hhh]j)}(hhh](j)}(hhh]h)}(hBPF_IMM | BPF_DW | BPF_LDh]hBPF_IMM | BPF_DW | BPF_LD}(hjEhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK(hjBubah}(h]h ]h"]h$]h&]uh1jhj?ubj)}(hhh]h)}(h0x18h]h0x18}(hj\hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK(hjYubah}(h]h ]h"]h$]h&]uh1jhj?ubj)}(hhh]h)}(h0x3h]h0x3}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK(hjpubah}(h]h ]h"]h$]h&]uh1jhj?ubj)}(hhh]h)}(hdst = var_addr(imm)h]hdst = var_addr(imm)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK(hjubah}(h]h ]h"]h$]h&]uh1jhj?ubj)}(hhh]h)}(h variable idh]h variable id}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK(hjubah}(h]h ]h"]h$]h&]uh1jhj?ubj)}(hhh]h)}(h data pointerh]h data pointer}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK(hjubah}(h]h ]h"]h$]h&]uh1jhj?ubeh}(h]h ]h"]h$]h&]uh1jhj<ubah}(h]h ]h"]h$]h&]uh1j:hjWubeh}(h]h ]h"]h$]h&]colsKuh1jUhjRubah}(h]h ]h"]h$]h&]uh1jPhj$hhhhhNubh)}(h#On Linux, this integer is a BTF ID.h]h#On Linux, this integer is a BTF ID.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK+hj$hhubeh}(h]jah ]h"] variablesah$]h&]uh1jhjhhhhhK ubj)}(hhh](h)}(h%Legacy BPF Packet access instructionsh](h)}(hhh]h 1.5   }(hjhhhNhNubah}(h]h ]hah"]h$]h&]uh1hhjhhhNhNubh%Legacy BPF Packet access instructions}(hjhhhNhNubeh}(h]h ]h"]h$]h&]jKjjuh1hhjhhhhhK.ubh)}(hX.As mentioned in the `ISA standard documentation `_, Linux has special eBPF instructions for access to packet data that have been carried over from classic BPF to retain the performance of legacy socket filters running in the eBPF interpreter.h](hAs mentioned in the }(hjhhhNhNubh)}(hZ`ISA standard documentation `_h]hISA standard documentation}(hj hhhNhNubah}(h]h ]h"]h$]h&]nameISA standard documentationrefuri:instruction-set.html#legacy-bpf-packet-access-instructionsuh1hhjubhtarget)}(h= h]h}(h]isa-standard-documentationah ]h"]isa standard documentationah$]h&]refurij1uh1j2 referencedKhjubh, Linux has special eBPF instructions for access to packet data that have been carried over from classic BPF to retain the performance of legacy socket filters running in the eBPF interpreter.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK0hjhhubh)}(hdThe instructions come in two forms: ``BPF_ABS | | BPF_LD`` and ``BPF_IND | | BPF_LD``.h](h$The instructions come in two forms: }(hjLhhhNhNubjL)}(h``BPF_ABS | | BPF_LD``h]hBPF_ABS | | BPF_LD}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjLubh and }(hjLhhhNhNubjL)}(h``BPF_IND | | BPF_LD``h]hBPF_IND | | BPF_LD}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjLubh.}(hjLhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK6hjhhubh)}(hXUThese instructions are used to access packet data and can only be used when the program context is a pointer to a networking packet. ``BPF_ABS`` accesses packet data at an absolute offset specified by the immediate data and ``BPF_IND`` access packet data at an offset that includes the value of a register in addition to the immediate data.h](hThese instructions are used to access packet data and can only be used when the program context is a pointer to a networking packet. }(hj~hhhNhNubjL)}(h ``BPF_ABS``h]hBPF_ABS}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj~ubhP accesses packet data at an absolute offset specified by the immediate data and }(hj~hhhNhNubjL)}(h ``BPF_IND``h]hBPF_IND}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj~ubhi access packet data at an offset that includes the value of a register in addition to the immediate data.}(hj~hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK9hjhhubh)}(h0These instructions have seven implicit operands:h]h0These instructions have seven implicit operands:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK?hjhhubh)}(hhh](h)}(hQRegister R6 is an implicit input that must contain a pointer to a struct sk_buff.h]h)}(hQRegister R6 is an implicit input that must contain a pointer to a struct sk_buff.h]hQRegister R6 is an implicit input that must contain a pointer to a struct sk_buff.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKAhjubah}(h]h ]h"]h$]h&]uh1hhjhhhhhNubh)}(hRRegister R0 is an implicit output which contains the data fetched from the packet.h]h)}(hRRegister R0 is an implicit output which contains the data fetched from the packet.h]hRRegister R0 is an implicit output which contains the data fetched from the packet.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKChjubah}(h]h ]h"]h$]h&]uh1hhjhhhhhNubh)}(hMRegisters R1-R5 are scratch registers that are clobbered by the instruction. h]h)}(hLRegisters R1-R5 are scratch registers that are clobbered by the instruction.h]hLRegisters R1-R5 are scratch registers that are clobbered by the instruction.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKEhjubah}(h]h ]h"]h$]h&]uh1hhjhhhhhNubeh}(h]h ]h"]h$]h&]bullet*uh1hhhhKAhjhhubh)}(hThese instructions have an implicit program exit condition as well. If an eBPF program attempts access data beyond the packet boundary, the program execution will be aborted.h]hThese instructions have an implicit program exit condition as well. If an eBPF program attempts access data beyond the packet boundary, the program execution will be aborted.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKHhjhhubh)}(h+``BPF_ABS | BPF_W | BPF_LD`` (0x20) means::h](jL)}(h``BPF_ABS | BPF_W | BPF_LD``h]hBPF_ABS | BPF_W | BPF_LD}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh (0x20) means:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKLhjhhubh literal_block)}(h8R0 = ntohl(*(u32 *) ((struct sk_buff *) R6->data + imm))h]h8R0 = ntohl(*(u32 *) ((struct sk_buff *) R6->data + imm))}hj=sbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1j;hhhKNhjhhubh)}(hUwhere ``ntohl()`` converts a 32-bit value from network byte order to host byte order.h](hwhere }(hjMhhhNhNubjL)}(h ``ntohl()``h]hntohl()}(hjUhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjMubhD converts a 32-bit value from network byte order to host byte order.}(hjMhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKPhjhhubh)}(h+``BPF_IND | BPF_W | BPF_LD`` (0x40) means::h](jL)}(h``BPF_IND | BPF_W | BPF_LD``h]hBPF_IND | BPF_W | BPF_LD}(hjqhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjmubh (0x40) means:}(hjmhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKRhjhhubj<)}(h>R0 = ntohl(*(u32 *) ((struct sk_buff *) R6->data + src + imm))h]h>R0 = ntohl(*(u32 *) ((struct sk_buff *) R6->data + src + imm))}hjsbah}(h]h ]h"]h$]h&]jKjLuh1j;hhhKThjhhubeh}(h]jah ]h"]%legacy bpf packet access instructionsah$]h&]uh1jhjhhhhhK.ubeh}(h]hah ]h"]linux implementation notesah$]h&]uh1jhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksjfootnote_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_handlerjerror_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}(jjjhjjjjCj!jrjjjjj=j:u nametypes}(jjjjj!jjj=uh}(jhhjjj)jCjjrjjj$jjj:j4hhjhj=j'jljVjjjju footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}jKsRparse_messages]transform_messages] transformerN include_log] decorationNhhub.