€• ïŒsphinx.addnodes”Œdocument”“”)�”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)�”}”(hhh]”(hŒ pending_xref”“”)�”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…”�”}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ#/translations/zh_CN/dev-tools/kmsan”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)�”}”(hhh]”hŒChinese (Traditional)”…”�”}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ#/translations/zh_TW/dev-tools/kmsan”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒItalian”…”�”}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ#/translations/it_IT/dev-tools/kmsan”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒJapanese”…”�”}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ#/translations/ja_JP/dev-tools/kmsan”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒKorean”…”�”}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ#/translations/ko_KR/dev-tools/kmsan”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒPortuguese (Brazilian)”…”�”}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ#/translations/pt_BR/dev-tools/kmsan”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒSpanish”…”�”}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ#/translations/sp_SP/dev-tools/kmsan”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒcomment”“”)�”}”(hŒ SPDX-License-Identifier: GPL-2.0”h]”hŒ SPDX-License-Identifier: GPL-2.0”…”�”}”hh·sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1hµhhh²hh³Œ=/var/lib/git/docbuild/linux/Documentation/dev-tools/kmsan.rst”h´Kubh¶)�”}”(hŒCopyright (C) 2022, Google LLC.”h]”hŒCopyright (C) 2022, Google LLC.”…”�”}”hhÈsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1hµhhh²hh³hÇh´KubhŒsection”“”)�”}”(hhh]”(hŒtitle”“”)�”}”(hŒKernel Memory Sanitizer (KMSAN)”h]”hŒKernel Memory Sanitizer (KMSAN)”…”�”}”(hhÝh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhhØh²hh³hÇh´KubhŒ paragraph”“”)�”}”(hŒ¸KMSAN is a dynamic error detector aimed at finding uses of uninitialized values. It is based on compiler instrumentation, and is quite similar to the userspace `MemorySanitizer tool`_.”h]”(hŒ KMSAN is a dynamic error detector aimed at finding uses of uninitialized values. It is based on compiler instrumentation, and is quite similar to the userspace ”…”�”}”(hhíh²hh³Nh´NubhŒ reference”“”)�”}”(hŒ`MemorySanitizer tool`_”h]”hŒMemorySanitizer tool”…”�”}”(hh÷h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œname”ŒMemorySanitizer tool”Œrefuri”Œ0https://clang.llvm.org/docs/MemorySanitizer.html”uh1hõhhíŒresolved”KubhŒ.”…”�”}”(hhíh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´KhhØh²hubhì)�”}”(hŒ�An important note is that KMSAN is not intended for production use, because it drastically increases kernel memory footprint and slows the whole system down.”h]”hŒ�An important note is that KMSAN is not intended for production use, because it drastically increases kernel memory footprint and slows the whole system down.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´K hhØh²hubh×)�”}”(hhh]”(hÜ)�”}”(hŒUsage”h]”hŒUsage”…”�”}”(hj%h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhj"h²hh³hÇh´Kubh×)�”}”(hhh]”(hÜ)�”}”(hŒBuilding the kernel”h]”hŒBuilding the kernel”…”�”}”(hj6h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhj3h²hh³hÇh´Kubhì)�”}”(hŒžIn order to build a kernel with KMSAN you will need a fresh Clang (14.0.6+). Please refer to `LLVM documentation`_ for the instructions on how to build Clang.”h]”(hŒ]In order to build a kernel with KMSAN you will need a fresh Clang (14.0.6+). Please refer to ”…”�”}”(hjDh²hh³Nh´Nubhö)�”}”(hŒ`LLVM documentation`_”h]”hŒLLVM documentation”…”�”}”(hjLh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œname”ŒLLVM documentation”jŒ)https://llvm.org/docs/GettingStarted.html”uh1hõhjDj KubhŒ, for the instructions on how to build Clang.”…”�”}”(hjDh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´Khj3h²hubhì)�”}”(hŒ=Now configure and build the kernel with CONFIG_KMSAN enabled.”h]”hŒ=Now configure and build the kernel with CONFIG_KMSAN enabled.”…”�”}”(hjgh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´Khj3h²hubeh}”(h]”Œbuilding-the-kernel”ah ]”h"]”Œbuilding the kernel”ah$]”h&]”uh1hÖhj"h²hh³hÇh´Kubh×)�”}”(hhh]”(hÜ)�”}”(hŒExample report”h]”hŒExample report”…”�”}”(hj€h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhj}h²hh³hÇh´Kubhì)�”}”(hŒ&Here is an example of a KMSAN report::”h]”hŒ%Here is an example of a KMSAN report:”…”�”}”(hjŽh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´Khj}h²hubhŒ literal_block”“”)�”}”(hX+===================================================== BUG: KMSAN: uninit-value in test_uninit_kmsan_check_memory+0x1be/0x380 [kmsan_test] test_uninit_kmsan_check_memory+0x1be/0x380 mm/kmsan/kmsan_test.c:273 kunit_run_case_internal lib/kunit/test.c:333 kunit_try_run_case+0x206/0x420 lib/kunit/test.c:374 kunit_generic_run_threadfn_adapter+0x6d/0xc0 lib/kunit/try-catch.c:28 kthread+0x721/0x850 kernel/kthread.c:327 ret_from_fork+0x1f/0x30 ??:? Uninit was stored to memory at: do_uninit_local_array+0xfa/0x110 mm/kmsan/kmsan_test.c:260 test_uninit_kmsan_check_memory+0x1a2/0x380 mm/kmsan/kmsan_test.c:271 kunit_run_case_internal lib/kunit/test.c:333 kunit_try_run_case+0x206/0x420 lib/kunit/test.c:374 kunit_generic_run_threadfn_adapter+0x6d/0xc0 lib/kunit/try-catch.c:28 kthread+0x721/0x850 kernel/kthread.c:327 ret_from_fork+0x1f/0x30 ??:? Local variable uninit created at: do_uninit_local_array+0x4a/0x110 mm/kmsan/kmsan_test.c:256 test_uninit_kmsan_check_memory+0x1a2/0x380 mm/kmsan/kmsan_test.c:271 Bytes 4-7 of 8 are uninitialized Memory access of size 8 starts at ffff888083fe3da0 CPU: 0 PID: 6731 Comm: kunit_try_catch Tainted: G B E 5.16.0-rc3+ #104 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014 =====================================================”h]”hX+===================================================== BUG: KMSAN: uninit-value in test_uninit_kmsan_check_memory+0x1be/0x380 [kmsan_test] test_uninit_kmsan_check_memory+0x1be/0x380 mm/kmsan/kmsan_test.c:273 kunit_run_case_internal lib/kunit/test.c:333 kunit_try_run_case+0x206/0x420 lib/kunit/test.c:374 kunit_generic_run_threadfn_adapter+0x6d/0xc0 lib/kunit/try-catch.c:28 kthread+0x721/0x850 kernel/kthread.c:327 ret_from_fork+0x1f/0x30 ??:? Uninit was stored to memory at: do_uninit_local_array+0xfa/0x110 mm/kmsan/kmsan_test.c:260 test_uninit_kmsan_check_memory+0x1a2/0x380 mm/kmsan/kmsan_test.c:271 kunit_run_case_internal lib/kunit/test.c:333 kunit_try_run_case+0x206/0x420 lib/kunit/test.c:374 kunit_generic_run_threadfn_adapter+0x6d/0xc0 lib/kunit/try-catch.c:28 kthread+0x721/0x850 kernel/kthread.c:327 ret_from_fork+0x1f/0x30 ??:? Local variable uninit created at: do_uninit_local_array+0x4a/0x110 mm/kmsan/kmsan_test.c:256 test_uninit_kmsan_check_memory+0x1a2/0x380 mm/kmsan/kmsan_test.c:271 Bytes 4-7 of 8 are uninitialized Memory access of size 8 starts at ffff888083fe3da0 CPU: 0 PID: 6731 Comm: kunit_try_catch Tainted: G B E 5.16.0-rc3+ #104 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014 =====================================================”…”�”}”hjžsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jœh³hÇh´Khj}h²hubhì)�”}”(hŒ¼The report says that the local variable ``uninit`` was created uninitialized in ``do_uninit_local_array()``. The third stack trace corresponds to the place where this variable was created.”h]”(hŒ(The report says that the local variable ”…”�”}”(hj¬h²hh³Nh´NubhŒliteral”“”)�”}”(hŒ ``uninit``”h]”hŒuninit”…”�”}”(hj¶h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j´hj¬ubhŒ was created uninitialized in ”…”�”}”(hj¬h²hh³Nh´Nubjµ)�”}”(hŒ``do_uninit_local_array()``”h]”hŒdo_uninit_local_array()”…”�”}”(hjÈh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j´hj¬ubhŒQ. The third stack trace corresponds to the place where this variable was created.”…”�”}”(hj¬h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´KKMSAN instruments every inline assembly output with a call to:”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´MFhj h²hubj�)�”}”(hŒkmsan.cstate`` to hold the metadata for function parameters and return values.”h]”(hŒ2When running in a kernel task context, KMSAN uses ”…”�”}”(hjâ h²hh³Nh´Nubjµ)�”}”(hŒ``current->kmsan.cstate``”h]”hŒcurrent->kmsan.cstate”…”�”}”(hjê h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j´hjâ ubhŒ@ to hold the metadata for function parameters and return values.”…”�”}”(hjâ h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´MnhjÑ h²hubhì)�”}”(hŒ�But in the case the kernel is running in the interrupt, softirq or NMI context, where ``current`` is unavailable, KMSAN switches to per-cpu interrupt state::”h]”(hŒVBut in the case the kernel is running in the interrupt, softirq or NMI context, where ”…”�”}”(hj h²hh³Nh´Nubjµ)�”}”(hŒ ``current``”h]”hŒcurrent”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j´hj ubhŒ; is unavailable, KMSAN switches to per-cpu interrupt state:”…”�”}”(hj h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´MqhjÑ h²hubj�)�”}”(hŒ3DEFINE_PER_CPU(struct kmsan_ctx, kmsan_percpu_ctx);”h]”hŒ3DEFINE_PER_CPU(struct kmsan_ctx, kmsan_percpu_ctx);”…”�”}”hj" sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jœh³hÇh´MthjÑ h²hubeh}”(h]”Œkmsan-contexts”ah ]”h"]”Œkmsan contexts”ah$]”h&]”uh1hÖhjk h²hh³hÇh´Mlubh×)�”}”(hhh]”(hÜ)�”}”(hŒMetadata allocation”h]”hŒMetadata allocation”…”�”}”(hj; h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhj8 h²hh³hÇh´Mwubhì)�”}”(hŒHThere are several places in the kernel for which the metadata is stored.”h]”hŒHThere are several places in the kernel for which the metadata is stored.”…”�”}”(hjI h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´Myhj8 h²hubhì)�”}”(hŒW1. Each ``struct page`` instance contains two pointers to its shadow and origin pages::”h]”(hŒ1. Each ”…”�”}”(hjW h²hh³Nh´Nubjµ)�”}”(hŒ``struct page``”h]”hŒ struct page”…”�”}”(hj_ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j´hjW ubhŒ? instance contains two pointers to its shadow and origin pages:”…”�”}”(hjW h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´M{hj8 h²hubj�)�”}”(hŒ`_. In Proceedings of CGO 2015.”h]”(hŒE. Stepanov, K. Serebryany. ”…”�”}”(hj¸ h²hh³Nh´Nubhö)�”}”(hŒ `MemorySanitizer: fast detector of uninitialized memory use in C++ `_”h]”hŒAMemorySanitizer: fast detector of uninitialized memory use in C++”…”�”}”(hjÀ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œname”ŒAMemorySanitizer: fast detector of uninitialized memory use in C++”jŒYhttps://static.googleusercontent.com/media/research.google.com/en//pubs/archive/43308.pdf”uh1hõhj¸ ubhŒtarget”“”)�”}”(hŒ\ ”h]”h}”(h]”Œ>memorysanitizer-fast-detector-of-uninitialized-memory-use-in-c”ah ]”h"]”ŒAmemorysanitizer: fast detector of uninitialized memory use in c++”ah$]”h&]”Œrefuri”jÐ uh1jÑ Œ referenced”Khj¸ ubhŒ. In Proceedings of CGO 2015.”…”�”}”(hj¸ h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´M¬hj§ h²hubjÒ )�”}”(hŒJ.. _MemorySanitizer tool: https://clang.llvm.org/docs/MemorySanitizer.html”h]”h}”(h]”Œmemorysanitizer-tool”ah ]”h"]”Œmemorysanitizer tool”ah$]”h&]”jjuh1jÑ h´M±hj§ h²hh³hÇjà KubjÒ )�”}”(hŒA.. _LLVM documentation: https://llvm.org/docs/GettingStarted.html”h]”h}”(h]”Œllvm-documentation”ah ]”h"]”Œllvm documentation”ah$]”h&]”jj\uh1jÑ h´M²hj§ h²hh³hÇjà KubjÒ )�”}”(hŒ\.. _LKML discussion: https://lore.kernel.org/all/20220614144853.3693273-1-glider@google.com/”h]”h}”(h]”Œlkml-discussion”ah ]”h"]”Œlkml discussion”ah$]”h&]”jjñuh1jÑ h´M³hj§ h²hh³hÇjà Kubeh}”(h]”Œ references”ah ]”h"]”Œ references”ah$]”h&]”uh1hÖhhØh²hh³hÇh´Mªubeh}”(h]”Œkernel-memory-sanitizer-kmsan”ah ]”h"]”Œkernel memory sanitizer (kmsan)”ah$]”h&]”uh1hÖhhh²hh³hÇh´Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”hÇuh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)�”}”(hÛNŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”jB Œerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”hÇŒ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”(Œmemorysanitizer tool”]”(h÷j‚eŒllvm documentation”]”jLaŒlkml discussion”]”jáauŒrefids”}”Œnameids”}”(j j jfjcjzjwjjj^j[j¯j¬j¤ j¡ jjþj9j6j1j.jh je j»j¸jðjíj“j�j3 j0 jž j› j jþ j` j] jœ j™ jÎ jË j5 j2 j” j‘ j j jÜ jÙ jô jñ j jý j j uŒ nametypes”}”(j ‰jf‰jz‰j‰j^‰j¯‰j¤ ‰j‰j9‰j1‰jh ‰j»‰jð‰j“‰j3 ‰jž ‰j ‰j` ‰jœ ‰jÎ ‰j5 ‰j” ‰j ‰jÜ ˆjô ˆj ˆj ˆuh}”(j hØjcj"jwj3jj}j[jj¬jij¡ j²jþjÃj6jj.j je j<j¸jmjíj¾j�jój0 j–j› j6 jþ j¡ j] j j™ jk jË jœ j2 jÑ j‘ j8 j j§ jÙ jÓ jñ jë jý j÷ j j uŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nh²hub.