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