€•Œ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/trace/kprobes”Œ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/trace/kprobes”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒItalian”…”�”}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ!/translations/it_IT/trace/kprobes”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒJapanese”…”�”}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ!/translations/ja_JP/trace/kprobes”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒKorean”…”�”}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ!/translations/ko_KR/trace/kprobes”Œ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/trace/kprobes”Œ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/trace/kprobes”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒsection”“”)�”}”(hhh]”(hŒtitle”“”)�”}”(hŒKernel Probes (Kprobes)”h]”hŒKernel Probes (Kprobes)”…”�”}”(hh¼h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhh·h²hh³Œ;/var/lib/git/docbuild/linux/Documentation/trace/kprobes.rst”h´KubhŒ field_list”“”)�”}”(hhh]”(hŒfield”“”)�”}”(hhh]”(hŒ field_name”“”)�”}”(hŒAuthor”h]”hŒAuthor”…”�”}”(hh×h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÕhhÒh³hÊh´KubhŒ field_body”“”)�”}”(hŒ"Jim Keniston ”h]”hŒ paragraph”“”)�”}”(hhéh]”(hŒJim Keniston <”…”�”}”(hhíh²hh³Nh´NubhŒ reference”“”)�”}”(hŒjkenisto@us.ibm.com”h]”hŒjkenisto@us.ibm.com”…”�”}”(hhöh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”Œmailto:jkenisto@us.ibm.com”uh1hôhhíubhŒ>”…”�”}”(hhíh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Khhçubah}”(h]”h ]”h"]”h$]”h&]”uh1håhhÒubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÐh³hÊh´KhhÍh²hubhÑ)�”}”(hhh]”(hÖ)�”}”(hŒAuthor”h]”hŒAuthor”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÕhjh³hÊh´Kubhæ)�”}”(hŒ7Prasanna S Panchamukhi ”h]”hì)�”}”(hj/h]”(hŒPrasanna S Panchamukhi <”…”�”}”(hj1h²hh³Nh´Nubhõ)�”}”(hŒprasanna.panchamukhi@gmail.com”h]”hŒprasanna.panchamukhi@gmail.com”…”�”}”(hj8h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”Œ%mailto:prasanna.panchamukhi@gmail.com”uh1hôhj1ubhŒ>”…”�”}”(hj1h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Khj-ubah}”(h]”h ]”h"]”h$]”h&]”uh1håhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÐh³hÊh´KhhÍh²hubhÑ)�”}”(hhh]”(hÖ)�”}”(hŒAuthor”h]”hŒAuthor”…”�”}”(hjah²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÕhj^h³hÊh´Kubhæ)�”}”(hŒ'Masami Hiramatsu ”h]”hì)�”}”(hŒ&Masami Hiramatsu ”h]”(hŒMasami Hiramatsu <”…”�”}”(hjsh²hh³Nh´Nubhõ)�”}”(hŒmhiramat@kernel.org”h]”hŒmhiramat@kernel.org”…”�”}”(hj{h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”Œmailto:mhiramat@kernel.org”uh1hôhjsubhŒ>”…”�”}”(hjsh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Khjoubah}”(h]”h ]”h"]”h$]”h&]”uh1håhj^ubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÐh³hÊh´KhhÍh²hubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËhh·h²hh³hÊh´KubhŒcomment”“”)�”}”(hX]CONTENTS 1. Concepts: Kprobes, and Return Probes 2. Architectures Supported 3. Configuring Kprobes 4. API Reference 5. Kprobes Features and Limitations 6. Probe Overhead 7. TODO 8. Kprobes Example 9. Kretprobes Example 10. Deprecated Features Appendix A: The kprobes debugfs interface Appendix B: The kprobes sysctl interface Appendix C: References”h]”hX]CONTENTS 1. Concepts: Kprobes, and Return Probes 2. Architectures Supported 3. Configuring Kprobes 4. API Reference 5. Kprobes Features and Limitations 6. Probe Overhead 7. TODO 8. Kprobes Example 9. Kretprobes Example 10. Deprecated Features Appendix A: The kprobes debugfs interface Appendix B: The kprobes sysctl interface Appendix C: References”…”�”}”hj©sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1j§hh·h²hh³hÊh´Kubh¶)�”}”(hhh]”(h»)�”}”(hŒ#Concepts: Kprobes and Return Probes”h]”hŒ#Concepts: Kprobes and Return Probes”…”�”}”(hj¼h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj¹h²hh³hÊh´Kubhì)�”}”(hXKprobes enables you to dynamically break into any kernel routine and collect debugging and performance information non-disruptively. You can trap at almost any kernel code address [1]_, specifying a handler routine to be invoked when the breakpoint is hit.”h]”(hŒ´Kprobes enables you to dynamically break into any kernel routine and collect debugging and performance information non-disruptively. You can trap at almost any kernel code address ”…”�”}”(hjÊh²hh³Nh´NubhŒfootnote_reference”“”)�”}”(hŒ[1]_”h]”hŒ1”…”�”}”(hjÔh²hh³Nh´Nubah}”(h]”Œid1”ah ]”h"]”h$]”h&]”Œrefid”Œid2”Œdocname”Œ trace/kprobes”uh1jÒhjÊŒresolved”KubhŒH, specifying a handler routine to be invoked when the breakpoint is hit.”…”�”}”(hjÊh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Khj¹h²hubhŒfootnote”“”)�”}”(hŒPsome parts of the kernel code can not be trapped, see :ref:`kprobes_blacklist`) ”h]”(hŒlabel”“”)�”}”(hŒ1”h]”hŒ1”…”�”}”(hjúh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jøhjôubhì)�”}”(hŒOsome parts of the kernel code can not be trapped, see :ref:`kprobes_blacklist`)”h]”(hŒ6some parts of the kernel code can not be trapped, see ”…”�”}”(hjh²hh³Nh´Nubh)�”}”(hŒ:ref:`kprobes_blacklist`”h]”hŒinline”“”)�”}”(hjh]”hŒkprobes_blacklist”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”(Œxref”Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jhjubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”jæŒ refdomain”j!Œreftype”Œref”Œ refexplicit”‰Œrefwarn”ˆŒ reftarget”Œkprobes_blacklist”uh1hh³hÊh´K!hjubhŒ)”…”�”}”(hjh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K!hjôubeh}”(h]”jäah ]”h"]”Œ1”ah$]”h&]”jÞajåjæuh1jòh³hÊh´K!hj¹h²hjçKubhì)�”}”(hŒÜThere are currently two types of probes: kprobes, and kretprobes (also called return probes). A kprobe can be inserted on virtually any instruction in the kernel. A return probe fires when a specified function returns.”h]”hŒÜThere are currently two types of probes: kprobes, and kretprobes (also called return probes). A kprobe can be inserted on virtually any instruction in the kernel. A return probe fires when a specified function returns.”…”�”}”(hjEh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K$hj¹h²hubhì)�”}”(hXXIn the typical case, Kprobes-based instrumentation is packaged as a kernel module. The module's init function installs ("registers") one or more probes, and the exit function unregisters them. A registration function such as register_kprobe() specifies where the probe is to be inserted and what handler is to be called when the probe is hit.”h]”hX^In the typical case, Kprobes-based instrumentation is packaged as a kernel module. The module’s init function installs (“registersâ€�) one or more probes, and the exit function unregisters them. A registration function such as register_kprobe() specifies where the probe is to be inserted and what handler is to be called when the probe is hit.”…”�”}”(hjSh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K)hj¹h²hubhì)�”}”(hŒåThere are also ``register_/unregister_*probes()`` functions for batch registration/unregistration of a group of ``*probes``. These functions can speed up unregistration process when you have to unregister a lot of probes at once.”h]”(hŒThere are also ”…”�”}”(hjah²hh³Nh´NubhŒliteral”“”)�”}”(hŒ"``register_/unregister_*probes()``”h]”hŒregister_/unregister_*probes()”…”�”}”(hjkh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jihjaubhŒ? functions for batch registration/unregistration of a group of ”…”�”}”(hjah²hh³Nh´Nubjj)�”}”(hŒ ``*probes``”h]”hŒ*probes”…”�”}”(hj}h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jihjaubhŒj. These functions can speed up unregistration process when you have to unregister a lot of probes at once.”…”�”}”(hjah²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K0hj¹h²hubhì)�”}”(hX²The next four subsections explain how the different types of probes work and how jump optimization works. They explain certain things that you'll need to know in order to make the best use of Kprobes -- e.g., the difference between a pre_handler and a post_handler, and how to use the maxactive and nmissed fields of a kretprobe. But if you're in a hurry to start using Kprobes, you can skip ahead to :ref:`kprobes_archs_supported`.”h]”(hX—The next four subsections explain how the different types of probes work and how jump optimization works. They explain certain things that you’ll need to know in order to make the best use of Kprobes -- e.g., the difference between a pre_handler and a post_handler, and how to use the maxactive and nmissed fields of a kretprobe. But if you’re in a hurry to start using Kprobes, you can skip ahead to ”…”�”}”(hj•h²hh³Nh´Nubh)�”}”(hŒ:ref:`kprobes_archs_supported`”h]”j)�”}”(hjŸh]”hŒkprobes_archs_supported”…”�”}”(hj¡h²hh³Nh´Nubah}”(h]”h ]”(j Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jhj�ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”jæŒ refdomain”j«Œreftype”Œref”Œ refexplicit”‰Œrefwarn”ˆj2Œkprobes_archs_supported”uh1hh³hÊh´K5hj•ubhŒ.”…”�”}”(hj•h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K5hj¹h²hubh¶)�”}”(hhh]”(h»)�”}”(hŒHow Does a Kprobe Work?”h]”hŒHow Does a Kprobe Work?”…”�”}”(hjÊh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjÇh²hh³hÊh´K>ubhì)�”}”(hŒÃWhen a kprobe is registered, Kprobes makes a copy of the probed instruction and replaces the first byte(s) of the probed instruction with a breakpoint instruction (e.g., int3 on i386 and x86_64).”h]”hŒÃWhen a kprobe is registered, Kprobes makes a copy of the probed instruction and replaces the first byte(s) of the probed instruction with a breakpoint instruction (e.g., int3 on i386 and x86_64).”…”�”}”(hjØh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K@hjÇh²hubhì)�”}”(hX.When a CPU hits the breakpoint instruction, a trap occurs, the CPU's registers are saved, and control passes to Kprobes via the notifier_call_chain mechanism. Kprobes executes the "pre_handler" associated with the kprobe, passing the handler the addresses of the kprobe struct and the saved registers.”h]”hX4When a CPU hits the breakpoint instruction, a trap occurs, the CPU’s registers are saved, and control passes to Kprobes via the notifier_call_chain mechanism. Kprobes executes the “pre_handlerâ€� associated with the kprobe, passing the handler the addresses of the kprobe struct and the saved registers.”…”�”}”(hjæh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KDhjÇh²hubhì)�”}”(hX.Next, Kprobes single-steps its copy of the probed instruction. (It would be simpler to single-step the actual instruction in place, but then Kprobes would have to temporarily remove the breakpoint instruction. This would open a small time window when another CPU could sail right past the probepoint.)”h]”hX.Next, Kprobes single-steps its copy of the probed instruction. (It would be simpler to single-step the actual instruction in place, but then Kprobes would have to temporarily remove the breakpoint instruction. This would open a small time window when another CPU could sail right past the probepoint.)”…”�”}”(hjôh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KJhjÇh²hubhì)�”}”(hŒÁAfter the instruction is single-stepped, Kprobes executes the "post_handler," if any, that is associated with the kprobe. Execution then continues with the instruction following the probepoint.”h]”hŒÅAfter the instruction is single-stepped, Kprobes executes the “post_handler,â€� if any, that is associated with the kprobe. Execution then continues with the instruction following the probepoint.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KPhjÇh²hubeh}”(h]”Œhow-does-a-kprobe-work”ah ]”h"]”Œhow does a kprobe work?”ah$]”h&]”uh1hµhj¹h²hh³hÊh´K>ubh¶)�”}”(hhh]”(h»)�”}”(hŒChanging Execution Path”h]”hŒChanging Execution Path”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´KUubhì)�”}”(hXnSince kprobes can probe into a running kernel code, it can change the register set, including instruction pointer. This operation requires maximum care, such as keeping the stack frame, recovering the execution path etc. Since it operates on a running kernel and needs deep knowledge of computer architecture and concurrent computing, you can easily shoot your foot.”h]”hXnSince kprobes can probe into a running kernel code, it can change the register set, including instruction pointer. This operation requires maximum care, such as keeping the stack frame, recovering the execution path etc. Since it operates on a running kernel and needs deep knowledge of computer architecture and concurrent computing, you can easily shoot your foot.”…”�”}”(hj)h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KWhjh²hubhì)�”}”(hŒõIf you change the instruction pointer (and set up other related registers) in pre_handler, you must return !0 so that kprobes stops single stepping and just returns to the given address. This also means post_handler should not be called anymore.”h]”hŒõIf you change the instruction pointer (and set up other related registers) in pre_handler, you must return !0 so that kprobes stops single stepping and just returns to the given address. This also means post_handler should not be called anymore.”…”�”}”(hj7h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K^hjh²hubhì)�”}”(hŒæNote that this operation may be harder on some architectures which use TOC (Table of Contents) for function call, since you have to setup a new TOC for your function in your module, and recover the old one after returning from it.”h]”hŒæNote that this operation may be harder on some architectures which use TOC (Table of Contents) for function call, since you have to setup a new TOC for your function in your module, and recover the old one after returning from it.”…”�”}”(hjEh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Kchjh²hubeh}”(h]”Œchanging-execution-path”ah ]”h"]”Œchanging execution path”ah$]”h&]”uh1hµhj¹h²hh³hÊh´KUubh¶)�”}”(hhh]”(h»)�”}”(hŒ Return Probes”h]”hŒ Return Probes”…”�”}”(hj^h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj[h²hh³hÊh´Kiubh¶)�”}”(hhh]”(h»)�”}”(hŒHow Does a Return Probe Work?”h]”hŒHow Does a Return Probe Work?”…”�”}”(hjoh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjlh²hh³hÊh´Klubhì)�”}”(hX˜When you call register_kretprobe(), Kprobes establishes a kprobe at the entry to the function. When the probed function is called and this probe is hit, Kprobes saves a copy of the return address, and replaces the return address with the address of a "trampoline." The trampoline is an arbitrary piece of code -- typically just a nop instruction. At boot time, Kprobes registers a kprobe at the trampoline.”h]”hXœWhen you call register_kretprobe(), Kprobes establishes a kprobe at the entry to the function. When the probed function is called and this probe is hit, Kprobes saves a copy of the return address, and replaces the return address with the address of a “trampoline.â€� The trampoline is an arbitrary piece of code -- typically just a nop instruction. At boot time, Kprobes registers a kprobe at the trampoline.”…”�”}”(hj}h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Knhjlh²hubhì)�”}”(hXXWhen the probed function executes its return instruction, control passes to the trampoline and that probe is hit. Kprobes' trampoline handler calls the user-specified return handler associated with the kretprobe, then sets the saved instruction pointer to the saved return address, and that's where execution resumes upon return from the trap.”h]”hX\When the probed function executes its return instruction, control passes to the trampoline and that probe is hit. Kprobes’ trampoline handler calls the user-specified return handler associated with the kretprobe, then sets the saved instruction pointer to the saved return address, and that’s where execution resumes upon return from the trap.”…”�”}”(hj‹h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Kuhjlh²hubhì)�”}”(hX{While the probed function is executing, its return address is stored in an object of type kretprobe_instance. Before calling register_kretprobe(), the user sets the maxactive field of the kretprobe struct to specify how many instances of the specified function can be probed simultaneously. register_kretprobe() pre-allocates the indicated number of kretprobe_instance objects.”h]”hX{While the probed function is executing, its return address is stored in an object of type kretprobe_instance. Before calling register_kretprobe(), the user sets the maxactive field of the kretprobe struct to specify how many instances of the specified function can be probed simultaneously. register_kretprobe() pre-allocates the indicated number of kretprobe_instance objects.”…”�”}”(hj™h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K{hjlh²hubhì)�”}”(hX;For example, if the function is non-recursive and is called with a spinlock held, maxactive = 1 should be enough. If the function is non-recursive and can never relinquish the CPU (e.g., via a semaphore or preemption), NR_CPUS should be enough. If maxactive <= 0, it is set to a default value: max(10, 2*NR_CPUS).”h]”hX;For example, if the function is non-recursive and is called with a spinlock held, maxactive = 1 should be enough. If the function is non-recursive and can never relinquish the CPU (e.g., via a semaphore or preemption), NR_CPUS should be enough. If maxactive <= 0, it is set to a default value: max(10, 2*NR_CPUS).”…”�”}”(hj§h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K‚hjlh²hubhì)�”}”(hXCIt's not a disaster if you set maxactive too low; you'll just miss some probes. In the kretprobe struct, the nmissed field is set to zero when the return probe is registered, and is incremented every time the probed function is entered but there is no kretprobe_instance object available for establishing the return probe.”h]”hXGIt’s not a disaster if you set maxactive too low; you’ll just miss some probes. In the kretprobe struct, the nmissed field is set to zero when the return probe is registered, and is incremented every time the probed function is entered but there is no kretprobe_instance object available for establishing the return probe.”…”�”}”(hjµh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Kˆhjlh²hubeh}”(h]”Œhow-does-a-return-probe-work”ah ]”h"]”Œhow does a return probe work?”ah$]”h&]”uh1hµhj[h²hh³hÊh´Klubh¶)�”}”(hhh]”(h»)�”}”(hŒKretprobe entry-handler”h]”hŒKretprobe entry-handler”…”�”}”(hjÎh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjËh²hh³hÊh´K�ubhì)�”}”(hXRKretprobes also provides an optional user-specified handler which runs on function entry. This handler is specified by setting the entry_handler field of the kretprobe struct. Whenever the kprobe placed by kretprobe at the function entry is hit, the user-defined entry_handler, if any, is invoked. If the entry_handler returns 0 (success) then a corresponding return handler is guaranteed to be called upon function return. If the entry_handler returns a non-zero error then Kprobes leaves the return address as is, and the kretprobe has no further effect for that particular function instance.”h]”hXRKretprobes also provides an optional user-specified handler which runs on function entry. This handler is specified by setting the entry_handler field of the kretprobe struct. Whenever the kprobe placed by kretprobe at the function entry is hit, the user-defined entry_handler, if any, is invoked. If the entry_handler returns 0 (success) then a corresponding return handler is guaranteed to be called upon function return. If the entry_handler returns a non-zero error then Kprobes leaves the return address as is, and the kretprobe has no further effect for that particular function instance.”…”�”}”(hjÜh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K‘hjËh²hubhì)�”}”(hX:Multiple entry and return handler invocations are matched using the unique kretprobe_instance object associated with them. Additionally, a user may also specify per return-instance private data to be part of each kretprobe_instance object. This is especially useful when sharing private data between corresponding user entry and return handlers. The size of each private data object can be specified at kretprobe registration time by setting the data_size field of the kretprobe struct. This data can be accessed through the data field of each kretprobe_instance object.”h]”hX:Multiple entry and return handler invocations are matched using the unique kretprobe_instance object associated with them. Additionally, a user may also specify per return-instance private data to be part of each kretprobe_instance object. This is especially useful when sharing private data between corresponding user entry and return handlers. The size of each private data object can be specified at kretprobe registration time by setting the data_size field of the kretprobe struct. This data can be accessed through the data field of each kretprobe_instance object.”…”�”}”(hjêh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KšhjËh²hubhì)�”}”(hŒ¾In case probed function is entered but there is no kretprobe_instance object available, then in addition to incrementing the nmissed count, the user entry_handler invocation is also skipped.”h]”hŒ¾In case probed function is entered but there is no kretprobe_instance object available, then in addition to incrementing the nmissed count, the user entry_handler invocation is also skipped.”…”�”}”(hjøh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K£hjËh²hubhŒtarget”“”)�”}”(hŒ.. _kprobes_jump_optimization:”h]”h}”(h]”h ]”h"]”h$]”h&]”jãŒkprobes-jump-optimization”uh1jh´K§hjËh²hh³hÊubeh}”(h]”Œkretprobe-entry-handler”ah ]”h"]”Œkretprobe entry-handler”ah$]”h&]”uh1hµhj[h²hh³hÊh´K�ubeh}”(h]”Œ return-probes”ah ]”h"]”Œ return probes”ah$]”h&]”uh1hµhj¹h²hh³hÊh´Kiubh¶)�”}”(hhh]”(h»)�”}”(hŒ How Does Jump Optimization Work?”h]”hŒ How Does Jump Optimization Work?”…”�”}”(hj&h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj#h²hh³hÊh´Kªubhì)�”}”(hXUIf your kernel is built with CONFIG_OPTPROBES=y (currently this flag is automatically set 'y' on x86/x86-64, non-preemptive kernel) and the "debug.kprobes_optimization" kernel parameter is set to 1 (see sysctl(8)), Kprobes tries to reduce probe-hit overhead by using a jump instruction instead of a breakpoint instruction at each probepoint.”h]”hX]If your kernel is built with CONFIG_OPTPROBES=y (currently this flag is automatically set ‘y’ on x86/x86-64, non-preemptive kernel) and the “debug.kprobes_optimizationâ€� kernel parameter is set to 1 (see sysctl(8)), Kprobes tries to reduce probe-hit overhead by using a jump instruction instead of a breakpoint instruction at each probepoint.”…”�”}”(hj4h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K¬hj#h²hubh¶)�”}”(hhh]”(h»)�”}”(hŒ Init a Kprobe”h]”hŒ Init a Kprobe”…”�”}”(hjEh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjBh²hh³hÊh´K³ubhì)�”}”(hŒðWhen a probe is registered, before attempting this optimization, Kprobes inserts an ordinary, breakpoint-based kprobe at the specified address. So, even if it's not possible to optimize this particular probepoint, there'll be a probe there.”h]”hŒôWhen a probe is registered, before attempting this optimization, Kprobes inserts an ordinary, breakpoint-based kprobe at the specified address. So, even if it’s not possible to optimize this particular probepoint, there’ll be a probe there.”…”�”}”(hjSh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KµhjBh²hubeh}”(h]”Œ init-a-kprobe”ah ]”h"]”Œ init a kprobe”ah$]”h&]”uh1hµhj#h²hh³hÊh´K³ubh¶)�”}”(hhh]”(h»)�”}”(hŒ Safety Check”h]”hŒ Safety Check”…”�”}”(hjlh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjih²hh³hÊh´K»ubhì)�”}”(hŒHBefore optimizing a probe, Kprobes performs the following safety checks:”h]”hŒHBefore optimizing a probe, Kprobes performs the following safety checks:”…”�”}”(hjzh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K½hjih²hubhŒ bullet_list”“”)�”}”(hhh]”(hŒ list_item”“”)�”}”(hŒÝKprobes verifies that the region that will be replaced by the jump instruction (the "optimized region") lies entirely within one function. (A jump instruction is multiple bytes, and so may overlay multiple instructions.) ”h]”hì)�”}”(hŒÜKprobes verifies that the region that will be replaced by the jump instruction (the "optimized region") lies entirely within one function. (A jump instruction is multiple bytes, and so may overlay multiple instructions.)”h]”hŒàKprobes verifies that the region that will be replaced by the jump instruction (the “optimized regionâ€�) lies entirely within one function. (A jump instruction is multiple bytes, and so may overlay multiple instructions.)”…”�”}”(hj“h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K¿hj�ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjŠh²hh³hÊh´NubjŽ)�”}”(hXÆKprobes analyzes the entire function and verifies that there is no jump into the optimized region. Specifically: - the function contains no indirect jump; - the function contains no instruction that causes an exception (since the fixup code triggered by the exception could jump back into the optimized region -- Kprobes checks the exception tables to verify this); - there is no near jump to the optimized region (other than to the first byte). ”h]”(hì)�”}”(hŒqKprobes analyzes the entire function and verifies that there is no jump into the optimized region. Specifically:”h]”hŒqKprobes analyzes the entire function and verifies that there is no jump into the optimized region. Specifically:”…”�”}”(hj«h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KÄhj§ubj‰)�”}”(hhh]”(jŽ)�”}”(hŒ'the function contains no indirect jump;”h]”hì)�”}”(hj¾h]”hŒ'the function contains no indirect jump;”…”�”}”(hjÀh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KÇhj¼ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj¹ubjŽ)�”}”(hŒÐthe function contains no instruction that causes an exception (since the fixup code triggered by the exception could jump back into the optimized region -- Kprobes checks the exception tables to verify this);”h]”hì)�”}”(hŒÐthe function contains no instruction that causes an exception (since the fixup code triggered by the exception could jump back into the optimized region -- Kprobes checks the exception tables to verify this);”h]”hŒÐthe function contains no instruction that causes an exception (since the fixup code triggered by the exception could jump back into the optimized region -- Kprobes checks the exception tables to verify this);”…”�”}”(hj×h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KÈhjÓubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj¹ubjŽ)�”}”(hŒNthere is no near jump to the optimized region (other than to the first byte). ”h]”hì)�”}”(hŒMthere is no near jump to the optimized region (other than to the first byte).”h]”hŒMthere is no near jump to the optimized region (other than to the first byte).”…”�”}”(hjïh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KËhjëubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj¹ubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1jˆh³hÊh´KÇhj§ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j�hjŠh²hh³Nh´NubjŽ)�”}”(hŒqFor each instruction in the optimized region, Kprobes verifies that the instruction can be executed out of line. ”h]”hì)�”}”(hŒpFor each instruction in the optimized region, Kprobes verifies that the instruction can be executed out of line.”h]”hŒpFor each instruction in the optimized region, Kprobes verifies that the instruction can be executed out of line.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KÎhjubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjŠh²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”j j uh1jˆh³hÊh´K¿hjih²hubeh}”(h]”Œ safety-check”ah ]”h"]”Œ safety check”ah$]”h&]”uh1hµhj#h²hh³hÊh´K»ubh¶)�”}”(hhh]”(h»)�”}”(hŒPreparing Detour Buffer”h]”hŒPreparing Detour Buffer”…”�”}”(hj:h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj7h²hh³hÊh´KÒubhì)�”}”(hŒ\Next, Kprobes prepares a "detour" buffer, which contains the following instruction sequence:”h]”hŒ`Next, Kprobes prepares a “detourâ€� buffer, which contains the following instruction sequence:”…”�”}”(hjHh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KÔhj7h²hubj‰)�”}”(hhh]”(jŽ)�”}”(hŒ>code to push the CPU's registers (emulating a breakpoint trap)”h]”hì)�”}”(hj[h]”hŒ@code to push the CPU’s registers (emulating a breakpoint trap)”…”�”}”(hj]h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K×hjYubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjVh²hh³hÊh´NubjŽ)�”}”(hŒ@a call to the trampoline code which calls user's probe handlers.”h]”hì)�”}”(hjrh]”hŒBa call to the trampoline code which calls user’s probe handlers.”…”�”}”(hjth²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KØhjpubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjVh²hh³hÊh´NubjŽ)�”}”(hŒcode to restore registers”h]”hì)�”}”(hj‰h]”hŒcode to restore registers”…”�”}”(hj‹h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KÙhj‡ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjVh²hh³hÊh´NubjŽ)�”}”(hŒ*the instructions from the optimized region”h]”hì)�”}”(hj h]”hŒ*the instructions from the optimized region”…”�”}”(hj¢h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KÚhjžubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjVh²hh³hÊh´NubjŽ)�”}”(hŒ,a jump back to the original execution path. ”h]”hì)�”}”(hŒ+a jump back to the original execution path.”h]”hŒ+a jump back to the original execution path.”…”�”}”(hj¹h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KÛhjµubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjVh²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”j j uh1jˆh³hÊh´K×hj7h²hubeh}”(h]”Œpreparing-detour-buffer”ah ]”h"]”Œpreparing detour buffer”ah$]”h&]”uh1hµhj#h²hh³hÊh´KÒubh¶)�”}”(hhh]”(h»)�”}”(hŒPre-optimization”h]”hŒPre-optimization”…”�”}”(hjÞh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjÛh²hh³hÊh´KÞubhì)�”}”(hŒ`After preparing the detour buffer, Kprobes verifies that none of the following situations exist:”h]”hŒ`After preparing the detour buffer, Kprobes verifies that none of the following situations exist:”…”�”}”(hjìh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KàhjÛh²hubj‰)�”}”(hhh]”(jŽ)�”}”(hŒThe probe has a post_handler.”h]”hì)�”}”(hjÿh]”hŒThe probe has a post_handler.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Kãhjýubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjúh²hh³hÊh´NubjŽ)�”}”(hŒ6Other instructions in the optimized region are probed.”h]”hì)�”}”(hjh]”hŒ6Other instructions in the optimized region are probed.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Kähjubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjúh²hh³hÊh´NubjŽ)�”}”(hŒThe probe is disabled. ”h]”hì)�”}”(hŒThe probe is disabled.”h]”hŒThe probe is disabled.”…”�”}”(hj/h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Kåhj+ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjúh²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”j j uh1jˆh³hÊh´KãhjÛh²hubhì)�”}”(hŒ²In any of the above cases, Kprobes won't start optimizing the probe. Since these are temporary situations, Kprobes tries to start optimizing it again if the situation is changed.”h]”hŒ´In any of the above cases, Kprobes won’t start optimizing the probe. Since these are temporary situations, Kprobes tries to start optimizing it again if the situation is changed.”…”�”}”(hjIh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KçhjÛh²hubhì)�”}”(hX‚If the kprobe can be optimized, Kprobes enqueues the kprobe to an optimizing list, and kicks the kprobe-optimizer workqueue to optimize it. If the to-be-optimized probepoint is hit before being optimized, Kprobes returns control to the original instruction path by setting the CPU's instruction pointer to the copied code in the detour buffer -- thus at least avoiding the single-step.”h]”hX„If the kprobe can be optimized, Kprobes enqueues the kprobe to an optimizing list, and kicks the kprobe-optimizer workqueue to optimize it. If the to-be-optimized probepoint is hit before being optimized, Kprobes returns control to the original instruction path by setting the CPU’s instruction pointer to the copied code in the detour buffer -- thus at least avoiding the single-step.”…”�”}”(hjWh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´KëhjÛh²hubeh}”(h]”Œpre-optimization”ah ]”h"]”Œpre-optimization”ah$]”h&]”uh1hµhj#h²hh³hÊh´KÞubh¶)�”}”(hhh]”(h»)�”}”(hŒ Optimization”h]”hŒ Optimization”…”�”}”(hjph²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjmh²hh³hÊh´Kóubhì)�”}”(hXÚThe Kprobe-optimizer doesn't insert the jump instruction immediately; rather, it calls synchronize_rcu() for safety first, because it's possible for a CPU to be interrupted in the middle of executing the optimized region [3]_. As you know, synchronize_rcu() can ensure that all interruptions that were active when synchronize_rcu() was called are done, but only if CONFIG_PREEMPT=n. So, this version of kprobe optimization supports only kernels with CONFIG_PREEMPT=n [4]_.”h]”(hŒáThe Kprobe-optimizer doesn’t insert the jump instruction immediately; rather, it calls synchronize_rcu() for safety first, because it’s possible for a CPU to be interrupted in the middle of executing the optimized region ”…”�”}”(hj~h²hh³Nh´NubjÓ)�”}”(hŒ[3]_”h]”hŒ3”…”�”}”(hj†h²hh³Nh´Nubah}”(h]”Œid3”ah ]”h"]”h$]”h&]”jãŒid5”jåjæuh1jÒhj~jçKubhŒô. As you know, synchronize_rcu() can ensure that all interruptions that were active when synchronize_rcu() was called are done, but only if CONFIG_PREEMPT=n. So, this version of kprobe optimization supports only kernels with CONFIG_PREEMPT=n ”…”�”}”(hj~h²hh³Nh´NubjÓ)�”}”(hŒ[4]_”h]”hŒ4”…”�”}”(hjšh²hh³Nh´Nubah}”(h]”Œid4”ah ]”h"]”h$]”h&]”jãŒid6”jåjæuh1jÒhj~jçKubhŒ.”…”�”}”(hj~h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Kõhjmh²hubhì)�”}”(hŒšAfter that, the Kprobe-optimizer calls stop_machine() to replace the optimized region with a jump instruction to the detour buffer, using text_poke_smp().”h]”hŒšAfter that, the Kprobe-optimizer calls stop_machine() to replace the optimized region with a jump instruction to the detour buffer, using text_poke_smp().”…”�”}”(hj´h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Kýhjmh²hubeh}”(h]”Œ optimization”ah ]”h"]”Œ optimization”ah$]”h&]”uh1hµhj#h²hh³hÊh´Kóubh¶)�”}”(hhh]”(h»)�”}”(hŒUnoptimization”h]”hŒUnoptimization”…”�”}”(hjÍh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjÊh²hh³hÊh´Mubhì)�”}”(hXpWhen an optimized kprobe is unregistered, disabled, or blocked by another kprobe, it will be unoptimized. If this happens before the optimization is complete, the kprobe is just dequeued from the optimized list. If the optimization has been done, the jump is replaced with the original code (except for an int3 breakpoint in the first byte) by using text_poke_smp().”h]”hXpWhen an optimized kprobe is unregistered, disabled, or blocked by another kprobe, it will be unoptimized. If this happens before the optimization is complete, the kprobe is just dequeued from the optimized list. If the optimization has been done, the jump is replaced with the original code (except for an int3 breakpoint in the first byte) by using text_poke_smp().”…”�”}”(hjÛh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MhjÊh²hubjó)�”}”(hXPlease imagine that the 2nd instruction is interrupted and then the optimizer replaces the 2nd instruction with the jump *address* while the interrupt handler is running. When the interrupt returns to original address, there is no valid instruction, and it causes an unexpected result. ”h]”(jù)�”}”(hŒ3”h]”hŒ3”…”�”}”(hjíh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jøhjéubhì)�”}”(hXPlease imagine that the 2nd instruction is interrupted and then the optimizer replaces the 2nd instruction with the jump *address* while the interrupt handler is running. When the interrupt returns to original address, there is no valid instruction, and it causes an unexpected result.”h]”(hŒyPlease imagine that the 2nd instruction is interrupted and then the optimizer replaces the 2nd instruction with the jump ”…”�”}”(hjûh²hh³Nh´NubhŒemphasis”“”)�”}”(hŒ *address*”h]”hŒaddress”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjûubhŒ› while the interrupt handler is running. When the interrupt returns to original address, there is no valid instruction, and it causes an unexpected result.”…”�”}”(hjûh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M hjéubeh}”(h]”j•ah ]”h"]”Œ3”ah$]”h&]”j�ajåjæuh1jòh³hÊh´M hjÊh²hjçKubjó)�”}”(hŒ‹This optimization-safety checking may be replaced with the stop-machine method that ksplice uses for supporting a CONFIG_PREEMPT=y kernel. ”h]”(jù)�”}”(hŒ4”h]”hŒ4”…”�”}”(hj(h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jøhj$ubhì)�”}”(hŒŠThis optimization-safety checking may be replaced with the stop-machine method that ksplice uses for supporting a CONFIG_PREEMPT=y kernel.”h]”hŒŠThis optimization-safety checking may be replaced with the stop-machine method that ksplice uses for supporting a CONFIG_PREEMPT=y kernel.”…”�”}”(hj6h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Mhj$ubeh}”(h]”j©ah ]”h"]”Œ4”ah$]”h&]”j¤ajåjæuh1jòh³hÊh´MhjÊh²hjçKubhì)�”}”(hX‹NOTE for geeks: The jump optimization changes the kprobe's pre_handler behavior. Without optimization, the pre_handler can change the kernel's execution path by changing regs->ip and returning 1. However, when the probe is optimized, that modification is ignored. Thus, if you want to tweak the kernel's execution path, you need to suppress optimization, using one of the following techniques:”h]”hX‘NOTE for geeks: The jump optimization changes the kprobe’s pre_handler behavior. Without optimization, the pre_handler can change the kernel’s execution path by changing regs->ip and returning 1. However, when the probe is optimized, that modification is ignored. Thus, if you want to tweak the kernel’s execution path, you need to suppress optimization, using one of the following techniques:”…”�”}”(hjKh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MhjÊh²hubj‰)�”}”(hhh]”jŽ)�”}”(hŒ9Specify an empty function for the kprobe's post_handler. ”h]”hì)�”}”(hŒ8Specify an empty function for the kprobe's post_handler.”h]”hŒ:Specify an empty function for the kprobe’s post_handler.”…”�”}”(hj`h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Mhj\ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjYh²hh³hÊh´Nubah}”(h]”h ]”h"]”h$]”h&]”j j uh1jˆh³hÊh´MhjÊh²hubhì)�”}”(hŒor”h]”hŒor”…”�”}”(hjzh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MhjÊh²hubj‰)�”}”(hhh]”jŽ)�”}”(hŒ1Execute 'sysctl -w debug.kprobes_optimization=n' ”h]”hì)�”}”(hŒ0Execute 'sysctl -w debug.kprobes_optimization=n'”h]”hŒ4Execute ‘sysctl -w debug.kprobes_optimization=n’”…”�”}”(hj�h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M!hj‹ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjˆh²hh³hÊh´Nubah}”(h]”h ]”h"]”h$]”h&]”j j uh1jˆh³hÊh´M!hjÊh²hubj)�”}”(hŒ.. _kprobes_blacklist:”h]”h}”(h]”h ]”h"]”h$]”h&]”jãŒkprobes-blacklist”uh1jh´M#hjÊh²hh³hÊubeh}”(h]”Œunoptimization”ah ]”h"]”Œunoptimization”ah$]”h&]”uh1hµhj#h²hh³hÊh´Mubeh}”(h]”(Œhow-does-jump-optimization-work”jeh ]”h"]”(Œ how does jump optimization work?”Œkprobes_jump_optimization”eh$]”h&]”uh1hµhj¹h²hh³hÊh´KªŒexpect_referenced_by_name”}”jÂjsŒexpect_referenced_by_id”}”jjsubh¶)�”}”(hhh]”(h»)�”}”(hŒ Blacklist”h]”hŒ Blacklist”…”�”}”(hjÌh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjÉh²hh³hÊh´M&ubhì)�”}”(hXRKprobes can probe most of the kernel except itself. This means that there are some functions where kprobes cannot probe. Probing (trapping) such functions can cause a recursive trap (e.g. double fault) or the nested probe handler may never be called. Kprobes manages such functions as a blacklist. If you want to add a function into the blacklist, you just need to (1) include linux/kprobes.h and (2) use NOKPROBE_SYMBOL() macro to specify a blacklisted function. Kprobes checks the given probe address against the blacklist and rejects registering it, if the given address is in the blacklist.”h]”hXRKprobes can probe most of the kernel except itself. This means that there are some functions where kprobes cannot probe. Probing (trapping) such functions can cause a recursive trap (e.g. double fault) or the nested probe handler may never be called. Kprobes manages such functions as a blacklist. If you want to add a function into the blacklist, you just need to (1) include linux/kprobes.h and (2) use NOKPROBE_SYMBOL() macro to specify a blacklisted function. Kprobes checks the given probe address against the blacklist and rejects registering it, if the given address is in the blacklist.”…”�”}”(hjÚh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M(hjÉh²hubj)�”}”(hŒ.. _kprobes_archs_supported:”h]”h}”(h]”h ]”h"]”h$]”h&]”jãŒkprobes-archs-supported”uh1jh´M3hjÉh²hh³hÊubeh}”(h]”(Œ blacklist”j³eh ]”h"]”(Œ blacklist”Œkprobes_blacklist”eh$]”h&]”uh1hµhj¹h²hh³hÊh´M&jÅ}”jùj©sjÇ}”j³j©subeh}”(h]”Œ"concepts-kprobes-and-return-probes”ah ]”h"]”Œ#concepts: kprobes and return probes”ah$]”h&]”uh1hµhh·h²hh³hÊh´Kubh¶)�”}”(hhh]”(h»)�”}”(hŒArchitectures Supported”h]”hŒArchitectures Supported”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´M6ubhì)�”}”(hŒIKprobes and return probes are implemented on the following architectures:”h]”hŒIKprobes and return probes are implemented on the following architectures:”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M8hjh²hubj‰)�”}”(hhh]”(jŽ)�”}”(hŒ!i386 (Supports jump optimization)”h]”hì)�”}”(hj*h]”hŒ!i386 (Supports jump optimization)”…”�”}”(hj,h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M;hj(ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj%h²hh³hÊh´NubjŽ)�”}”(hŒ3x86_64 (AMD-64, EM64T) (Supports jump optimization)”h]”hì)�”}”(hjAh]”hŒ3x86_64 (AMD-64, EM64T) (Supports jump optimization)”…”�”}”(hjCh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M<hj?ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj%h²hh³hÊh´NubjŽ)�”}”(hŒppc64”h]”hì)�”}”(hjXh]”hŒppc64”…”�”}”(hjZh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M=hjVubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj%h²hh³hÊh´NubjŽ)�”}”(hŒ,sparc64 (Return probes not yet implemented.)”h]”hì)�”}”(hjoh]”hŒ,sparc64 (Return probes not yet implemented.)”…”�”}”(hjqh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M>hjmubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj%h²hh³hÊh´NubjŽ)�”}”(hŒarm”h]”hì)�”}”(hj†h]”hŒarm”…”�”}”(hjˆh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M?hj„ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj%h²hh³hÊh´NubjŽ)�”}”(hŒppc”h]”hì)�”}”(hj�h]”hŒppc”…”�”}”(hjŸh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M@hj›ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj%h²hh³hÊh´NubjŽ)�”}”(hŒmips”h]”hì)�”}”(hj´h]”hŒmips”…”�”}”(hj¶h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MAhj²ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj%h²hh³hÊh´NubjŽ)�”}”(hŒs390”h]”hì)�”}”(hjËh]”hŒs390”…”�”}”(hjÍh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MBhjÉubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj%h²hh³hÊh´NubjŽ)�”}”(hŒparisc”h]”hì)�”}”(hjâh]”hŒparisc”…”�”}”(hjäh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MChjàubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj%h²hh³hÊh´NubjŽ)�”}”(hŒ loongarch”h]”hì)�”}”(hjùh]”hŒ loongarch”…”�”}”(hjûh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MDhj÷ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj%h²hh³hÊh´NubjŽ)�”}”(hŒriscv ”h]”hì)�”}”(hŒriscv”h]”hŒriscv”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MEhj ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj%h²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”j j uh1jˆh³hÊh´M;hjh²hubeh}”(h]”(Œarchitectures-supported”jòeh ]”h"]”(Œarchitectures supported”Œkprobes_archs_supported”eh$]”h&]”uh1hµhh·h²hh³hÊh´M6jÅ}”j2 jèsjÇ}”jòjèsubh¶)�”}”(hhh]”(h»)�”}”(hŒConfiguring Kprobes”h]”hŒConfiguring Kprobes”…”�”}”(hj: h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj7 h²hh³hÊh´MHubhì)�”}”(hŒ±When configuring the kernel using make menuconfig/xconfig/oldconfig, ensure that CONFIG_KPROBES is set to "y", look for "Kprobes" under "General architecture-dependent options".”h]”hŒ½When configuring the kernel using make menuconfig/xconfig/oldconfig, ensure that CONFIG_KPROBES is set to “yâ€�, look for “Kprobesâ€� under “General architecture-dependent optionsâ€�.”…”�”}”(hjH h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MJhj7 h²hubhì)�”}”(hŒ¹So that you can load and unload Kprobes-based instrumentation modules, make sure "Loadable module support" (CONFIG_MODULES) and "Module unloading" (CONFIG_MODULE_UNLOAD) are set to "y".”h]”hŒÅSo that you can load and unload Kprobes-based instrumentation modules, make sure “Loadable module supportâ€� (CONFIG_MODULES) and “Module unloadingâ€� (CONFIG_MODULE_UNLOAD) are set to “yâ€�.”…”�”}”(hjV h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MNhj7 h²hubhì)�”}”(hŒ®Also make sure that CONFIG_KALLSYMS and perhaps even CONFIG_KALLSYMS_ALL are set to "y", since kallsyms_lookup_name() is used by the in-kernel kprobe address resolution code.”h]”hŒ²Also make sure that CONFIG_KALLSYMS and perhaps even CONFIG_KALLSYMS_ALL are set to “yâ€�, since kallsyms_lookup_name() is used by the in-kernel kprobe address resolution code.”…”�”}”(hjd h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MRhj7 h²hubhì)�”}”(hŒßIf you need to insert a probe in the middle of a function, you may find it useful to "Compile the kernel with debug info" (CONFIG_DEBUG_INFO), so you can use "objdump -d -l vmlinux" to see the source-to-object code mapping.”h]”hŒçIf you need to insert a probe in the middle of a function, you may find it useful to “Compile the kernel with debug infoâ€� (CONFIG_DEBUG_INFO), so you can use “objdump -d -l vmlinuxâ€� to see the source-to-object code mapping.”…”�”}”(hjr h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MVhj7 h²hubeh}”(h]”Œconfiguring-kprobes”ah ]”h"]”Œconfiguring kprobes”ah$]”h&]”uh1hµhh·h²hh³hÊh´MHubh¶)�”}”(hhh]”(h»)�”}”(hŒ API Reference”h]”hŒ API Reference”…”�”}”(hj‹ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjˆ h²hh³hÊh´M\ubhì)�”}”(hX�The Kprobes API includes a "register" function and an "unregister" function for each type of probe. The API also includes "register_*probes" and "unregister_*probes" functions for (un)registering arrays of probes. Here are terse, mini-man-page specifications for these functions and the associated probe handlers that you'll write. See the files in the samples/kprobes/ sub-directory for examples.”h]”hXŸThe Kprobes API includes a “registerâ€� function and an “unregisterâ€� function for each type of probe. The API also includes “register_*probesâ€� and “unregister_*probesâ€� functions for (un)registering arrays of probes. Here are terse, mini-man-page specifications for these functions and the associated probe handlers that you’ll write. See the files in the samples/kprobes/ sub-directory for examples.”…”�”}”(hj™ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M^hjˆ h²hubh¶)�”}”(hhh]”(h»)�”}”(hŒregister_kprobe”h]”hŒregister_kprobe”…”�”}”(hjª h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj§ h²hh³hÊh´MfubhŒ literal_block”“”)�”}”(hŒB#include int register_kprobe(struct kprobe *kp);”h]”hŒB#include int register_kprobe(struct kprobe *kp);”…”�”}”hjº sbah}”(h]”h ]”h"]”h$]”h&]”j·j¸uh1j¸ h³hÊh´Mjhj§ h²hubhì)�”}”(hXhSets a breakpoint at the address kp->addr. When the breakpoint is hit, Kprobes calls kp->pre_handler. After the probed instruction is single-stepped, Kprobe calls kp->post_handler. Any or all handlers can be NULL. If kp->flags is set KPROBE_FLAG_DISABLED, that kp will be registered but disabled, so, its handlers aren't hit until calling enable_kprobe(kp).”h]”hXjSets a breakpoint at the address kp->addr. When the breakpoint is hit, Kprobes calls kp->pre_handler. After the probed instruction is single-stepped, Kprobe calls kp->post_handler. Any or all handlers can be NULL. If kp->flags is set KPROBE_FLAG_DISABLED, that kp will be registered but disabled, so, its handlers aren’t hit until calling enable_kprobe(kp).”…”�”}”(hjÈ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Mmhj§ h²hubhŒnote”“”)�”}”(hX1. With the introduction of the "symbol_name" field to struct kprobe, the probepoint address resolution will now be taken care of by the kernel. The following will now work:: kp.symbol_name = "symbol_name"; (64-bit powerpc intricacies such as function descriptors are handled transparently) 2. Use the "offset" field of struct kprobe if the offset into the symbol to install a probepoint is known. This field is used to calculate the probepoint. 3. Specify either the kprobe "symbol_name" OR the "addr". If both are specified, kprobe registration will fail with -EINVAL. 4. With CISC architectures (such as i386 and x86_64), the kprobes code does not validate if the kprobe.addr is at an instruction boundary. Use "offset" with caution.”h]”hŒenumerated_list”“”)�”}”(hhh]”(jŽ)�”}”(hX$With the introduction of the "symbol_name" field to struct kprobe, the probepoint address resolution will now be taken care of by the kernel. The following will now work:: kp.symbol_name = "symbol_name"; (64-bit powerpc intricacies such as function descriptors are handled transparently) ”h]”(hì)�”}”(hŒ«With the introduction of the "symbol_name" field to struct kprobe, the probepoint address resolution will now be taken care of by the kernel. The following will now work::”h]”hŒ®With the introduction of the “symbol_nameâ€� field to struct kprobe, the probepoint address resolution will now be taken care of by the kernel. The following will now work:”…”�”}”(hjå h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Muhjá ubj¹ )�”}”(hŒkp.symbol_name = "symbol_name";”h]”hŒkp.symbol_name = "symbol_name";”…”�”}”hjó sbah}”(h]”h ]”h"]”h$]”h&]”j·j¸uh1j¸ h³hÊh´Myhjá ubhì)�”}”(hŒS(64-bit powerpc intricacies such as function descriptors are handled transparently)”h]”hŒS(64-bit powerpc intricacies such as function descriptors are handled transparently)”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M{hjá ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j�hjÞ ubjŽ)�”}”(hŒ˜Use the "offset" field of struct kprobe if the offset into the symbol to install a probepoint is known. This field is used to calculate the probepoint. ”h]”hì)�”}”(hŒ—Use the "offset" field of struct kprobe if the offset into the symbol to install a probepoint is known. This field is used to calculate the probepoint.”h]”hŒ›Use the “offsetâ€� field of struct kprobe if the offset into the symbol to install a probepoint is known. This field is used to calculate the probepoint.”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M~hj ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjÞ ubjŽ)�”}”(hŒzSpecify either the kprobe "symbol_name" OR the "addr". If both are specified, kprobe registration will fail with -EINVAL. ”h]”hì)�”}”(hŒySpecify either the kprobe "symbol_name" OR the "addr". If both are specified, kprobe registration will fail with -EINVAL.”h]”hŒ�Specify either the kprobe “symbol_nameâ€� OR the “addrâ€�. If both are specified, kprobe registration will fail with -EINVAL.”…”�”}”(hj1 h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M‚hj- ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjÞ ubjŽ)�”}”(hŒ¢With CISC architectures (such as i386 and x86_64), the kprobes code does not validate if the kprobe.addr is at an instruction boundary. Use "offset" with caution.”h]”hì)�”}”(hŒ¢With CISC architectures (such as i386 and x86_64), the kprobes code does not validate if the kprobe.addr is at an instruction boundary. Use "offset" with caution.”h]”hŒ¦With CISC architectures (such as i386 and x86_64), the kprobes code does not validate if the kprobe.addr is at an instruction boundary. Use “offsetâ€� with caution.”…”�”}”(hjI h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M…hjE ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjÞ ubeh}”(h]”h ]”h"]”h$]”h&]”Œenumtype”Œarabic”Œprefix”hŒsuffix”Œ.”uh1jÜ hjØ ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÖ hj§ h²hh³Nh´Nubhì)�”}”(hŒFregister_kprobe() returns 0 on success, or a negative errno otherwise.”h]”hŒFregister_kprobe() returns 0 on success, or a negative errno otherwise.”…”�”}”(hjn h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M‰hj§ h²hubhì)�”}”(hŒ&User's pre-handler (kp->pre_handler)::”h]”hŒ'User’s pre-handler (kp->pre_handler):”…”�”}”(hj| h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M‹hj§ h²hubj¹ )�”}”(hŒm#include #include int pre_handler(struct kprobe *p, struct pt_regs *regs);”h]”hŒm#include #include int pre_handler(struct kprobe *p, struct pt_regs *regs);”…”�”}”hjŠ sbah}”(h]”h ]”h"]”h$]”h&]”j·j¸uh1j¸ h³hÊh´M�hj§ h²hubhì)�”}”(hŒÍCalled with p pointing to the kprobe associated with the breakpoint, and regs pointing to the struct containing the registers saved when the breakpoint was hit. Return 0 here unless you're a Kprobes geek.”h]”hŒÏCalled with p pointing to the kprobe associated with the breakpoint, and regs pointing to the struct containing the registers saved when the breakpoint was hit. Return 0 here unless you’re a Kprobes geek.”…”�”}”(hj˜ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M‘hj§ h²hubhì)�”}”(hŒ(User's post-handler (kp->post_handler)::”h]”hŒ)User’s post-handler (kp->post_handler):”…”�”}”(hj¦ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M•hj§ h²hubj¹ )�”}”(hŒ–#include #include void post_handler(struct kprobe *p, struct pt_regs *regs, unsigned long flags);”h]”hŒ–#include #include void post_handler(struct kprobe *p, struct pt_regs *regs, unsigned long flags);”…”�”}”hj´ sbah}”(h]”h ]”h"]”h$]”h&]”j·j¸uh1j¸ h³hÊh´M—hj§ h²hubhì)�”}”(hŒPp and regs are as described for the pre_handler. flags always seems to be zero.”h]”hŒPp and regs are as described for the pre_handler. flags always seems to be zero.”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Mœhj§ h²hubeh}”(h]”Œregister-kprobe”ah ]”h"]”Œregister_kprobe”ah$]”h&]”uh1hµhjˆ h²hh³hÊh´Mfubh¶)�”}”(hhh]”(h»)�”}”(hŒregister_kretprobe”h]”hŒregister_kretprobe”…”�”}”(hjÛ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjØ h²hh³hÊh´M ubj¹ )�”}”(hŒH#include int register_kretprobe(struct kretprobe *rp);”h]”hŒH#include int register_kretprobe(struct kretprobe *rp);”…”�”}”hjé sbah}”(h]”h ]”h"]”h$]”h&]”j·j¸uh1j¸ h³hÊh´M¤hjØ h²hubhì)�”}”(hXEstablishes a return probe for the function whose address is rp->kp.addr. When that function returns, Kprobes calls rp->handler. You must set rp->maxactive appropriately before you call register_kretprobe(); see "How Does a Return Probe Work?" for details.”h]”hXEstablishes a return probe for the function whose address is rp->kp.addr. When that function returns, Kprobes calls rp->handler. You must set rp->maxactive appropriately before you call register_kretprobe(); see “How Does a Return Probe Work?â€� for details.”…”�”}”(hj÷ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M§hjØ h²hubhì)�”}”(hŒIregister_kretprobe() returns 0 on success, or a negative errno otherwise.”h]”hŒIregister_kretprobe() returns 0 on success, or a negative errno otherwise.”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M¬hjØ h²hubhì)�”}”(hŒ+User's return-probe handler (rp->handler)::”h]”hŒ,User’s return-probe handler (rp->handler):”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M¯hjØ h²hubj¹ )�”}”(hŒ–#include #include int kretprobe_handler(struct kretprobe_instance *ri, struct pt_regs *regs);”h]”hŒ–#include #include int kretprobe_handler(struct kretprobe_instance *ri, struct pt_regs *regs);”…”�”}”hj! sbah}”(h]”h ]”h"]”h$]”h&]”j·j¸uh1j¸ h³hÊh´M±hjØ h²hubhì)�”}”(hŒ‹regs is as described for kprobe.pre_handler. ri points to the kretprobe_instance object, of which the following fields may be of interest:”h]”hŒ‹regs is as described for kprobe.pre_handler. ri points to the kretprobe_instance object, of which the following fields may be of interest:”…”�”}”(hj/ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M¶hjØ h²hubj‰)�”}”(hhh]”(jŽ)�”}”(hŒret_addr: the return address”h]”hì)�”}”(hjB h]”hŒret_addr: the return address”…”�”}”(hjD h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Mºhj@ ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj= h²hh³hÊh´NubjŽ)�”}”(hŒ0rp: points to the corresponding kretprobe object”h]”hì)�”}”(hjY h]”hŒ0rp: points to the corresponding kretprobe object”…”�”}”(hj[ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M»hjW ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj= h²hh³hÊh´NubjŽ)�”}”(hŒ-task: points to the corresponding task struct”h]”hì)�”}”(hjp h]”hŒ-task: points to the corresponding task struct”…”�”}”(hjr h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M¼hjn ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj= h²hh³hÊh´NubjŽ)�”}”(hŒcdata: points to per return-instance private data; see "Kretprobe entry-handler" for details. ”h]”hŒdefinition_list”“”)�”}”(hhh]”hŒdefinition_list_item”“”)�”}”(hŒ]data: points to per return-instance private data; see "Kretprobe entry-handler" for details. ”h]”(hŒterm”“”)�”}”(hŒ@data: points to per return-instance private data; see "Kretprobe”h]”hŒBdata: points to per return-instance private data; see “Kretprobe”…”�”}”(hj– h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j” h³hÊh´M¾hj� ubhŒ definition”“”)�”}”(hhh]”hì)�”}”(hŒentry-handler" for details.”h]”hŒentry-handlerâ€� for details.”…”�”}”(hj© h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M¾hj¦ ubah}”(h]”h ]”h"]”h$]”h&]”uh1j¤ hj� ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jŽ h³hÊh´M¾hj‹ ubah}”(h]”h ]”h"]”h$]”h&]”uh1j‰ hj… ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj= h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”j j uh1jˆh³hÊh´MºhjØ h²hubhì)�”}”(hŒŸThe regs_return_value(regs) macro provides a simple abstraction to extract the return value from the appropriate register as defined by the architecture's ABI.”h]”hŒ¡The regs_return_value(regs) macro provides a simple abstraction to extract the return value from the appropriate register as defined by the architecture’s ABI.”…”�”}”(hjÕ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MÀhjØ h²hubhì)�”}”(hŒ0The handler's return value is currently ignored.”h]”hŒ2The handler’s return value is currently ignored.”…”�”}”(hjã h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MÄhjØ h²hubeh}”(h]”Œregister-kretprobe”ah ]”h"]”Œregister_kretprobe”ah$]”h&]”uh1hµhjˆ h²hh³hÊh´M ubh¶)�”}”(hhh]”(h»)�”}”(hŒunregister_*probe”h]”hŒunregister_*probe”…”�”}”(hjü h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjù h²hh³hÊh´MÇubj¹ )�”}”(hŒv#include void unregister_kprobe(struct kprobe *kp); void unregister_kretprobe(struct kretprobe *rp);”h]”hŒv#include void unregister_kprobe(struct kprobe *kp); void unregister_kretprobe(struct kretprobe *rp);”…”�”}”hj sbah}”(h]”h ]”h"]”h$]”h&]”j·j¸uh1j¸ h³hÊh´MËhjù h²hubhì)�”}”(hŒtRemoves the specified probe. The unregister function can be called at any time after the probe has been registered.”h]”hŒtRemoves the specified probe. The unregister function can be called at any time after the probe has been registered.”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MÏhjù h²hubj× )�”}”(hŒmIf the functions find an incorrect probe (ex. an unregistered probe), they clear the addr field of the probe.”h]”hì)�”}”(hŒmIf the functions find an incorrect probe (ex. an unregistered probe), they clear the addr field of the probe.”h]”hŒmIf the functions find an incorrect probe (ex. an unregistered probe), they clear the addr field of the probe.”…”�”}”(hj* h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MÔhj& ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÖ hjù h²hh³hÊh´Nubeh}”(h]”Œunregister-probe”ah ]”h"]”Œunregister_*probe”ah$]”h&]”uh1hµhjˆ h²hh³hÊh´MÇubh¶)�”}”(hhh]”(h»)�”}”(hŒregister_*probes”h]”hŒregister_*probes”…”�”}”(hjI h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjF h²hh³hÊh´MØubj¹ )�”}”(hŒˆ#include int register_kprobes(struct kprobe **kps, int num); int register_kretprobes(struct kretprobe **rps, int num);”h]”hŒˆ#include int register_kprobes(struct kprobe **kps, int num); int register_kretprobes(struct kretprobe **rps, int num);”…”�”}”hjW sbah}”(h]”h ]”h"]”h$]”h&]”j·j¸uh1j¸ h³hÊh´MÜhjF h²hubhì)�”}”(hŒÖRegisters each of the num probes in the specified array. If any error occurs during registration, all probes in the array, up to the bad probe, are safely unregistered before the register_*probes function returns.”h]”hŒÖRegisters each of the num probes in the specified array. If any error occurs during registration, all probes in the array, up to the bad probe, are safely unregistered before the register_*probes function returns.”…”�”}”(hje h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MàhjF h²hubj‰)�”}”(hhh]”(jŽ)�”}”(hŒ;kps/rps: an array of pointers to ``*probe`` data structures”h]”hì)�”}”(hjx h]”(hŒ!kps/rps: an array of pointers to ”…”�”}”(hjz h²hh³Nh´Nubjj)�”}”(hŒ ``*probe``”h]”hŒ*probe”…”�”}”(hj� h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jihjz ubhŒ data structures”…”�”}”(hjz h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Måhjv ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjs h²hh³hÊh´NubjŽ)�”}”(hŒ&num: the number of the array entries. ”h]”hì)�”}”(hŒ%num: the number of the array entries.”h]”hŒ%num: the number of the array entries.”…”�”}”(hj£ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MæhjŸ ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjs h²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”j j uh1jˆh³hÊh´MåhjF h²hubj× )�”}”(hŒsYou have to allocate(or define) an array of pointers and set all of the array entries before using these functions.”h]”hì)�”}”(hŒsYou have to allocate(or define) an array of pointers and set all of the array entries before using these functions.”h]”hŒsYou have to allocate(or define) an array of pointers and set all of the array entries before using these functions.”…”�”}”(hjÁ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Mêhj½ ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÖ hjF h²hh³hÊh´Nubeh}”(h]”Œregister-probes”ah ]”h"]”Œregister_*probes”ah$]”h&]”uh1hµhjˆ h²hh³hÊh´MØubh¶)�”}”(hhh]”(h»)�”}”(hŒunregister_*probes”h]”hŒunregister_*probes”…”�”}”(hjà h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjÝ h²hh³hÊh´Mîubj¹ )�”}”(hŒŽ#include void unregister_kprobes(struct kprobe **kps, int num); void unregister_kretprobes(struct kretprobe **rps, int num);”•›h]”hŒŽ#include void unregister_kprobes(struct kprobe **kps, int num); void unregister_kretprobes(struct kretprobe **rps, int num);”…”�”}”hjî sbah}”(h]”h ]”h"]”h$]”h&]”j·j¸uh1j¸ h³hÊh´MòhjÝ h²hubhì)�”}”(hŒ>Removes each of the num probes in the specified array at once.”h]”hŒ>Removes each of the num probes in the specified array at once.”…”�”}”(hjü h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MöhjÝ h²hubj× )�”}”(hŒÑIf the functions find some incorrect probes (ex. unregistered probes) in the specified array, they clear the addr field of those incorrect probes. However, other probes in the array are unregistered correctly.”h]”hì)�”}”(hŒÑIf the functions find some incorrect probes (ex. unregistered probes) in the specified array, they clear the addr field of those incorrect probes. However, other probes in the array are unregistered correctly.”h]”hŒÑIf the functions find some incorrect probes (ex. unregistered probes) in the specified array, they clear the addr field of those incorrect probes. However, other probes in the array are unregistered correctly.”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Múhj ubah}”(h]”h ]”h"]”h$]”h&]”uh1jÖ hjÝ h²hh³hÊh´Nubeh}”(h]”Œunregister-probes”ah ]”h"]”Œunregister_*probes”ah$]”h&]”uh1hµhjˆ h²hh³hÊh´Mîubh¶)�”}”(hhh]”(h»)�”}”(hŒdisable_*probe”h]”hŒdisable_*probe”…”�”}”(hj- h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj* h²hh³hÊh´Mubj¹ )�”}”(hŒn#include int disable_kprobe(struct kprobe *kp); int disable_kretprobe(struct kretprobe *rp);”h]”hŒn#include int disable_kprobe(struct kprobe *kp); int disable_kretprobe(struct kretprobe *rp);”…”�”}”hj; sbah}”(h]”h ]”h"]”h$]”h&]”j·j¸uh1j¸ h³hÊh´Mhj* h²hubhì)�”}”(hŒ–Temporarily disables the specified ``*probe``. You can enable it again by using enable_*probe(). You must specify the probe which has been registered.”h]”(hŒ#Temporarily disables the specified ”…”�”}”(hjI h²hh³Nh´Nubjj)�”}”(hŒ ``*probe``”h]”hŒ*probe”…”�”}”(hjQ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jihjI ubhŒi. You can enable it again by using enable_*probe(). You must specify the probe which has been registered.”…”�”}”(hjI h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Mhj* h²hubeh}”(h]”Œ disable-probe”ah ]”h"]”Œdisable_*probe”ah$]”h&]”uh1hµhjˆ h²hh³hÊh´Mubh¶)�”}”(hhh]”(h»)�”}”(hŒ enable_*probe”h]”hŒ enable_*probe”…”�”}”(hjt h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjq h²hh³hÊh´M ubj¹ )�”}”(hŒl#include int enable_kprobe(struct kprobe *kp); int enable_kretprobe(struct kretprobe *rp);”h]”hŒl#include int enable_kprobe(struct kprobe *kp); int enable_kretprobe(struct kretprobe *rp);”…”�”}”hj‚ sbah}”(h]”h ]”h"]”h$]”h&]”j·j¸uh1j¸ h³hÊh´Mhjq h²hubhì)�”}”(hŒuEnables ``*probe`` which has been disabled by disable_*probe(). You must specify the probe which has been registered.”h]”(hŒEnables ”…”�”}”(hj� h²hh³Nh´Nubjj)�”}”(hŒ ``*probe``”h]”hŒ*probe”…”�”}”(hj˜ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jihj� ubhŒc which has been disabled by disable_*probe(). You must specify the probe which has been registered.”…”�”}”(hj� h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Mhjq h²hubeh}”(h]”Œ enable-probe”ah ]”h"]”Œ enable_*probe”ah$]”h&]”uh1hµhjˆ h²hh³hÊh´M ubeh}”(h]”Œ api-reference”ah ]”h"]”Œ api reference”ah$]”h&]”uh1hµhh·h²hh³hÊh´M\ubh¶)�”}”(hhh]”(h»)�”}”(hŒ Kprobes Features and Limitations”h]”hŒ Kprobes Features and Limitations”…”�”}”(hjà h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjÀ h²hh³hÊh´Mubhì)�”}”(hŒûKprobes allows multiple probes at the same address. Also, a probepoint for which there is a post_handler cannot be optimized. So if you install a kprobe with a post_handler, at an optimized probepoint, the probepoint will be unoptimized automatically.”h]”hŒûKprobes allows multiple probes at the same address. Also, a probepoint for which there is a post_handler cannot be optimized. So if you install a kprobe with a post_handler, at an optimized probepoint, the probepoint will be unoptimized automatically.”…”�”}”(hjÑ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MhjÀ h²hubhì)�”}”(hŒ�In general, you can install a probe anywhere in the kernel. In particular, you can probe interrupt handlers. Known exceptions are discussed in this section.”h]”hŒ�In general, you can install a probe anywhere in the kernel. In particular, you can probe interrupt handlers. Known exceptions are discussed in this section.”…”�”}”(hjß h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MhjÀ h²hubhì)�”}”(hŒôThe register_*probe functions will return -EINVAL if you attempt to install a probe in the code that implements Kprobes (mostly kernel/kprobes.c and ``arch/*/kernel/kprobes.c``, but also functions such as do_page_fault and notifier_call_chain).”h]”(hŒ•The register_*probe functions will return -EINVAL if you attempt to install a probe in the code that implements Kprobes (mostly kernel/kprobes.c and ”…”�”}”(hjí h²hh³Nh´Nubjj)�”}”(hŒ``arch/*/kernel/kprobes.c``”h]”hŒarch/*/kernel/kprobes.c”…”�”}”(hjõ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jihjí ubhŒD, but also functions such as do_page_fault and notifier_call_chain).”…”�”}”(hjí h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M#hjÀ h²hubhì)�”}”(hX If you install a probe in an inline-able function, Kprobes makes no attempt to chase down all inline instances of the function and install probes there. gcc may inline a function without being asked, so keep this in mind if you're not seeing the probe hits you expect.”h]”hXIf you install a probe in an inline-able function, Kprobes makes no attempt to chase down all inline instances of the function and install probes there. gcc may inline a function without being asked, so keep this in mind if you’re not seeing the probe hits you expect.”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M(hjÀ h²hubhì)�”}”(hXÇA probe handler can modify the environment of the probed function -- e.g., by modifying kernel data structures, or by modifying the contents of the pt_regs struct (which are restored to the registers upon return from the breakpoint). So Kprobes can be used, for example, to install a bug fix or to inject faults for testing. Kprobes, of course, has no way to distinguish the deliberately injected faults from the accidental ones. Don't drink and probe.”h]”hXÉA probe handler can modify the environment of the probed function -- e.g., by modifying kernel data structures, or by modifying the contents of the pt_regs struct (which are restored to the registers upon return from the breakpoint). So Kprobes can be used, for example, to install a bug fix or to inject faults for testing. Kprobes, of course, has no way to distinguish the deliberately injected faults from the accidental ones. Don’t drink and probe.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M-hjÀ h²hubhì)�”}”(hX=Kprobes makes no attempt to prevent probe handlers from stepping on each other -- e.g., probing printk() and then calling printk() from a probe handler. If a probe handler hits a probe, that second probe's handlers won't be run in that instance, and the kprobe.nmissed member of the second probe will be incremented.”h]”hXAKprobes makes no attempt to prevent probe handlers from stepping on each other -- e.g., probing printk() and then calling printk() from a probe handler. If a probe handler hits a probe, that second probe’s handlers won’t be run in that instance, and the kprobe.nmissed member of the second probe will be incremented.”…”�”}”(hj)h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M5hjÀ h²hubhì)�”}”(hŒ~As of Linux v2.6.15-rc1, multiple handlers (or multiple instances of the same handler) may run concurrently on different CPUs.”h]”hŒ~As of Linux v2.6.15-rc1, multiple handlers (or multiple instances of the same handler) may run concurrently on different CPUs.”…”�”}”(hj7h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M;hjÀ h²hubhì)�”}”(hŒ^Kprobes does not use mutexes or allocate memory except during registration and unregistration.”h]”hŒ^Kprobes does not use mutexes or allocate memory except during registration and unregistration.”…”�”}”(hjEh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M>hjÀ h²hubhì)�”}”(hXZProbe handlers are run with preemption disabled or interrupt disabled, which depends on the architecture and optimization state. (e.g., kretprobe handlers and optimized kprobe handlers run without interrupt disabled on x86/x86-64). In any case, your handler should not yield the CPU (e.g., by attempting to acquire a semaphore, or waiting I/O).”h]”hXZProbe handlers are run with preemption disabled or interrupt disabled, which depends on the architecture and optimization state. (e.g., kretprobe handlers and optimized kprobe handlers run without interrupt disabled on x86/x86-64). In any case, your handler should not yield the CPU (e.g., by attempting to acquire a semaphore, or waiting I/O).”…”�”}”(hjSh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MAhjÀ h²hubhì)�”}”(hXpSince a return probe is implemented by replacing the return address with the trampoline's address, stack backtraces and calls to __builtin_return_address() will typically yield the trampoline's address instead of the real return address for kretprobed functions. (As far as we can tell, __builtin_return_address() is used only for instrumentation and error reporting.)”h]”hXtSince a return probe is implemented by replacing the return address with the trampoline’s address, stack backtraces and calls to __builtin_return_address() will typically yield the trampoline’s address instead of the real return address for kretprobed functions. (As far as we can tell, __builtin_return_address() is used only for instrumentation and error reporting.)”…”�”}”(hjah²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MGhjÀ h²hubhì)�”}”(hXIf the number of times a function is called does not match the number of times it returns, registering a return probe on that function may produce undesirable results. In such a case, a line: kretprobe BUG!: Processing kretprobe d000000000041aa8 @ c00000000004f48c gets printed. With this information, one will be able to correlate the exact instance of the kretprobe that caused the problem. We have the do_exit() case covered. do_execve() and do_fork() are not an issue. We're unaware of other specific cases where this could be a problem.”h]”hXIf the number of times a function is called does not match the number of times it returns, registering a return probe on that function may produce undesirable results. In such a case, a line: kretprobe BUG!: Processing kretprobe d000000000041aa8 @ c00000000004f48c gets printed. With this information, one will be able to correlate the exact instance of the kretprobe that caused the problem. We have the do_exit() case covered. do_execve() and do_fork() are not an issue. We’re unaware of other specific cases where this could be a problem.”…”�”}”(hjoh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MNhjÀ h²hubhì)�”}”(hXRIf, upon entry to or exit from a function, the CPU is running on a stack other than that of the current task, registering a return probe on that function may produce undesirable results. For this reason, Kprobes doesn't support return probes (or kprobes) on the x86_64 version of __switch_to(); the registration functions return -EINVAL.”h]”hXTIf, upon entry to or exit from a function, the CPU is running on a stack other than that of the current task, registering a return probe on that function may produce undesirable results. For this reason, Kprobes doesn’t support return probes (or kprobes) on the x86_64 version of __switch_to(); the registration functions return -EINVAL.”…”�”}”(hj}h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MWhjÀ h²hubhì)�”}”(hXOn x86/x86-64, since the Jump Optimization of Kprobes modifies instructions widely, there are some limitations to optimization. To explain it, we introduce some terminology. Imagine a 3-instruction sequence consisting of a two 2-byte instructions and one 3-byte instruction.”h]”hXOn x86/x86-64, since the Jump Optimization of Kprobes modifies instructions widely, there are some limitations to optimization. To explain it, we introduce some terminology. Imagine a 3-instruction sequence consisting of a two 2-byte instructions and one 3-byte instruction.”…”�”}”(hj‹h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M^hjÀ h²hubj¹ )�”}”(hX IA | [-2][-1][0][1][2][3][4][5][6][7] [ins1][ins2][ ins3 ] [<- DCR ->] [<- JTPR ->] ins1: 1st Instruction ins2: 2nd Instruction ins3: 3rd Instruction IA: Insertion Address JTPR: Jump Target Prohibition Region DCR: Detoured Code Region”h]”hX IA | [-2][-1][0][1][2][3][4][5][6][7] [ins1][ins2][ ins3 ] [<- DCR ->] [<- JTPR ->] ins1: 1st Instruction ins2: 2nd Instruction ins3: 3rd Instruction IA: Insertion Address JTPR: Jump Target Prohibition Region DCR: Detoured Code Region”…”�”}”hj™sbah}”(h]”h ]”h"]”h$]”h&]”j·j¸uh1j¸ h³hÊh´MfhjÀ h²hubhì)�”}”(hŒ±The instructions in DCR are copied to the out-of-line buffer of the kprobe, because the bytes in DCR are replaced by a 5-byte jump instruction. So there are several limitations.”h]”hŒ±The instructions in DCR are copied to the out-of-line buffer of the kprobe, because the bytes in DCR are replaced by a 5-byte jump instruction. So there are several limitations.”…”�”}”(hj§h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MthjÀ h²hubjÝ )�”}”(hhh]”(jŽ)�”}”(hŒ,The instructions in DCR must be relocatable.”h]”hì)�”}”(hjºh]”hŒ,The instructions in DCR must be relocatable.”…”�”}”(hj¼h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Mxhj¸ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjµh²hh³hÊh´NubjŽ)�”}”(hŒubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjùubeh}”(h]”h ]”h"]”h$]”h&]”j j uh1jˆh³hÊh´MËhjõubah}”(h]”h ]”h"]”h$]”h&]”uh1jóh³hÊh´MËhjÅubeh}”(h]”h ]”h"]”h$]”h&]”uh1j�hjÂh²hh³hÊh´NubjŽ)�”}”(hX‘Use ftrace dynamic events (kprobe event) with perf-probe. If you build your kernel with debug info (CONFIG_DEBUG_INFO=y), you can find which register/stack is assigned to which local variable or arguments by using perf-probe and set up new event to trace it. See following documents: - Documentation/trace/kprobetrace.rst - Documentation/trace/events.rst - tools/perf/Documentation/perf-probe.txt ”h]”(hì)�”}”(hŒ9Use ftrace dynamic events (kprobe event) with perf-probe.”h]”hŒ9Use ftrace dynamic events (kprobe event) with perf-probe.”…”�”}”(hjvh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MÏhjrubhì)�”}”(hŒÈIf you build your kernel with debug info (CONFIG_DEBUG_INFO=y), you can find which register/stack is assigned to which local variable or arguments by using perf-probe and set up new event to trace it.”h]”hŒÈIf you build your kernel with debug info (CONFIG_DEBUG_INFO=y), you can find which register/stack is assigned to which local variable or arguments by using perf-probe and set up new event to trace it.”…”�”}”(hj„h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MÑhjrubhì)�”}”(hŒSee following documents:”h]”hŒSee following documents:”…”�”}”(hj’h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MÕhjrubj‰)�”}”(hhh]”(jŽ)�”}”(hŒ#Documentation/trace/kprobetrace.rst”h]”hì)�”}”(hj¥h]”hŒ#Documentation/trace/kprobetrace.rst”…”�”}”(hj§h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M×hj£ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj ubjŽ)�”}”(hŒDocumentation/trace/events.rst”h]”hì)�”}”(hj¼h]”hŒDocumentation/trace/events.rst”…”�”}”(hj¾h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MØhjºubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj ubjŽ)�”}”(hŒ)tools/perf/Documentation/perf-probe.txt ”h]”hì)�”}”(hŒ'tools/perf/Documentation/perf-probe.txt”h]”hŒ'tools/perf/Documentation/perf-probe.txt”…”�”}”(hjÕh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´MÙhjÑubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hj ubeh}”(h]”h ]”h"]”h$]”h&]”j j uh1jˆh³hÊh´M×hjrubeh}”(h]”h ]”h"]”h$]”h&]”uh1j�hjÂh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”j j uh1jˆh³hÊh´MÃhj£h²hubeh}”(h]”Œdeprecated-features”ah ]”h"]”Œdeprecated features”ah$]”h&]”uh1hµhh·h²hh³hÊh´M½ubh¶)�”}”(hhh]”(h»)�”}”(hŒThe kprobes debugfs interface”h]”hŒThe kprobes debugfs interface”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´MÝubhì)�”}”(hŒ¬With recent kernels (> 2.6.20) the list of registered kprobes is visible under the /sys/kernel/debug/kprobes/ directory (assuming debugfs is mounted at //sys/kernel/debug).”h]”hŒ¬With recent kernels (> 2.6.20) the list of registered kprobes is visible under the /sys/kernel/debug/kprobes/ directory (assuming debugfs is mounted at //sys/kernel/debug).”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Màhjh²hubhì)�”}”(hŒK/sys/kernel/debug/kprobes/list: Lists all registered probes on the system::”h]”hŒJ/sys/kernel/debug/kprobes/list: Lists all registered probes on the system:”…”�”}”(hj"h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Mãhjh²hubj¹ )�”}”(hŒ5c015d71a k vfs_read+0x0 c03dedc5 r tcp_v4_rcv+0x0”h]”hŒ5c015d71a k vfs_read+0x0 c03dedc5 r tcp_v4_rcv+0x0”…”�”}”hj0sbah}”(h]”h ]”h"]”h$]”h&]”j·j¸uh1j¸ h³hÊh´Måhjh²hubhì)�”}”(hXÒThe first column provides the kernel address where the probe is inserted. The second column identifies the type of probe (k - kprobe and r - kretprobe) while the third column specifies the symbol+offset of the probe. If the probed function belongs to a module, the module name is also specified. Following columns show probe status. If the probe is on a virtual address that is no longer valid (module init sections, module virtual addresses that correspond to modules that've been unloaded), such probes are marked with [GONE]. If the probe is temporarily disabled, such probes are marked with [DISABLED]. If the probe is optimized, it is marked with [OPTIMIZED]. If the probe is ftrace-based, it is marked with [FTRACE].”h]”hXÔThe first column provides the kernel address where the probe is inserted. The second column identifies the type of probe (k - kprobe and r - kretprobe) while the third column specifies the symbol+offset of the probe. If the probed function belongs to a module, the module name is also specified. Following columns show probe status. If the probe is on a virtual address that is no longer valid (module init sections, module virtual addresses that correspond to modules that’ve been unloaded), such probes are marked with [GONE]. If the probe is temporarily disabled, such probes are marked with [DISABLED]. If the probe is optimized, it is marked with [OPTIMIZED]. If the probe is ftrace-based, it is marked with [FTRACE].”…”�”}”(hj>h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Mèhjh²hubhì)�”}”(hŒ@/sys/kernel/debug/kprobes/enabled: Turn kprobes ON/OFF forcibly.”h]”hŒ@/sys/kernel/debug/kprobes/enabled: Turn kprobes ON/OFF forcibly.”…”�”}”(hjLh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Môhjh²hubhì)�”}”(hX»Provides a knob to globally and forcibly turn registered kprobes ON or OFF. By default, all kprobes are enabled. By echoing "0" to this file, all registered probes will be disarmed, till such time a "1" is echoed to this file. Note that this knob just disarms and arms all kprobes and doesn't change each probe's disabling state. This means that disabled kprobes (marked [DISABLED]) will be not enabled if you turn ON all kprobes by this knob.”h]”hXÇProvides a knob to globally and forcibly turn registered kprobes ON or OFF. By default, all kprobes are enabled. By echoing “0â€� to this file, all registered probes will be disarmed, till such time a “1â€� is echoed to this file. Note that this knob just disarms and arms all kprobes and doesn’t change each probe’s disabling state. This means that disabled kprobes (marked [DISABLED]) will be not enabled if you turn ON all kprobes by this knob.”…”�”}”(hjZh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Möhjh²hubeh}”(h]”Œthe-kprobes-debugfs-interface”ah ]”h"]”Œthe kprobes debugfs interface”ah$]”h&]”uh1hµhh·h²hh³hÊh´MÝubh¶)�”}”(hhh]”(h»)�”}”(hŒThe kprobes sysctl interface”h]”hŒThe kprobes sysctl interface”…”�”}”(hjsh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjph²hh³hÊh´Mÿubhì)�”}”(hŒG/proc/sys/debug/kprobes-optimization: Turn kprobes optimization ON/OFF.”h]”hŒG/proc/sys/debug/kprobes-optimization: Turn kprobes optimization ON/OFF.”…”�”}”(hj�h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Mhjph²hubhì)�”}”(hX¢When CONFIG_OPTPROBES=y, this sysctl interface appears and it provides a knob to globally and forcibly turn jump optimization (see section :ref:`kprobes_jump_optimization`) ON or OFF. By default, jump optimization is allowed (ON). If you echo "0" to this file or set "debug.kprobes_optimization" to 0 via sysctl, all optimized probes will be unoptimized, and any new probes registered after that will not be optimized.”h]”(hŒ‹When CONFIG_OPTPROBES=y, this sysctl interface appears and it provides a knob to globally and forcibly turn jump optimization (see section ”…”�”}”(hj�h²hh³Nh´Nubh)�”}”(hŒ :ref:`kprobes_jump_optimization`”h]”j)�”}”(hj™h]”hŒkprobes_jump_optimization”…”�”}”(hj›h²hh³Nh´Nubah}”(h]”h ]”(j Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jhj—ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”jæŒ refdomain”j¥Œreftype”Œref”Œ refexplicit”‰Œrefwarn”ˆj2Œkprobes_jump_optimization”uh1hh³hÊh´Mhj�ubhŒÿ) ON or OFF. By default, jump optimization is allowed (ON). If you echo “0â€� to this file or set “debug.kprobes_optimizationâ€� to 0 via sysctl, all optimized probes will be unoptimized, and any new probes registered after that will not be optimized.”…”�”}”(hj�h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Mhjph²hubhì)�”}”(hŒ×Note that this knob *changes* the optimized state. This means that optimized probes (marked [OPTIMIZED]) will be unoptimized ([OPTIMIZED] tag will be removed). If the knob is turned on, they will be optimized again.”h]”(hŒNote that this knob ”…”�”}”(hjÁh²hh³Nh´Nubj)�”}”(hŒ *changes*”h]”hŒchanges”…”�”}”(hjÉh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjÁubhŒº the optimized state. This means that optimized probes (marked [OPTIMIZED]) will be unoptimized ([OPTIMIZED] tag will be removed). If the knob is turned on, they will be optimized again.”…”�”}”(hjÁh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´M hjph²hubeh}”(h]”Œthe-kprobes-sysctl-interface”ah ]”h"]”Œthe kprobes sysctl interface”ah$]”h&]”uh1hµhh·h²hh³hÊh´Mÿubh¶)�”}”(hhh]”(h»)�”}”(hŒ References”h]”hŒ References”…”�”}”(hjìh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjéh²hh³hÊh´Mubhì)�”}”(hŒCFor additional information on Kprobes, refer to the following URLs:”h]”hŒCFor additional information on Kprobes, refer to the following URLs:”…”�”}”(hjúh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Mhjéh²hubj‰)�”}”(hhh]”(jŽ)�”}”(hŒ https://lwn.net/Articles/132196/”h]”hì)�”}”(hj h]”hõ)�”}”(hj h]”hŒ https://lwn.net/Articles/132196/”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”j uh1hôhjubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Mhj ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjh²hh³hÊh´NubjŽ)�”}”(hŒ@https://www.kernel.org/doc/ols/2006/ols2006v2-pages-109-124.pdf ”h]”hì)�”}”(hŒ?https://www.kernel.org/doc/ols/2006/ols2006v2-pages-109-124.pdf”h]”hõ)�”}”(hj2h]”hŒ?https://www.kernel.org/doc/ols/2006/ols2006v2-pages-109-124.pdf”…”�”}”(hj4h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”j2uh1hôhj0ubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Mhj,ubah}”(h]”h ]”h"]”h$]”h&]”uh1j�hjh²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”j j uh1jˆh³hÊh´Mhjéh²hubeh}”(h]”Œ references”ah ]”h"]”Œ references”ah$]”h&]”uh1hµhh·h²hh³hÊh´Mubeh}”(h]”Œkernel-probes-kprobes”ah ]”h"]”Œkernel probes (kprobes)”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”j‡Œ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”}”(Œ1”]”jÔaŒ3”]”j†aŒ4”]”jšauŒrefids”}”(j]”jaj³]”j©ajò]”jèauŒnameids”}”(jaj^jjjBjäjjjXjUj jjÈjÅjjjÂjjÁj¾jfjcj4j1jØjÕjjjgjÇjÄj¹j¶j!j•jHj©jùj³jøjõj2 jòj1 j. j… j‚ j½ jº jÕ jÒ jö jó jC j@ jÚ j× j' j$ jn jk jµ j² j0j-j¨j¥j j�jRjOjyjvj j�jjýjmjjjæjãjYjVuŒ nametypes”}”(ja‰j‰jBˆj‰jX‰j ‰jȉj‰jˆjÁ‰jf‰j4‰j؉jj‰jljj¹‰j!ˆjHˆjùˆjø‰j2 ˆj1 ‰j… ‰j½ ‰jÕ ‰jö ‰jC ‰jÚ ‰j' ‰jn ‰jµ ‰j0‰j¨‰j ‰jR‰jy‰j ‰j‰jm‰jæ‰jY‰uh}”(j^h·jj¹jÞjÔjäjôjjÇjUjjj[jÅjljjËjj#j¾j#jcjBj1jijÕj7jgjÛjÄjmj�j†j¤jšj¶jÊj•jéj©j$j³jÉjõjÉjòjj. jj‚ j7 jº jˆ jÒ j§ jó jØ j@ jù j× jF j$ jÝ jk j* j² jq j-jÀ j¥j3j�jnjOj«jvjUj�j|jýj£jjjjãjpjVjéuŒ footnote_refs”}”(jÇ]”jÔajÉ]”j†ajË]”jšauŒ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”(jôjéj$eŒ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”j•Ks…”R”Œparse_messages”]”Œtransform_messages”]”(hŒsystem_message”“”)�”}”(hhh]”hì)�”}”(hhh]”hŒ?Hyperlink target "kprobes-jump-optimization" is not referenced.”…”�”}”hjüsbah}”(h]”h ]”h"]”h$]”h&]”uh1hëhjùubah}”(h]”h ]”h"]”h$]”h&]”Œlevel”KŒtype”ŒINFO”Œsource”hÊŒline”K§uh1j÷ubjø)�”}”(hhh]”hì)�”}”(hhh]”hŒ7Hyperlink target "kprobes-blacklist" is not referenced.”…”�”}”hjsbah}”(h]”h ]”h"]”h$]”h&]”uh1hëhjubah}”(h]”h ]”h"]”h$]”h&]”Œlevel”KŒtype”jŒsource”hÊŒline”M#uh1j÷ubjø)�”}”(hhh]”hì)�”}”(hhh]”hŒ=Hyperlink target "kprobes-archs-supported" is not referenced.”…”�”}”hj1sbah}”(h]”h ]”h"]”h$]”h&]”uh1hëhj.ubah}”(h]”h ]”h"]”h$]”h&]”Œlevel”KŒtype”jŒsource”hÊŒline”M3uh1j÷ubeŒ transformer”NŒ include_log”]”Œ decoration”Nh²hub.