5.Posting.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. .. _development_posting:
  2. Posting patches
  3. ===============
  4. Sooner or later, the time comes when your work is ready to be presented to
  5. the community for review and, eventually, inclusion into the mainline
  6. kernel. Unsurprisingly, the kernel development community has evolved a set
  7. of conventions and procedures which are used in the posting of patches;
  8. following them will make life much easier for everybody involved. This
  9. document will attempt to cover these expectations in reasonable detail;
  10. more information can also be found in the files
  11. :ref:`Documentation/process/submitting-patches.rst <submittingpatches>`
  12. and :ref:`Documentation/process/submit-checklist.rst <submitchecklist>`.
  13. When to post
  14. ------------
  15. There is a constant temptation to avoid posting patches before they are
  16. completely "ready." For simple patches, that is not a problem. If the
  17. work being done is complex, though, there is a lot to be gained by getting
  18. feedback from the community before the work is complete. So you should
  19. consider posting in-progress work, or even making a git tree available so
  20. that interested developers can catch up with your work at any time.
  21. When posting code which is not yet considered ready for inclusion, it is a
  22. good idea to say so in the posting itself. Also mention any major work
  23. which remains to be done and any known problems. Fewer people will look at
  24. patches which are known to be half-baked, but those who do will come in
  25. with the idea that they can help you drive the work in the right direction.
  26. Before creating patches
  27. -----------------------
  28. There are a number of things which should be done before you consider
  29. sending patches to the development community. These include:
  30. - Test the code to the extent that you can. Make use of the kernel's
  31. debugging tools, ensure that the kernel will build with all reasonable
  32. combinations of configuration options, use cross-compilers to build for
  33. different architectures, etc. Add tests, likely using an existing
  34. testing framework like KUnit, and include them as a separate member
  35. of your series (see the next section for more about patch series).
  36. Note that this may be mandatory when affecting some subsystems. For
  37. example, library functions (resides under lib/) are extensively used
  38. almost everywhere and expected to be tested appropriately.
  39. - Make sure your code is compliant with the kernel coding style
  40. guidelines.
  41. - Does your change have performance implications? If so, you should run
  42. benchmarks showing what the impact (or benefit) of your change is; a
  43. summary of the results should be included with the patch.
  44. - Be sure that you have the right to post the code. If this work was done
  45. for an employer, the employer likely has a right to the work and must be
  46. agreeable with its release under the GPL.
  47. As a general rule, putting in some extra thought before posting code almost
  48. always pays back the effort in short order.
  49. Patch preparation
  50. -----------------
  51. The preparation of patches for posting can be a surprising amount of work,
  52. but, once again, attempting to save time here is not generally advisable
  53. even in the short term.
  54. Patches must be prepared against a specific version of the kernel. As a
  55. general rule, a patch should be based on the current mainline as found in
  56. Linus's git tree. When basing on mainline, start with a well-known release
  57. point - a stable or -rc release - rather than branching off the mainline at
  58. an arbitrary spot.
  59. It may become necessary to make versions against -mm, linux-next, or a
  60. subsystem tree, though, to facilitate wider testing and review. Depending
  61. on the area of your patch and what is going on elsewhere, basing a patch
  62. against these other trees can require a significant amount of work
  63. resolving conflicts and dealing with API changes.
  64. Only the most simple changes should be formatted as a single patch;
  65. everything else should be made as a logical series of changes. Splitting
  66. up patches is a bit of an art; some developers spend a long time figuring
  67. out how to do it in the way that the community expects. There are a few
  68. rules of thumb, however, which can help considerably:
  69. - The patch series you post will almost certainly not be the series of
  70. changes found in your working revision control system. Instead, the
  71. changes you have made need to be considered in their final form, then
  72. split apart in ways which make sense. The developers are interested in
  73. discrete, self-contained changes, not the path you took to get to those
  74. changes.
  75. - Each logically independent change should be formatted as a separate
  76. patch. These changes can be small ("add a field to this structure") or
  77. large (adding a significant new driver, for example), but they should be
  78. conceptually small and amenable to a one-line description. Each patch
  79. should make a specific change which can be reviewed on its own and
  80. verified to do what it says it does.
  81. - As a way of restating the guideline above: do not mix different types of
  82. changes in the same patch. If a single patch fixes a critical security
  83. bug, rearranges a few structures, and reformats the code, there is a
  84. good chance that it will be passed over and the important fix will be
  85. lost.
  86. - Each patch should yield a kernel which builds and runs properly; if your
  87. patch series is interrupted in the middle, the result should still be a
  88. working kernel. Partial application of a patch series is a common
  89. scenario when the "git bisect" tool is used to find regressions; if the
  90. result is a broken kernel, you will make life harder for developers and
  91. users who are engaging in the noble work of tracking down problems.
  92. - Do not overdo it, though. One developer once posted a set of edits
  93. to a single file as 500 separate patches - an act which did not make him
  94. the most popular person on the kernel mailing list. A single patch can
  95. be reasonably large as long as it still contains a single *logical*
  96. change.
  97. - It can be tempting to add a whole new infrastructure with a series of
  98. patches, but to leave that infrastructure unused until the final patch
  99. in the series enables the whole thing. This temptation should be
  100. avoided if possible; if that series adds regressions, bisection will
  101. finger the last patch as the one which caused the problem, even though
  102. the real bug is elsewhere. Whenever possible, a patch which adds new
  103. code should make that code active immediately.
  104. Working to create the perfect patch series can be a frustrating process
  105. which takes quite a bit of time and thought after the "real work" has been
  106. done. When done properly, though, it is time well spent.
  107. Patch formatting and changelogs
  108. -------------------------------
  109. So now you have a perfect series of patches for posting, but the work is
  110. not done quite yet. Each patch needs to be formatted into a message which
  111. quickly and clearly communicates its purpose to the rest of the world. To
  112. that end, each patch will be composed of the following:
  113. - An optional "From" line naming the author of the patch. This line is
  114. only necessary if you are passing on somebody else's patch via email,
  115. but it never hurts to add it when in doubt.
  116. - A one-line description of what the patch does. This message should be
  117. enough for a reader who sees it with no other context to figure out the
  118. scope of the patch; it is the line that will show up in the "short form"
  119. changelogs. This message is usually formatted with the relevant
  120. subsystem name first, followed by the purpose of the patch. For
  121. example:
  122. ::
  123. gpio: fix build on CONFIG_GPIO_SYSFS=n
  124. - A blank line followed by a detailed description of the contents of the
  125. patch. This description can be as long as is required; it should say
  126. what the patch does and why it should be applied to the kernel.
  127. - One or more tag lines, with, at a minimum, one Signed-off-by: line from
  128. the author of the patch. Tags will be described in more detail below.
  129. The items above, together, form the changelog for the patch. Writing good
  130. changelogs is a crucial but often-neglected art; it's worth spending
  131. another moment discussing this issue. When writing a changelog, you should
  132. bear in mind that a number of different people will be reading your words.
  133. These include subsystem maintainers and reviewers who need to decide
  134. whether the patch should be included, distributors and other maintainers
  135. trying to decide whether a patch should be backported to other kernels, bug
  136. hunters wondering whether the patch is responsible for a problem they are
  137. chasing, users who want to know how the kernel has changed, and more. A
  138. good changelog conveys the needed information to all of these people in the
  139. most direct and concise way possible.
  140. To that end, the summary line should describe the effects of and motivation
  141. for the change as well as possible given the one-line constraint. The
  142. detailed description can then amplify on those topics and provide any
  143. needed additional information. If the patch fixes a bug, cite the commit
  144. which introduced the bug if possible (and please provide both the commit ID
  145. and the title when citing commits). If a problem is associated with
  146. specific log or compiler output, include that output to help others
  147. searching for a solution to the same problem. If the change is meant to
  148. support other changes coming in later patch, say so. If internal APIs are
  149. changed, detail those changes and how other developers should respond. In
  150. general, the more you can put yourself into the shoes of everybody who will
  151. be reading your changelog, the better that changelog (and the kernel as a
  152. whole) will be.
  153. Needless to say, the changelog should be the text used when committing the
  154. change to a revision control system. It will be followed by:
  155. - The patch itself, in the unified ("-u") patch format. Using the "-p"
  156. option to diff will associate function names with changes, making the
  157. resulting patch easier for others to read.
  158. The tags already briefly mentioned above are used to provide insights how
  159. the patch came into being. They are described in detail in the
  160. :ref:`Documentation/process/submitting-patches.rst <submittingpatches>`
  161. document; what follows here is a brief summary.
  162. One tag is used to refer to earlier commits which introduced problems fixed by
  163. the patch::
  164. Fixes: 1f2e3d4c5b6a ("The first line of the commit specified by the first 12 characters of its SHA-1 ID")
  165. Another tag is used for linking web pages with additional backgrounds or
  166. details, for example an earlier discussion which leads to the patch or a
  167. document with a specification implemented by the patch::
  168. Link: https://example.com/somewhere.html optional-other-stuff
  169. As per guidance from the Chief Penguin, a Link: tag should only be added to
  170. a commit if it leads to useful information that is not found in the commit
  171. itself.
  172. If the URL points to a public bug report being fixed by the patch, use the
  173. "Closes:" tag instead::
  174. Closes: https://example.com/issues/1234 optional-other-stuff
  175. Some bug trackers have the ability to close issues automatically when a
  176. commit with such a tag is applied. Some bots monitoring mailing lists can
  177. also track such tags and take certain actions. Private bug trackers and
  178. invalid URLs are forbidden.
  179. Another kind of tag is used to document who was involved in the development of
  180. the patch. Each of these uses this format::
  181. tag: Full Name <email address> optional-other-stuff
  182. The tags in common use are:
  183. - Signed-off-by: this is a developer's certification that he or she has
  184. the right to submit the patch for inclusion into the kernel. It is an
  185. agreement to the Developer's Certificate of Origin, the full text of
  186. which can be found in :ref:`Documentation/process/submitting-patches.rst <submittingpatches>`
  187. Code without a proper signoff cannot be merged into the mainline.
  188. - Co-developed-by: states that the patch was co-created by several developers;
  189. it is a used to give attribution to co-authors (in addition to the author
  190. attributed by the From: tag) when multiple people work on a single patch.
  191. Every Co-developed-by: must be immediately followed by a Signed-off-by: of
  192. the associated co-author. Details and examples can be found in
  193. :ref:`Documentation/process/submitting-patches.rst <submittingpatches>`.
  194. - Acked-by: indicates an agreement by another developer (often a
  195. maintainer of the relevant code) that the patch is appropriate for
  196. inclusion into the kernel.
  197. - Tested-by: states that the named person has tested the patch and found
  198. it to work.
  199. - Reviewed-by: the named developer has reviewed the patch for correctness;
  200. see the reviewer's statement in :ref:`Documentation/process/submitting-patches.rst <submittingpatches>`
  201. for more detail.
  202. - Reported-by: names a user who reported a problem which is fixed by this
  203. patch; this tag is used to give credit to the (often underappreciated)
  204. people who test our code and let us know when things do not work
  205. correctly. Note, this tag should be followed by a Closes: tag pointing to
  206. the report, unless the report is not available on the web. The Link: tag
  207. can be used instead of Closes: if the patch fixes a part of the issue(s)
  208. being reported.
  209. - A Suggested-by: tag indicates that the patch idea is suggested by the person
  210. named and ensures credit to the person for the idea. This will, hopefully,
  211. inspire them to help us again in the future.
  212. - Cc: the named person received a copy of the patch and had the
  213. opportunity to comment on it.
  214. Be careful in the addition of the aforementioned tags to your patches, as all
  215. except for Cc:, Reported-by:, and Suggested-by: need explicit permission of the
  216. person named. For those three implicit permission is sufficient if the person
  217. contributed to the Linux kernel using that name and email address according
  218. to the lore archives or the commit history -- and in case of Reported-by:
  219. and Suggested-by: did the reporting or suggestion in public. Note,
  220. bugzilla.kernel.org is a public place in this sense, but email addresses
  221. used there are private; so do not expose them in tags, unless the person
  222. used them in earlier contributions.
  223. Sending the patch
  224. -----------------
  225. Before you mail your patches, there are a couple of other things you should
  226. take care of:
  227. - Are you sure that your mailer will not corrupt the patches? Patches
  228. which have had gratuitous white-space changes or line wrapping performed
  229. by the mail client will not apply at the other end, and often will not
  230. be examined in any detail. If there is any doubt at all, mail the patch
  231. to yourself and convince yourself that it shows up intact.
  232. :ref:`Documentation/process/email-clients.rst <email_clients>` has some
  233. helpful hints on making specific mail clients work for sending patches.
  234. - Are you sure your patch is free of silly mistakes? You should always
  235. run patches through scripts/checkpatch.pl and address the complaints it
  236. comes up with. Please bear in mind that checkpatch.pl, while being the
  237. embodiment of a fair amount of thought about what kernel patches should
  238. look like, is not smarter than you. If fixing a checkpatch.pl complaint
  239. would make the code worse, don't do it.
  240. Patches should always be sent as plain text. Please do not send them as
  241. attachments; that makes it much harder for reviewers to quote sections of
  242. the patch in their replies. Instead, just put the patch directly into your
  243. message.
  244. When mailing patches, it is important to send copies to anybody who might
  245. be interested in it. Unlike some other projects, the kernel encourages
  246. people to err on the side of sending too many copies; don't assume that the
  247. relevant people will see your posting on the mailing lists. In particular,
  248. copies should go to:
  249. - The maintainer(s) of the affected subsystem(s). As described earlier,
  250. the MAINTAINERS file is the first place to look for these people.
  251. - Other developers who have been working in the same area - especially
  252. those who might be working there now. Using git to see who else has
  253. modified the files you are working on can be helpful.
  254. - If you are responding to a bug report or a feature request, copy the
  255. original poster as well.
  256. - Send a copy to the relevant mailing list, or, if nothing else applies,
  257. the linux-kernel list.
  258. - If you are fixing a bug, think about whether the fix should go into the
  259. next stable update. If so, stable@vger.kernel.org should get a copy of
  260. the patch. Also add a "Cc: stable@vger.kernel.org" to the tags within
  261. the patch itself; that will cause the stable team to get a notification
  262. when your fix goes into the mainline.
  263. When selecting recipients for a patch, it is good to have an idea of who
  264. you think will eventually accept the patch and get it merged. While it
  265. is possible to send patches directly to Linus Torvalds and have him merge
  266. them, things are not normally done that way. Linus is busy, and there are
  267. subsystem maintainers who watch over specific parts of the kernel. Usually
  268. you will be wanting that maintainer to merge your patches. If there is no
  269. obvious maintainer, Andrew Morton is often the patch target of last resort.
  270. Patches need good subject lines. The canonical format for a patch line is
  271. something like:
  272. ::
  273. [PATCH nn/mm] subsys: one-line description of the patch
  274. where "nn" is the ordinal number of the patch, "mm" is the total number of
  275. patches in the series, and "subsys" is the name of the affected subsystem.
  276. Clearly, nn/mm can be omitted for a single, standalone patch.
  277. If you have a significant series of patches, it is customary to send an
  278. introductory description as part zero. This convention is not universally
  279. followed though; if you use it, remember that information in the
  280. introduction does not make it into the kernel changelogs. So please ensure
  281. that the patches, themselves, have complete changelog information.
  282. In general, the second and following parts of a multi-part patch should be
  283. sent as a reply to the first part so that they all thread together at the
  284. receiving end. Tools like git and quilt have commands to mail out a set of
  285. patches with the proper threading. If you have a long series, though, and
  286. are using git, please stay away from the --chain-reply-to option to avoid
  287. creating exceptionally deep nesting.