1*54222838SJesper Dangaard Brouer================================= 2*54222838SJesper Dangaard BrouerHOWTO interact with BPF subsystem 3*54222838SJesper Dangaard Brouer================================= 4*54222838SJesper 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*54222838SJesper Dangaard Brouer`Documentation/process/`_. This document only describes additional specifics 11192092faSJesper Dangaard Brouerrelated to BPF. 12192092faSJesper Dangaard Brouer 13*54222838SJesper Dangaard Brouer.. contents:: 14*54222838SJesper Dangaard Brouer :local: 15*54222838SJesper Dangaard Brouer :depth: 2 16*54222838SJesper Dangaard Brouer 17*54222838SJesper Dangaard BrouerReporting bugs 18*54222838SJesper Dangaard Brouer============== 19192092faSJesper Dangaard Brouer 20192092faSJesper Dangaard BrouerQ: How do I report bugs for BPF kernel code? 21*54222838SJesper Dangaard Brouer-------------------------------------------- 22192092faSJesper Dangaard BrouerA: Since all BPF kernel development as well as bpftool and iproute2 BPF 23192092faSJesper Dangaard Brouerloader development happens through the netdev kernel mailing list, 24192092faSJesper Dangaard Brouerplease report any found issues around BPF to the following mailing 25192092faSJesper Dangaard Brouerlist: 26192092faSJesper Dangaard Brouer 27192092faSJesper Dangaard Brouer netdev@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 32*54222838SJesper Dangaard Brouermaintainers to Cc (from kernel MAINTAINERS_ file): 33192092faSJesper Dangaard Brouer 34*54222838SJesper Dangaard Brouer* Alexei Starovoitov <ast@kernel.org> 35*54222838SJesper 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 41*54222838SJesper Dangaard Brouer**Please do NOT report BPF issues to bugzilla.kernel.org since it 42*54222838SJesper Dangaard Broueris a guarantee that the reported issue will be overlooked.** 43192092faSJesper Dangaard Brouer 44*54222838SJesper Dangaard BrouerSubmitting patches 45*54222838SJesper Dangaard Brouer================== 46192092faSJesper Dangaard Brouer 47192092faSJesper Dangaard BrouerQ: To which mailing list do I need to submit my BPF patches? 48*54222838SJesper Dangaard Brouer------------------------------------------------------------ 49192092faSJesper Dangaard BrouerA: Please submit your BPF patches to the netdev kernel mailing list: 50192092faSJesper Dangaard Brouer 51192092faSJesper Dangaard Brouer netdev@vger.kernel.org 52192092faSJesper Dangaard Brouer 53192092faSJesper Dangaard BrouerHistorically, BPF came out of networking and has always been maintained 54192092faSJesper Dangaard Brouerby the kernel networking community. Although these days BPF touches 55192092faSJesper Dangaard Brouermany other subsystems as well, the patches are still routed mainly 56192092faSJesper Dangaard Brouerthrough the networking community. 57192092faSJesper Dangaard Brouer 58192092faSJesper Dangaard BrouerIn case your patch has changes in various different subsystems (e.g. 59192092faSJesper Dangaard Brouertracing, security, etc), make sure to Cc the related kernel mailing 60192092faSJesper Dangaard Brouerlists and maintainers from there as well, so they are able to review 61192092faSJesper Dangaard Brouerthe changes and provide their Acked-by's to the patches. 62192092faSJesper Dangaard Brouer 63192092faSJesper Dangaard BrouerQ: Where can I find patches currently under discussion for BPF subsystem? 64*54222838SJesper Dangaard Brouer------------------------------------------------------------------------- 65192092faSJesper Dangaard BrouerA: All patches that are Cc'ed to netdev are queued for review under netdev 66192092faSJesper Dangaard Brouerpatchwork project: 67192092faSJesper Dangaard Brouer 68192092faSJesper Dangaard Brouer http://patchwork.ozlabs.org/project/netdev/list/ 69192092faSJesper Dangaard Brouer 70192092faSJesper Dangaard BrouerThose patches which target BPF, are assigned to a 'bpf' delegate for 71192092faSJesper Dangaard Brouerfurther processing from BPF maintainers. The current queue with 72192092faSJesper Dangaard Brouerpatches under review can be found at: 73192092faSJesper Dangaard Brouer 74192092faSJesper Dangaard Brouer https://patchwork.ozlabs.org/project/netdev/list/?delegate=77147 75192092faSJesper Dangaard Brouer 76192092faSJesper Dangaard BrouerOnce the patches have been reviewed by the BPF community as a whole 77192092faSJesper Dangaard Brouerand approved by the BPF maintainers, their status in patchwork will be 78192092faSJesper Dangaard Brouerchanged to 'Accepted' and the submitter will be notified by mail. This 79192092faSJesper Dangaard Brouermeans that the patches look good from a BPF perspective and have been 80192092faSJesper Dangaard Brouerapplied to one of the two BPF kernel trees. 81192092faSJesper Dangaard Brouer 82192092faSJesper Dangaard BrouerIn case feedback from the community requires a respin of the patches, 83192092faSJesper Dangaard Brouertheir status in patchwork will be set to 'Changes Requested', and purged 84192092faSJesper Dangaard Brouerfrom the current review queue. Likewise for cases where patches would 85192092faSJesper Dangaard Brouerget rejected or are not applicable to the BPF trees (but assigned to 86192092faSJesper Dangaard Brouerthe 'bpf' delegate). 87192092faSJesper Dangaard Brouer 88192092faSJesper Dangaard BrouerQ: How do the changes make their way into Linux? 89*54222838SJesper Dangaard Brouer------------------------------------------------ 90192092faSJesper Dangaard BrouerA: There are two BPF kernel trees (git repositories). Once patches have 91192092faSJesper Dangaard Brouerbeen accepted by the BPF maintainers, they will be applied to one 92192092faSJesper Dangaard Brouerof the two BPF trees: 93192092faSJesper Dangaard Brouer 94*54222838SJesper Dangaard Brouer * https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/ 95*54222838SJesper Dangaard Brouer * https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/ 96192092faSJesper Dangaard Brouer 97192092faSJesper Dangaard BrouerThe bpf tree itself is for fixes only, whereas bpf-next for features, 98192092faSJesper Dangaard Brouercleanups or other kind of improvements ("next-like" content). This is 99192092faSJesper Dangaard Broueranalogous to net and net-next trees for networking. Both bpf and 100192092faSJesper Dangaard Brouerbpf-next will only have a master branch in order to simplify against 101192092faSJesper Dangaard Brouerwhich branch patches should get rebased to. 102192092faSJesper Dangaard Brouer 103192092faSJesper Dangaard BrouerAccumulated BPF patches in the bpf tree will regularly get pulled 104192092faSJesper Dangaard Brouerinto the net kernel tree. Likewise, accumulated BPF patches accepted 105192092faSJesper Dangaard Brouerinto the bpf-next tree will make their way into net-next tree. net and 106192092faSJesper Dangaard Brouernet-next are both run by David S. Miller. From there, they will go 107192092faSJesper Dangaard Brouerinto the kernel mainline tree run by Linus Torvalds. To read up on the 108192092faSJesper Dangaard Brouerprocess of net and net-next being merged into the mainline tree, see 109*54222838SJesper Dangaard Brouerthe `netdev FAQ`_ under: 110192092faSJesper Dangaard Brouer 111*54222838SJesper Dangaard Brouer `Documentation/networking/netdev-FAQ.txt`_ 112192092faSJesper Dangaard Brouer 113192092faSJesper Dangaard BrouerOccasionally, to prevent merge conflicts, we might send pull requests 114192092faSJesper Dangaard Brouerto other trees (e.g. tracing) with a small subset of the patches, but 115192092faSJesper Dangaard Brouernet and net-next are always the main trees targeted for integration. 116192092faSJesper Dangaard Brouer 117192092faSJesper Dangaard BrouerThe pull requests will contain a high-level summary of the accumulated 118192092faSJesper Dangaard Brouerpatches and can be searched on netdev kernel mailing list through the 119*54222838SJesper Dangaard Brouerfollowing subject lines (``yyyy-mm-dd`` is the date of the pull 120*54222838SJesper Dangaard Brouerrequest):: 121192092faSJesper Dangaard Brouer 122192092faSJesper Dangaard Brouer pull-request: bpf yyyy-mm-dd 123192092faSJesper Dangaard Brouer pull-request: bpf-next yyyy-mm-dd 124192092faSJesper Dangaard Brouer 125*54222838SJesper Dangaard BrouerQ: How do I indicate which tree (bpf vs. bpf-next) my patch should be applied to? 126*54222838SJesper Dangaard Brouer--------------------------------------------------------------------------------- 127192092faSJesper Dangaard Brouer 128*54222838SJesper Dangaard BrouerA: The process is the very same as described in the `netdev FAQ`_, so 129192092faSJesper Dangaard Brouerplease read up on it. The subject line must indicate whether the 130192092faSJesper Dangaard Brouerpatch is a fix or rather "next-like" content in order to let the 131192092faSJesper Dangaard Brouermaintainers know whether it is targeted at bpf or bpf-next. 132192092faSJesper Dangaard Brouer 133192092faSJesper Dangaard BrouerFor fixes eventually landing in bpf -> net tree, the subject must 134*54222838SJesper Dangaard Brouerlook like:: 135192092faSJesper Dangaard Brouer 136192092faSJesper Dangaard Brouer git format-patch --subject-prefix='PATCH bpf' start..finish 137192092faSJesper Dangaard Brouer 138192092faSJesper Dangaard BrouerFor features/improvements/etc that should eventually land in 139*54222838SJesper Dangaard Brouerbpf-next -> net-next, the subject must look like:: 140192092faSJesper Dangaard Brouer 141192092faSJesper Dangaard Brouer git format-patch --subject-prefix='PATCH bpf-next' start..finish 142192092faSJesper Dangaard Brouer 143192092faSJesper Dangaard BrouerIf unsure whether the patch or patch series should go into bpf 144192092faSJesper Dangaard Broueror net directly, or bpf-next or net-next directly, it is not a 145192092faSJesper Dangaard Brouerproblem either if the subject line says net or net-next as target. 146192092faSJesper Dangaard BrouerIt is eventually up to the maintainers to do the delegation of 147192092faSJesper Dangaard Brouerthe patches. 148192092faSJesper Dangaard Brouer 149192092faSJesper Dangaard BrouerIf it is clear that patches should go into bpf or bpf-next tree, 150192092faSJesper Dangaard Brouerplease make sure to rebase the patches against those trees in 151192092faSJesper Dangaard Brouerorder to reduce potential conflicts. 152192092faSJesper Dangaard Brouer 153192092faSJesper Dangaard BrouerIn case the patch or patch series has to be reworked and sent out 154192092faSJesper Dangaard Broueragain in a second or later revision, it is also required to add a 155*54222838SJesper Dangaard Brouerversion number (``v2``, ``v3``, ...) into the subject prefix:: 156192092faSJesper Dangaard Brouer 157192092faSJesper Dangaard Brouer git format-patch --subject-prefix='PATCH net-next v2' start..finish 158192092faSJesper Dangaard Brouer 159192092faSJesper Dangaard BrouerWhen changes have been requested to the patch series, always send the 160192092faSJesper Dangaard Brouerwhole patch series again with the feedback incorporated (never send 161192092faSJesper Dangaard Brouerindividual diffs on top of the old series). 162192092faSJesper Dangaard Brouer 163192092faSJesper Dangaard BrouerQ: What does it mean when a patch gets applied to bpf or bpf-next tree? 164*54222838SJesper Dangaard Brouer----------------------------------------------------------------------- 165192092faSJesper Dangaard BrouerA: It means that the patch looks good for mainline inclusion from 166192092faSJesper Dangaard Brouera BPF point of view. 167192092faSJesper Dangaard Brouer 168192092faSJesper Dangaard BrouerBe aware that this is not a final verdict that the patch will 169192092faSJesper Dangaard Brouerautomatically get accepted into net or net-next trees eventually: 170192092faSJesper Dangaard Brouer 171192092faSJesper Dangaard BrouerOn the netdev kernel mailing list reviews can come in at any point 172192092faSJesper Dangaard Brouerin time. If discussions around a patch conclude that they cannot 173192092faSJesper Dangaard Brouerget included as-is, we will either apply a follow-up fix or drop 174192092faSJesper Dangaard Brouerthem from the trees entirely. Therefore, we also reserve to rebase 175192092faSJesper Dangaard Brouerthe trees when deemed necessary. After all, the purpose of the tree 176*54222838SJesper Dangaard Broueris to: 177*54222838SJesper Dangaard Brouer 178*54222838SJesper Dangaard Broueri) accumulate and stage BPF patches for integration into trees 179*54222838SJesper Dangaard Brouer like net and net-next, and 180*54222838SJesper Dangaard Brouer 181*54222838SJesper Dangaard Brouerii) run extensive BPF test suite and 182192092faSJesper Dangaard Brouer workloads on the patches before they make their way any further. 183192092faSJesper Dangaard Brouer 184192092faSJesper Dangaard BrouerOnce the BPF pull request was accepted by David S. Miller, then 185192092faSJesper Dangaard Brouerthe patches end up in net or net-next tree, respectively, and 186192092faSJesper Dangaard Brouermake their way from there further into mainline. Again, see the 187*54222838SJesper Dangaard Brouer`netdev FAQ`_ for additional information e.g. on how often they are 188192092faSJesper Dangaard Brouermerged to mainline. 189192092faSJesper Dangaard Brouer 190192092faSJesper Dangaard BrouerQ: How long do I need to wait for feedback on my BPF patches? 191*54222838SJesper Dangaard Brouer------------------------------------------------------------- 192192092faSJesper Dangaard BrouerA: We try to keep the latency low. The usual time to feedback will 193192092faSJesper Dangaard Brouerbe around 2 or 3 business days. It may vary depending on the 194192092faSJesper Dangaard Brouercomplexity of changes and current patch load. 195192092faSJesper Dangaard Brouer 196*54222838SJesper Dangaard BrouerQ: How often do you send pull requests to major kernel trees like net or net-next? 197*54222838SJesper Dangaard Brouer---------------------------------------------------------------------------------- 198192092faSJesper Dangaard Brouer 199192092faSJesper Dangaard BrouerA: Pull requests will be sent out rather often in order to not 200192092faSJesper Dangaard Broueraccumulate too many patches in bpf or bpf-next. 201192092faSJesper Dangaard Brouer 202192092faSJesper Dangaard BrouerAs a rule of thumb, expect pull requests for each tree regularly 203192092faSJesper Dangaard Brouerat the end of the week. In some cases pull requests could additionally 204192092faSJesper Dangaard Brouercome also in the middle of the week depending on the current patch 205192092faSJesper Dangaard Brouerload or urgency. 206192092faSJesper Dangaard Brouer 207192092faSJesper Dangaard BrouerQ: Are patches applied to bpf-next when the merge window is open? 208*54222838SJesper Dangaard Brouer----------------------------------------------------------------- 209192092faSJesper Dangaard BrouerA: For the time when the merge window is open, bpf-next will not be 210192092faSJesper Dangaard Brouerprocessed. This is roughly analogous to net-next patch processing, 211*54222838SJesper Dangaard Brouerso feel free to read up on the `netdev FAQ`_ about further details. 212192092faSJesper Dangaard Brouer 213192092faSJesper Dangaard BrouerDuring those two weeks of merge window, we might ask you to resend 214192092faSJesper Dangaard Broueryour patch series once bpf-next is open again. Once Linus released 215*54222838SJesper Dangaard Brouera ``v*-rc1`` after the merge window, we continue processing of bpf-next. 216192092faSJesper Dangaard Brouer 217192092faSJesper Dangaard BrouerFor non-subscribers to kernel mailing lists, there is also a status 218192092faSJesper Dangaard Brouerpage run by David S. Miller on net-next that provides guidance: 219192092faSJesper Dangaard Brouer 220192092faSJesper Dangaard Brouer http://vger.kernel.org/~davem/net-next.html 221192092faSJesper Dangaard Brouer 222*54222838SJesper Dangaard BrouerQ: Verifier changes and test cases 223*54222838SJesper Dangaard Brouer---------------------------------- 224192092faSJesper Dangaard BrouerQ: I made a BPF verifier change, do I need to add test cases for 225*54222838SJesper Dangaard BrouerBPF kernel selftests_? 226192092faSJesper Dangaard Brouer 227192092faSJesper Dangaard BrouerA: If the patch has changes to the behavior of the verifier, then yes, 228192092faSJesper Dangaard Brouerit is absolutely necessary to add test cases to the BPF kernel 229*54222838SJesper Dangaard Brouerselftests_ suite. If they are not present and we think they are 230192092faSJesper Dangaard Brouerneeded, then we might ask for them before accepting any changes. 231192092faSJesper Dangaard Brouer 232192092faSJesper Dangaard BrouerIn particular, test_verifier.c is tracking a high number of BPF test 233192092faSJesper Dangaard Brouercases, including a lot of corner cases that LLVM BPF back end may 234192092faSJesper Dangaard Brouergenerate out of the restricted C code. Thus, adding test cases is 235192092faSJesper Dangaard Brouerabsolutely crucial to make sure future changes do not accidentally 236192092faSJesper Dangaard Broueraffect prior use-cases. Thus, treat those test cases as: verifier 237192092faSJesper Dangaard Brouerbehavior that is not tracked in test_verifier.c could potentially 238192092faSJesper Dangaard Brouerbe subject to change. 239192092faSJesper Dangaard Brouer 240*54222838SJesper Dangaard BrouerQ: samples/bpf preference vs selftests? 241*54222838SJesper Dangaard Brouer--------------------------------------- 242*54222838SJesper Dangaard BrouerQ: When should I add code to `samples/bpf/`_ and when to BPF kernel 243*54222838SJesper Dangaard Brouerselftests_ ? 244192092faSJesper Dangaard Brouer 245*54222838SJesper Dangaard BrouerA: In general, we prefer additions to BPF kernel selftests_ rather than 246*54222838SJesper Dangaard Brouer`samples/bpf/`_. The rationale is very simple: kernel selftests are 247192092faSJesper Dangaard Brouerregularly run by various bots to test for kernel regressions. 248192092faSJesper Dangaard Brouer 249192092faSJesper Dangaard BrouerThe more test cases we add to BPF selftests, the better the coverage 250192092faSJesper Dangaard Brouerand the less likely it is that those could accidentally break. It is 251192092faSJesper Dangaard Brouernot that BPF kernel selftests cannot demo how a specific feature can 252192092faSJesper Dangaard Brouerbe used. 253192092faSJesper Dangaard Brouer 254*54222838SJesper Dangaard BrouerThat said, `samples/bpf/`_ may be a good place for people to get started, 255192092faSJesper Dangaard Brouerso it might be advisable that simple demos of features could go into 256*54222838SJesper Dangaard Brouer`samples/bpf/`_, but advanced functional and corner-case testing rather 257192092faSJesper Dangaard Brouerinto kernel selftests. 258192092faSJesper Dangaard Brouer 259192092faSJesper Dangaard BrouerIf your sample looks like a test case, then go for BPF kernel selftests 260192092faSJesper Dangaard Brouerinstead! 261192092faSJesper Dangaard Brouer 262192092faSJesper Dangaard BrouerQ: When should I add code to the bpftool? 263*54222838SJesper Dangaard Brouer----------------------------------------- 264192092faSJesper Dangaard BrouerA: The main purpose of bpftool (under tools/bpf/bpftool/) is to provide 265192092faSJesper Dangaard Brouera central user space tool for debugging and introspection of BPF programs 266192092faSJesper Dangaard Brouerand maps that are active in the kernel. If UAPI changes related to BPF 267192092faSJesper Dangaard Brouerenable for dumping additional information of programs or maps, then 268192092faSJesper Dangaard Brouerbpftool should be extended as well to support dumping them. 269192092faSJesper Dangaard Brouer 270192092faSJesper Dangaard BrouerQ: When should I add code to iproute2's BPF loader? 271*54222838SJesper Dangaard Brouer--------------------------------------------------- 272*54222838SJesper Dangaard BrouerA: For UAPI changes related to the XDP or tc layer (e.g. ``cls_bpf``), 273*54222838SJesper Dangaard Brouerthe convention is that those control-path related changes are added to 274192092faSJesper Dangaard Broueriproute2's BPF loader as well from user space side. This is not only 275192092faSJesper Dangaard Broueruseful to have UAPI changes properly designed to be usable, but also 276192092faSJesper Dangaard Brouerto make those changes available to a wider user base of major 277192092faSJesper Dangaard Brouerdownstream distributions. 278192092faSJesper Dangaard Brouer 279192092faSJesper Dangaard BrouerQ: Do you accept patches as well for iproute2's BPF loader? 280*54222838SJesper Dangaard Brouer----------------------------------------------------------- 281192092faSJesper Dangaard BrouerA: Patches for the iproute2's BPF loader have to be sent to: 282192092faSJesper Dangaard Brouer 283192092faSJesper Dangaard Brouer netdev@vger.kernel.org 284192092faSJesper Dangaard Brouer 285192092faSJesper Dangaard BrouerWhile those patches are not processed by the BPF kernel maintainers, 286192092faSJesper Dangaard Brouerplease keep them in Cc as well, so they can be reviewed. 287192092faSJesper Dangaard Brouer 288192092faSJesper Dangaard BrouerThe official git repository for iproute2 is run by Stephen Hemminger 289192092faSJesper Dangaard Brouerand can be found at: 290192092faSJesper Dangaard Brouer 291192092faSJesper Dangaard Brouer https://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git/ 292192092faSJesper Dangaard Brouer 293*54222838SJesper Dangaard BrouerThe patches need to have a subject prefix of '``[PATCH iproute2 294*54222838SJesper Dangaard Brouermaster]``' or '``[PATCH iproute2 net-next]``'. '``master``' or 295*54222838SJesper Dangaard Brouer'``net-next``' describes the target branch where the patch should be 296*54222838SJesper Dangaard Brouerapplied to. Meaning, if kernel changes went into the net-next kernel 297*54222838SJesper Dangaard Brouertree, then the related iproute2 changes need to go into the iproute2 298*54222838SJesper Dangaard Brouernet-next branch, otherwise they can be targeted at master branch. The 299*54222838SJesper Dangaard Broueriproute2 net-next branch will get merged into the master branch after 300*54222838SJesper Dangaard Brouerthe current iproute2 version from master has been released. 301192092faSJesper Dangaard Brouer 302192092faSJesper Dangaard BrouerLike BPF, the patches end up in patchwork under the netdev project and 303192092faSJesper Dangaard Brouerare delegated to 'shemminger' for further processing: 304192092faSJesper Dangaard Brouer 305192092faSJesper Dangaard Brouer http://patchwork.ozlabs.org/project/netdev/list/?delegate=389 306192092faSJesper Dangaard Brouer 307192092faSJesper Dangaard BrouerQ: What is the minimum requirement before I submit my BPF patches? 308*54222838SJesper Dangaard Brouer------------------------------------------------------------------ 309192092faSJesper Dangaard BrouerA: When submitting patches, always take the time and properly test your 310192092faSJesper Dangaard Brouerpatches *prior* to submission. Never rush them! If maintainers find 311192092faSJesper Dangaard Brouerthat your patches have not been properly tested, it is a good way to 312192092faSJesper Dangaard Brouerget them grumpy. Testing patch submissions is a hard requirement! 313192092faSJesper Dangaard Brouer 314*54222838SJesper Dangaard BrouerNote, fixes that go to bpf tree *must* have a ``Fixes:`` tag included. 315*54222838SJesper Dangaard BrouerThe same applies to fixes that target bpf-next, where the affected 316*54222838SJesper Dangaard Brouercommit is in net-next (or in some cases bpf-next). The ``Fixes:`` tag is 317*54222838SJesper Dangaard Brouercrucial in order to identify follow-up commits and tremendously helps 318*54222838SJesper Dangaard Brouerfor people having to do backporting, so it is a must have! 319192092faSJesper Dangaard Brouer 320192092faSJesper Dangaard BrouerWe also don't accept patches with an empty commit message. Take your 321192092faSJesper Dangaard Brouertime and properly write up a high quality commit message, it is 322192092faSJesper Dangaard Broueressential! 323192092faSJesper Dangaard Brouer 324192092faSJesper Dangaard BrouerThink about it this way: other developers looking at your code a month 325192092faSJesper Dangaard Brouerfrom now need to understand *why* a certain change has been done that 326192092faSJesper Dangaard Brouerway, and whether there have been flaws in the analysis or assumptions 327192092faSJesper Dangaard Brouerthat the original author did. Thus providing a proper rationale and 328192092faSJesper Dangaard Brouerdescribing the use-case for the changes is a must. 329192092faSJesper Dangaard Brouer 330192092faSJesper Dangaard BrouerPatch submissions with >1 patch must have a cover letter which includes 331192092faSJesper Dangaard Brouera high level description of the series. This high level summary will 332192092faSJesper Dangaard Brouerthen be placed into the merge commit by the BPF maintainers such that 333192092faSJesper Dangaard Brouerit is also accessible from the git log for future reference. 334192092faSJesper Dangaard Brouer 335*54222838SJesper Dangaard BrouerQ: Features changing BPF JIT and/or LLVM 336*54222838SJesper Dangaard Brouer---------------------------------------- 337192092faSJesper Dangaard BrouerQ: What do I need to consider when adding a new instruction or feature 338192092faSJesper Dangaard Brouerthat would require BPF JIT and/or LLVM integration as well? 339192092faSJesper Dangaard Brouer 340192092faSJesper Dangaard BrouerA: We try hard to keep all BPF JITs up to date such that the same user 341192092faSJesper Dangaard Brouerexperience can be guaranteed when running BPF programs on different 342192092faSJesper Dangaard Brouerarchitectures without having the program punt to the less efficient 343192092faSJesper Dangaard Brouerinterpreter in case the in-kernel BPF JIT is enabled. 344192092faSJesper Dangaard Brouer 345192092faSJesper Dangaard BrouerIf you are unable to implement or test the required JIT changes for 346192092faSJesper Dangaard Brouercertain architectures, please work together with the related BPF JIT 347192092faSJesper Dangaard Brouerdevelopers in order to get the feature implemented in a timely manner. 348*54222838SJesper Dangaard BrouerPlease refer to the git log (``arch/*/net/``) to locate the necessary 349192092faSJesper Dangaard Brouerpeople for helping out. 350192092faSJesper Dangaard Brouer 351192092faSJesper Dangaard BrouerAlso always make sure to add BPF test cases (e.g. test_bpf.c and 352192092faSJesper Dangaard Brouertest_verifier.c) for new instructions, so that they can receive 353192092faSJesper Dangaard Brouerbroad test coverage and help run-time testing the various BPF JITs. 354192092faSJesper Dangaard Brouer 355192092faSJesper Dangaard BrouerIn case of new BPF instructions, once the changes have been accepted 356192092faSJesper Dangaard Brouerinto the Linux kernel, please implement support into LLVM's BPF back 357*54222838SJesper Dangaard Brouerend. See LLVM_ section below for further information. 358192092faSJesper Dangaard Brouer 359*54222838SJesper Dangaard BrouerStable submission 360*54222838SJesper Dangaard Brouer================= 361192092faSJesper Dangaard Brouer 362192092faSJesper Dangaard BrouerQ: I need a specific BPF commit in stable kernels. What should I do? 363*54222838SJesper Dangaard Brouer-------------------------------------------------------------------- 364192092faSJesper Dangaard BrouerA: In case you need a specific fix in stable kernels, first check whether 365*54222838SJesper Dangaard Brouerthe commit has already been applied in the related ``linux-*.y`` branches: 366192092faSJesper Dangaard Brouer 367192092faSJesper Dangaard Brouer https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/ 368192092faSJesper Dangaard Brouer 369192092faSJesper Dangaard BrouerIf not the case, then drop an email to the BPF maintainers with the 370192092faSJesper Dangaard Brouernetdev kernel mailing list in Cc and ask for the fix to be queued up: 371192092faSJesper Dangaard Brouer 372192092faSJesper Dangaard Brouer netdev@vger.kernel.org 373192092faSJesper Dangaard Brouer 374192092faSJesper Dangaard BrouerThe process in general is the same as on netdev itself, see also the 375*54222838SJesper Dangaard Brouer`netdev FAQ`_ document. 376192092faSJesper Dangaard Brouer 377192092faSJesper Dangaard BrouerQ: Do you also backport to kernels not currently maintained as stable? 378*54222838SJesper Dangaard Brouer---------------------------------------------------------------------- 379192092faSJesper Dangaard BrouerA: No. If you need a specific BPF commit in kernels that are currently not 380192092faSJesper Dangaard Brouermaintained by the stable maintainers, then you are on your own. 381192092faSJesper Dangaard Brouer 382192092faSJesper Dangaard BrouerThe current stable and longterm stable kernels are all listed here: 383192092faSJesper Dangaard Brouer 384192092faSJesper Dangaard Brouer https://www.kernel.org/ 385192092faSJesper Dangaard Brouer 386*54222838SJesper Dangaard BrouerQ: The BPF patch I am about to submit needs to go to stable as well 387*54222838SJesper Dangaard Brouer------------------------------------------------------------------- 388*54222838SJesper Dangaard BrouerWhat should I do? 389192092faSJesper Dangaard Brouer 390192092faSJesper Dangaard BrouerA: The same rules apply as with netdev patch submissions in general, see 391*54222838SJesper Dangaard Brouer`netdev FAQ`_ under: 392192092faSJesper Dangaard Brouer 393*54222838SJesper Dangaard Brouer `Documentation/networking/netdev-FAQ.txt`_ 394192092faSJesper Dangaard Brouer 395*54222838SJesper Dangaard BrouerNever add "``Cc: stable@vger.kernel.org``" to the patch description, but 396192092faSJesper Dangaard Brouerask the BPF maintainers to queue the patches instead. This can be done 397*54222838SJesper Dangaard Brouerwith a note, for example, under the ``---`` part of the patch which does 398192092faSJesper Dangaard Brouernot go into the git log. Alternatively, this can be done as a simple 399192092faSJesper Dangaard Brouerrequest by mail instead. 400192092faSJesper Dangaard Brouer 401*54222838SJesper Dangaard BrouerQ: Queue stable patches 402*54222838SJesper Dangaard Brouer----------------------- 403192092faSJesper Dangaard BrouerQ: Where do I find currently queued BPF patches that will be submitted 404192092faSJesper Dangaard Brouerto stable? 405192092faSJesper Dangaard Brouer 406192092faSJesper Dangaard BrouerA: Once patches that fix critical bugs got applied into the bpf tree, they 407192092faSJesper Dangaard Brouerare queued up for stable submission under: 408192092faSJesper Dangaard Brouer 409192092faSJesper Dangaard Brouer http://patchwork.ozlabs.org/bundle/bpf/stable/?state=* 410192092faSJesper Dangaard Brouer 411192092faSJesper Dangaard BrouerThey will be on hold there at minimum until the related commit made its 412192092faSJesper Dangaard Brouerway into the mainline kernel tree. 413192092faSJesper Dangaard Brouer 414192092faSJesper Dangaard BrouerAfter having been under broader exposure, the queued patches will be 415192092faSJesper Dangaard Brouersubmitted by the BPF maintainers to the stable maintainers. 416192092faSJesper Dangaard Brouer 417*54222838SJesper Dangaard BrouerTesting patches 418*54222838SJesper Dangaard Brouer=============== 419192092faSJesper Dangaard Brouer 420192092faSJesper Dangaard BrouerQ: Which BPF kernel selftests version should I run my kernel against? 421*54222838SJesper Dangaard Brouer--------------------------------------------------------------------- 422*54222838SJesper Dangaard BrouerA: If you run a kernel ``xyz``, then always run the BPF kernel selftests 423*54222838SJesper Dangaard Brouerfrom that kernel ``xyz`` as well. Do not expect that the BPF selftest 424*54222838SJesper Dangaard Brouerfrom the latest mainline tree will pass all the time. 425192092faSJesper Dangaard Brouer 426192092faSJesper Dangaard BrouerIn particular, test_bpf.c and test_verifier.c have a large number of 427192092faSJesper Dangaard Brouertest cases and are constantly updated with new BPF test sequences, or 428192092faSJesper Dangaard Brouerexisting ones are adapted to verifier changes e.g. due to verifier 429192092faSJesper Dangaard Brouerbecoming smarter and being able to better track certain things. 430192092faSJesper Dangaard Brouer 431*54222838SJesper Dangaard BrouerLLVM 432*54222838SJesper Dangaard Brouer==== 433192092faSJesper Dangaard Brouer 434192092faSJesper Dangaard BrouerQ: Where do I find LLVM with BPF support? 435*54222838SJesper Dangaard Brouer----------------------------------------- 436192092faSJesper Dangaard BrouerA: The BPF back end for LLVM is upstream in LLVM since version 3.7.1. 437192092faSJesper Dangaard Brouer 438192092faSJesper Dangaard BrouerAll major distributions these days ship LLVM with BPF back end enabled, 439192092faSJesper Dangaard Brouerso for the majority of use-cases it is not required to compile LLVM by 440192092faSJesper Dangaard Brouerhand anymore, just install the distribution provided package. 441192092faSJesper Dangaard Brouer 442*54222838SJesper Dangaard BrouerLLVM's static compiler lists the supported targets through 443*54222838SJesper Dangaard Brouer``llc --version``, make sure BPF targets are listed. Example:: 444192092faSJesper Dangaard Brouer 445192092faSJesper Dangaard Brouer $ llc --version 446192092faSJesper Dangaard Brouer LLVM (http://llvm.org/): 447192092faSJesper Dangaard Brouer LLVM version 6.0.0svn 448192092faSJesper Dangaard Brouer Optimized build. 449192092faSJesper Dangaard Brouer Default target: x86_64-unknown-linux-gnu 450192092faSJesper Dangaard Brouer Host CPU: skylake 451192092faSJesper Dangaard Brouer 452192092faSJesper Dangaard Brouer Registered Targets: 453192092faSJesper Dangaard Brouer bpf - BPF (host endian) 454192092faSJesper Dangaard Brouer bpfeb - BPF (big endian) 455192092faSJesper Dangaard Brouer bpfel - BPF (little endian) 456192092faSJesper Dangaard Brouer x86 - 32-bit X86: Pentium-Pro and above 457192092faSJesper Dangaard Brouer x86-64 - 64-bit X86: EM64T and AMD64 458192092faSJesper Dangaard Brouer 459192092faSJesper Dangaard BrouerFor developers in order to utilize the latest features added to LLVM's 460192092faSJesper Dangaard BrouerBPF back end, it is advisable to run the latest LLVM releases. Support 461192092faSJesper Dangaard Brouerfor new BPF kernel features such as additions to the BPF instruction 462192092faSJesper Dangaard Brouerset are often developed together. 463192092faSJesper Dangaard Brouer 464192092faSJesper Dangaard BrouerAll LLVM releases can be found at: http://releases.llvm.org/ 465192092faSJesper Dangaard Brouer 466192092faSJesper Dangaard BrouerQ: Got it, so how do I build LLVM manually anyway? 467*54222838SJesper Dangaard Brouer-------------------------------------------------- 468192092faSJesper Dangaard BrouerA: You need cmake and gcc-c++ as build requisites for LLVM. Once you have 469192092faSJesper Dangaard Brouerthat set up, proceed with building the latest LLVM and clang version 470*54222838SJesper Dangaard Brouerfrom the git repositories:: 471192092faSJesper Dangaard Brouer 472192092faSJesper Dangaard Brouer $ git clone http://llvm.org/git/llvm.git 473192092faSJesper Dangaard Brouer $ cd llvm/tools 474192092faSJesper Dangaard Brouer $ git clone --depth 1 http://llvm.org/git/clang.git 475192092faSJesper Dangaard Brouer $ cd ..; mkdir build; cd build 476192092faSJesper Dangaard Brouer $ cmake .. -DLLVM_TARGETS_TO_BUILD="BPF;X86" \ 477192092faSJesper Dangaard Brouer -DBUILD_SHARED_LIBS=OFF \ 478192092faSJesper Dangaard Brouer -DCMAKE_BUILD_TYPE=Release \ 479192092faSJesper Dangaard Brouer -DLLVM_BUILD_RUNTIME=OFF 480192092faSJesper Dangaard Brouer $ make -j $(getconf _NPROCESSORS_ONLN) 481192092faSJesper Dangaard Brouer 482192092faSJesper Dangaard BrouerThe built binaries can then be found in the build/bin/ directory, where 483192092faSJesper Dangaard Broueryou can point the PATH variable to. 484192092faSJesper Dangaard Brouer 485*54222838SJesper Dangaard BrouerQ: Reporting LLVM BPF issues 486*54222838SJesper Dangaard Brouer---------------------------- 487192092faSJesper Dangaard BrouerQ: Should I notify BPF kernel maintainers about issues in LLVM's BPF code 488192092faSJesper Dangaard Brouergeneration back end or about LLVM generated code that the verifier 489192092faSJesper Dangaard Brouerrefuses to accept? 490192092faSJesper Dangaard Brouer 491*54222838SJesper Dangaard BrouerA: Yes, please do! 492*54222838SJesper Dangaard Brouer 493*54222838SJesper Dangaard BrouerLLVM's BPF back end is a key piece of the whole BPF 494192092faSJesper Dangaard Brouerinfrastructure and it ties deeply into verification of programs from the 495192092faSJesper Dangaard Brouerkernel side. Therefore, any issues on either side need to be investigated 496192092faSJesper Dangaard Brouerand fixed whenever necessary. 497192092faSJesper Dangaard Brouer 498192092faSJesper Dangaard BrouerTherefore, please make sure to bring them up at netdev kernel mailing 499192092faSJesper Dangaard Brouerlist and Cc BPF maintainers for LLVM and kernel bits: 500192092faSJesper Dangaard Brouer 501*54222838SJesper Dangaard Brouer* Yonghong Song <yhs@fb.com> 502*54222838SJesper Dangaard Brouer* Alexei Starovoitov <ast@kernel.org> 503*54222838SJesper Dangaard Brouer* Daniel Borkmann <daniel@iogearbox.net> 504192092faSJesper Dangaard Brouer 505192092faSJesper Dangaard BrouerLLVM also has an issue tracker where BPF related bugs can be found: 506192092faSJesper Dangaard Brouer 507192092faSJesper Dangaard Brouer https://bugs.llvm.org/buglist.cgi?quicksearch=bpf 508192092faSJesper Dangaard Brouer 509192092faSJesper Dangaard BrouerHowever, it is better to reach out through mailing lists with having 510192092faSJesper Dangaard Brouermaintainers in Cc. 511192092faSJesper Dangaard Brouer 512*54222838SJesper Dangaard BrouerQ: New BPF instruction for kernel and LLVM 513*54222838SJesper Dangaard Brouer------------------------------------------ 514192092faSJesper Dangaard BrouerQ: I have added a new BPF instruction to the kernel, how can I integrate 515192092faSJesper Dangaard Brouerit into LLVM? 516192092faSJesper Dangaard Brouer 517*54222838SJesper Dangaard BrouerA: LLVM has a ``-mcpu`` selector for the BPF back end in order to allow 518*54222838SJesper Dangaard Brouerthe selection of BPF instruction set extensions. By default the 519*54222838SJesper Dangaard Brouer``generic`` processor target is used, which is the base instruction set 520*54222838SJesper Dangaard Brouer(v1) of BPF. 521192092faSJesper Dangaard Brouer 522*54222838SJesper Dangaard BrouerLLVM has an option to select ``-mcpu=probe`` where it will probe the host 523192092faSJesper Dangaard Brouerkernel for supported BPF instruction set extensions and selects the 524192092faSJesper Dangaard Broueroptimal set automatically. 525192092faSJesper Dangaard Brouer 526*54222838SJesper Dangaard BrouerFor cross-compilation, a specific version can be select manually as well :: 527192092faSJesper Dangaard Brouer 528192092faSJesper Dangaard Brouer $ llc -march bpf -mcpu=help 529192092faSJesper Dangaard Brouer Available CPUs for this target: 530192092faSJesper Dangaard Brouer 531192092faSJesper Dangaard Brouer generic - Select the generic processor. 532192092faSJesper Dangaard Brouer probe - Select the probe processor. 533192092faSJesper Dangaard Brouer v1 - Select the v1 processor. 534192092faSJesper Dangaard Brouer v2 - Select the v2 processor. 535192092faSJesper Dangaard Brouer [...] 536192092faSJesper Dangaard Brouer 537192092faSJesper Dangaard BrouerNewly added BPF instructions to the Linux kernel need to follow the same 538192092faSJesper Dangaard Brouerscheme, bump the instruction set version and implement probing for the 539*54222838SJesper Dangaard Brouerextensions such that ``-mcpu=probe`` users can benefit from the 540*54222838SJesper Dangaard Broueroptimization transparently when upgrading their kernels. 541192092faSJesper Dangaard Brouer 542192092faSJesper Dangaard BrouerIf you are unable to implement support for the newly added BPF instruction 543192092faSJesper Dangaard Brouerplease reach out to BPF developers for help. 544192092faSJesper Dangaard Brouer 545*54222838SJesper Dangaard BrouerBy the way, the BPF kernel selftests run with ``-mcpu=probe`` for better 546192092faSJesper Dangaard Brouertest coverage. 547192092faSJesper Dangaard Brouer 548*54222838SJesper Dangaard BrouerQ: clang flag for target bpf? 549*54222838SJesper Dangaard Brouer----------------------------- 550*54222838SJesper Dangaard BrouerQ: In some cases clang flag ``-target bpf`` is used but in other cases the 551192092faSJesper Dangaard Brouerdefault clang target, which matches the underlying architecture, is used. 552192092faSJesper Dangaard BrouerWhat is the difference and when I should use which? 553192092faSJesper Dangaard Brouer 554192092faSJesper Dangaard BrouerA: Although LLVM IR generation and optimization try to stay architecture 555*54222838SJesper Dangaard Brouerindependent, ``-target <arch>`` still has some impact on generated code: 556192092faSJesper Dangaard Brouer 557192092faSJesper Dangaard Brouer- BPF program may recursively include header file(s) with file scope 558192092faSJesper Dangaard Brouer inline assembly codes. The default target can handle this well, 559*54222838SJesper Dangaard Brouer while ``bpf`` target may fail if bpf backend assembler does not 560192092faSJesper Dangaard Brouer understand these assembly codes, which is true in most cases. 561192092faSJesper Dangaard Brouer 562*54222838SJesper Dangaard Brouer- When compiled without ``-g``, additional elf sections, e.g., 563192092faSJesper Dangaard Brouer .eh_frame and .rela.eh_frame, may be present in the object file 564*54222838SJesper Dangaard Brouer with default target, but not with ``bpf`` target. 565192092faSJesper Dangaard Brouer 566192092faSJesper Dangaard Brouer- The default target may turn a C switch statement into a switch table 567192092faSJesper Dangaard Brouer lookup and jump operation. Since the switch table is placed 568192092faSJesper Dangaard Brouer in the global readonly section, the bpf program will fail to load. 569192092faSJesper Dangaard Brouer The bpf target does not support switch table optimization. 570*54222838SJesper Dangaard Brouer The clang option ``-fno-jump-tables`` can be used to disable 571192092faSJesper Dangaard Brouer switch table generation. 572192092faSJesper Dangaard Brouer 573*54222838SJesper Dangaard Brouer- For clang ``-target bpf``, it is guaranteed that pointer or long / 574192092faSJesper Dangaard Brouer unsigned long types will always have a width of 64 bit, no matter 575192092faSJesper Dangaard Brouer whether underlying clang binary or default target (or kernel) is 576192092faSJesper Dangaard Brouer 32 bit. However, when native clang target is used, then it will 577192092faSJesper Dangaard Brouer compile these types based on the underlying architecture's conventions, 578192092faSJesper Dangaard Brouer meaning in case of 32 bit architecture, pointer or long / unsigned 579192092faSJesper Dangaard Brouer long types e.g. in BPF context structure will have width of 32 bit 580192092faSJesper Dangaard Brouer while the BPF LLVM back end still operates in 64 bit. The native 581*54222838SJesper Dangaard Brouer target is mostly needed in tracing for the case of walking ``pt_regs`` 582192092faSJesper Dangaard Brouer or other kernel structures where CPU's register width matters. 583*54222838SJesper Dangaard Brouer Otherwise, ``clang -target bpf`` is generally recommended. 584192092faSJesper Dangaard Brouer 585192092faSJesper Dangaard BrouerYou should use default target when: 586192092faSJesper Dangaard Brouer 587192092faSJesper Dangaard Brouer- Your program includes a header file, e.g., ptrace.h, which eventually 588192092faSJesper Dangaard Brouer pulls in some header files containing file scope host assembly codes. 589192092faSJesper Dangaard Brouer 590*54222838SJesper Dangaard Brouer- You can add ``-fno-jump-tables`` to work around the switch table issue. 591*54222838SJesper Dangaard Brouer 592*54222838SJesper Dangaard BrouerOtherwise, you can use ``bpf`` target. Additionally, you *must* use bpf target 593192092faSJesper Dangaard Brouerwhen: 594192092faSJesper Dangaard Brouer 595192092faSJesper Dangaard Brouer- Your program uses data structures with pointer or long / unsigned long 596192092faSJesper Dangaard Brouer types that interface with BPF helpers or context data structures. Access 597192092faSJesper Dangaard Brouer into these structures is verified by the BPF verifier and may result 598192092faSJesper Dangaard Brouer in verification failures if the native architecture is not aligned with 599192092faSJesper Dangaard Brouer the BPF architecture, e.g. 64-bit. An example of this is 600*54222838SJesper Dangaard Brouer BPF_PROG_TYPE_SK_MSG require ``-target bpf`` 601*54222838SJesper Dangaard Brouer 602*54222838SJesper Dangaard Brouer 603*54222838SJesper Dangaard Brouer.. Links 604*54222838SJesper Dangaard Brouer.. _Documentation/process/: https://www.kernel.org/doc/html/latest/process/ 605*54222838SJesper Dangaard Brouer.. _MAINTAINERS: ../../MAINTAINERS 606*54222838SJesper Dangaard Brouer.. _Documentation/networking/netdev-FAQ.txt: ../networking/netdev-FAQ.txt 607*54222838SJesper Dangaard Brouer.. _netdev FAQ: ../networking/netdev-FAQ.txt 608*54222838SJesper Dangaard Brouer.. _samples/bpf/: ../../samples/bpf/ 609*54222838SJesper Dangaard Brouer.. _selftests: ../../tools/testing/selftests/bpf/ 610192092faSJesper Dangaard Brouer 611192092faSJesper Dangaard BrouerHappy BPF hacking! 612