hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/Documentation/process/submitting-patches.rst
....@@ -10,22 +10,18 @@
1010
1111 This document contains a large number of suggestions in a relatively terse
1212 format. For detailed information on how the kernel development process
13
-works, see :ref:`Documentation/process <development_process_main>`.
14
-Also, read :ref:`Documentation/process/submit-checklist.rst <submitchecklist>`
15
-for a list of items to check before
16
-submitting code. If you are submitting a driver, also read
17
-:ref:`Documentation/process/submitting-drivers.rst <submittingdrivers>`;
18
-for device tree binding patches, read
19
-Documentation/devicetree/bindings/submitting-patches.txt.
13
+works, see :doc:`development-process`. Also, read :doc:`submit-checklist`
14
+for a list of items to check before submitting code. If you are submitting
15
+a driver, also read :doc:`submitting-drivers`; for device tree binding patches,
16
+read :doc:`submitting-patches`.
2017
21
-Many of these steps describe the default behavior of the ``git`` version
22
-control system; if you use ``git`` to prepare your patches, you'll find much
23
-of the mechanical work done for you, though you'll still need to prepare
24
-and document a sensible set of patches. In general, use of ``git`` will make
25
-your life as a kernel developer easier.
18
+This documentation assumes that you're using ``git`` to prepare your patches.
19
+If you're unfamiliar with ``git``, you would be well-advised to learn how to
20
+use it, it will make your life as a kernel developer and in general much
21
+easier.
2622
27
-0) Obtain a current source tree
28
--------------------------------
23
+Obtain a current source tree
24
+----------------------------
2925
3026 If you do not have a repository with the current kernel source handy, use
3127 ``git`` to obtain one. You'll want to start with the mainline repository,
....@@ -39,68 +35,10 @@
3935 in the MAINTAINERS file to find that tree, or simply ask the maintainer if
4036 the tree is not listed there.
4137
42
-It is still possible to download kernel releases via tarballs (as described
43
-in the next section), but that is the hard way to do kernel development.
44
-
45
-1) ``diff -up``
46
----------------
47
-
48
-If you must generate your patches by hand, use ``diff -up`` or ``diff -uprN``
49
-to create patches. Git generates patches in this form by default; if
50
-you're using ``git``, you can skip this section entirely.
51
-
52
-All changes to the Linux kernel occur in the form of patches, as
53
-generated by :manpage:`diff(1)`. When creating your patch, make sure to
54
-create it in "unified diff" format, as supplied by the ``-u`` argument
55
-to :manpage:`diff(1)`.
56
-Also, please use the ``-p`` argument which shows which C function each
57
-change is in - that makes the resultant ``diff`` a lot easier to read.
58
-Patches should be based in the root kernel source directory,
59
-not in any lower subdirectory.
60
-
61
-To create a patch for a single file, it is often sufficient to do::
62
-
63
- SRCTREE= linux
64
- MYFILE= drivers/net/mydriver.c
65
-
66
- cd $SRCTREE
67
- cp $MYFILE $MYFILE.orig
68
- vi $MYFILE # make your change
69
- cd ..
70
- diff -up $SRCTREE/$MYFILE{.orig,} > /tmp/patch
71
-
72
-To create a patch for multiple files, you should unpack a "vanilla",
73
-or unmodified kernel source tree, and generate a ``diff`` against your
74
-own source tree. For example::
75
-
76
- MYSRC= /devel/linux
77
-
78
- tar xvfz linux-3.19.tar.gz
79
- mv linux-3.19 linux-3.19-vanilla
80
- diff -uprN -X linux-3.19-vanilla/Documentation/dontdiff \
81
- linux-3.19-vanilla $MYSRC > /tmp/patch
82
-
83
-``dontdiff`` is a list of files which are generated by the kernel during
84
-the build process, and should be ignored in any :manpage:`diff(1)`-generated
85
-patch.
86
-
87
-Make sure your patch does not include any extra files which do not
88
-belong in a patch submission. Make sure to review your patch -after-
89
-generating it with :manpage:`diff(1)`, to ensure accuracy.
90
-
91
-If your changes produce a lot of deltas, you need to split them into
92
-individual patches which modify things in logical stages; see
93
-:ref:`split_changes`. This will facilitate review by other kernel developers,
94
-very important if you want your patch accepted.
95
-
96
-If you're using ``git``, ``git rebase -i`` can help you with this process. If
97
-you're not using ``git``, ``quilt`` <http://savannah.nongnu.org/projects/quilt>
98
-is another popular alternative.
99
-
10038 .. _describe_changes:
10139
102
-2) Describe your changes
103
-------------------------
40
+Describe your changes
41
+---------------------
10442
10543 Describe your problem. Whether your patch is a one-line bug fix or
10644 5000 lines of a new feature, there must be an underlying problem that
....@@ -133,7 +71,7 @@
13371
13472 The maintainer will thank you if you write your patch description in a
13573 form which can be easily pulled into Linux's source code management
136
-system, ``git``, as a "commit log". See :ref:`explicit_in_reply_to`.
74
+system, ``git``, as a "commit log". See :ref:`the_canonical_patch_format`.
13775
13876 Solve only one problem per patch. If your description starts to get
13977 long, that's a sign that you probably need to split up your patch.
....@@ -182,9 +120,11 @@
182120
183121 If your patch fixes a bug in a specific commit, e.g. you found an issue using
184122 ``git bisect``, please use the 'Fixes:' tag with the first 12 characters of
185
-the SHA-1 ID, and the one line summary. For example::
123
+the SHA-1 ID, and the one line summary. Do not split the tag across multiple
124
+lines, tags are exempt from the "wrap at 75 columns" rule in order to simplify
125
+parsing scripts. For example::
186126
187
- Fixes: e21d2170f366 ("video: remove unnecessary platform_set_drvdata()")
127
+ Fixes: 54a4f0239f2e ("KVM: MMU: make kvm_mmu_zap_page() return the number of pages it actually freed")
188128
189129 The following ``git config`` settings can be used to add a pretty format for
190130 outputting the above style in the ``git log`` or ``git show`` commands::
....@@ -194,10 +134,15 @@
194134 [pretty]
195135 fixes = Fixes: %h (\"%s\")
196136
137
+An example call::
138
+
139
+ $ git log -1 --pretty=fixes 54a4f0239f2e
140
+ Fixes: 54a4f0239f2e ("KVM: MMU: make kvm_mmu_zap_page() return the number of pages it actually freed")
141
+
197142 .. _split_changes:
198143
199
-3) Separate your changes
200
-------------------------
144
+Separate your changes
145
+---------------------
201146
202147 Separate each **logical change** into a separate patch.
203148
....@@ -229,8 +174,8 @@
229174
230175
231176
232
-4) Style-check your changes
233
----------------------------
177
+Style-check your changes
178
+------------------------
234179
235180 Check your patch for basic style violations, details of which can be
236181 found in
....@@ -260,8 +205,8 @@
260205 patch.
261206
262207
263
-5) Select the recipients for your patch
264
----------------------------------------
208
+Select the recipients for your patch
209
+------------------------------------
265210
266211 You should always copy the appropriate subsystem maintainer(s) on any patch
267212 to code that they maintain; look through the MAINTAINERS file and the
....@@ -292,7 +237,8 @@
292237 If you have a patch that fixes an exploitable security bug, send that patch
293238 to security@kernel.org. For severe bugs, a short embargo may be considered
294239 to allow distributors to get the patch out to users; in such cases,
295
-obviously, the patch should not be sent to any public lists.
240
+obviously, the patch should not be sent to any public lists. See also
241
+:doc:`/admin-guide/security-bugs`.
296242
297243 Patches that fix a severe bug in a released kernel should be directed
298244 toward the stable maintainers by putting a line like this::
....@@ -303,11 +249,6 @@
303249 should also read
304250 :ref:`Documentation/process/stable-kernel-rules.rst <stable_kernel_rules>`
305251 in addition to this file.
306
-
307
-Note, however, that some subsystem maintainers want to come to their own
308
-conclusions on which patches should go to the stable trees. The networking
309
-maintainer, in particular, would rather not see individual developers
310
-adding lines like the above to their patches.
311252
312253 If changes affect userland-kernel interfaces, please send the MAN-PAGES
313254 maintainer (as listed in the MAINTAINERS file) a man-pages patch, or at
....@@ -335,15 +276,20 @@
335276
336277
337278
338
-6) No MIME, no links, no compression, no attachments. Just plain text
339
-----------------------------------------------------------------------
279
+No MIME, no links, no compression, no attachments. Just plain text
280
+-------------------------------------------------------------------
340281
341282 Linus and other kernel developers need to be able to read and comment
342283 on the changes you are submitting. It is important for a kernel
343284 developer to be able to "quote" your changes, using standard e-mail
344285 tools, so that they may comment on specific portions of your code.
345286
346
-For this reason, all patches should be submitted by e-mail "inline".
287
+For this reason, all patches should be submitted by e-mail "inline". The
288
+easiest way to do this is with ``git send-email``, which is strongly
289
+recommended. An interactive tutorial for ``git send-email`` is available at
290
+https://git-send-email.io.
291
+
292
+If you choose not to use ``git send-email``:
347293
348294 .. warning::
349295
....@@ -359,27 +305,17 @@
359305 Exception: If your mailer is mangling patches then someone may ask
360306 you to re-send them using MIME.
361307
362
-See :ref:`Documentation/process/email-clients.rst <email_clients>`
363
-for hints about configuring your e-mail client so that it sends your patches
364
-untouched.
308
+See :doc:`/process/email-clients` for hints about configuring your e-mail
309
+client so that it sends your patches untouched.
365310
366
-7) E-mail size
367
---------------
368
-
369
-Large changes are not appropriate for mailing lists, and some
370
-maintainers. If your patch, uncompressed, exceeds 300 kB in size,
371
-it is preferred that you store your patch on an Internet-accessible
372
-server, and provide instead a URL (link) pointing to your patch. But note
373
-that if your patch exceeds 300 kB, it almost certainly needs to be broken up
374
-anyway.
375
-
376
-8) Respond to review comments
377
------------------------------
311
+Respond to review comments
312
+--------------------------
378313
379314 Your patch will almost certainly get comments from reviewers on ways in
380
-which the patch can be improved. You must respond to those comments;
381
-ignoring reviewers is a good way to get ignored in return. Review comments
382
-or questions that do not lead to a code change should almost certainly
315
+which the patch can be improved, in the form of a reply to your email. You must
316
+respond to those comments; ignoring reviewers is a good way to get ignored in
317
+return. You can simply reply to their emails to answer their comments. Review
318
+comments or questions that do not lead to a code change should almost certainly
383319 bring about a comment or changelog entry so that the next reviewer better
384320 understands what is going on.
385321
....@@ -388,9 +324,12 @@
388324 reviewers sometimes get grumpy. Even in that case, though, respond
389325 politely and address the problems they have pointed out.
390326
327
+See :doc:`email-clients` for recommendations on email
328
+clients and mailing list etiquette.
391329
392
-9) Don't get discouraged - or impatient
393
----------------------------------------
330
+
331
+Don't get discouraged - or impatient
332
+------------------------------------
394333
395334 After you have submitted your change, be patient and wait. Reviewers are
396335 busy people and may not get to your patch right away.
....@@ -403,18 +342,19 @@
403342 busy times like merge windows.
404343
405344
406
-10) Include PATCH in the subject
407
---------------------------------
345
+Include PATCH in the subject
346
+-----------------------------
408347
409348 Due to high e-mail traffic to Linus, and to linux-kernel, it is common
410349 convention to prefix your subject line with [PATCH]. This lets Linus
411350 and other kernel developers more easily distinguish patches from other
412351 e-mail discussions.
413352
353
+``git send-email`` will do this for you automatically.
414354
415355
416
-11) Sign your work - the Developer's Certificate of Origin
417
-----------------------------------------------------------
356
+Sign your work - the Developer's Certificate of Origin
357
+------------------------------------------------------
418358
419359 To improve tracking of who did what, especially with patches that can
420360 percolate to their final resting place in the kernel through several
....@@ -458,60 +398,15 @@
458398 Signed-off-by: Random J Developer <random@developer.example.org>
459399
460400 using your real name (sorry, no pseudonyms or anonymous contributions.)
401
+This will be done for you automatically if you use ``git commit -s``.
461402
462403 Some people also put extra tags at the end. They'll just be ignored for
463404 now, but you can do this to mark internal company procedures or just
464405 point out some special detail about the sign-off.
465406
466
-If you are a subsystem or branch maintainer, sometimes you need to slightly
467
-modify patches you receive in order to merge them, because the code is not
468
-exactly the same in your tree and the submitters'. If you stick strictly to
469
-rule (c), you should ask the submitter to rediff, but this is a totally
470
-counter-productive waste of time and energy. Rule (b) allows you to adjust
471
-the code, but then it is very impolite to change one submitter's code and
472
-make him endorse your bugs. To solve this problem, it is recommended that
473
-you add a line between the last Signed-off-by header and yours, indicating
474
-the nature of your changes. While there is nothing mandatory about this, it
475
-seems like prepending the description with your mail and/or name, all
476
-enclosed in square brackets, is noticeable enough to make it obvious that
477
-you are responsible for last-minute changes. Example::
478407
479
- Signed-off-by: Random J Developer <random@developer.example.org>
480
- [lucky@maintainer.example.org: struct foo moved from foo.c to foo.h]
481
- Signed-off-by: Lucky K Maintainer <lucky@maintainer.example.org>
482
-
483
-This practice is particularly helpful if you maintain a stable branch and
484
-want at the same time to credit the author, track changes, merge the fix,
485
-and protect the submitter from complaints. Note that under no circumstances
486
-can you change the author's identity (the From header), as it is the one
487
-which appears in the changelog.
488
-
489
-Special note to back-porters: It seems to be a common and useful practice
490
-to insert an indication of the origin of a patch at the top of the commit
491
-message (just after the subject line) to facilitate tracking. For instance,
492
-here's what we see in a 3.x-stable release::
493
-
494
- Date: Tue Oct 7 07:26:38 2014 -0400
495
-
496
- libata: Un-break ATA blacklist
497
-
498
- commit 1c40279960bcd7d52dbdf1d466b20d24b99176c8 upstream.
499
-
500
-And here's what might appear in an older kernel once a patch is backported::
501
-
502
- Date: Tue May 13 22:12:27 2008 +0200
503
-
504
- wireless, airo: waitbusy() won't delay
505
-
506
- [backport of 2.6 commit b7acbdfbd1f277c1eb23f344f899cfa4cd0bf36a]
507
-
508
-Whatever the format, this information provides a valuable help to people
509
-tracking your trees, and to people trying to troubleshoot bugs in your
510
-tree.
511
-
512
-
513
-12) When to use Acked-by:, Cc:, and Co-Developed-by:
514
--------------------------------------------------------
408
+When to use Acked-by:, Cc:, and Co-developed-by:
409
+------------------------------------------------
515410
516411 The Signed-off-by: tag indicates that the signer was involved in the
517412 development of the patch, or that he/she was in the patch's delivery path.
....@@ -543,14 +438,44 @@
543438 patch. This tag documents that potentially interested parties
544439 have been included in the discussion.
545440
546
-A Co-Developed-by: states that the patch was also created by another developer
547
-along with the original author. This is useful at times when multiple people
548
-work on a single patch. Note, this person also needs to have a Signed-off-by:
549
-line in the patch as well.
441
+Co-developed-by: states that the patch was co-created by multiple developers;
442
+it is a used to give attribution to co-authors (in addition to the author
443
+attributed by the From: tag) when several people work on a single patch. Since
444
+Co-developed-by: denotes authorship, every Co-developed-by: must be immediately
445
+followed by a Signed-off-by: of the associated co-author. Standard sign-off
446
+procedure applies, i.e. the ordering of Signed-off-by: tags should reflect the
447
+chronological history of the patch insofar as possible, regardless of whether
448
+the author is attributed via From: or Co-developed-by:. Notably, the last
449
+Signed-off-by: must always be that of the developer submitting the patch.
450
+
451
+Note, the From: tag is optional when the From: author is also the person (and
452
+email) listed in the From: line of the email header.
453
+
454
+Example of a patch submitted by the From: author::
455
+
456
+ <changelog>
457
+
458
+ Co-developed-by: First Co-Author <first@coauthor.example.org>
459
+ Signed-off-by: First Co-Author <first@coauthor.example.org>
460
+ Co-developed-by: Second Co-Author <second@coauthor.example.org>
461
+ Signed-off-by: Second Co-Author <second@coauthor.example.org>
462
+ Signed-off-by: From Author <from@author.example.org>
463
+
464
+Example of a patch submitted by a Co-developed-by: author::
465
+
466
+ From: From Author <from@author.example.org>
467
+
468
+ <changelog>
469
+
470
+ Co-developed-by: Random Co-Author <random@coauthor.example.org>
471
+ Signed-off-by: Random Co-Author <random@coauthor.example.org>
472
+ Signed-off-by: From Author <from@author.example.org>
473
+ Co-developed-by: Submitting Co-Author <sub@coauthor.example.org>
474
+ Signed-off-by: Submitting Co-Author <sub@coauthor.example.org>
550475
551476
552
-13) Using Reported-by:, Tested-by:, Reviewed-by:, Suggested-by: and Fixes:
553
---------------------------------------------------------------------------
477
+Using Reported-by:, Tested-by:, Reviewed-by:, Suggested-by: and Fixes:
478
+----------------------------------------------------------------------
554479
555480 The Reported-by tag gives credit to people who find bugs and report them and it
556481 hopefully inspires them to help us again in the future. Please note that if
....@@ -597,6 +522,13 @@
597522 understand the subject area and to perform thorough reviews, will normally
598523 increase the likelihood of your patch getting into the kernel.
599524
525
+Both Tested-by and Reviewed-by tags, once received on mailing list from tester
526
+or reviewer, should be added by author to the applicable patches when sending
527
+next versions. However if the patch has changed substantially in following
528
+version, these tags might not be applicable anymore and thus should be removed.
529
+Usually removal of someone's Tested-by or Reviewed-by tags should be mentioned
530
+in the patch changelog (after the '---' separator).
531
+
600532 A Suggested-by: tag indicates that the patch idea is suggested by the person
601533 named and ensures credit to the person for the idea. Please note that this
602534 tag should not be added without the reporter's permission, especially if the
....@@ -613,8 +545,8 @@
613545
614546 .. _the_canonical_patch_format:
615547
616
-14) The canonical patch format
617
-------------------------------
548
+The canonical patch format
549
+--------------------------
618550
619551 This section describes how the patch itself should be formatted. Note
620552 that, if you have your patches stored in a ``git`` repository, proper patch
....@@ -694,7 +626,7 @@
694626 The ``from`` line must be the very first line in the message body,
695627 and has the form:
696628
697
- From: Original Author <author@example.com>
629
+ From: Patch Author <author@example.com>
698630
699631 The ``from`` line specifies who will be credited as the author of the
700632 patch in the permanent changelog. If the ``from`` line is missing,
....@@ -736,8 +668,8 @@
736668
737669 .. _explicit_in_reply_to:
738670
739
-15) Explicit In-Reply-To headers
740
---------------------------------
671
+Explicit In-Reply-To headers
672
+----------------------------
741673
742674 It can be helpful to manually add In-Reply-To: headers to a patch
743675 (e.g., when using ``git send-email``) to associate the patch with
....@@ -750,69 +682,65 @@
750682 the cover email text) to link to an earlier version of the patch series.
751683
752684
753
-16) Sending ``git pull`` requests
754
----------------------------------
685
+Providing base tree information
686
+-------------------------------
755687
756
-If you have a series of patches, it may be most convenient to have the
757
-maintainer pull them directly into the subsystem repository with a
758
-``git pull`` operation. Note, however, that pulling patches from a developer
759
-requires a higher degree of trust than taking patches from a mailing list.
760
-As a result, many subsystem maintainers are reluctant to take pull
761
-requests, especially from new, unknown developers. If in doubt you can use
762
-the pull request as the cover letter for a normal posting of the patch
763
-series, giving the maintainer the option of using either.
688
+When other developers receive your patches and start the review process,
689
+it is often useful for them to know where in the tree history they
690
+should place your work. This is particularly useful for automated CI
691
+processes that attempt to run a series of tests in order to establish
692
+the quality of your submission before the maintainer starts the review.
764693
765
-A pull request should have [GIT PULL] in the subject line. The
766
-request itself should include the repository name and the branch of
767
-interest on a single line; it should look something like::
694
+If you are using ``git format-patch`` to generate your patches, you can
695
+automatically include the base tree information in your submission by
696
+using the ``--base`` flag. The easiest and most convenient way to use
697
+this option is with topical branches::
768698
769
- Please pull from
699
+ $ git checkout -t -b my-topical-branch master
700
+ Branch 'my-topical-branch' set up to track local branch 'master'.
701
+ Switched to a new branch 'my-topical-branch'
770702
771
- git://jdelvare.pck.nerim.net/jdelvare-2.6 i2c-for-linus
703
+ [perform your edits and commits]
772704
773
- to get these changes:
705
+ $ git format-patch --base=auto --cover-letter -o outgoing/ master
706
+ outgoing/0000-cover-letter.patch
707
+ outgoing/0001-First-Commit.patch
708
+ outgoing/...
774709
775
-A pull request should also include an overall message saying what will be
776
-included in the request, a ``git shortlog`` listing of the patches
777
-themselves, and a ``diffstat`` showing the overall effect of the patch series.
778
-The easiest way to get all this information together is, of course, to let
779
-``git`` do it for you with the ``git request-pull`` command.
710
+When you open ``outgoing/0000-cover-letter.patch`` for editing, you will
711
+notice that it will have the ``base-commit:`` trailer at the very
712
+bottom, which provides the reviewer and the CI tools enough information
713
+to properly perform ``git am`` without worrying about conflicts::
780714
781
-Some maintainers (including Linus) want to see pull requests from signed
782
-commits; that increases their confidence that the request actually came
783
-from you. Linus, in particular, will not pull from public hosting sites
784
-like GitHub in the absence of a signed tag.
715
+ $ git checkout -b patch-review [base-commit-id]
716
+ Switched to a new branch 'patch-review'
717
+ $ git am patches.mbox
718
+ Applying: First Commit
719
+ Applying: ...
785720
786
-The first step toward creating such tags is to make a GNUPG key and get it
787
-signed by one or more core kernel developers. This step can be hard for
788
-new developers, but there is no way around it. Attending conferences can
789
-be a good way to find developers who can sign your key.
721
+Please see ``man git-format-patch`` for more information about this
722
+option.
790723
791
-Once you have prepared a patch series in ``git`` that you wish to have somebody
792
-pull, create a signed tag with ``git tag -s``. This will create a new tag
793
-identifying the last commit in the series and containing a signature
794
-created with your private key. You will also have the opportunity to add a
795
-changelog-style message to the tag; this is an ideal place to describe the
796
-effects of the pull request as a whole.
724
+.. note::
797725
798
-If the tree the maintainer will be pulling from is not the repository you
799
-are working from, don't forget to push the signed tag explicitly to the
800
-public tree.
726
+ The ``--base`` feature was introduced in git version 2.9.0.
801727
802
-When generating your pull request, use the signed tag as the target. A
803
-command like this will do the trick::
804
-
805
- git request-pull master git://my.public.tree/linux.git my-signed-tag
728
+If you are not using git to format your patches, you can still include
729
+the same ``base-commit`` trailer to indicate the commit hash of the tree
730
+on which your work is based. You should add it either in the cover
731
+letter or in the first patch of the series and it should be placed
732
+either below the ``---`` line or at the very bottom of all other
733
+content, right before your email signature.
806734
807735
808736 References
809737 ----------
810738
811739 Andrew Morton, "The perfect patch" (tpp).
812
- <http://www.ozlabs.org/~akpm/stuff/tpp.txt>
740
+ <https://www.ozlabs.org/~akpm/stuff/tpp.txt>
813741
814742 Jeff Garzik, "Linux kernel patch submission format".
815
- <http://linux.yyz.us/patch-format.html>
743
+ <https://web.archive.org/web/20180829112450/http://linux.yyz.us/patch-format.html>
816744
817745 Greg Kroah-Hartman, "How to piss off a kernel subsystem maintainer".
818746 <http://www.kroah.com/log/linux/maintainer.html>