5.Posting.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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 SubmittingPatches,
  11. SubmittingDrivers, and SubmitChecklist in the kernel documentation
  12. directory.
  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.
  34. - Make sure your code is compliant with the kernel coding style
  35. guidelines.
  36. - Does your change have performance implications? If so, you should run
  37. benchmarks showing what the impact (or benefit) of your change is; a
  38. summary of the results should be included with the patch.
  39. - Be sure that you have the right to post the code. If this work was done
  40. for an employer, the employer likely has a right to the work and must be
  41. agreeable with its release under the GPL.
  42. As a general rule, putting in some extra thought before posting code almost
  43. always pays back the effort in short order.
  44. Patch preparation
  45. -----------------
  46. The preparation of patches for posting can be a surprising amount of work,
  47. but, once again, attempting to save time here is not generally advisable
  48. even in the short term.
  49. Patches must be prepared against a specific version of the kernel. As a
  50. general rule, a patch should be based on the current mainline as found in
  51. Linus's git tree. When basing on mainline, start with a well-known release
  52. point - a stable or -rc release - rather than branching off the mainline at
  53. an arbitrary spot.
  54. It may become necessary to make versions against -mm, linux-next, or a
  55. subsystem tree, though, to facilitate wider testing and review. Depending
  56. on the area of your patch and what is going on elsewhere, basing a patch
  57. against these other trees can require a significant amount of work
  58. resolving conflicts and dealing with API changes.
  59. Only the most simple changes should be formatted as a single patch;
  60. everything else should be made as a logical series of changes. Splitting
  61. up patches is a bit of an art; some developers spend a long time figuring
  62. out how to do it in the way that the community expects. There are a few
  63. rules of thumb, however, which can help considerably:
  64. - The patch series you post will almost certainly not be the series of
  65. changes found in your working revision control system. Instead, the
  66. changes you have made need to be considered in their final form, then
  67. split apart in ways which make sense. The developers are interested in
  68. discrete, self-contained changes, not the path you took to get to those
  69. changes.
  70. - Each logically independent change should be formatted as a separate
  71. patch. These changes can be small ("add a field to this structure") or
  72. large (adding a significant new driver, for example), but they should be
  73. conceptually small and amenable to a one-line description. Each patch
  74. should make a specific change which can be reviewed on its own and
  75. verified to do what it says it does.
  76. - As a way of restating the guideline above: do not mix different types of
  77. changes in the same patch. If a single patch fixes a critical security
  78. bug, rearranges a few structures, and reformats the code, there is a
  79. good chance that it will be passed over and the important fix will be
  80. lost.
  81. - Each patch should yield a kernel which builds and runs properly; if your
  82. patch series is interrupted in the middle, the result should still be a
  83. working kernel. Partial application of a patch series is a common
  84. scenario when the "git bisect" tool is used to find regressions; if the
  85. result is a broken kernel, you will make life harder for developers and
  86. users who are engaging in the noble work of tracking down problems.
  87. - Do not overdo it, though. One developer once posted a set of edits
  88. to a single file as 500 separate patches - an act which did not make him
  89. the most popular person on the kernel mailing list. A single patch can
  90. be reasonably large as long as it still contains a single *logical*
  91. change.
  92. - It can be tempting to add a whole new infrastructure with a series of
  93. patches, but to leave that infrastructure unused until the final patch
  94. in the series enables the whole thing. This temptation should be
  95. avoided if possible; if that series adds regressions, bisection will
  96. finger the last patch as the one which caused the problem, even though
  97. the real bug is elsewhere. Whenever possible, a patch which adds new
  98. code should make that code active immediately.
  99. Working to create the perfect patch series can be a frustrating process
  100. which takes quite a bit of time and thought after the "real work" has been
  101. done. When done properly, though, it is time well spent.
  102. Patch formatting and changelogs
  103. -------------------------------
  104. So now you have a perfect series of patches for posting, but the work is
  105. not done quite yet. Each patch needs to be formatted into a message which
  106. quickly and clearly communicates its purpose to the rest of the world. To
  107. that end, each patch will be composed of the following:
  108. - An optional "From" line naming the author of the patch. This line is
  109. only necessary if you are passing on somebody else's patch via email,
  110. but it never hurts to add it when in doubt.
  111. - A one-line description of what the patch does. This message should be
  112. enough for a reader who sees it with no other context to figure out the
  113. scope of the patch; it is the line that will show up in the "short form"
  114. changelogs. This message is usually formatted with the relevant
  115. subsystem name first, followed by the purpose of the patch. For
  116. example:
  117. ::
  118. gpio: fix build on CONFIG_GPIO_SYSFS=n
  119. - A blank line followed by a detailed description of the contents of the
  120. patch. This description can be as long as is required; it should say
  121. what the patch does and why it should be applied to the kernel.
  122. - One or more tag lines, with, at a minimum, one Signed-off-by: line from
  123. the author of the patch. Tags will be described in more detail below.
  124. The items above, together, form the changelog for the patch. Writing good
  125. changelogs is a crucial but often-neglected art; it's worth spending
  126. another moment discussing this issue. When writing a changelog, you should
  127. bear in mind that a number of different people will be reading your words.
  128. These include subsystem maintainers and reviewers who need to decide
  129. whether the patch should be included, distributors and other maintainers
  130. trying to decide whether a patch should be backported to other kernels, bug
  131. hunters wondering whether the patch is responsible for a problem they are
  132. chasing, users who want to know how the kernel has changed, and more. A
  133. good changelog conveys the needed information to all of these people in the
  134. most direct and concise way possible.
  135. To that end, the summary line should describe the effects of and motivation
  136. for the change as well as possible given the one-line constraint. The
  137. detailed description can then amplify on those topics and provide any
  138. needed additional information. If the patch fixes a bug, cite the commit
  139. which introduced the bug if possible (and please provide both the commit ID
  140. and the title when citing commits). If a problem is associated with
  141. specific log or compiler output, include that output to help others
  142. searching for a solution to the same problem. If the change is meant to
  143. support other changes coming in later patch, say so. If internal APIs are
  144. changed, detail those changes and how other developers should respond. In
  145. general, the more you can put yourself into the shoes of everybody who will
  146. be reading your changelog, the better that changelog (and the kernel as a
  147. whole) will be.
  148. Needless to say, the changelog should be the text used when committing the
  149. change to a revision control system. It will be followed by:
  150. - The patch itself, in the unified ("-u") patch format. Using the "-p"
  151. option to diff will associate function names with changes, making the
  152. resulting patch easier for others to read.
  153. You should avoid including changes to irrelevant files (those generated by
  154. the build process, for example, or editor backup files) in the patch. The
  155. file "dontdiff" in the Documentation directory can help in this regard;
  156. pass it to diff with the "-X" option.
  157. The tags mentioned above are used to describe how various developers have
  158. been associated with the development of this patch. They are described in
  159. detail in the SubmittingPatches document; what follows here is a brief
  160. summary. Each of these lines has the format:
  161. ::
  162. tag: Full Name <email address> optional-other-stuff
  163. The tags in common use are:
  164. - Signed-off-by: this is a developer's certification that he or she has
  165. the right to submit the patch for inclusion into the kernel. It is an
  166. agreement to the Developer's Certificate of Origin, the full text of
  167. which can be found in Documentation/SubmittingPatches. Code without a
  168. proper signoff cannot be merged into the mainline.
  169. - Acked-by: indicates an agreement by another developer (often a
  170. maintainer of the relevant code) that the patch is appropriate for
  171. inclusion into the kernel.
  172. - Tested-by: states that the named person has tested the patch and found
  173. it to work.
  174. - Reviewed-by: the named developer has reviewed the patch for correctness;
  175. see the reviewer's statement in Documentation/SubmittingPatches for more
  176. detail.
  177. - Reported-by: names a user who reported a problem which is fixed by this
  178. patch; this tag is used to give credit to the (often underappreciated)
  179. people who test our code and let us know when things do not work
  180. correctly.
  181. - Cc: the named person received a copy of the patch and had the
  182. opportunity to comment on it.
  183. Be careful in the addition of tags to your patches: only Cc: is appropriate
  184. for addition without the explicit permission of the person named.
  185. Sending the patch
  186. -----------------
  187. Before you mail your patches, there are a couple of other things you should
  188. take care of:
  189. - Are you sure that your mailer will not corrupt the patches? Patches
  190. which have had gratuitous white-space changes or line wrapping performed
  191. by the mail client will not apply at the other end, and often will not
  192. be examined in any detail. If there is any doubt at all, mail the patch
  193. to yourself and convince yourself that it shows up intact.
  194. Documentation/email-clients.txt has some helpful hints on making
  195. specific mail clients work for sending patches.
  196. - Are you sure your patch is free of silly mistakes? You should always
  197. run patches through scripts/checkpatch.pl and address the complaints it
  198. comes up with. Please bear in mind that checkpatch.pl, while being the
  199. embodiment of a fair amount of thought about what kernel patches should
  200. look like, is not smarter than you. If fixing a checkpatch.pl complaint
  201. would make the code worse, don't do it.
  202. Patches should always be sent as plain text. Please do not send them as
  203. attachments; that makes it much harder for reviewers to quote sections of
  204. the patch in their replies. Instead, just put the patch directly into your
  205. message.
  206. When mailing patches, it is important to send copies to anybody who might
  207. be interested in it. Unlike some other projects, the kernel encourages
  208. people to err on the side of sending too many copies; don't assume that the
  209. relevant people will see your posting on the mailing lists. In particular,
  210. copies should go to:
  211. - The maintainer(s) of the affected subsystem(s). As described earlier,
  212. the MAINTAINERS file is the first place to look for these people.
  213. - Other developers who have been working in the same area - especially
  214. those who might be working there now. Using git to see who else has
  215. modified the files you are working on can be helpful.
  216. - If you are responding to a bug report or a feature request, copy the
  217. original poster as well.
  218. - Send a copy to the relevant mailing list, or, if nothing else applies,
  219. the linux-kernel list.
  220. - If you are fixing a bug, think about whether the fix should go into the
  221. next stable update. If so, [email protected] should get a copy of
  222. the patch. Also add a "Cc: [email protected]" to the tags within
  223. the patch itself; that will cause the stable team to get a notification
  224. when your fix goes into the mainline.
  225. When selecting recipients for a patch, it is good to have an idea of who
  226. you think will eventually accept the patch and get it merged. While it
  227. is possible to send patches directly to Linus Torvalds and have him merge
  228. them, things are not normally done that way. Linus is busy, and there are
  229. subsystem maintainers who watch over specific parts of the kernel. Usually
  230. you will be wanting that maintainer to merge your patches. If there is no
  231. obvious maintainer, Andrew Morton is often the patch target of last resort.
  232. Patches need good subject lines. The canonical format for a patch line is
  233. something like:
  234. ::
  235. [PATCH nn/mm] subsys: one-line description of the patch
  236. where "nn" is the ordinal number of the patch, "mm" is the total number of
  237. patches in the series, and "subsys" is the name of the affected subsystem.
  238. Clearly, nn/mm can be omitted for a single, standalone patch.
  239. If you have a significant series of patches, it is customary to send an
  240. introductory description as part zero. This convention is not universally
  241. followed though; if you use it, remember that information in the
  242. introduction does not make it into the kernel changelogs. So please ensure
  243. that the patches, themselves, have complete changelog information.
  244. In general, the second and following parts of a multi-part patch should be
  245. sent as a reply to the first part so that they all thread together at the
  246. receiving end. Tools like git and quilt have commands to mail out a set of
  247. patches with the proper threading. If you have a long series, though, and
  248. are using git, please stay away from the --chain-reply-to option to avoid
  249. creating exceptionally deep nesting.