154222838SJesper Dangaard Brouer================================= 254222838SJesper Dangaard BrouerHOWTO interact with BPF subsystem 354222838SJesper Dangaard Brouer================================= 454222838SJesper Dangaard Brouer 5192092faSJesper Dangaard BrouerThis document provides information for the BPF subsystem about various 6192092faSJesper Dangaard Brouerworkflows related to reporting bugs, submitting patches, and queueing 7192092faSJesper Dangaard Brouerpatches for stable kernels. 8192092faSJesper Dangaard Brouer 9192092faSJesper Dangaard BrouerFor general information about submitting patches, please refer to 10*b7abcd9cSBagas SanjayaDocumentation/process/submitting-patches.rst. This document only describes 11*b7abcd9cSBagas Sanjayaadditional specifics related to BPF. 12192092faSJesper Dangaard Brouer 1354222838SJesper Dangaard Brouer.. contents:: 1454222838SJesper Dangaard Brouer :local: 1554222838SJesper Dangaard Brouer :depth: 2 1654222838SJesper Dangaard Brouer 1754222838SJesper Dangaard BrouerReporting bugs 1854222838SJesper Dangaard Brouer============== 19192092faSJesper Dangaard Brouer 20192092faSJesper Dangaard BrouerQ: How do I report bugs for BPF kernel code? 2154222838SJesper Dangaard Brouer-------------------------------------------- 22192092faSJesper Dangaard BrouerA: Since all BPF kernel development as well as bpftool and iproute2 BPF 23e42da4c6SYonghong Songloader development happens through the bpf kernel mailing list, 24192092faSJesper Dangaard Brouerplease report any found issues around BPF to the following mailing 25192092faSJesper Dangaard Brouerlist: 26192092faSJesper Dangaard Brouer 27e42da4c6SYonghong Song bpf@vger.kernel.org 28192092faSJesper Dangaard Brouer 29192092faSJesper Dangaard BrouerThis may also include issues related to XDP, BPF tracing, etc. 30192092faSJesper Dangaard Brouer 31192092faSJesper Dangaard BrouerGiven netdev has a high volume of traffic, please also add the BPF 3264ef3ddfSTiezhu Yangmaintainers to Cc (from kernel ``MAINTAINERS`` file): 33192092faSJesper Dangaard Brouer 3454222838SJesper Dangaard Brouer* Alexei Starovoitov <ast@kernel.org> 3554222838SJesper Dangaard Brouer* Daniel Borkmann <daniel@iogearbox.net> 36192092faSJesper Dangaard Brouer 37192092faSJesper Dangaard BrouerIn case a buggy commit has already been identified, make sure to keep 38192092faSJesper Dangaard Brouerthe actual commit authors in Cc as well for the report. They can 39192092faSJesper Dangaard Brouertypically be identified through the kernel's git tree. 40192092faSJesper Dangaard Brouer 4154222838SJesper Dangaard Brouer**Please do NOT report BPF issues to bugzilla.kernel.org since it 4254222838SJesper Dangaard Broueris a guarantee that the reported issue will be overlooked.** 43192092faSJesper Dangaard Brouer 4454222838SJesper Dangaard BrouerSubmitting patches 4554222838SJesper Dangaard Brouer================== 46192092faSJesper Dangaard Brouer 4726a9b433SDaniel MüllerQ: How do I run BPF CI on my changes before sending them out for review? 4826a9b433SDaniel Müller------------------------------------------------------------------------ 4926a9b433SDaniel MüllerA: BPF CI is GitHub based and hosted at https://github.com/kernel-patches/bpf. 5026a9b433SDaniel MüllerWhile GitHub also provides a CLI that can be used to accomplish the same 5126a9b433SDaniel Müllerresults, here we focus on the UI based workflow. 5226a9b433SDaniel Müller 5326a9b433SDaniel MüllerThe following steps lay out how to start a CI run for your patches: 54383f1a8dSDaniel Müller 5526a9b433SDaniel Müller- Create a fork of the aforementioned repository in your own account (one time 5626a9b433SDaniel Müller action) 57383f1a8dSDaniel Müller 5826a9b433SDaniel Müller- Clone the fork locally, check out a new branch tracking either the bpf-next 5926a9b433SDaniel Müller or bpf branch, and apply your to-be-tested patches on top of it 60383f1a8dSDaniel Müller 6126a9b433SDaniel Müller- Push the local branch to your fork and create a pull request against 6226a9b433SDaniel Müller kernel-patches/bpf's bpf-next_base or bpf_base branch, respectively 6326a9b433SDaniel Müller 6426a9b433SDaniel MüllerShortly after the pull request has been created, the CI workflow will run. Note 6526a9b433SDaniel Müllerthat capacity is shared with patches submitted upstream being checked and so 6626a9b433SDaniel Müllerdepending on utilization the run can take a while to finish. 6726a9b433SDaniel Müller 6826a9b433SDaniel MüllerNote furthermore that both base branches (bpf-next_base and bpf_base) will be 6926a9b433SDaniel Müllerupdated as patches are pushed to the respective upstream branches they track. As 7026a9b433SDaniel Müllersuch, your patch set will automatically (be attempted to) be rebased as well. 7126a9b433SDaniel MüllerThis behavior can result in a CI run being aborted and restarted with the new 7226a9b433SDaniel Müllerbase line. 7326a9b433SDaniel Müller 74192092faSJesper Dangaard BrouerQ: To which mailing list do I need to submit my BPF patches? 7554222838SJesper Dangaard Brouer------------------------------------------------------------ 76e42da4c6SYonghong SongA: Please submit your BPF patches to the bpf kernel mailing list: 77192092faSJesper Dangaard Brouer 78e42da4c6SYonghong Song bpf@vger.kernel.org 79192092faSJesper Dangaard Brouer 80192092faSJesper Dangaard BrouerIn case your patch has changes in various different subsystems (e.g. 81e42da4c6SYonghong Songnetworking, tracing, security, etc), make sure to Cc the related kernel mailing 82192092faSJesper Dangaard Brouerlists and maintainers from there as well, so they are able to review 83192092faSJesper Dangaard Brouerthe changes and provide their Acked-by's to the patches. 84192092faSJesper Dangaard Brouer 85192092faSJesper Dangaard BrouerQ: Where can I find patches currently under discussion for BPF subsystem? 8654222838SJesper Dangaard Brouer------------------------------------------------------------------------- 87192092faSJesper Dangaard BrouerA: All patches that are Cc'ed to netdev are queued for review under netdev 88192092faSJesper Dangaard Brouerpatchwork project: 89192092faSJesper Dangaard Brouer 90ebb034b1SAlexei Starovoitov https://patchwork.kernel.org/project/netdevbpf/list/ 91192092faSJesper Dangaard Brouer 92192092faSJesper Dangaard BrouerThose patches which target BPF, are assigned to a 'bpf' delegate for 93192092faSJesper Dangaard Brouerfurther processing from BPF maintainers. The current queue with 94192092faSJesper Dangaard Brouerpatches under review can be found at: 95192092faSJesper Dangaard Brouer 96ebb034b1SAlexei Starovoitov https://patchwork.kernel.org/project/netdevbpf/list/?delegate=121173 97192092faSJesper Dangaard Brouer 98192092faSJesper Dangaard BrouerOnce the patches have been reviewed by the BPF community as a whole 99192092faSJesper Dangaard Brouerand approved by the BPF maintainers, their status in patchwork will be 100192092faSJesper Dangaard Brouerchanged to 'Accepted' and the submitter will be notified by mail. This 101192092faSJesper Dangaard Brouermeans that the patches look good from a BPF perspective and have been 102192092faSJesper Dangaard Brouerapplied to one of the two BPF kernel trees. 103192092faSJesper Dangaard Brouer 104192092faSJesper Dangaard BrouerIn case feedback from the community requires a respin of the patches, 105192092faSJesper Dangaard Brouertheir status in patchwork will be set to 'Changes Requested', and purged 106192092faSJesper Dangaard Brouerfrom the current review queue. Likewise for cases where patches would 107192092faSJesper Dangaard Brouerget rejected or are not applicable to the BPF trees (but assigned to 108192092faSJesper Dangaard Brouerthe 'bpf' delegate). 109192092faSJesper Dangaard Brouer 110192092faSJesper Dangaard BrouerQ: How do the changes make their way into Linux? 11154222838SJesper Dangaard Brouer------------------------------------------------ 112192092faSJesper Dangaard BrouerA: There are two BPF kernel trees (git repositories). Once patches have 113192092faSJesper Dangaard Brouerbeen accepted by the BPF maintainers, they will be applied to one 114192092faSJesper Dangaard Brouerof the two BPF trees: 115192092faSJesper Dangaard Brouer 11654222838SJesper Dangaard Brouer * https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/ 11754222838SJesper Dangaard Brouer * https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/ 118192092faSJesper Dangaard Brouer 119192092faSJesper Dangaard BrouerThe bpf tree itself is for fixes only, whereas bpf-next for features, 120192092faSJesper Dangaard Brouercleanups or other kind of improvements ("next-like" content). This is 121192092faSJesper Dangaard Broueranalogous to net and net-next trees for networking. Both bpf and 122192092faSJesper Dangaard Brouerbpf-next will only have a master branch in order to simplify against 123192092faSJesper Dangaard Brouerwhich branch patches should get rebased to. 124192092faSJesper Dangaard Brouer 125192092faSJesper Dangaard BrouerAccumulated BPF patches in the bpf tree will regularly get pulled 126192092faSJesper Dangaard Brouerinto the net kernel tree. Likewise, accumulated BPF patches accepted 127192092faSJesper Dangaard Brouerinto the bpf-next tree will make their way into net-next tree. net and 128192092faSJesper Dangaard Brouernet-next are both run by David S. Miller. From there, they will go 129192092faSJesper Dangaard Brouerinto the kernel mainline tree run by Linus Torvalds. To read up on the 130192092faSJesper Dangaard Brouerprocess of net and net-next being merged into the mainline tree, see 131287f4fa9STobin C. Hardingthe :ref:`netdev-FAQ` 132192092faSJesper Dangaard Brouer 133287f4fa9STobin C. Harding 134192092faSJesper Dangaard Brouer 135192092faSJesper Dangaard BrouerOccasionally, to prevent merge conflicts, we might send pull requests 136192092faSJesper Dangaard Brouerto other trees (e.g. tracing) with a small subset of the patches, but 137192092faSJesper Dangaard Brouernet and net-next are always the main trees targeted for integration. 138192092faSJesper Dangaard Brouer 139192092faSJesper Dangaard BrouerThe pull requests will contain a high-level summary of the accumulated 140192092faSJesper Dangaard Brouerpatches and can be searched on netdev kernel mailing list through the 14154222838SJesper Dangaard Brouerfollowing subject lines (``yyyy-mm-dd`` is the date of the pull 14254222838SJesper Dangaard Brouerrequest):: 143192092faSJesper Dangaard Brouer 144192092faSJesper Dangaard Brouer pull-request: bpf yyyy-mm-dd 145192092faSJesper Dangaard Brouer pull-request: bpf-next yyyy-mm-dd 146192092faSJesper Dangaard Brouer 14754222838SJesper Dangaard BrouerQ: How do I indicate which tree (bpf vs. bpf-next) my patch should be applied to? 14854222838SJesper Dangaard Brouer--------------------------------------------------------------------------------- 149192092faSJesper Dangaard Brouer 150287f4fa9STobin C. HardingA: The process is the very same as described in the :ref:`netdev-FAQ`, 151287f4fa9STobin C. Hardingso please read up on it. The subject line must indicate whether the 152192092faSJesper Dangaard Brouerpatch is a fix or rather "next-like" content in order to let the 153192092faSJesper Dangaard Brouermaintainers know whether it is targeted at bpf or bpf-next. 154192092faSJesper Dangaard Brouer 155192092faSJesper Dangaard BrouerFor fixes eventually landing in bpf -> net tree, the subject must 15654222838SJesper Dangaard Brouerlook like:: 157192092faSJesper Dangaard Brouer 158192092faSJesper Dangaard Brouer git format-patch --subject-prefix='PATCH bpf' start..finish 159192092faSJesper Dangaard Brouer 160192092faSJesper Dangaard BrouerFor features/improvements/etc that should eventually land in 16154222838SJesper Dangaard Brouerbpf-next -> net-next, the subject must look like:: 162192092faSJesper Dangaard Brouer 163192092faSJesper Dangaard Brouer git format-patch --subject-prefix='PATCH bpf-next' start..finish 164192092faSJesper Dangaard Brouer 165192092faSJesper Dangaard BrouerIf unsure whether the patch or patch series should go into bpf 166192092faSJesper Dangaard Broueror net directly, or bpf-next or net-next directly, it is not a 167192092faSJesper Dangaard Brouerproblem either if the subject line says net or net-next as target. 168192092faSJesper Dangaard BrouerIt is eventually up to the maintainers to do the delegation of 169192092faSJesper Dangaard Brouerthe patches. 170192092faSJesper Dangaard Brouer 171192092faSJesper Dangaard BrouerIf it is clear that patches should go into bpf or bpf-next tree, 172192092faSJesper Dangaard Brouerplease make sure to rebase the patches against those trees in 173192092faSJesper Dangaard Brouerorder to reduce potential conflicts. 174192092faSJesper Dangaard Brouer 175192092faSJesper Dangaard BrouerIn case the patch or patch series has to be reworked and sent out 176192092faSJesper Dangaard Broueragain in a second or later revision, it is also required to add a 17754222838SJesper Dangaard Brouerversion number (``v2``, ``v3``, ...) into the subject prefix:: 178192092faSJesper Dangaard Brouer 1794d0d1673SJianlin Lv git format-patch --subject-prefix='PATCH bpf-next v2' start..finish 180192092faSJesper Dangaard Brouer 181192092faSJesper Dangaard BrouerWhen changes have been requested to the patch series, always send the 182192092faSJesper Dangaard Brouerwhole patch series again with the feedback incorporated (never send 183192092faSJesper Dangaard Brouerindividual diffs on top of the old series). 184192092faSJesper Dangaard Brouer 185192092faSJesper Dangaard BrouerQ: What does it mean when a patch gets applied to bpf or bpf-next tree? 18654222838SJesper Dangaard Brouer----------------------------------------------------------------------- 187192092faSJesper Dangaard BrouerA: It means that the patch looks good for mainline inclusion from 188192092faSJesper Dangaard Brouera BPF point of view. 189192092faSJesper Dangaard Brouer 190192092faSJesper Dangaard BrouerBe aware that this is not a final verdict that the patch will 191192092faSJesper Dangaard Brouerautomatically get accepted into net or net-next trees eventually: 192192092faSJesper Dangaard Brouer 193e42da4c6SYonghong SongOn the bpf kernel mailing list reviews can come in at any point 194192092faSJesper Dangaard Brouerin time. If discussions around a patch conclude that they cannot 195192092faSJesper Dangaard Brouerget included as-is, we will either apply a follow-up fix or drop 196192092faSJesper Dangaard Brouerthem from the trees entirely. Therefore, we also reserve to rebase 197192092faSJesper Dangaard Brouerthe trees when deemed necessary. After all, the purpose of the tree 19854222838SJesper Dangaard Broueris to: 19954222838SJesper Dangaard Brouer 20054222838SJesper Dangaard Broueri) accumulate and stage BPF patches for integration into trees 20154222838SJesper Dangaard Brouer like net and net-next, and 20254222838SJesper Dangaard Brouer 20354222838SJesper Dangaard Brouerii) run extensive BPF test suite and 204192092faSJesper Dangaard Brouer workloads on the patches before they make their way any further. 205192092faSJesper Dangaard Brouer 206192092faSJesper Dangaard BrouerOnce the BPF pull request was accepted by David S. Miller, then 207192092faSJesper Dangaard Brouerthe patches end up in net or net-next tree, respectively, and 208192092faSJesper Dangaard Brouermake their way from there further into mainline. Again, see the 209287f4fa9STobin C. Harding:ref:`netdev-FAQ` for additional information e.g. on how often they are 210192092faSJesper Dangaard Brouermerged to mainline. 211192092faSJesper Dangaard Brouer 212192092faSJesper Dangaard BrouerQ: How long do I need to wait for feedback on my BPF patches? 21354222838SJesper Dangaard Brouer------------------------------------------------------------- 214192092faSJesper Dangaard BrouerA: We try to keep the latency low. The usual time to feedback will 215192092faSJesper Dangaard Brouerbe around 2 or 3 business days. It may vary depending on the 216192092faSJesper Dangaard Brouercomplexity of changes and current patch load. 217192092faSJesper Dangaard Brouer 21854222838SJesper Dangaard BrouerQ: How often do you send pull requests to major kernel trees like net or net-next? 21954222838SJesper Dangaard Brouer---------------------------------------------------------------------------------- 220192092faSJesper Dangaard Brouer 221192092faSJesper Dangaard BrouerA: Pull requests will be sent out rather often in order to not 222192092faSJesper Dangaard Broueraccumulate too many patches in bpf or bpf-next. 223192092faSJesper Dangaard Brouer 224192092faSJesper Dangaard BrouerAs a rule of thumb, expect pull requests for each tree regularly 225192092faSJesper Dangaard Brouerat the end of the week. In some cases pull requests could additionally 226192092faSJesper Dangaard Brouercome also in the middle of the week depending on the current patch 227192092faSJesper Dangaard Brouerload or urgency. 228192092faSJesper Dangaard Brouer 229192092faSJesper Dangaard BrouerQ: Are patches applied to bpf-next when the merge window is open? 23054222838SJesper Dangaard Brouer----------------------------------------------------------------- 231192092faSJesper Dangaard BrouerA: For the time when the merge window is open, bpf-next will not be 232192092faSJesper Dangaard Brouerprocessed. This is roughly analogous to net-next patch processing, 233287f4fa9STobin C. Hardingso feel free to read up on the :ref:`netdev-FAQ` about further details. 234192092faSJesper Dangaard Brouer 235192092faSJesper Dangaard BrouerDuring those two weeks of merge window, we might ask you to resend 236192092faSJesper Dangaard Broueryour patch series once bpf-next is open again. Once Linus released 23754222838SJesper Dangaard Brouera ``v*-rc1`` after the merge window, we continue processing of bpf-next. 238192092faSJesper Dangaard Brouer 239192092faSJesper Dangaard BrouerFor non-subscribers to kernel mailing lists, there is also a status 240192092faSJesper Dangaard Brouerpage run by David S. Miller on net-next that provides guidance: 241192092faSJesper Dangaard Brouer 242192092faSJesper Dangaard Brouer http://vger.kernel.org/~davem/net-next.html 243192092faSJesper Dangaard Brouer 24454222838SJesper Dangaard BrouerQ: Verifier changes and test cases 24554222838SJesper Dangaard Brouer---------------------------------- 246192092faSJesper Dangaard BrouerQ: I made a BPF verifier change, do I need to add test cases for 24754222838SJesper Dangaard BrouerBPF kernel selftests_? 248192092faSJesper Dangaard Brouer 249192092faSJesper Dangaard BrouerA: If the patch has changes to the behavior of the verifier, then yes, 250192092faSJesper Dangaard Brouerit is absolutely necessary to add test cases to the BPF kernel 25154222838SJesper Dangaard Brouerselftests_ suite. If they are not present and we think they are 252192092faSJesper Dangaard Brouerneeded, then we might ask for them before accepting any changes. 253192092faSJesper Dangaard Brouer 254192092faSJesper Dangaard BrouerIn particular, test_verifier.c is tracking a high number of BPF test 255192092faSJesper Dangaard Brouercases, including a lot of corner cases that LLVM BPF back end may 256192092faSJesper Dangaard Brouergenerate out of the restricted C code. Thus, adding test cases is 257192092faSJesper Dangaard Brouerabsolutely crucial to make sure future changes do not accidentally 258192092faSJesper Dangaard Broueraffect prior use-cases. Thus, treat those test cases as: verifier 259192092faSJesper Dangaard Brouerbehavior that is not tracked in test_verifier.c could potentially 260192092faSJesper Dangaard Brouerbe subject to change. 261192092faSJesper Dangaard Brouer 26254222838SJesper Dangaard BrouerQ: samples/bpf preference vs selftests? 26354222838SJesper Dangaard Brouer--------------------------------------- 26464ef3ddfSTiezhu YangQ: When should I add code to ``samples/bpf/`` and when to BPF kernel 26554222838SJesper Dangaard Brouerselftests_? 266192092faSJesper Dangaard Brouer 26754222838SJesper Dangaard BrouerA: In general, we prefer additions to BPF kernel selftests_ rather than 26864ef3ddfSTiezhu Yang``samples/bpf/``. The rationale is very simple: kernel selftests are 269192092faSJesper Dangaard Brouerregularly run by various bots to test for kernel regressions. 270192092faSJesper Dangaard Brouer 271192092faSJesper Dangaard BrouerThe more test cases we add to BPF selftests, the better the coverage 272192092faSJesper Dangaard Brouerand the less likely it is that those could accidentally break. It is 273192092faSJesper Dangaard Brouernot that BPF kernel selftests cannot demo how a specific feature can 274192092faSJesper Dangaard Brouerbe used. 275192092faSJesper Dangaard Brouer 27664ef3ddfSTiezhu YangThat said, ``samples/bpf/`` may be a good place for people to get started, 277192092faSJesper Dangaard Brouerso it might be advisable that simple demos of features could go into 27864ef3ddfSTiezhu Yang``samples/bpf/``, but advanced functional and corner-case testing rather 279192092faSJesper Dangaard Brouerinto kernel selftests. 280192092faSJesper Dangaard Brouer 281192092faSJesper Dangaard BrouerIf your sample looks like a test case, then go for BPF kernel selftests 282192092faSJesper Dangaard Brouerinstead! 283192092faSJesper Dangaard Brouer 284192092faSJesper Dangaard BrouerQ: When should I add code to the bpftool? 28554222838SJesper Dangaard Brouer----------------------------------------- 286192092faSJesper Dangaard BrouerA: The main purpose of bpftool (under tools/bpf/bpftool/) is to provide 287192092faSJesper Dangaard Brouera central user space tool for debugging and introspection of BPF programs 288192092faSJesper Dangaard Brouerand maps that are active in the kernel. If UAPI changes related to BPF 289192092faSJesper Dangaard Brouerenable for dumping additional information of programs or maps, then 290192092faSJesper Dangaard Brouerbpftool should be extended as well to support dumping them. 291192092faSJesper Dangaard Brouer 292192092faSJesper Dangaard BrouerQ: When should I add code to iproute2's BPF loader? 29354222838SJesper Dangaard Brouer--------------------------------------------------- 29454222838SJesper Dangaard BrouerA: For UAPI changes related to the XDP or tc layer (e.g. ``cls_bpf``), 29554222838SJesper Dangaard Brouerthe convention is that those control-path related changes are added to 296192092faSJesper Dangaard Broueriproute2's BPF loader as well from user space side. This is not only 297192092faSJesper Dangaard Broueruseful to have UAPI changes properly designed to be usable, but also 298192092faSJesper Dangaard Brouerto make those changes available to a wider user base of major 299192092faSJesper Dangaard Brouerdownstream distributions. 300192092faSJesper Dangaard Brouer 301192092faSJesper Dangaard BrouerQ: Do you accept patches as well for iproute2's BPF loader? 30254222838SJesper Dangaard Brouer----------------------------------------------------------- 303192092faSJesper Dangaard BrouerA: Patches for the iproute2's BPF loader have to be sent to: 304192092faSJesper Dangaard Brouer 305192092faSJesper Dangaard Brouer netdev@vger.kernel.org 306192092faSJesper Dangaard Brouer 307192092faSJesper Dangaard BrouerWhile those patches are not processed by the BPF kernel maintainers, 308192092faSJesper Dangaard Brouerplease keep them in Cc as well, so they can be reviewed. 309192092faSJesper Dangaard Brouer 310192092faSJesper Dangaard BrouerThe official git repository for iproute2 is run by Stephen Hemminger 311192092faSJesper Dangaard Brouerand can be found at: 312192092faSJesper Dangaard Brouer 313192092faSJesper Dangaard Brouer https://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git/ 314192092faSJesper Dangaard Brouer 31554222838SJesper Dangaard BrouerThe patches need to have a subject prefix of '``[PATCH iproute2 31654222838SJesper Dangaard Brouermaster]``' or '``[PATCH iproute2 net-next]``'. '``master``' or 31754222838SJesper Dangaard Brouer'``net-next``' describes the target branch where the patch should be 31854222838SJesper Dangaard Brouerapplied to. Meaning, if kernel changes went into the net-next kernel 31954222838SJesper Dangaard Brouertree, then the related iproute2 changes need to go into the iproute2 32054222838SJesper Dangaard Brouernet-next branch, otherwise they can be targeted at master branch. The 32154222838SJesper Dangaard Broueriproute2 net-next branch will get merged into the master branch after 32254222838SJesper Dangaard Brouerthe current iproute2 version from master has been released. 323192092faSJesper Dangaard Brouer 324192092faSJesper Dangaard BrouerLike BPF, the patches end up in patchwork under the netdev project and 325192092faSJesper Dangaard Brouerare delegated to 'shemminger' for further processing: 326192092faSJesper Dangaard Brouer 327192092faSJesper Dangaard Brouer http://patchwork.ozlabs.org/project/netdev/list/?delegate=389 328192092faSJesper Dangaard Brouer 329192092faSJesper Dangaard BrouerQ: What is the minimum requirement before I submit my BPF patches? 33054222838SJesper Dangaard Brouer------------------------------------------------------------------ 331192092faSJesper Dangaard BrouerA: When submitting patches, always take the time and properly test your 332192092faSJesper Dangaard Brouerpatches *prior* to submission. Never rush them! If maintainers find 333192092faSJesper Dangaard Brouerthat your patches have not been properly tested, it is a good way to 334192092faSJesper Dangaard Brouerget them grumpy. Testing patch submissions is a hard requirement! 335192092faSJesper Dangaard Brouer 33654222838SJesper Dangaard BrouerNote, fixes that go to bpf tree *must* have a ``Fixes:`` tag included. 33754222838SJesper Dangaard BrouerThe same applies to fixes that target bpf-next, where the affected 33854222838SJesper Dangaard Brouercommit is in net-next (or in some cases bpf-next). The ``Fixes:`` tag is 33954222838SJesper Dangaard Brouercrucial in order to identify follow-up commits and tremendously helps 34054222838SJesper Dangaard Brouerfor people having to do backporting, so it is a must have! 341192092faSJesper Dangaard Brouer 342192092faSJesper Dangaard BrouerWe also don't accept patches with an empty commit message. Take your 343192092faSJesper Dangaard Brouertime and properly write up a high quality commit message, it is 344192092faSJesper Dangaard Broueressential! 345192092faSJesper Dangaard Brouer 346192092faSJesper Dangaard BrouerThink about it this way: other developers looking at your code a month 347192092faSJesper Dangaard Brouerfrom now need to understand *why* a certain change has been done that 348192092faSJesper Dangaard Brouerway, and whether there have been flaws in the analysis or assumptions 349192092faSJesper Dangaard Brouerthat the original author did. Thus providing a proper rationale and 350192092faSJesper Dangaard Brouerdescribing the use-case for the changes is a must. 351192092faSJesper Dangaard Brouer 352192092faSJesper Dangaard BrouerPatch submissions with >1 patch must have a cover letter which includes 353192092faSJesper Dangaard Brouera high level description of the series. This high level summary will 354192092faSJesper Dangaard Brouerthen be placed into the merge commit by the BPF maintainers such that 355192092faSJesper Dangaard Brouerit is also accessible from the git log for future reference. 356192092faSJesper Dangaard Brouer 35754222838SJesper Dangaard BrouerQ: Features changing BPF JIT and/or LLVM 35854222838SJesper Dangaard Brouer---------------------------------------- 359192092faSJesper Dangaard BrouerQ: What do I need to consider when adding a new instruction or feature 360192092faSJesper Dangaard Brouerthat would require BPF JIT and/or LLVM integration as well? 361192092faSJesper Dangaard Brouer 362192092faSJesper Dangaard BrouerA: We try hard to keep all BPF JITs up to date such that the same user 363192092faSJesper Dangaard Brouerexperience can be guaranteed when running BPF programs on different 364192092faSJesper Dangaard Brouerarchitectures without having the program punt to the less efficient 365192092faSJesper Dangaard Brouerinterpreter in case the in-kernel BPF JIT is enabled. 366192092faSJesper Dangaard Brouer 367192092faSJesper Dangaard BrouerIf you are unable to implement or test the required JIT changes for 368192092faSJesper Dangaard Brouercertain architectures, please work together with the related BPF JIT 369192092faSJesper Dangaard Brouerdevelopers in order to get the feature implemented in a timely manner. 37054222838SJesper Dangaard BrouerPlease refer to the git log (``arch/*/net/``) to locate the necessary 371192092faSJesper Dangaard Brouerpeople for helping out. 372192092faSJesper Dangaard Brouer 373192092faSJesper Dangaard BrouerAlso always make sure to add BPF test cases (e.g. test_bpf.c and 374192092faSJesper Dangaard Brouertest_verifier.c) for new instructions, so that they can receive 375192092faSJesper Dangaard Brouerbroad test coverage and help run-time testing the various BPF JITs. 376192092faSJesper Dangaard Brouer 377192092faSJesper Dangaard BrouerIn case of new BPF instructions, once the changes have been accepted 378192092faSJesper Dangaard Brouerinto the Linux kernel, please implement support into LLVM's BPF back 37954222838SJesper Dangaard Brouerend. See LLVM_ section below for further information. 380192092faSJesper Dangaard Brouer 38154222838SJesper Dangaard BrouerStable submission 38254222838SJesper Dangaard Brouer================= 383192092faSJesper Dangaard Brouer 384192092faSJesper Dangaard BrouerQ: I need a specific BPF commit in stable kernels. What should I do? 38554222838SJesper Dangaard Brouer-------------------------------------------------------------------- 386192092faSJesper Dangaard BrouerA: In case you need a specific fix in stable kernels, first check whether 38754222838SJesper Dangaard Brouerthe commit has already been applied in the related ``linux-*.y`` branches: 388192092faSJesper Dangaard Brouer 389192092faSJesper Dangaard Brouer https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/ 390192092faSJesper Dangaard Brouer 391192092faSJesper Dangaard BrouerIf not the case, then drop an email to the BPF maintainers with the 392192092faSJesper Dangaard Brouernetdev kernel mailing list in Cc and ask for the fix to be queued up: 393192092faSJesper Dangaard Brouer 394192092faSJesper Dangaard Brouer netdev@vger.kernel.org 395192092faSJesper Dangaard Brouer 396192092faSJesper Dangaard BrouerThe process in general is the same as on netdev itself, see also the 397287f4fa9STobin C. Harding:ref:`netdev-FAQ`. 398192092faSJesper Dangaard Brouer 399192092faSJesper Dangaard BrouerQ: Do you also backport to kernels not currently maintained as stable? 40054222838SJesper Dangaard Brouer---------------------------------------------------------------------- 401192092faSJesper Dangaard BrouerA: No. If you need a specific BPF commit in kernels that are currently not 402192092faSJesper Dangaard Brouermaintained by the stable maintainers, then you are on your own. 403192092faSJesper Dangaard Brouer 404192092faSJesper Dangaard BrouerThe current stable and longterm stable kernels are all listed here: 405192092faSJesper Dangaard Brouer 406192092faSJesper Dangaard Brouer https://www.kernel.org/ 407192092faSJesper Dangaard Brouer 40854222838SJesper Dangaard BrouerQ: The BPF patch I am about to submit needs to go to stable as well 40954222838SJesper Dangaard Brouer------------------------------------------------------------------- 41054222838SJesper Dangaard BrouerWhat should I do? 411192092faSJesper Dangaard Brouer 412192092faSJesper Dangaard BrouerA: The same rules apply as with netdev patch submissions in general, see 413287f4fa9STobin C. Hardingthe :ref:`netdev-FAQ`. 414192092faSJesper Dangaard Brouer 41554222838SJesper Dangaard BrouerNever add "``Cc: stable@vger.kernel.org``" to the patch description, but 416192092faSJesper Dangaard Brouerask the BPF maintainers to queue the patches instead. This can be done 41754222838SJesper Dangaard Brouerwith a note, for example, under the ``---`` part of the patch which does 418192092faSJesper Dangaard Brouernot go into the git log. Alternatively, this can be done as a simple 419192092faSJesper Dangaard Brouerrequest by mail instead. 420192092faSJesper Dangaard Brouer 42154222838SJesper Dangaard BrouerQ: Queue stable patches 42254222838SJesper Dangaard Brouer----------------------- 423192092faSJesper Dangaard BrouerQ: Where do I find currently queued BPF patches that will be submitted 424192092faSJesper Dangaard Brouerto stable? 425192092faSJesper Dangaard Brouer 426192092faSJesper Dangaard BrouerA: Once patches that fix critical bugs got applied into the bpf tree, they 427192092faSJesper Dangaard Brouerare queued up for stable submission under: 428192092faSJesper Dangaard Brouer 429192092faSJesper Dangaard Brouer http://patchwork.ozlabs.org/bundle/bpf/stable/?state=* 430192092faSJesper Dangaard Brouer 431192092faSJesper Dangaard BrouerThey will be on hold there at minimum until the related commit made its 432192092faSJesper Dangaard Brouerway into the mainline kernel tree. 433192092faSJesper Dangaard Brouer 434192092faSJesper Dangaard BrouerAfter having been under broader exposure, the queued patches will be 435192092faSJesper Dangaard Brouersubmitted by the BPF maintainers to the stable maintainers. 436192092faSJesper Dangaard Brouer 43754222838SJesper Dangaard BrouerTesting patches 43854222838SJesper Dangaard Brouer=============== 439192092faSJesper Dangaard Brouer 440b7a27c3aSJesper Dangaard BrouerQ: How to run BPF selftests 441b7a27c3aSJesper Dangaard Brouer--------------------------- 442b7a27c3aSJesper Dangaard BrouerA: After you have booted into the newly compiled kernel, navigate to 443b7a27c3aSJesper Dangaard Brouerthe BPF selftests_ suite in order to test BPF functionality (current 444b7a27c3aSJesper Dangaard Brouerworking directory points to the root of the cloned git tree):: 445b7a27c3aSJesper Dangaard Brouer 446b7a27c3aSJesper Dangaard Brouer $ cd tools/testing/selftests/bpf/ 447b7a27c3aSJesper Dangaard Brouer $ make 448b7a27c3aSJesper Dangaard Brouer 449b7a27c3aSJesper Dangaard BrouerTo run the verifier tests:: 450b7a27c3aSJesper Dangaard Brouer 451b7a27c3aSJesper Dangaard Brouer $ sudo ./test_verifier 452b7a27c3aSJesper Dangaard Brouer 453b7a27c3aSJesper Dangaard BrouerThe verifier tests print out all the current checks being 454b7a27c3aSJesper Dangaard Brouerperformed. The summary at the end of running all tests will dump 455b7a27c3aSJesper Dangaard Brouerinformation of test successes and failures:: 456b7a27c3aSJesper Dangaard Brouer 457b7a27c3aSJesper Dangaard Brouer Summary: 418 PASSED, 0 FAILED 458b7a27c3aSJesper Dangaard Brouer 459b7a27c3aSJesper Dangaard BrouerIn order to run through all BPF selftests, the following command is 460b7a27c3aSJesper Dangaard Brouerneeded:: 461b7a27c3aSJesper Dangaard Brouer 462b7a27c3aSJesper Dangaard Brouer $ sudo make run_tests 463b7a27c3aSJesper Dangaard Brouer 46432db18d6SBagas SanjayaSee :doc:`kernel selftest documentation </dev-tools/kselftest>` 46532db18d6SBagas Sanjayafor details. 466b7a27c3aSJesper Dangaard Brouer 4676736aa79SAlan MaguireTo maximize the number of tests passing, the .config of the kernel 4686736aa79SAlan Maguireunder test should match the config file fragment in 4696736aa79SAlan Maguiretools/testing/selftests/bpf as closely as possible. 4706736aa79SAlan Maguire 4716736aa79SAlan MaguireFinally to ensure support for latest BPF Type Format features - 472a07484c0SBagas Sanjayadiscussed in Documentation/bpf/btf.rst - pahole version 1.16 4736736aa79SAlan Maguireis required for kernels built with CONFIG_DEBUG_INFO_BTF=y. 4746736aa79SAlan Maguirepahole is delivered in the dwarves package or can be built 4756736aa79SAlan Maguirefrom source at 4766736aa79SAlan Maguire 4776736aa79SAlan Maguirehttps://github.com/acmel/dwarves 4786736aa79SAlan Maguire 479350a62caSTiezhu Yangpahole starts to use libbpf definitions and APIs since v1.13 after the 480350a62caSTiezhu Yangcommit 21507cd3e97b ("pahole: add libbpf as submodule under lib/bpf"). 481350a62caSTiezhu YangIt works well with the git repository because the libbpf submodule will 482350a62caSTiezhu Yanguse "git submodule update --init --recursive" to update. 483350a62caSTiezhu Yang 484350a62caSTiezhu YangUnfortunately, the default github release source code does not contain 485350a62caSTiezhu Yanglibbpf submodule source code and this will cause build issues, the tarball 486350a62caSTiezhu Yangfrom https://git.kernel.org/pub/scm/devel/pahole/pahole.git/ is same with 487350a62caSTiezhu Yanggithub, you can get the source tarball with corresponding libbpf submodule 488350a62caSTiezhu Yangcodes from 489350a62caSTiezhu Yang 490350a62caSTiezhu Yanghttps://fedorapeople.org/~acme/dwarves 491350a62caSTiezhu Yang 4926736aa79SAlan MaguireSome distros have pahole version 1.16 packaged already, e.g. 4936736aa79SAlan MaguireFedora, Gentoo. 4946736aa79SAlan Maguire 495192092faSJesper Dangaard BrouerQ: Which BPF kernel selftests version should I run my kernel against? 49654222838SJesper Dangaard Brouer--------------------------------------------------------------------- 49754222838SJesper Dangaard BrouerA: If you run a kernel ``xyz``, then always run the BPF kernel selftests 49854222838SJesper Dangaard Brouerfrom that kernel ``xyz`` as well. Do not expect that the BPF selftest 49954222838SJesper Dangaard Brouerfrom the latest mainline tree will pass all the time. 500192092faSJesper Dangaard Brouer 501192092faSJesper Dangaard BrouerIn particular, test_bpf.c and test_verifier.c have a large number of 502192092faSJesper Dangaard Brouertest cases and are constantly updated with new BPF test sequences, or 503192092faSJesper Dangaard Brouerexisting ones are adapted to verifier changes e.g. due to verifier 504192092faSJesper Dangaard Brouerbecoming smarter and being able to better track certain things. 505192092faSJesper Dangaard Brouer 50654222838SJesper Dangaard BrouerLLVM 50754222838SJesper Dangaard Brouer==== 508192092faSJesper Dangaard Brouer 509192092faSJesper Dangaard BrouerQ: Where do I find LLVM with BPF support? 51054222838SJesper Dangaard Brouer----------------------------------------- 511192092faSJesper Dangaard BrouerA: The BPF back end for LLVM is upstream in LLVM since version 3.7.1. 512192092faSJesper Dangaard Brouer 513192092faSJesper Dangaard BrouerAll major distributions these days ship LLVM with BPF back end enabled, 514192092faSJesper Dangaard Brouerso for the majority of use-cases it is not required to compile LLVM by 515192092faSJesper Dangaard Brouerhand anymore, just install the distribution provided package. 516192092faSJesper Dangaard Brouer 51754222838SJesper Dangaard BrouerLLVM's static compiler lists the supported targets through 51854222838SJesper Dangaard Brouer``llc --version``, make sure BPF targets are listed. Example:: 519192092faSJesper Dangaard Brouer 520192092faSJesper Dangaard Brouer $ llc --version 521192092faSJesper Dangaard Brouer LLVM (http://llvm.org/): 5224d0d1673SJianlin Lv LLVM version 10.0.0 523192092faSJesper Dangaard Brouer Optimized build. 524192092faSJesper Dangaard Brouer Default target: x86_64-unknown-linux-gnu 525192092faSJesper Dangaard Brouer Host CPU: skylake 526192092faSJesper Dangaard Brouer 527192092faSJesper Dangaard Brouer Registered Targets: 5284d0d1673SJianlin Lv aarch64 - AArch64 (little endian) 529192092faSJesper Dangaard Brouer bpf - BPF (host endian) 530192092faSJesper Dangaard Brouer bpfeb - BPF (big endian) 531192092faSJesper Dangaard Brouer bpfel - BPF (little endian) 532192092faSJesper Dangaard Brouer x86 - 32-bit X86: Pentium-Pro and above 533192092faSJesper Dangaard Brouer x86-64 - 64-bit X86: EM64T and AMD64 534192092faSJesper Dangaard Brouer 535192092faSJesper Dangaard BrouerFor developers in order to utilize the latest features added to LLVM's 536192092faSJesper Dangaard BrouerBPF back end, it is advisable to run the latest LLVM releases. Support 537192092faSJesper Dangaard Brouerfor new BPF kernel features such as additions to the BPF instruction 538192092faSJesper Dangaard Brouerset are often developed together. 539192092faSJesper Dangaard Brouer 540192092faSJesper Dangaard BrouerAll LLVM releases can be found at: http://releases.llvm.org/ 541192092faSJesper Dangaard Brouer 542192092faSJesper Dangaard BrouerQ: Got it, so how do I build LLVM manually anyway? 54354222838SJesper Dangaard Brouer-------------------------------------------------- 544628add78STiezhu YangA: We recommend that developers who want the fastest incremental builds 545628add78STiezhu Yanguse the Ninja build system, you can find it in your system's package 546628add78STiezhu Yangmanager, usually the package is ninja or ninja-build. 547628add78STiezhu Yang 548628add78STiezhu YangYou need ninja, cmake and gcc-c++ as build requisites for LLVM. Once you 549628add78STiezhu Yanghave that set up, proceed with building the latest LLVM and clang version 55054222838SJesper Dangaard Brouerfrom the git repositories:: 551192092faSJesper Dangaard Brouer 552e42da4c6SYonghong Song $ git clone https://github.com/llvm/llvm-project.git 553628add78STiezhu Yang $ mkdir -p llvm-project/llvm/build 554e42da4c6SYonghong Song $ cd llvm-project/llvm/build 555e42da4c6SYonghong Song $ cmake .. -G "Ninja" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \ 556e42da4c6SYonghong Song -DLLVM_ENABLE_PROJECTS="clang" \ 557192092faSJesper Dangaard Brouer -DCMAKE_BUILD_TYPE=Release \ 558192092faSJesper Dangaard Brouer -DLLVM_BUILD_RUNTIME=OFF 559e42da4c6SYonghong Song $ ninja 560192092faSJesper Dangaard Brouer 561192092faSJesper Dangaard BrouerThe built binaries can then be found in the build/bin/ directory, where 562192092faSJesper Dangaard Broueryou can point the PATH variable to. 563192092faSJesper Dangaard Brouer 5644d0d1673SJianlin LvSet ``-DLLVM_TARGETS_TO_BUILD`` equal to the target you wish to build, you 5654d0d1673SJianlin Lvwill find a full list of targets within the llvm-project/llvm/lib/Target 5664d0d1673SJianlin Lvdirectory. 5674d0d1673SJianlin Lv 56854222838SJesper Dangaard BrouerQ: Reporting LLVM BPF issues 56954222838SJesper Dangaard Brouer---------------------------- 570192092faSJesper Dangaard BrouerQ: Should I notify BPF kernel maintainers about issues in LLVM's BPF code 571192092faSJesper Dangaard Brouergeneration back end or about LLVM generated code that the verifier 572192092faSJesper Dangaard Brouerrefuses to accept? 573192092faSJesper Dangaard Brouer 57454222838SJesper Dangaard BrouerA: Yes, please do! 57554222838SJesper Dangaard Brouer 57654222838SJesper Dangaard BrouerLLVM's BPF back end is a key piece of the whole BPF 577192092faSJesper Dangaard Brouerinfrastructure and it ties deeply into verification of programs from the 578192092faSJesper Dangaard Brouerkernel side. Therefore, any issues on either side need to be investigated 579192092faSJesper Dangaard Brouerand fixed whenever necessary. 580192092faSJesper Dangaard Brouer 581192092faSJesper Dangaard BrouerTherefore, please make sure to bring them up at netdev kernel mailing 582192092faSJesper Dangaard Brouerlist and Cc BPF maintainers for LLVM and kernel bits: 583192092faSJesper Dangaard Brouer 58454222838SJesper Dangaard Brouer* Yonghong Song <yhs@fb.com> 58554222838SJesper Dangaard Brouer* Alexei Starovoitov <ast@kernel.org> 58654222838SJesper Dangaard Brouer* Daniel Borkmann <daniel@iogearbox.net> 587192092faSJesper Dangaard Brouer 588192092faSJesper Dangaard BrouerLLVM also has an issue tracker where BPF related bugs can be found: 589192092faSJesper Dangaard Brouer 590192092faSJesper Dangaard Brouer https://bugs.llvm.org/buglist.cgi?quicksearch=bpf 591192092faSJesper Dangaard Brouer 592192092faSJesper Dangaard BrouerHowever, it is better to reach out through mailing lists with having 593192092faSJesper Dangaard Brouermaintainers in Cc. 594192092faSJesper Dangaard Brouer 59554222838SJesper Dangaard BrouerQ: New BPF instruction for kernel and LLVM 59654222838SJesper Dangaard Brouer------------------------------------------ 597192092faSJesper Dangaard BrouerQ: I have added a new BPF instruction to the kernel, how can I integrate 598192092faSJesper Dangaard Brouerit into LLVM? 599192092faSJesper Dangaard Brouer 60054222838SJesper Dangaard BrouerA: LLVM has a ``-mcpu`` selector for the BPF back end in order to allow 60154222838SJesper Dangaard Brouerthe selection of BPF instruction set extensions. By default the 60254222838SJesper Dangaard Brouer``generic`` processor target is used, which is the base instruction set 60354222838SJesper Dangaard Brouer(v1) of BPF. 604192092faSJesper Dangaard Brouer 60554222838SJesper Dangaard BrouerLLVM has an option to select ``-mcpu=probe`` where it will probe the host 606192092faSJesper Dangaard Brouerkernel for supported BPF instruction set extensions and selects the 607192092faSJesper Dangaard Broueroptimal set automatically. 608192092faSJesper Dangaard Brouer 60954222838SJesper Dangaard BrouerFor cross-compilation, a specific version can be select manually as well :: 610192092faSJesper Dangaard Brouer 611192092faSJesper Dangaard Brouer $ llc -march bpf -mcpu=help 612192092faSJesper Dangaard Brouer Available CPUs for this target: 613192092faSJesper Dangaard Brouer 614192092faSJesper Dangaard Brouer generic - Select the generic processor. 615192092faSJesper Dangaard Brouer probe - Select the probe processor. 616192092faSJesper Dangaard Brouer v1 - Select the v1 processor. 617192092faSJesper Dangaard Brouer v2 - Select the v2 processor. 618192092faSJesper Dangaard Brouer [...] 619192092faSJesper Dangaard Brouer 620192092faSJesper Dangaard BrouerNewly added BPF instructions to the Linux kernel need to follow the same 621192092faSJesper Dangaard Brouerscheme, bump the instruction set version and implement probing for the 62254222838SJesper Dangaard Brouerextensions such that ``-mcpu=probe`` users can benefit from the 62354222838SJesper Dangaard Broueroptimization transparently when upgrading their kernels. 624192092faSJesper Dangaard Brouer 625192092faSJesper Dangaard BrouerIf you are unable to implement support for the newly added BPF instruction 626192092faSJesper Dangaard Brouerplease reach out to BPF developers for help. 627192092faSJesper Dangaard Brouer 62854222838SJesper Dangaard BrouerBy the way, the BPF kernel selftests run with ``-mcpu=probe`` for better 629192092faSJesper Dangaard Brouertest coverage. 630192092faSJesper Dangaard Brouer 63154222838SJesper Dangaard BrouerQ: clang flag for target bpf? 63254222838SJesper Dangaard Brouer----------------------------- 63354222838SJesper Dangaard BrouerQ: In some cases clang flag ``-target bpf`` is used but in other cases the 634192092faSJesper Dangaard Brouerdefault clang target, which matches the underlying architecture, is used. 635192092faSJesper Dangaard BrouerWhat is the difference and when I should use which? 636192092faSJesper Dangaard Brouer 637192092faSJesper Dangaard BrouerA: Although LLVM IR generation and optimization try to stay architecture 63854222838SJesper Dangaard Brouerindependent, ``-target <arch>`` still has some impact on generated code: 639192092faSJesper Dangaard Brouer 640192092faSJesper Dangaard Brouer- BPF program may recursively include header file(s) with file scope 641192092faSJesper Dangaard Brouer inline assembly codes. The default target can handle this well, 64254222838SJesper Dangaard Brouer while ``bpf`` target may fail if bpf backend assembler does not 643192092faSJesper Dangaard Brouer understand these assembly codes, which is true in most cases. 644192092faSJesper Dangaard Brouer 64554222838SJesper Dangaard Brouer- When compiled without ``-g``, additional elf sections, e.g., 646192092faSJesper Dangaard Brouer .eh_frame and .rela.eh_frame, may be present in the object file 64754222838SJesper Dangaard Brouer with default target, but not with ``bpf`` target. 648192092faSJesper Dangaard Brouer 649192092faSJesper Dangaard Brouer- The default target may turn a C switch statement into a switch table 650192092faSJesper Dangaard Brouer lookup and jump operation. Since the switch table is placed 651192092faSJesper Dangaard Brouer in the global readonly section, the bpf program will fail to load. 652192092faSJesper Dangaard Brouer The bpf target does not support switch table optimization. 65354222838SJesper Dangaard Brouer The clang option ``-fno-jump-tables`` can be used to disable 654192092faSJesper Dangaard Brouer switch table generation. 655192092faSJesper Dangaard Brouer 65654222838SJesper Dangaard Brouer- For clang ``-target bpf``, it is guaranteed that pointer or long / 657192092faSJesper Dangaard Brouer unsigned long types will always have a width of 64 bit, no matter 658192092faSJesper Dangaard Brouer whether underlying clang binary or default target (or kernel) is 659192092faSJesper Dangaard Brouer 32 bit. However, when native clang target is used, then it will 660192092faSJesper Dangaard Brouer compile these types based on the underlying architecture's conventions, 661192092faSJesper Dangaard Brouer meaning in case of 32 bit architecture, pointer or long / unsigned 662192092faSJesper Dangaard Brouer long types e.g. in BPF context structure will have width of 32 bit 663192092faSJesper Dangaard Brouer while the BPF LLVM back end still operates in 64 bit. The native 66454222838SJesper Dangaard Brouer target is mostly needed in tracing for the case of walking ``pt_regs`` 665192092faSJesper Dangaard Brouer or other kernel structures where CPU's register width matters. 66654222838SJesper Dangaard Brouer Otherwise, ``clang -target bpf`` is generally recommended. 667192092faSJesper Dangaard Brouer 668192092faSJesper Dangaard BrouerYou should use default target when: 669192092faSJesper Dangaard Brouer 670192092faSJesper Dangaard Brouer- Your program includes a header file, e.g., ptrace.h, which eventually 671192092faSJesper Dangaard Brouer pulls in some header files containing file scope host assembly codes. 672192092faSJesper Dangaard Brouer 67354222838SJesper Dangaard Brouer- You can add ``-fno-jump-tables`` to work around the switch table issue. 67454222838SJesper Dangaard Brouer 67554222838SJesper Dangaard BrouerOtherwise, you can use ``bpf`` target. Additionally, you *must* use bpf target 676192092faSJesper Dangaard Brouerwhen: 677192092faSJesper Dangaard Brouer 678192092faSJesper Dangaard Brouer- Your program uses data structures with pointer or long / unsigned long 679192092faSJesper Dangaard Brouer types that interface with BPF helpers or context data structures. Access 680192092faSJesper Dangaard Brouer into these structures is verified by the BPF verifier and may result 681192092faSJesper Dangaard Brouer in verification failures if the native architecture is not aligned with 682192092faSJesper Dangaard Brouer the BPF architecture, e.g. 64-bit. An example of this is 68354222838SJesper Dangaard Brouer BPF_PROG_TYPE_SK_MSG require ``-target bpf`` 68454222838SJesper Dangaard Brouer 68554222838SJesper Dangaard Brouer 68654222838SJesper Dangaard Brouer.. Links 6878df01363SJakub Kicinski.. _netdev-FAQ: Documentation/process/maintainer-netdev.rst 68864ef3ddfSTiezhu Yang.. _selftests: 68964ef3ddfSTiezhu Yang https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/bpf/ 690192092faSJesper Dangaard Brouer 691192092faSJesper Dangaard BrouerHappy BPF hacking! 692