maintainer-kvm-x86.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. .. SPDX-License-Identifier: GPL-2.0
  2. KVM x86
  3. =======
  4. Foreword
  5. --------
  6. KVM strives to be a welcoming community; contributions from newcomers are
  7. valued and encouraged. Please do not be discouraged or intimidated by the
  8. length of this document and the many rules/guidelines it contains. Everyone
  9. makes mistakes, and everyone was a newbie at some point. So long as you make
  10. an honest effort to follow KVM x86's guidelines, are receptive to feedback,
  11. and learn from any mistakes you make, you will be welcomed with open arms, not
  12. torches and pitchforks.
  13. TL;DR
  14. -----
  15. Testing is mandatory. Be consistent with established styles and patterns.
  16. Trees
  17. -----
  18. KVM x86 is currently in a transition period from being part of the main KVM
  19. tree, to being "just another KVM arch". As such, KVM x86 is split across the
  20. main KVM tree, ``git.kernel.org/pub/scm/virt/kvm/kvm.git``, and a KVM x86
  21. specific tree, ``github.com/kvm-x86/linux.git``.
  22. Generally speaking, fixes for the current cycle are applied directly to the
  23. main KVM tree, while all development for the next cycle is routed through the
  24. KVM x86 tree. In the unlikely event that a fix for the current cycle is routed
  25. through the KVM x86 tree, it will be applied to the ``fixes`` branch before
  26. making its way to the main KVM tree.
  27. Note, this transition period is expected to last quite some time, i.e. will be
  28. the status quo for the foreseeable future.
  29. Branches
  30. ~~~~~~~~
  31. The KVM x86 tree is organized into multiple topic branches. The purpose of
  32. using finer-grained topic branches is to make it easier to keep tabs on an area
  33. of development, and to limit the collateral damage of human errors and/or buggy
  34. commits, e.g. dropping the HEAD commit of a topic branch has no impact on other
  35. in-flight commits' SHA1 hashes, and having to reject a pull request due to bugs
  36. delays only that topic branch.
  37. All topic branches, except for ``next`` and ``fixes``, are rolled into ``next``
  38. via a Cthulhu merge on an as-needed basis, i.e. when a topic branch is updated.
  39. As a result, force pushes to ``next`` are common.
  40. Lifecycle
  41. ~~~~~~~~~
  42. Fixes that target the current release, a.k.a. mainline, are typically applied
  43. directly to the main KVM tree, i.e. do not route through the KVM x86 tree.
  44. Changes that target the next release are routed through the KVM x86 tree. Pull
  45. requests (from KVM x86 to main KVM) are sent for each KVM x86 topic branch,
  46. typically the week before Linus' opening of the merge window, e.g. the week
  47. following rc7 for "normal" releases. If all goes well, the topic branches are
  48. rolled into the main KVM pull request sent during Linus' merge window.
  49. The KVM x86 tree doesn't have its own official merge window, but there's a soft
  50. close around rc5 for new features, and a soft close around rc6 for fixes (for
  51. the next release; see above for fixes that target the current release).
  52. Timeline
  53. ~~~~~~~~
  54. Submissions are typically reviewed and applied in FIFO order, with some wiggle
  55. room for the size of a series, patches that are "cache hot", etc. Fixes,
  56. especially for the current release and or stable trees, get to jump the queue.
  57. Patches that will be taken through a non-KVM tree (most often through the tip
  58. tree) and/or have other acks/reviews also jump the queue to some extent.
  59. Note, the vast majority of review is done between rc1 and rc6, give or take.
  60. The period between rc6 and the next rc1 is used to catch up on other tasks,
  61. i.e. radio silence during this period isn't unusual.
  62. Pings to get a status update are welcome, but keep in mind the timing of the
  63. current release cycle and have realistic expectations. If you are pinging for
  64. acceptance, i.e. not just for feedback or an update, please do everything you
  65. can, within reason, to ensure that your patches are ready to be merged! Pings
  66. on series that break the build or fail tests lead to unhappy maintainers!
  67. Development
  68. -----------
  69. Base Tree/Branch
  70. ~~~~~~~~~~~~~~~~
  71. Fixes that target the current release, a.k.a. mainline, should be based on
  72. ``git://git.kernel.org/pub/scm/virt/kvm/kvm.git master``. Note, fixes do not
  73. automatically warrant inclusion in the current release. There is no singular
  74. rule, but typically only fixes for bugs that are urgent, critical, and/or were
  75. introduced in the current release should target the current release.
  76. Everything else should be based on ``kvm-x86/next``, i.e. there is no need to
  77. select a specific topic branch as the base. If there are conflicts and/or
  78. dependencies across topic branches, it is the maintainer's job to sort them
  79. out.
  80. The only exception to using ``kvm-x86/next`` as the base is if a patch/series
  81. is a multi-arch series, i.e. has non-trivial modifications to common KVM code
  82. and/or has more than superficial changes to other architectures' code. Multi-
  83. arch patch/series should instead be based on a common, stable point in KVM's
  84. history, e.g. the release candidate upon which ``kvm-x86 next`` is based. If
  85. you're unsure whether a patch/series is truly multi-arch, err on the side of
  86. caution and treat it as multi-arch, i.e. use a common base.
  87. Coding Style
  88. ~~~~~~~~~~~~
  89. When it comes to style, naming, patterns, etc., consistency is the number one
  90. priority in KVM x86. If all else fails, match what already exists.
  91. With a few caveats listed below, follow the tip tree maintainers' preferred
  92. :ref:`maintainer-tip-coding-style`, as patches/series often touch both KVM and
  93. non-KVM x86 files, i.e. draw the attention of KVM *and* tip tree maintainers.
  94. Using reverse fir tree, a.k.a. reverse Christmas tree or reverse XMAS tree, for
  95. variable declarations isn't strictly required, though it is still preferred.
  96. Except for a handful of special snowflakes, do not use kernel-doc comments for
  97. functions. The vast majority of "public" KVM functions aren't truly public as
  98. they are intended only for KVM-internal consumption (there are plans to
  99. privatize KVM's headers and exports to enforce this).
  100. Comments
  101. ~~~~~~~~
  102. Write comments using imperative mood and avoid pronouns. Use comments to
  103. provide a high level overview of the code, and/or to explain why the code does
  104. what it does. Do not reiterate what the code literally does; let the code
  105. speak for itself. If the code itself is inscrutable, comments will not help.
  106. SDM and APM References
  107. ~~~~~~~~~~~~~~~~~~~~~~
  108. Much of KVM's code base is directly tied to architectural behavior defined in
  109. Intel's Software Development Manual (SDM) and AMD's Architecture Programmer’s
  110. Manual (APM). Use of "Intel's SDM" and "AMD's APM", or even just "SDM" or
  111. "APM", without additional context is a-ok.
  112. Do not reference specific sections, tables, figures, etc. by number, especially
  113. not in comments. Instead, if necessary (see below), copy-paste the relevant
  114. snippet and reference sections/tables/figures by name. The layouts of the SDM
  115. and APM are constantly changing, and so the numbers/labels aren't stable.
  116. Generally speaking, do not explicitly reference or copy-paste from the SDM or
  117. APM in comments. With few exceptions, KVM *must* honor architectural behavior,
  118. therefore it's implied that KVM behavior is emulating SDM and/or APM behavior.
  119. Note, referencing the SDM/APM in changelogs to justify the change and provide
  120. context is perfectly ok and encouraged.
  121. Shortlog
  122. ~~~~~~~~
  123. The preferred prefix format is ``KVM: <topic>:``, where ``<topic>`` is one of::
  124. - x86
  125. - x86/mmu
  126. - x86/pmu
  127. - x86/xen
  128. - selftests
  129. - SVM
  130. - nSVM
  131. - VMX
  132. - nVMX
  133. **DO NOT use x86/kvm!** ``x86/kvm`` is used exclusively for Linux-as-a-KVM-guest
  134. changes, i.e. for arch/x86/kernel/kvm.c. Do not use file names or complete file
  135. paths as the subject/shortlog prefix.
  136. Note, these don't align with the topics branches (the topic branches care much
  137. more about code conflicts).
  138. All names are case sensitive! ``KVM: x86:`` is good, ``kvm: vmx:`` is not.
  139. Capitalize the first word of the condensed patch description, but omit ending
  140. punctionation. E.g.::
  141. KVM: x86: Fix a null pointer dereference in function_xyz()
  142. not::
  143. kvm: x86: fix a null pointer dereference in function_xyz.
  144. If a patch touches multiple topics, traverse up the conceptual tree to find the
  145. first common parent (which is often simply ``x86``). When in doubt,
  146. ``git log path/to/file`` should provide a reasonable hint.
  147. New topics do occasionally pop up, but please start an on-list discussion if
  148. you want to propose introducing a new topic, i.e. don't go rogue.
  149. See :ref:`the_canonical_patch_format` for more information, with one amendment:
  150. do not treat the 70-75 character limit as an absolute, hard limit. Instead,
  151. use 75 characters as a firm-but-not-hard limit, and use 80 characters as a hard
  152. limit. I.e. let the shortlog run a few characters over the standard limit if
  153. you have good reason to do so.
  154. Changelog
  155. ~~~~~~~~~
  156. Most importantly, write changelogs using imperative mood and avoid pronouns.
  157. See :ref:`describe_changes` for more information, with one amendment: lead with
  158. a short blurb on the actual changes, and then follow up with the context and
  159. background. Note! This order directly conflicts with the tip tree's preferred
  160. approach! Please follow the tip tree's preferred style when sending patches
  161. that primarily target arch/x86 code that is _NOT_ KVM code.
  162. Stating what a patch does before diving into details is preferred by KVM x86
  163. for several reasons. First and foremost, what code is actually being changed
  164. is arguably the most important information, and so that info should be easy to
  165. find. Changelogs that bury the "what's actually changing" in a one-liner after
  166. 3+ paragraphs of background make it very hard to find that information.
  167. For initial review, one could argue the "what's broken" is more important, but
  168. for skimming logs and git archaeology, the gory details matter less and less.
  169. E.g. when doing a series of "git blame", the details of each change along the
  170. way are useless, the details only matter for the culprit. Providing the "what
  171. changed" makes it easy to quickly determine whether or not a commit might be of
  172. interest.
  173. Another benefit of stating "what's changing" first is that it's almost always
  174. possible to state "what's changing" in a single sentence. Conversely, all but
  175. the most simple bugs require multiple sentences or paragraphs to fully describe
  176. the problem. If both the "what's changing" and "what's the bug" are super
  177. short then the order doesn't matter. But if one is shorter (almost always the
  178. "what's changing), then covering the shorter one first is advantageous because
  179. it's less of an inconvenience for readers/reviewers that have a strict ordering
  180. preference. E.g. having to skip one sentence to get to the context is less
  181. painful than having to skip three paragraphs to get to "what's changing".
  182. Fixes
  183. ~~~~~
  184. If a change fixes a KVM/kernel bug, add a Fixes: tag even if the change doesn't
  185. need to be backported to stable kernels, and even if the change fixes a bug in
  186. an older release.
  187. Conversely, if a fix does need to be backported, explicitly tag the patch with
  188. "Cc: stable@vger.kernel" (though the email itself doesn't need to Cc: stable);
  189. KVM x86 opts out of backporting Fixes: by default. Some auto-selected patches
  190. do get backported, but require explicit maintainer approval (search MANUALSEL).
  191. Function References
  192. ~~~~~~~~~~~~~~~~~~~
  193. When a function is mentioned in a comment, changelog, or shortlog (or anywhere
  194. for that matter), use the format ``function_name()``. The parentheses provide
  195. context and disambiguate the reference.
  196. Testing
  197. -------
  198. At a bare minimum, *all* patches in a series must build cleanly for KVM_INTEL=m
  199. KVM_AMD=m, and KVM_WERROR=y. Building every possible combination of Kconfigs
  200. isn't feasible, but the more the merrier. KVM_SMM, KVM_XEN, PROVE_LOCKING, and
  201. X86_64 are particularly interesting knobs to turn.
  202. Running KVM selftests and KVM-unit-tests is also mandatory (and stating the
  203. obvious, the tests need to pass). The only exception is for changes that have
  204. negligible probability of affecting runtime behavior, e.g. patches that only
  205. modify comments. When possible and relevant, testing on both Intel and AMD is
  206. strongly preferred. Booting an actual VM is encouraged, but not mandatory.
  207. For changes that touch KVM's shadow paging code, running with TDP (EPT/NPT)
  208. disabled is mandatory. For changes that affect common KVM MMU code, running
  209. with TDP disabled is strongly encouraged. For all other changes, if the code
  210. being modified depends on and/or interacts with a module param, testing with
  211. the relevant settings is mandatory.
  212. Note, KVM selftests and KVM-unit-tests do have known failures. If you suspect
  213. a failure is not due to your changes, verify that the *exact same* failure
  214. occurs with and without your changes.
  215. Changes that touch reStructured Text documentation, i.e. .rst files, must build
  216. htmldocs cleanly, i.e. with no new warnings or errors.
  217. If you can't fully test a change, e.g. due to lack of hardware, clearly state
  218. what level of testing you were able to do, e.g. in the cover letter.
  219. New Features
  220. ~~~~~~~~~~~~
  221. With one exception, new features *must* come with test coverage. KVM specific
  222. tests aren't strictly required, e.g. if coverage is provided by running a
  223. sufficiently enabled guest VM, or by running a related kernel selftest in a VM,
  224. but dedicated KVM tests are preferred in all cases. Negative testcases in
  225. particular are mandatory for enabling of new hardware features as error and
  226. exception flows are rarely exercised simply by running a VM.
  227. The only exception to this rule is if KVM is simply advertising support for a
  228. feature via KVM_GET_SUPPORTED_CPUID, i.e. for instructions/features that KVM
  229. can't prevent a guest from using and for which there is no true enabling.
  230. Note, "new features" does not just mean "new hardware features"! New features
  231. that can't be well validated using existing KVM selftests and/or KVM-unit-tests
  232. must come with tests.
  233. Posting new feature development without tests to get early feedback is more
  234. than welcome, but such submissions should be tagged RFC, and the cover letter
  235. should clearly state what type of feedback is requested/expected. Do not abuse
  236. the RFC process; RFCs will typically not receive in-depth review.
  237. Bug Fixes
  238. ~~~~~~~~~
  239. Except for "obvious" found-by-inspection bugs, fixes must be accompanied by a
  240. reproducer for the bug being fixed. In many cases the reproducer is implicit,
  241. e.g. for build errors and test failures, but it should still be clear to
  242. readers what is broken and how to verify the fix. Some leeway is given for
  243. bugs that are found via non-public workloads/tests, but providing regression
  244. tests for such bugs is strongly preferred.
  245. In general, regression tests are preferred for any bug that is not trivial to
  246. hit. E.g. even if the bug was originally found by a fuzzer such as syzkaller,
  247. a targeted regression test may be warranted if the bug requires hitting a
  248. one-in-a-million type race condition.
  249. Note, KVM bugs are rarely urgent *and* non-trivial to reproduce. Ask yourself
  250. if a bug is really truly the end of the world before posting a fix without a
  251. reproducer.
  252. Posting
  253. -------
  254. Links
  255. ~~~~~
  256. Do not explicitly reference bug reports, prior versions of a patch/series, etc.
  257. via ``In-Reply-To:`` headers. Using ``In-Reply-To:`` becomes an unholy mess
  258. for large series and/or when the version count gets high, and ``In-Reply-To:``
  259. is useless for anyone that doesn't have the original message, e.g. if someone
  260. wasn't Cc'd on the bug report or if the list of recipients changes between
  261. versions.
  262. To link to a bug report, previous version, or anything of interest, use lore
  263. links. For referencing previous version(s), generally speaking do not include
  264. a Link: in the changelog as there is no need to record the history in git, i.e.
  265. put the link in the cover letter or in the section git ignores. Do provide a
  266. formal Link: for bug reports and/or discussions that led to the patch. The
  267. context of why a change was made is highly valuable for future readers.
  268. Git Base
  269. ~~~~~~~~
  270. If you are using git version 2.9.0 or later (Googlers, this is all of you!),
  271. use ``git format-patch`` with the ``--base`` flag to automatically include the
  272. base tree information in the generated patches.
  273. Note, ``--base=auto`` works as expected if and only if a branch's upstream is
  274. set to the base topic branch, e.g. it will do the wrong thing if your upstream
  275. is set to your personal repository for backup purposes. An alternative "auto"
  276. solution is to derive the names of your development branches based on their
  277. KVM x86 topic, and feed that into ``--base``. E.g. ``x86/pmu/my_branch_name``,
  278. and then write a small wrapper to extract ``pmu`` from the current branch name
  279. to yield ``--base=x/pmu``, where ``x`` is whatever name your repository uses to
  280. track the KVM x86 remote.
  281. Co-Posting Tests
  282. ~~~~~~~~~~~~~~~~
  283. KVM selftests that are associated with KVM changes, e.g. regression tests for
  284. bug fixes, should be posted along with the KVM changes as a single series. The
  285. standard kernel rules for bisection apply, i.e. KVM changes that result in test
  286. failures should be ordered after the selftests updates, and vice versa, new
  287. tests that fail due to KVM bugs should be ordered after the KVM fixes.
  288. KVM-unit-tests should *always* be posted separately. Tools, e.g. b4 am, don't
  289. know that KVM-unit-tests is a separate repository and get confused when patches
  290. in a series apply on different trees. To tie KVM-unit-tests patches back to
  291. KVM patches, first post the KVM changes and then provide a lore Link: to the
  292. KVM patch/series in the KVM-unit-tests patch(es).
  293. Notifications
  294. -------------
  295. When a patch/series is officially accepted, a notification email will be sent
  296. in reply to the original posting (cover letter for multi-patch series). The
  297. notification will include the tree and topic branch, along with the SHA1s of
  298. the commits of applied patches.
  299. If a subset of patches is applied, this will be clearly stated in the
  300. notification. Unless stated otherwise, it's implied that any patches in the
  301. series that were not accepted need more work and should be submitted in a new
  302. version.
  303. If for some reason a patch is dropped after officially being accepted, a reply
  304. will be sent to the notification email explaining why the patch was dropped, as
  305. well as the next steps.
  306. SHA1 Stability
  307. ~~~~~~~~~~~~~~
  308. SHA1s are not 100% guaranteed to be stable until they land in Linus' tree! A
  309. SHA1 is *usually* stable once a notification has been sent, but things happen.
  310. In most cases, an update to the notification email be provided if an applied
  311. patch's SHA1 changes. However, in some scenarios, e.g. if all KVM x86 branches
  312. need to be rebased, individual notifications will not be given.
  313. Vulnerabilities
  314. ---------------
  315. Bugs that can be exploited by the guest to attack the host (kernel or
  316. userspace), or that can be exploited by a nested VM to *its* host (L2 attacking
  317. L1), are of particular interest to KVM. Please follow the protocol for
  318. :ref:`securitybugs` if you suspect a bug can lead to an escape, data leak, etc.