Re: [PATCH V7 04/15] kprobes: Add perf ksymbol events for kprobe insn pages

2020-05-28 Thread Adrian Hunter
On 27/05/20 8:20 pm, Peter Zijlstra wrote:
> On Wed, May 27, 2020 at 06:17:32PM +0200, Peter Zijlstra wrote:
>> On Tue, May 12, 2020 at 03:19:11PM +0300, Adrian Hunter wrote:
>>> @@ -202,6 +207,13 @@ static int collect_one_slot(struct kprobe_insn_page 
>>> *kip, int idx)
>>>  * next time somebody inserts a probe.
>>>  */
>>> if (!list_is_singular(&kip->list)) {
>>> +   /*
>>> +* Record perf ksymbol unregister event before removing
>>> +* the page.
>>> +*/
>>> +   perf_event_ksymbol(PERF_RECORD_KSYMBOL_TYPE_OOL,
>>> +  (u64)kip->insns, PAGE_SIZE, true,
>>> +  kip->cache->sym);
>>> list_del_rcu(&kip->list);
>>> synchronize_rcu();
>>> kip->cache->free(kip->insns);
>>
>> My manual build script haz complaints:
>>
>> i386-defconfig  ../kernel/kprobes.c: In function ‘__get_insn_slot’:
>> ../kernel/kprobes.c:190:51: warning: cast from pointer to integer of 
>> different size [-Wpointer-to-int-cast]
>> perf_event_ksymbol(PERF_RECORD_KSYMBOL_TYPE_OOL, (u64)kip->insns,
>> ^
>> ../kernel/kprobes.c: In function ‘collect_one_slot’:
>> ../kernel/kprobes.c:215:9: warning: cast from pointer to integer of 
>> different size [-Wpointer-to-int-cast]
>> (u64)kip->insns, PAGE_SIZE, true,
>> ^
>> FAIL
>>
>>
>> Now, there's a ton of such warnings elsewhere in the tree, but still I
>> feel we should perhaps strive for a clean build.
> 
> Fixed those for you. On to cross-builds... :/
> 

Thank you!


Re: [PATCH V7 04/15] kprobes: Add perf ksymbol events for kprobe insn pages

2020-05-27 Thread Peter Zijlstra
On Wed, May 27, 2020 at 06:17:32PM +0200, Peter Zijlstra wrote:
> On Tue, May 12, 2020 at 03:19:11PM +0300, Adrian Hunter wrote:
> > @@ -202,6 +207,13 @@ static int collect_one_slot(struct kprobe_insn_page 
> > *kip, int idx)
> >  * next time somebody inserts a probe.
> >  */
> > if (!list_is_singular(&kip->list)) {
> > +   /*
> > +* Record perf ksymbol unregister event before removing
> > +* the page.
> > +*/
> > +   perf_event_ksymbol(PERF_RECORD_KSYMBOL_TYPE_OOL,
> > +  (u64)kip->insns, PAGE_SIZE, true,
> > +  kip->cache->sym);
> > list_del_rcu(&kip->list);
> > synchronize_rcu();
> > kip->cache->free(kip->insns);
> 
> My manual build script haz complaints:
> 
> i386-defconfig  ../kernel/kprobes.c: In function ‘__get_insn_slot’:
> ../kernel/kprobes.c:190:51: warning: cast from pointer to integer of 
> different size [-Wpointer-to-int-cast]
> perf_event_ksymbol(PERF_RECORD_KSYMBOL_TYPE_OOL, (u64)kip->insns,
> ^
> ../kernel/kprobes.c: In function ‘collect_one_slot’:
> ../kernel/kprobes.c:215:9: warning: cast from pointer to integer of different 
> size [-Wpointer-to-int-cast]
> (u64)kip->insns, PAGE_SIZE, true,
> ^
> FAIL
> 
> 
> Now, there's a ton of such warnings elsewhere in the tree, but still I
> feel we should perhaps strive for a clean build.

Fixed those for you. On to cross-builds... :/


Re: [PATCH V7 04/15] kprobes: Add perf ksymbol events for kprobe insn pages

2020-05-27 Thread Peter Zijlstra
On Tue, May 12, 2020 at 03:19:11PM +0300, Adrian Hunter wrote:
> @@ -202,6 +207,13 @@ static int collect_one_slot(struct kprobe_insn_page 
> *kip, int idx)
>* next time somebody inserts a probe.
>*/
>   if (!list_is_singular(&kip->list)) {
> + /*
> +  * Record perf ksymbol unregister event before removing
> +  * the page.
> +  */
> + perf_event_ksymbol(PERF_RECORD_KSYMBOL_TYPE_OOL,
> +(u64)kip->insns, PAGE_SIZE, true,
> +kip->cache->sym);
>   list_del_rcu(&kip->list);
>   synchronize_rcu();
>   kip->cache->free(kip->insns);

My manual build script haz complaints:

i386-defconfig  ../kernel/kprobes.c: In function ‘__get_insn_slot’:
../kernel/kprobes.c:190:51: warning: cast from pointer to integer of different 
size [-Wpointer-to-int-cast]
perf_event_ksymbol(PERF_RECORD_KSYMBOL_TYPE_OOL, (u64)kip->insns,
^
../kernel/kprobes.c: In function ‘collect_one_slot’:
../kernel/kprobes.c:215:9: warning: cast from pointer to integer of different 
size [-Wpointer-to-int-cast]
(u64)kip->insns, PAGE_SIZE, true,
^
FAIL


Now, there's a ton of such warnings elsewhere in the tree, but still I
feel we should perhaps strive for a clean build.


[PATCH V7 04/15] kprobes: Add perf ksymbol events for kprobe insn pages

2020-05-12 Thread Adrian Hunter
Symbols are needed for tools to describe instruction addresses. Pages
allocated for kprobe's purposes need symbols to be created for them.
Add such symbols to be visible via perf ksymbol events.

Signed-off-by: Adrian Hunter 
Acked-by: Masami Hiramatsu 
Acked-by: Peter Zijlstra (Intel) 
---
 include/uapi/linux/perf_event.h |  5 +
 kernel/kprobes.c| 12 
 2 files changed, 17 insertions(+)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index e5bee6c17b86..e1a4179144a1 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -1049,6 +1049,11 @@ enum perf_event_type {
 enum perf_record_ksymbol_type {
PERF_RECORD_KSYMBOL_TYPE_UNKNOWN= 0,
PERF_RECORD_KSYMBOL_TYPE_BPF= 1,
+   /*
+* Out of line code such as kprobe-replaced instructions or optimized
+* kprobes.
+*/
+   PERF_RECORD_KSYMBOL_TYPE_OOL= 2,
PERF_RECORD_KSYMBOL_TYPE_MAX/* non-ABI */
 };
 
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 229d1b596690..f880eb2189c0 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -184,6 +185,10 @@ kprobe_opcode_t *__get_insn_slot(struct kprobe_insn_cache 
*c)
kip->cache = c;
list_add_rcu(&kip->list, &c->pages);
slot = kip->insns;
+
+   /* Record the perf ksymbol register event after adding the page */
+   perf_event_ksymbol(PERF_RECORD_KSYMBOL_TYPE_OOL, (u64)kip->insns,
+  PAGE_SIZE, false, c->sym);
 out:
mutex_unlock(&c->mutex);
return slot;
@@ -202,6 +207,13 @@ static int collect_one_slot(struct kprobe_insn_page *kip, 
int idx)
 * next time somebody inserts a probe.
 */
if (!list_is_singular(&kip->list)) {
+   /*
+* Record perf ksymbol unregister event before removing
+* the page.
+*/
+   perf_event_ksymbol(PERF_RECORD_KSYMBOL_TYPE_OOL,
+  (u64)kip->insns, PAGE_SIZE, true,
+  kip->cache->sym);
list_del_rcu(&kip->list);
synchronize_rcu();
kip->cache->free(kip->insns);
-- 
2.17.1