1*192092faSJesper Dangaard BrouerThis document provides information for the BPF subsystem about various 2*192092faSJesper Dangaard Brouerworkflows related to reporting bugs, submitting patches, and queueing 3*192092faSJesper Dangaard Brouerpatches for stable kernels. 4*192092faSJesper Dangaard Brouer 5*192092faSJesper Dangaard BrouerFor general information about submitting patches, please refer to 6*192092faSJesper Dangaard BrouerDocumentation/process/. This document only describes additional specifics 7*192092faSJesper Dangaard Brouerrelated to BPF. 8*192092faSJesper Dangaard Brouer 9*192092faSJesper Dangaard BrouerReporting bugs: 10*192092faSJesper Dangaard Brouer--------------- 11*192092faSJesper Dangaard Brouer 12*192092faSJesper Dangaard BrouerQ: How do I report bugs for BPF kernel code? 13*192092faSJesper Dangaard Brouer 14*192092faSJesper Dangaard BrouerA: Since all BPF kernel development as well as bpftool and iproute2 BPF 15*192092faSJesper Dangaard Brouer loader development happens through the netdev kernel mailing list, 16*192092faSJesper Dangaard Brouer please report any found issues around BPF to the following mailing 17*192092faSJesper Dangaard Brouer list: 18*192092faSJesper Dangaard Brouer 19*192092faSJesper Dangaard Brouer netdev@vger.kernel.org 20*192092faSJesper Dangaard Brouer 21*192092faSJesper Dangaard Brouer This may also include issues related to XDP, BPF tracing, etc. 22*192092faSJesper Dangaard Brouer 23*192092faSJesper Dangaard Brouer Given netdev has a high volume of traffic, please also add the BPF 24*192092faSJesper Dangaard Brouer maintainers to Cc (from kernel MAINTAINERS file): 25*192092faSJesper Dangaard Brouer 26*192092faSJesper Dangaard Brouer Alexei Starovoitov <ast@kernel.org> 27*192092faSJesper Dangaard Brouer Daniel Borkmann <daniel@iogearbox.net> 28*192092faSJesper Dangaard Brouer 29*192092faSJesper Dangaard Brouer In case a buggy commit has already been identified, make sure to keep 30*192092faSJesper Dangaard Brouer the actual commit authors in Cc as well for the report. They can 31*192092faSJesper Dangaard Brouer typically be identified through the kernel's git tree. 32*192092faSJesper Dangaard Brouer 33*192092faSJesper Dangaard Brouer Please do *not* report BPF issues to bugzilla.kernel.org since it 34*192092faSJesper Dangaard Brouer is a guarantee that the reported issue will be overlooked. 35*192092faSJesper Dangaard Brouer 36*192092faSJesper Dangaard BrouerSubmitting patches: 37*192092faSJesper Dangaard Brouer------------------- 38*192092faSJesper Dangaard Brouer 39*192092faSJesper Dangaard BrouerQ: To which mailing list do I need to submit my BPF patches? 40*192092faSJesper Dangaard Brouer 41*192092faSJesper Dangaard BrouerA: Please submit your BPF patches to the netdev kernel mailing list: 42*192092faSJesper Dangaard Brouer 43*192092faSJesper Dangaard Brouer netdev@vger.kernel.org 44*192092faSJesper Dangaard Brouer 45*192092faSJesper Dangaard Brouer Historically, BPF came out of networking and has always been maintained 46*192092faSJesper Dangaard Brouer by the kernel networking community. Although these days BPF touches 47*192092faSJesper Dangaard Brouer many other subsystems as well, the patches are still routed mainly 48*192092faSJesper Dangaard Brouer through the networking community. 49*192092faSJesper Dangaard Brouer 50*192092faSJesper Dangaard Brouer In case your patch has changes in various different subsystems (e.g. 51*192092faSJesper Dangaard Brouer tracing, security, etc), make sure to Cc the related kernel mailing 52*192092faSJesper Dangaard Brouer lists and maintainers from there as well, so they are able to review 53*192092faSJesper Dangaard Brouer the changes and provide their Acked-by's to the patches. 54*192092faSJesper Dangaard Brouer 55*192092faSJesper Dangaard BrouerQ: Where can I find patches currently under discussion for BPF subsystem? 56*192092faSJesper Dangaard Brouer 57*192092faSJesper Dangaard BrouerA: All patches that are Cc'ed to netdev are queued for review under netdev 58*192092faSJesper Dangaard Brouer patchwork project: 59*192092faSJesper Dangaard Brouer 60*192092faSJesper Dangaard Brouer http://patchwork.ozlabs.org/project/netdev/list/ 61*192092faSJesper Dangaard Brouer 62*192092faSJesper Dangaard Brouer Those patches which target BPF, are assigned to a 'bpf' delegate for 63*192092faSJesper Dangaard Brouer further processing from BPF maintainers. The current queue with 64*192092faSJesper Dangaard Brouer patches under review can be found at: 65*192092faSJesper Dangaard Brouer 66*192092faSJesper Dangaard Brouer https://patchwork.ozlabs.org/project/netdev/list/?delegate=77147 67*192092faSJesper Dangaard Brouer 68*192092faSJesper Dangaard Brouer Once the patches have been reviewed by the BPF community as a whole 69*192092faSJesper Dangaard Brouer and approved by the BPF maintainers, their status in patchwork will be 70*192092faSJesper Dangaard Brouer changed to 'Accepted' and the submitter will be notified by mail. This 71*192092faSJesper Dangaard Brouer means that the patches look good from a BPF perspective and have been 72*192092faSJesper Dangaard Brouer applied to one of the two BPF kernel trees. 73*192092faSJesper Dangaard Brouer 74*192092faSJesper Dangaard Brouer In case feedback from the community requires a respin of the patches, 75*192092faSJesper Dangaard Brouer their status in patchwork will be set to 'Changes Requested', and purged 76*192092faSJesper Dangaard Brouer from the current review queue. Likewise for cases where patches would 77*192092faSJesper Dangaard Brouer get rejected or are not applicable to the BPF trees (but assigned to 78*192092faSJesper Dangaard Brouer the 'bpf' delegate). 79*192092faSJesper Dangaard Brouer 80*192092faSJesper Dangaard BrouerQ: How do the changes make their way into Linux? 81*192092faSJesper Dangaard Brouer 82*192092faSJesper Dangaard BrouerA: There are two BPF kernel trees (git repositories). Once patches have 83*192092faSJesper Dangaard Brouer been accepted by the BPF maintainers, they will be applied to one 84*192092faSJesper Dangaard Brouer of the two BPF trees: 85*192092faSJesper Dangaard Brouer 86*192092faSJesper Dangaard Brouer https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/ 87*192092faSJesper Dangaard Brouer https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/ 88*192092faSJesper Dangaard Brouer 89*192092faSJesper Dangaard Brouer The bpf tree itself is for fixes only, whereas bpf-next for features, 90*192092faSJesper Dangaard Brouer cleanups or other kind of improvements ("next-like" content). This is 91*192092faSJesper Dangaard Brouer analogous to net and net-next trees for networking. Both bpf and 92*192092faSJesper Dangaard Brouer bpf-next will only have a master branch in order to simplify against 93*192092faSJesper Dangaard Brouer which branch patches should get rebased to. 94*192092faSJesper Dangaard Brouer 95*192092faSJesper Dangaard Brouer Accumulated BPF patches in the bpf tree will regularly get pulled 96*192092faSJesper Dangaard Brouer into the net kernel tree. Likewise, accumulated BPF patches accepted 97*192092faSJesper Dangaard Brouer into the bpf-next tree will make their way into net-next tree. net and 98*192092faSJesper Dangaard Brouer net-next are both run by David S. Miller. From there, they will go 99*192092faSJesper Dangaard Brouer into the kernel mainline tree run by Linus Torvalds. To read up on the 100*192092faSJesper Dangaard Brouer process of net and net-next being merged into the mainline tree, see 101*192092faSJesper Dangaard Brouer the netdev FAQ under: 102*192092faSJesper Dangaard Brouer 103*192092faSJesper Dangaard Brouer Documentation/networking/netdev-FAQ.txt 104*192092faSJesper Dangaard Brouer 105*192092faSJesper Dangaard Brouer Occasionally, to prevent merge conflicts, we might send pull requests 106*192092faSJesper Dangaard Brouer to other trees (e.g. tracing) with a small subset of the patches, but 107*192092faSJesper Dangaard Brouer net and net-next are always the main trees targeted for integration. 108*192092faSJesper Dangaard Brouer 109*192092faSJesper Dangaard Brouer The pull requests will contain a high-level summary of the accumulated 110*192092faSJesper Dangaard Brouer patches and can be searched on netdev kernel mailing list through the 111*192092faSJesper Dangaard Brouer following subject lines (yyyy-mm-dd is the date of the pull request): 112*192092faSJesper Dangaard Brouer 113*192092faSJesper Dangaard Brouer pull-request: bpf yyyy-mm-dd 114*192092faSJesper Dangaard Brouer pull-request: bpf-next yyyy-mm-dd 115*192092faSJesper Dangaard Brouer 116*192092faSJesper Dangaard BrouerQ: How do I indicate which tree (bpf vs. bpf-next) my patch should be 117*192092faSJesper Dangaard Brouer applied to? 118*192092faSJesper Dangaard Brouer 119*192092faSJesper Dangaard BrouerA: The process is the very same as described in the netdev FAQ, so 120*192092faSJesper Dangaard Brouer please read up on it. The subject line must indicate whether the 121*192092faSJesper Dangaard Brouer patch is a fix or rather "next-like" content in order to let the 122*192092faSJesper Dangaard Brouer maintainers know whether it is targeted at bpf or bpf-next. 123*192092faSJesper Dangaard Brouer 124*192092faSJesper Dangaard Brouer For fixes eventually landing in bpf -> net tree, the subject must 125*192092faSJesper Dangaard Brouer look like: 126*192092faSJesper Dangaard Brouer 127*192092faSJesper Dangaard Brouer git format-patch --subject-prefix='PATCH bpf' start..finish 128*192092faSJesper Dangaard Brouer 129*192092faSJesper Dangaard Brouer For features/improvements/etc that should eventually land in 130*192092faSJesper Dangaard Brouer bpf-next -> net-next, the subject must look like: 131*192092faSJesper Dangaard Brouer 132*192092faSJesper Dangaard Brouer git format-patch --subject-prefix='PATCH bpf-next' start..finish 133*192092faSJesper Dangaard Brouer 134*192092faSJesper Dangaard Brouer If unsure whether the patch or patch series should go into bpf 135*192092faSJesper Dangaard Brouer or net directly, or bpf-next or net-next directly, it is not a 136*192092faSJesper Dangaard Brouer problem either if the subject line says net or net-next as target. 137*192092faSJesper Dangaard Brouer It is eventually up to the maintainers to do the delegation of 138*192092faSJesper Dangaard Brouer the patches. 139*192092faSJesper Dangaard Brouer 140*192092faSJesper Dangaard Brouer If it is clear that patches should go into bpf or bpf-next tree, 141*192092faSJesper Dangaard Brouer please make sure to rebase the patches against those trees in 142*192092faSJesper Dangaard Brouer order to reduce potential conflicts. 143*192092faSJesper Dangaard Brouer 144*192092faSJesper Dangaard Brouer In case the patch or patch series has to be reworked and sent out 145*192092faSJesper Dangaard Brouer again in a second or later revision, it is also required to add a 146*192092faSJesper Dangaard Brouer version number (v2, v3, ...) into the subject prefix: 147*192092faSJesper Dangaard Brouer 148*192092faSJesper Dangaard Brouer git format-patch --subject-prefix='PATCH net-next v2' start..finish 149*192092faSJesper Dangaard Brouer 150*192092faSJesper Dangaard Brouer When changes have been requested to the patch series, always send the 151*192092faSJesper Dangaard Brouer whole patch series again with the feedback incorporated (never send 152*192092faSJesper Dangaard Brouer individual diffs on top of the old series). 153*192092faSJesper Dangaard Brouer 154*192092faSJesper Dangaard BrouerQ: What does it mean when a patch gets applied to bpf or bpf-next tree? 155*192092faSJesper Dangaard Brouer 156*192092faSJesper Dangaard BrouerA: It means that the patch looks good for mainline inclusion from 157*192092faSJesper Dangaard Brouer a BPF point of view. 158*192092faSJesper Dangaard Brouer 159*192092faSJesper Dangaard Brouer Be aware that this is not a final verdict that the patch will 160*192092faSJesper Dangaard Brouer automatically get accepted into net or net-next trees eventually: 161*192092faSJesper Dangaard Brouer 162*192092faSJesper Dangaard Brouer On the netdev kernel mailing list reviews can come in at any point 163*192092faSJesper Dangaard Brouer in time. If discussions around a patch conclude that they cannot 164*192092faSJesper Dangaard Brouer get included as-is, we will either apply a follow-up fix or drop 165*192092faSJesper Dangaard Brouer them from the trees entirely. Therefore, we also reserve to rebase 166*192092faSJesper Dangaard Brouer the trees when deemed necessary. After all, the purpose of the tree 167*192092faSJesper Dangaard Brouer is to i) accumulate and stage BPF patches for integration into trees 168*192092faSJesper Dangaard Brouer like net and net-next, and ii) run extensive BPF test suite and 169*192092faSJesper Dangaard Brouer workloads on the patches before they make their way any further. 170*192092faSJesper Dangaard Brouer 171*192092faSJesper Dangaard Brouer Once the BPF pull request was accepted by David S. Miller, then 172*192092faSJesper Dangaard Brouer the patches end up in net or net-next tree, respectively, and 173*192092faSJesper Dangaard Brouer make their way from there further into mainline. Again, see the 174*192092faSJesper Dangaard Brouer netdev FAQ for additional information e.g. on how often they are 175*192092faSJesper Dangaard Brouer merged to mainline. 176*192092faSJesper Dangaard Brouer 177*192092faSJesper Dangaard BrouerQ: How long do I need to wait for feedback on my BPF patches? 178*192092faSJesper Dangaard Brouer 179*192092faSJesper Dangaard BrouerA: We try to keep the latency low. The usual time to feedback will 180*192092faSJesper Dangaard Brouer be around 2 or 3 business days. It may vary depending on the 181*192092faSJesper Dangaard Brouer complexity of changes and current patch load. 182*192092faSJesper Dangaard Brouer 183*192092faSJesper Dangaard BrouerQ: How often do you send pull requests to major kernel trees like 184*192092faSJesper Dangaard Brouer net or net-next? 185*192092faSJesper Dangaard Brouer 186*192092faSJesper Dangaard BrouerA: Pull requests will be sent out rather often in order to not 187*192092faSJesper Dangaard Brouer accumulate too many patches in bpf or bpf-next. 188*192092faSJesper Dangaard Brouer 189*192092faSJesper Dangaard Brouer As a rule of thumb, expect pull requests for each tree regularly 190*192092faSJesper Dangaard Brouer at the end of the week. In some cases pull requests could additionally 191*192092faSJesper Dangaard Brouer come also in the middle of the week depending on the current patch 192*192092faSJesper Dangaard Brouer load or urgency. 193*192092faSJesper Dangaard Brouer 194*192092faSJesper Dangaard BrouerQ: Are patches applied to bpf-next when the merge window is open? 195*192092faSJesper Dangaard Brouer 196*192092faSJesper Dangaard BrouerA: For the time when the merge window is open, bpf-next will not be 197*192092faSJesper Dangaard Brouer processed. This is roughly analogous to net-next patch processing, 198*192092faSJesper Dangaard Brouer so feel free to read up on the netdev FAQ about further details. 199*192092faSJesper Dangaard Brouer 200*192092faSJesper Dangaard Brouer During those two weeks of merge window, we might ask you to resend 201*192092faSJesper Dangaard Brouer your patch series once bpf-next is open again. Once Linus released 202*192092faSJesper Dangaard Brouer a v*-rc1 after the merge window, we continue processing of bpf-next. 203*192092faSJesper Dangaard Brouer 204*192092faSJesper Dangaard Brouer For non-subscribers to kernel mailing lists, there is also a status 205*192092faSJesper Dangaard Brouer page run by David S. Miller on net-next that provides guidance: 206*192092faSJesper Dangaard Brouer 207*192092faSJesper Dangaard Brouer http://vger.kernel.org/~davem/net-next.html 208*192092faSJesper Dangaard Brouer 209*192092faSJesper Dangaard BrouerQ: I made a BPF verifier change, do I need to add test cases for 210*192092faSJesper Dangaard Brouer BPF kernel selftests? 211*192092faSJesper Dangaard Brouer 212*192092faSJesper Dangaard BrouerA: If the patch has changes to the behavior of the verifier, then yes, 213*192092faSJesper Dangaard Brouer it is absolutely necessary to add test cases to the BPF kernel 214*192092faSJesper Dangaard Brouer selftests suite. If they are not present and we think they are 215*192092faSJesper Dangaard Brouer needed, then we might ask for them before accepting any changes. 216*192092faSJesper Dangaard Brouer 217*192092faSJesper Dangaard Brouer In particular, test_verifier.c is tracking a high number of BPF test 218*192092faSJesper Dangaard Brouer cases, including a lot of corner cases that LLVM BPF back end may 219*192092faSJesper Dangaard Brouer generate out of the restricted C code. Thus, adding test cases is 220*192092faSJesper Dangaard Brouer absolutely crucial to make sure future changes do not accidentally 221*192092faSJesper Dangaard Brouer affect prior use-cases. Thus, treat those test cases as: verifier 222*192092faSJesper Dangaard Brouer behavior that is not tracked in test_verifier.c could potentially 223*192092faSJesper Dangaard Brouer be subject to change. 224*192092faSJesper Dangaard Brouer 225*192092faSJesper Dangaard BrouerQ: When should I add code to samples/bpf/ and when to BPF kernel 226*192092faSJesper Dangaard Brouer selftests? 227*192092faSJesper Dangaard Brouer 228*192092faSJesper Dangaard BrouerA: In general, we prefer additions to BPF kernel selftests rather than 229*192092faSJesper Dangaard Brouer samples/bpf/. The rationale is very simple: kernel selftests are 230*192092faSJesper Dangaard Brouer regularly run by various bots to test for kernel regressions. 231*192092faSJesper Dangaard Brouer 232*192092faSJesper Dangaard Brouer The more test cases we add to BPF selftests, the better the coverage 233*192092faSJesper Dangaard Brouer and the less likely it is that those could accidentally break. It is 234*192092faSJesper Dangaard Brouer not that BPF kernel selftests cannot demo how a specific feature can 235*192092faSJesper Dangaard Brouer be used. 236*192092faSJesper Dangaard Brouer 237*192092faSJesper Dangaard Brouer That said, samples/bpf/ may be a good place for people to get started, 238*192092faSJesper Dangaard Brouer so it might be advisable that simple demos of features could go into 239*192092faSJesper Dangaard Brouer samples/bpf/, but advanced functional and corner-case testing rather 240*192092faSJesper Dangaard Brouer into kernel selftests. 241*192092faSJesper Dangaard Brouer 242*192092faSJesper Dangaard Brouer If your sample looks like a test case, then go for BPF kernel selftests 243*192092faSJesper Dangaard Brouer instead! 244*192092faSJesper Dangaard Brouer 245*192092faSJesper Dangaard BrouerQ: When should I add code to the bpftool? 246*192092faSJesper Dangaard Brouer 247*192092faSJesper Dangaard BrouerA: The main purpose of bpftool (under tools/bpf/bpftool/) is to provide 248*192092faSJesper Dangaard Brouer a central user space tool for debugging and introspection of BPF programs 249*192092faSJesper Dangaard Brouer and maps that are active in the kernel. If UAPI changes related to BPF 250*192092faSJesper Dangaard Brouer enable for dumping additional information of programs or maps, then 251*192092faSJesper Dangaard Brouer bpftool should be extended as well to support dumping them. 252*192092faSJesper Dangaard Brouer 253*192092faSJesper Dangaard BrouerQ: When should I add code to iproute2's BPF loader? 254*192092faSJesper Dangaard Brouer 255*192092faSJesper Dangaard BrouerA: For UAPI changes related to the XDP or tc layer (e.g. cls_bpf), the 256*192092faSJesper Dangaard Brouer convention is that those control-path related changes are added to 257*192092faSJesper Dangaard Brouer iproute2's BPF loader as well from user space side. This is not only 258*192092faSJesper Dangaard Brouer useful to have UAPI changes properly designed to be usable, but also 259*192092faSJesper Dangaard Brouer to make those changes available to a wider user base of major 260*192092faSJesper Dangaard Brouer downstream distributions. 261*192092faSJesper Dangaard Brouer 262*192092faSJesper Dangaard BrouerQ: Do you accept patches as well for iproute2's BPF loader? 263*192092faSJesper Dangaard Brouer 264*192092faSJesper Dangaard BrouerA: Patches for the iproute2's BPF loader have to be sent to: 265*192092faSJesper Dangaard Brouer 266*192092faSJesper Dangaard Brouer netdev@vger.kernel.org 267*192092faSJesper Dangaard Brouer 268*192092faSJesper Dangaard Brouer While those patches are not processed by the BPF kernel maintainers, 269*192092faSJesper Dangaard Brouer please keep them in Cc as well, so they can be reviewed. 270*192092faSJesper Dangaard Brouer 271*192092faSJesper Dangaard Brouer The official git repository for iproute2 is run by Stephen Hemminger 272*192092faSJesper Dangaard Brouer and can be found at: 273*192092faSJesper Dangaard Brouer 274*192092faSJesper Dangaard Brouer https://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git/ 275*192092faSJesper Dangaard Brouer 276*192092faSJesper Dangaard Brouer The patches need to have a subject prefix of '[PATCH iproute2 master]' 277*192092faSJesper Dangaard Brouer or '[PATCH iproute2 net-next]'. 'master' or 'net-next' describes the 278*192092faSJesper Dangaard Brouer target branch where the patch should be applied to. Meaning, if kernel 279*192092faSJesper Dangaard Brouer changes went into the net-next kernel tree, then the related iproute2 280*192092faSJesper Dangaard Brouer changes need to go into the iproute2 net-next branch, otherwise they 281*192092faSJesper Dangaard Brouer can be targeted at master branch. The iproute2 net-next branch will get 282*192092faSJesper Dangaard Brouer merged into the master branch after the current iproute2 version from 283*192092faSJesper Dangaard Brouer master has been released. 284*192092faSJesper Dangaard Brouer 285*192092faSJesper Dangaard Brouer Like BPF, the patches end up in patchwork under the netdev project and 286*192092faSJesper Dangaard Brouer are delegated to 'shemminger' for further processing: 287*192092faSJesper Dangaard Brouer 288*192092faSJesper Dangaard Brouer http://patchwork.ozlabs.org/project/netdev/list/?delegate=389 289*192092faSJesper Dangaard Brouer 290*192092faSJesper Dangaard BrouerQ: What is the minimum requirement before I submit my BPF patches? 291*192092faSJesper Dangaard Brouer 292*192092faSJesper Dangaard BrouerA: When submitting patches, always take the time and properly test your 293*192092faSJesper Dangaard Brouer patches *prior* to submission. Never rush them! If maintainers find 294*192092faSJesper Dangaard Brouer that your patches have not been properly tested, it is a good way to 295*192092faSJesper Dangaard Brouer get them grumpy. Testing patch submissions is a hard requirement! 296*192092faSJesper Dangaard Brouer 297*192092faSJesper Dangaard Brouer Note, fixes that go to bpf tree *must* have a Fixes: tag included. The 298*192092faSJesper Dangaard Brouer same applies to fixes that target bpf-next, where the affected commit 299*192092faSJesper Dangaard Brouer is in net-next (or in some cases bpf-next). The Fixes: tag is crucial 300*192092faSJesper Dangaard Brouer in order to identify follow-up commits and tremendously helps for people 301*192092faSJesper Dangaard Brouer having to do backporting, so it is a must have! 302*192092faSJesper Dangaard Brouer 303*192092faSJesper Dangaard Brouer We also don't accept patches with an empty commit message. Take your 304*192092faSJesper Dangaard Brouer time and properly write up a high quality commit message, it is 305*192092faSJesper Dangaard Brouer essential! 306*192092faSJesper Dangaard Brouer 307*192092faSJesper Dangaard Brouer Think about it this way: other developers looking at your code a month 308*192092faSJesper Dangaard Brouer from now need to understand *why* a certain change has been done that 309*192092faSJesper Dangaard Brouer way, and whether there have been flaws in the analysis or assumptions 310*192092faSJesper Dangaard Brouer that the original author did. Thus providing a proper rationale and 311*192092faSJesper Dangaard Brouer describing the use-case for the changes is a must. 312*192092faSJesper Dangaard Brouer 313*192092faSJesper Dangaard Brouer Patch submissions with >1 patch must have a cover letter which includes 314*192092faSJesper Dangaard Brouer a high level description of the series. This high level summary will 315*192092faSJesper Dangaard Brouer then be placed into the merge commit by the BPF maintainers such that 316*192092faSJesper Dangaard Brouer it is also accessible from the git log for future reference. 317*192092faSJesper Dangaard Brouer 318*192092faSJesper Dangaard BrouerQ: What do I need to consider when adding a new instruction or feature 319*192092faSJesper Dangaard Brouer that would require BPF JIT and/or LLVM integration as well? 320*192092faSJesper Dangaard Brouer 321*192092faSJesper Dangaard BrouerA: We try hard to keep all BPF JITs up to date such that the same user 322*192092faSJesper Dangaard Brouer experience can be guaranteed when running BPF programs on different 323*192092faSJesper Dangaard Brouer architectures without having the program punt to the less efficient 324*192092faSJesper Dangaard Brouer interpreter in case the in-kernel BPF JIT is enabled. 325*192092faSJesper Dangaard Brouer 326*192092faSJesper Dangaard Brouer If you are unable to implement or test the required JIT changes for 327*192092faSJesper Dangaard Brouer certain architectures, please work together with the related BPF JIT 328*192092faSJesper Dangaard Brouer developers in order to get the feature implemented in a timely manner. 329*192092faSJesper Dangaard Brouer Please refer to the git log (arch/*/net/) to locate the necessary 330*192092faSJesper Dangaard Brouer people for helping out. 331*192092faSJesper Dangaard Brouer 332*192092faSJesper Dangaard Brouer Also always make sure to add BPF test cases (e.g. test_bpf.c and 333*192092faSJesper Dangaard Brouer test_verifier.c) for new instructions, so that they can receive 334*192092faSJesper Dangaard Brouer broad test coverage and help run-time testing the various BPF JITs. 335*192092faSJesper Dangaard Brouer 336*192092faSJesper Dangaard Brouer In case of new BPF instructions, once the changes have been accepted 337*192092faSJesper Dangaard Brouer into the Linux kernel, please implement support into LLVM's BPF back 338*192092faSJesper Dangaard Brouer end. See LLVM section below for further information. 339*192092faSJesper Dangaard Brouer 340*192092faSJesper Dangaard BrouerStable submission: 341*192092faSJesper Dangaard Brouer------------------ 342*192092faSJesper Dangaard Brouer 343*192092faSJesper Dangaard BrouerQ: I need a specific BPF commit in stable kernels. What should I do? 344*192092faSJesper Dangaard Brouer 345*192092faSJesper Dangaard BrouerA: In case you need a specific fix in stable kernels, first check whether 346*192092faSJesper Dangaard Brouer the commit has already been applied in the related linux-*.y branches: 347*192092faSJesper Dangaard Brouer 348*192092faSJesper Dangaard Brouer https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/ 349*192092faSJesper Dangaard Brouer 350*192092faSJesper Dangaard Brouer If not the case, then drop an email to the BPF maintainers with the 351*192092faSJesper Dangaard Brouer netdev kernel mailing list in Cc and ask for the fix to be queued up: 352*192092faSJesper Dangaard Brouer 353*192092faSJesper Dangaard Brouer netdev@vger.kernel.org 354*192092faSJesper Dangaard Brouer 355*192092faSJesper Dangaard Brouer The process in general is the same as on netdev itself, see also the 356*192092faSJesper Dangaard Brouer netdev FAQ document. 357*192092faSJesper Dangaard Brouer 358*192092faSJesper Dangaard BrouerQ: Do you also backport to kernels not currently maintained as stable? 359*192092faSJesper Dangaard Brouer 360*192092faSJesper Dangaard BrouerA: No. If you need a specific BPF commit in kernels that are currently not 361*192092faSJesper Dangaard Brouer maintained by the stable maintainers, then you are on your own. 362*192092faSJesper Dangaard Brouer 363*192092faSJesper Dangaard Brouer The current stable and longterm stable kernels are all listed here: 364*192092faSJesper Dangaard Brouer 365*192092faSJesper Dangaard Brouer https://www.kernel.org/ 366*192092faSJesper Dangaard Brouer 367*192092faSJesper Dangaard BrouerQ: The BPF patch I am about to submit needs to go to stable as well. What 368*192092faSJesper Dangaard Brouer should I do? 369*192092faSJesper Dangaard Brouer 370*192092faSJesper Dangaard BrouerA: The same rules apply as with netdev patch submissions in general, see 371*192092faSJesper Dangaard Brouer netdev FAQ under: 372*192092faSJesper Dangaard Brouer 373*192092faSJesper Dangaard Brouer Documentation/networking/netdev-FAQ.txt 374*192092faSJesper Dangaard Brouer 375*192092faSJesper Dangaard Brouer Never add "Cc: stable@vger.kernel.org" to the patch description, but 376*192092faSJesper Dangaard Brouer ask the BPF maintainers to queue the patches instead. This can be done 377*192092faSJesper Dangaard Brouer with a note, for example, under the "---" part of the patch which does 378*192092faSJesper Dangaard Brouer not go into the git log. Alternatively, this can be done as a simple 379*192092faSJesper Dangaard Brouer request by mail instead. 380*192092faSJesper Dangaard Brouer 381*192092faSJesper Dangaard BrouerQ: Where do I find currently queued BPF patches that will be submitted 382*192092faSJesper Dangaard Brouer to stable? 383*192092faSJesper Dangaard Brouer 384*192092faSJesper Dangaard BrouerA: Once patches that fix critical bugs got applied into the bpf tree, they 385*192092faSJesper Dangaard Brouer are queued up for stable submission under: 386*192092faSJesper Dangaard Brouer 387*192092faSJesper Dangaard Brouer http://patchwork.ozlabs.org/bundle/bpf/stable/?state=* 388*192092faSJesper Dangaard Brouer 389*192092faSJesper Dangaard Brouer They will be on hold there at minimum until the related commit made its 390*192092faSJesper Dangaard Brouer way into the mainline kernel tree. 391*192092faSJesper Dangaard Brouer 392*192092faSJesper Dangaard Brouer After having been under broader exposure, the queued patches will be 393*192092faSJesper Dangaard Brouer submitted by the BPF maintainers to the stable maintainers. 394*192092faSJesper Dangaard Brouer 395*192092faSJesper Dangaard BrouerTesting patches: 396*192092faSJesper Dangaard Brouer---------------- 397*192092faSJesper Dangaard Brouer 398*192092faSJesper Dangaard BrouerQ: Which BPF kernel selftests version should I run my kernel against? 399*192092faSJesper Dangaard Brouer 400*192092faSJesper Dangaard BrouerA: If you run a kernel xyz, then always run the BPF kernel selftests from 401*192092faSJesper Dangaard Brouer that kernel xyz as well. Do not expect that the BPF selftest from the 402*192092faSJesper Dangaard Brouer latest mainline tree will pass all the time. 403*192092faSJesper Dangaard Brouer 404*192092faSJesper Dangaard Brouer In particular, test_bpf.c and test_verifier.c have a large number of 405*192092faSJesper Dangaard Brouer test cases and are constantly updated with new BPF test sequences, or 406*192092faSJesper Dangaard Brouer existing ones are adapted to verifier changes e.g. due to verifier 407*192092faSJesper Dangaard Brouer becoming smarter and being able to better track certain things. 408*192092faSJesper Dangaard Brouer 409*192092faSJesper Dangaard BrouerLLVM: 410*192092faSJesper Dangaard Brouer----- 411*192092faSJesper Dangaard Brouer 412*192092faSJesper Dangaard BrouerQ: Where do I find LLVM with BPF support? 413*192092faSJesper Dangaard Brouer 414*192092faSJesper Dangaard BrouerA: The BPF back end for LLVM is upstream in LLVM since version 3.7.1. 415*192092faSJesper Dangaard Brouer 416*192092faSJesper Dangaard Brouer All major distributions these days ship LLVM with BPF back end enabled, 417*192092faSJesper Dangaard Brouer so for the majority of use-cases it is not required to compile LLVM by 418*192092faSJesper Dangaard Brouer hand anymore, just install the distribution provided package. 419*192092faSJesper Dangaard Brouer 420*192092faSJesper Dangaard Brouer LLVM's static compiler lists the supported targets through 'llc --version', 421*192092faSJesper Dangaard Brouer make sure BPF targets are listed. Example: 422*192092faSJesper Dangaard Brouer 423*192092faSJesper Dangaard Brouer $ llc --version 424*192092faSJesper Dangaard Brouer LLVM (http://llvm.org/): 425*192092faSJesper Dangaard Brouer LLVM version 6.0.0svn 426*192092faSJesper Dangaard Brouer Optimized build. 427*192092faSJesper Dangaard Brouer Default target: x86_64-unknown-linux-gnu 428*192092faSJesper Dangaard Brouer Host CPU: skylake 429*192092faSJesper Dangaard Brouer 430*192092faSJesper Dangaard Brouer Registered Targets: 431*192092faSJesper Dangaard Brouer bpf - BPF (host endian) 432*192092faSJesper Dangaard Brouer bpfeb - BPF (big endian) 433*192092faSJesper Dangaard Brouer bpfel - BPF (little endian) 434*192092faSJesper Dangaard Brouer x86 - 32-bit X86: Pentium-Pro and above 435*192092faSJesper Dangaard Brouer x86-64 - 64-bit X86: EM64T and AMD64 436*192092faSJesper Dangaard Brouer 437*192092faSJesper Dangaard Brouer For developers in order to utilize the latest features added to LLVM's 438*192092faSJesper Dangaard Brouer BPF back end, it is advisable to run the latest LLVM releases. Support 439*192092faSJesper Dangaard Brouer for new BPF kernel features such as additions to the BPF instruction 440*192092faSJesper Dangaard Brouer set are often developed together. 441*192092faSJesper Dangaard Brouer 442*192092faSJesper Dangaard Brouer All LLVM releases can be found at: http://releases.llvm.org/ 443*192092faSJesper Dangaard Brouer 444*192092faSJesper Dangaard BrouerQ: Got it, so how do I build LLVM manually anyway? 445*192092faSJesper Dangaard Brouer 446*192092faSJesper Dangaard BrouerA: You need cmake and gcc-c++ as build requisites for LLVM. Once you have 447*192092faSJesper Dangaard Brouer that set up, proceed with building the latest LLVM and clang version 448*192092faSJesper Dangaard Brouer from the git repositories: 449*192092faSJesper Dangaard Brouer 450*192092faSJesper Dangaard Brouer $ git clone http://llvm.org/git/llvm.git 451*192092faSJesper Dangaard Brouer $ cd llvm/tools 452*192092faSJesper Dangaard Brouer $ git clone --depth 1 http://llvm.org/git/clang.git 453*192092faSJesper Dangaard Brouer $ cd ..; mkdir build; cd build 454*192092faSJesper Dangaard Brouer $ cmake .. -DLLVM_TARGETS_TO_BUILD="BPF;X86" \ 455*192092faSJesper Dangaard Brouer -DBUILD_SHARED_LIBS=OFF \ 456*192092faSJesper Dangaard Brouer -DCMAKE_BUILD_TYPE=Release \ 457*192092faSJesper Dangaard Brouer -DLLVM_BUILD_RUNTIME=OFF 458*192092faSJesper Dangaard Brouer $ make -j $(getconf _NPROCESSORS_ONLN) 459*192092faSJesper Dangaard Brouer 460*192092faSJesper Dangaard Brouer The built binaries can then be found in the build/bin/ directory, where 461*192092faSJesper Dangaard Brouer you can point the PATH variable to. 462*192092faSJesper Dangaard Brouer 463*192092faSJesper Dangaard BrouerQ: Should I notify BPF kernel maintainers about issues in LLVM's BPF code 464*192092faSJesper Dangaard Brouer generation back end or about LLVM generated code that the verifier 465*192092faSJesper Dangaard Brouer refuses to accept? 466*192092faSJesper Dangaard Brouer 467*192092faSJesper Dangaard BrouerA: Yes, please do! LLVM's BPF back end is a key piece of the whole BPF 468*192092faSJesper Dangaard Brouer infrastructure and it ties deeply into verification of programs from the 469*192092faSJesper Dangaard Brouer kernel side. Therefore, any issues on either side need to be investigated 470*192092faSJesper Dangaard Brouer and fixed whenever necessary. 471*192092faSJesper Dangaard Brouer 472*192092faSJesper Dangaard Brouer Therefore, please make sure to bring them up at netdev kernel mailing 473*192092faSJesper Dangaard Brouer list and Cc BPF maintainers for LLVM and kernel bits: 474*192092faSJesper Dangaard Brouer 475*192092faSJesper Dangaard Brouer Yonghong Song <yhs@fb.com> 476*192092faSJesper Dangaard Brouer Alexei Starovoitov <ast@kernel.org> 477*192092faSJesper Dangaard Brouer Daniel Borkmann <daniel@iogearbox.net> 478*192092faSJesper Dangaard Brouer 479*192092faSJesper Dangaard Brouer LLVM also has an issue tracker where BPF related bugs can be found: 480*192092faSJesper Dangaard Brouer 481*192092faSJesper Dangaard Brouer https://bugs.llvm.org/buglist.cgi?quicksearch=bpf 482*192092faSJesper Dangaard Brouer 483*192092faSJesper Dangaard Brouer However, it is better to reach out through mailing lists with having 484*192092faSJesper Dangaard Brouer maintainers in Cc. 485*192092faSJesper Dangaard Brouer 486*192092faSJesper Dangaard BrouerQ: I have added a new BPF instruction to the kernel, how can I integrate 487*192092faSJesper Dangaard Brouer it into LLVM? 488*192092faSJesper Dangaard Brouer 489*192092faSJesper Dangaard BrouerA: LLVM has a -mcpu selector for the BPF back end in order to allow the 490*192092faSJesper Dangaard Brouer selection of BPF instruction set extensions. By default the 'generic' 491*192092faSJesper Dangaard Brouer processor target is used, which is the base instruction set (v1) of BPF. 492*192092faSJesper Dangaard Brouer 493*192092faSJesper Dangaard Brouer LLVM has an option to select -mcpu=probe where it will probe the host 494*192092faSJesper Dangaard Brouer kernel for supported BPF instruction set extensions and selects the 495*192092faSJesper Dangaard Brouer optimal set automatically. 496*192092faSJesper Dangaard Brouer 497*192092faSJesper Dangaard Brouer For cross-compilation, a specific version can be select manually as well. 498*192092faSJesper Dangaard Brouer 499*192092faSJesper Dangaard Brouer $ llc -march bpf -mcpu=help 500*192092faSJesper Dangaard Brouer Available CPUs for this target: 501*192092faSJesper Dangaard Brouer 502*192092faSJesper Dangaard Brouer generic - Select the generic processor. 503*192092faSJesper Dangaard Brouer probe - Select the probe processor. 504*192092faSJesper Dangaard Brouer v1 - Select the v1 processor. 505*192092faSJesper Dangaard Brouer v2 - Select the v2 processor. 506*192092faSJesper Dangaard Brouer [...] 507*192092faSJesper Dangaard Brouer 508*192092faSJesper Dangaard Brouer Newly added BPF instructions to the Linux kernel need to follow the same 509*192092faSJesper Dangaard Brouer scheme, bump the instruction set version and implement probing for the 510*192092faSJesper Dangaard Brouer extensions such that -mcpu=probe users can benefit from the optimization 511*192092faSJesper Dangaard Brouer transparently when upgrading their kernels. 512*192092faSJesper Dangaard Brouer 513*192092faSJesper Dangaard Brouer If you are unable to implement support for the newly added BPF instruction 514*192092faSJesper Dangaard Brouer please reach out to BPF developers for help. 515*192092faSJesper Dangaard Brouer 516*192092faSJesper Dangaard Brouer By the way, the BPF kernel selftests run with -mcpu=probe for better 517*192092faSJesper Dangaard Brouer test coverage. 518*192092faSJesper Dangaard Brouer 519*192092faSJesper Dangaard BrouerQ: In some cases clang flag "-target bpf" is used but in other cases the 520*192092faSJesper Dangaard Brouer default clang target, which matches the underlying architecture, is used. 521*192092faSJesper Dangaard Brouer What is the difference and when I should use which? 522*192092faSJesper Dangaard Brouer 523*192092faSJesper Dangaard BrouerA: Although LLVM IR generation and optimization try to stay architecture 524*192092faSJesper Dangaard Brouer independent, "-target <arch>" still has some impact on generated code: 525*192092faSJesper Dangaard Brouer 526*192092faSJesper Dangaard Brouer - BPF program may recursively include header file(s) with file scope 527*192092faSJesper Dangaard Brouer inline assembly codes. The default target can handle this well, 528*192092faSJesper Dangaard Brouer while bpf target may fail if bpf backend assembler does not 529*192092faSJesper Dangaard Brouer understand these assembly codes, which is true in most cases. 530*192092faSJesper Dangaard Brouer 531*192092faSJesper Dangaard Brouer - When compiled without -g, additional elf sections, e.g., 532*192092faSJesper Dangaard Brouer .eh_frame and .rela.eh_frame, may be present in the object file 533*192092faSJesper Dangaard Brouer with default target, but not with bpf target. 534*192092faSJesper Dangaard Brouer 535*192092faSJesper Dangaard Brouer - The default target may turn a C switch statement into a switch table 536*192092faSJesper Dangaard Brouer lookup and jump operation. Since the switch table is placed 537*192092faSJesper Dangaard Brouer in the global readonly section, the bpf program will fail to load. 538*192092faSJesper Dangaard Brouer The bpf target does not support switch table optimization. 539*192092faSJesper Dangaard Brouer The clang option "-fno-jump-tables" can be used to disable 540*192092faSJesper Dangaard Brouer switch table generation. 541*192092faSJesper Dangaard Brouer 542*192092faSJesper Dangaard Brouer - For clang -target bpf, it is guaranteed that pointer or long / 543*192092faSJesper Dangaard Brouer unsigned long types will always have a width of 64 bit, no matter 544*192092faSJesper Dangaard Brouer whether underlying clang binary or default target (or kernel) is 545*192092faSJesper Dangaard Brouer 32 bit. However, when native clang target is used, then it will 546*192092faSJesper Dangaard Brouer compile these types based on the underlying architecture's conventions, 547*192092faSJesper Dangaard Brouer meaning in case of 32 bit architecture, pointer or long / unsigned 548*192092faSJesper Dangaard Brouer long types e.g. in BPF context structure will have width of 32 bit 549*192092faSJesper Dangaard Brouer while the BPF LLVM back end still operates in 64 bit. The native 550*192092faSJesper Dangaard Brouer target is mostly needed in tracing for the case of walking pt_regs 551*192092faSJesper Dangaard Brouer or other kernel structures where CPU's register width matters. 552*192092faSJesper Dangaard Brouer Otherwise, clang -target bpf is generally recommended. 553*192092faSJesper Dangaard Brouer 554*192092faSJesper Dangaard Brouer You should use default target when: 555*192092faSJesper Dangaard Brouer 556*192092faSJesper Dangaard Brouer - Your program includes a header file, e.g., ptrace.h, which eventually 557*192092faSJesper Dangaard Brouer pulls in some header files containing file scope host assembly codes. 558*192092faSJesper Dangaard Brouer - You can add "-fno-jump-tables" to work around the switch table issue. 559*192092faSJesper Dangaard Brouer 560*192092faSJesper Dangaard Brouer Otherwise, you can use bpf target. Additionally, you _must_ use bpf target 561*192092faSJesper Dangaard Brouer when: 562*192092faSJesper Dangaard Brouer 563*192092faSJesper Dangaard Brouer - Your program uses data structures with pointer or long / unsigned long 564*192092faSJesper Dangaard Brouer types that interface with BPF helpers or context data structures. Access 565*192092faSJesper Dangaard Brouer into these structures is verified by the BPF verifier and may result 566*192092faSJesper Dangaard Brouer in verification failures if the native architecture is not aligned with 567*192092faSJesper Dangaard Brouer the BPF architecture, e.g. 64-bit. An example of this is 568*192092faSJesper Dangaard Brouer BPF_PROG_TYPE_SK_MSG require '-target bpf' 569*192092faSJesper Dangaard Brouer 570*192092faSJesper Dangaard BrouerHappy BPF hacking! 571