CINXE.COM

LKML: Ananth N Mavinakayanahalli: Re: [(resend)patch 7/7] Kprobes - Register for page fault notify on active probes

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>LKML: Ananth N Mavinakayanahalli: Re: [(resend)patch 7/7] Kprobes - Register for page fault notify on active probes</title><link href="/css/message.css" rel="stylesheet" type="text/css" /><link href="/css/wrap.css" rel="alternate stylesheet" type="text/css" title="wrap" /><link href="/css/nowrap.css" rel="stylesheet" type="text/css" title="nowrap" /><link href="/favicon.ico" rel="shortcut icon" /><script src="/js/simple-calendar.js" type="text/javascript"></script><script src="/js/styleswitcher.js" type="text/javascript"></script><link rel="alternate" type="application/rss+xml" title="lkml.org : last 100 messages" href="/rss.php" /><link rel="alternate" type="application/rss+xml" title="lkml.org : last messages by Ananth N Mavinakayanahalli" href="/groupie.php?aid=16741" /><!--Matomo--><script> var _paq = window._paq = window._paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ _paq.push(["setDoNotTrack", true]); _paq.push(["disableCookies"]); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="//m.lkml.org/"; _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '1']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); </script><!--End Matomo Code--></head><body onload="es.jasper.simpleCalendar.init();" itemscope="itemscope" itemtype="http://schema.org/BlogPosting"><table border="0" cellpadding="0" cellspacing="0"><tr><td width="180" align="center"><a href="/"><img style="border:0;width:135px;height:32px" src="/images/toprowlk.gif" alt="lkml.org" /></a></td><td width="32">聽</td><td class="nb"><div><a class="nb" href="/lkml"> [lkml]</a> 聽 <a class="nb" href="/lkml/2006"> [2006]</a> 聽 <a class="nb" href="/lkml/2006/4"> [Apr]</a> 聽 <a class="nb" href="/lkml/2006/4/19"> [19]</a> 聽 <a class="nb" href="/lkml/last100"> [last100]</a> 聽 <a href="/rss.php"><img src="/images/rss-or.gif" border="0" alt="RSS Feed" /></a></div><div>Views: <a href="#" class="nowrap" onclick="setActiveStyleSheet('wrap');return false;">[wrap]</a><a href="#" class="wrap" onclick="setActiveStyleSheet('nowrap');return false;">[no wrap]</a> 聽 <a class="nb" href="/lkml/mheaders/2006/4/19/368" onclick="this.href='/lkml/headers'+'/2006/4/19/368';">[headers]</a>聽 <a href="/lkml/bounce/2006/4/19/368">[forward]</a>聽 </div></td><td width="32">聽</td></tr><tr><td valign="top"><div class="es-jasper-simpleCalendar" baseurl="/lkml/"></div><div class="threadlist">Messages in this thread</div><ul class="threadlist"><li class="root"><a href="/lkml/2006/4/19/324">First message in thread</a></li><li><a href="/lkml/2006/4/19/324">Anil S Keshavamurthy</a><ul><li><a href="/lkml/2006/4/19/323">Anil S Keshavamurthy</a></li><li><a href="/lkml/2006/4/19/326">Anil S Keshavamurthy</a></li><li><a href="/lkml/2006/4/19/327">Anil S Keshavamurthy</a></li><li><a href="/lkml/2006/4/19/328">Anil S Keshavamurthy</a></li><li><a href="/lkml/2006/4/19/329">Anil S Keshavamurthy</a><ul><li class="origin"><a href="/lkml/2006/4/20/6">Ananth N Mavinakayanahalli</a><ul><li><a href="/lkml/2006/4/20/6">Keshavamurthy Anil S</a></li></ul></li></ul></li><li><a href="/lkml/2006/4/19/330">Anil S Keshavamurthy</a><ul><li><a href="/lkml/2006/4/19/363">Keith Owens</a><ul><li><a href="/lkml/2006/4/20/5">Keshavamurthy Anil S</a></li></ul></li></ul></li><li><a href="/lkml/2006/4/19/331">Anil S Keshavamurthy</a></li><li><a href="/lkml/2006/4/19/354">Keith Owens</a><ul><li><a href="/lkml/2006/4/20/4">Keshavamurthy Anil S</a></li></ul></li></ul></li></ul><div class="threadlist">Patch in this message</div><ul class="threadlist"><li><a href="/lkml/diff/2006/4/19/368/1">Get diff 1</a></li></ul></td><td width="32" rowspan="2" class="c" valign="top"><img src="/images/icornerl.gif" width="32" height="32" alt="/" /></td><td class="c" rowspan="2" valign="top" style="padding-top: 1em"><table><tr><td><table><tr><td class="lp">Date</td><td class="rp" itemprop="datePublished">Thu, 20 Apr 2006 09:27:35 +0530</td></tr><tr><td class="lp">From</td><td class="rp" itemprop="author">Ananth N Mavinakayanahalli &lt;&gt;</td></tr><tr><td class="lp">Subject</td><td class="rp" itemprop="name">Re: [(resend)patch 7/7] Kprobes - Register for page fault notify on active probes</td></tr></table></td><td></td></tr></table><pre itemprop="articleBody">On Wed, Apr 19, 2006 at 03:14:26PM -0700, Anil S Keshavamurthy wrote:<br />&gt; With this patch Kprobes now registers for page fault notifications only<br />&gt; when their is an active probe registered. Once all the active probes are<br />&gt; unregistered their is no need to be notified of page faults and kprobes<br />&gt; unregisters itself from the page fault notifications. Hence we<br />&gt; will have ZERO side effects when no probes are active.<br /><br />This patch isn't complete yet... comments below.<br /><br />&gt; Signed-off-by: Anil S Keshavamurthy &lt;anil.s.keshavamurthy&#64;intel.com&gt;<br />&gt; ---<br />&gt; kernel/kprobes.c | 25 +++++++++++++++++--------<br />&gt; 1 file changed, 17 insertions(+), 8 deletions(-)<br />&gt; <br />&gt; Index: linux-2.6.17-rc1-mm3/kernel/kprobes.c<br />&gt; ===================================================================<br />&gt; --- linux-2.6.17-rc1-mm3.orig/kernel/kprobes.c<br />&gt; +++ linux-2.6.17-rc1-mm3/kernel/kprobes.c<br />&gt; &#64;&#64; -47,11 +47,17 &#64;&#64;<br />&gt; <br />&gt; static struct hlist_head kprobe_table[KPROBE_TABLE_SIZE];<br />&gt; static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE];<br />&gt; +static atomic_t kprobe_count;<br />&gt; <br />&gt; DEFINE_MUTEX(kprobe_mutex); /* Protects kprobe_table */<br />&gt; DEFINE_SPINLOCK(kretprobe_lock); /* Protects kretprobe_inst_table */<br />&gt; static DEFINE_PER_CPU(struct kprobe *, kprobe_instance) = NULL;<br />&gt; <br />&gt; +static struct notifier_block kprobe_page_fault_nb = {<br />&gt; + .notifier_call = kprobe_exceptions_notify,<br />&gt; + .priority = 0x7fffffff /* we need to notified first */<br />&gt; +};<br />&gt; +<br />&gt; #ifdef __ARCH_WANT_KPROBES_INSN_SLOT<br />&gt; /*<br />&gt; * kprobe-&gt;ainsn.insn points to the copy of the instruction to be<br />&gt; &#64;&#64; -464,6 +470,8 &#64;&#64; static int __kprobes __register_kprobe(s<br />&gt; old_p = get_kprobe(p-&gt;addr);<br />&gt; if (old_p) {<br />&gt; ret = register_aggr_kprobe(old_p, p);<br />&gt; + if (!ret)<br />&gt; + atomic_inc(&amp;kprobe_count);<br />&gt; goto out;<br />&gt; }<br />&gt; <br />&gt; &#64;&#64; -474,6 +482,9 &#64;&#64; static int __kprobes __register_kprobe(s<br />&gt; hlist_add_head_rcu(&amp;p-&gt;hlist,<br />&gt; &amp;kprobe_table[hash_ptr(p-&gt;addr, KPROBE_HASH_BITS)]);<br />&gt; <br />&gt; + if(atomic_add_return(1, &amp;kprobe_count) == 2)<br /> ^^^<br /> if (..) please, here and elsewhere<br /><br />This will not work as desired for i386 (i386 no longer has a kprobe on the<br />trampoline) and sparc64 (no retprobe support).<br /><br />&gt; + register_page_fault_notifier(&amp;kprobe_page_fault_nb);<br />&gt; +<br />&gt; arch_arm_kprobe(p);<br />&gt; <br />&gt; out:<br />&gt; &#64;&#64; -523,9 +534,13 &#64;&#64; valid_p:<br />&gt; cleanup_p = 0;<br />&gt; }<br />&gt; <br />&gt; + if(atomic_add_return(-1, &amp;kprobe_count) == 1)<br />&gt; + unregister_page_fault_notifier(&amp;kprobe_page_fault_nb);<br /><br />Same here - i386 and sparc64 need different checks.<br /><br />&gt; + else<br />&gt; + synchronize_rcu();<br /><br />Why has this changed from synchronize_sched()? This *must* be<br />synchronize_sched() since, by definition it'll ensure that all<br />non-preemptive sections are completed. In contrast, synchronize_rcu()<br />will just enure rcu_read_lock() sections are complete.<br /><br />As of now, synchronize_sched() is aliased to synchronize_rcu() but I am<br />told its scheduled to change in the future.<br /><br />Please revert this back to synchronize_sched().<br /><br />Thanks,<br />Ananth<br /><br />&gt; +<br />&gt; mutex_unlock(&amp;kprobe_mutex);<br />&gt; <br />&gt; - synchronize_sched();<br />&gt; if (p-&gt;mod_refcounted &amp;&amp;<br />&gt; (mod = module_text_address((unsigned long)p-&gt;addr)))<br />&gt; module_put(mod);<br />&gt; &#64;&#64; -544,10 +559,6 &#64;&#64; static struct notifier_block kprobe_exce<br />&gt; .priority = 0x7fffffff /* we need to notified first */<br />&gt; };<br />&gt; <br />&gt; -static struct notifier_block kprobe_page_fault_nb = {<br />&gt; - .notifier_call = kprobe_exceptions_notify,<br />&gt; - .priority = 0x7fffffff /* we need to notified first */<br />&gt; -};<br />&gt; <br />&gt; int __kprobes register_jprobe(struct jprobe *jp)<br />&gt; {<br />&gt; &#64;&#64; -654,14 +665,12 &#64;&#64; static int __init init_kprobes(void)<br />&gt; INIT_HLIST_HEAD(&amp;kprobe_table[i]);<br />&gt; INIT_HLIST_HEAD(&amp;kretprobe_inst_table[i]);<br />&gt; }<br />&gt; + atomic_set(&amp;kprobe_count, 0);<br />&gt; <br />&gt; err = arch_init_kprobes();<br />&gt; if (!err)<br />&gt; err = register_die_notifier(&amp;kprobe_exceptions_nb);<br />&gt; <br />&gt; - if (!err)<br />&gt; - err = register_page_fault_notifier(&amp;kprobe_page_fault_nb);<br />&gt; -<br />&gt; return err;<br />&gt; }<br />&gt; <br />&gt; <br />&gt; --<br />-<br />To unsubscribe from this list: send the line "unsubscribe linux-kernel" in<br />the body of a message to majordomo&#64;vger.kernel.org<br />More majordomo info at <a href="http://vger.kernel.org/majordomo-info.html">http://vger.kernel.org/majordomo-info.html</a><br />Please read the FAQ at <a href="http://www.tux.org/lkml/">http://www.tux.org/lkml/</a><br /><br /></pre></td><td width="32" rowspan="2" class="c" valign="top"><img src="/images/icornerr.gif" width="32" height="32" alt="\" /></td></tr><tr><td align="right" valign="bottom"> 聽 </td></tr><tr><td align="right" valign="bottom">聽</td><td class="c" valign="bottom" style="padding-bottom: 0px"><img src="/images/bcornerl.gif" width="32" height="32" alt="\" /></td><td class="c">聽</td><td class="c" valign="bottom" style="padding-bottom: 0px"><img src="/images/bcornerr.gif" width="32" height="32" alt="/" /></td></tr><tr><td align="right" valign="top" colspan="2"> 聽 </td><td class="lm">Last update: 2006-04-20 06:01 聽聽 [from the cache]<br />漏2003-2020 <a href="http://blog.jasper.es/"><span itemprop="editor">Jasper Spaans</span></a>|hosted at <a href="https://www.digitalocean.com/?refcode=9a8e99d24cf9">Digital Ocean</a> and my Meterkast|<a href="http://blog.jasper.es/categories.html#lkml-ref">Read the blog</a></td><td>聽</td></tr></table><script language="javascript" src="/js/styleswitcher.js" type="text/javascript"></script></body></html>

Pages: 1 2 3 4 5 6 7 8 9 10