Skip to content

Commit 9b960a3

Browse files
mhiramatrostedt
authored andcommitted
tracing: probeevent: Unify fetch_insn processing common part
Unify the fetch_insn bottom process (from stage 2: dereference indirect data) from kprobe and uprobe events, since those are mostly same. Link: http://lkml.kernel.org/r/152465879965.26224.8547240824606804815.stgit@devbox Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 0a46c85 commit 9b960a3

3 files changed

Lines changed: 63 additions & 82 deletions

File tree

‎kernel/trace/trace_kprobe.c‎

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -899,13 +899,18 @@ fetch_store_string(unsigned long addr, void *dest, void *base)
899899
return ret;
900900
}
901901

902+
static nokprobe_inline int
903+
probe_mem_read(void *dest, void *src, size_t size)
904+
{
905+
return probe_kernel_read(dest, src, size);
906+
}
907+
902908
/* Note that we don't verify it, since the code does not come from user space */
903909
static int
904910
process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest,
905911
void *base)
906912
{
907913
unsigned long val;
908-
int ret = 0;
909914

910915
/* 1st stage: get value from context */
911916
switch (code->op) {
@@ -932,45 +937,7 @@ process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest,
932937
}
933938
code++;
934939

935-
/* 2nd stage: dereference memory if needed */
936-
while (code->op == FETCH_OP_DEREF) {
937-
ret = probe_kernel_read(&val, (void *)val + code->offset,
938-
sizeof(val));
939-
if (ret)
940-
return ret;
941-
code++;
942-
}
943-
944-
/* 3rd stage: store value to buffer */
945-
if (unlikely(!dest)) {
946-
if (code->op == FETCH_OP_ST_STRING)
947-
return fetch_store_strlen(val + code->offset);
948-
else
949-
return -EILSEQ;
950-
}
951-
952-
switch (code->op) {
953-
case FETCH_OP_ST_RAW:
954-
fetch_store_raw(val, code, dest);
955-
break;
956-
case FETCH_OP_ST_MEM:
957-
probe_kernel_read(dest, (void *)val + code->offset, code->size);
958-
break;
959-
case FETCH_OP_ST_STRING:
960-
ret = fetch_store_string(val + code->offset, dest, base);
961-
break;
962-
default:
963-
return -EILSEQ;
964-
}
965-
code++;
966-
967-
/* 4th stage: modify stored value if needed */
968-
if (code->op == FETCH_OP_MOD_BF) {
969-
fetch_apply_bitfield(code, dest);
970-
code++;
971-
}
972-
973-
return code->op == FETCH_OP_END ? ret : -EILSEQ;
940+
return process_fetch_insn_bottom(code, val, dest, base);
974941
}
975942
NOKPROBE_SYMBOL(process_fetch_insn)
976943

‎kernel/trace/trace_probe_tmpl.h‎

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,66 @@ fetch_apply_bitfield(struct fetch_insn *code, void *buf)
4949
}
5050

5151
/*
52-
* This must be defined for each callsite.
52+
* These functions must be defined for each callsite.
5353
* Return consumed dynamic data size (>= 0), or error (< 0).
5454
* If dest is NULL, don't store result and return required dynamic data size.
5555
*/
5656
static int
5757
process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs,
5858
void *dest, void *base);
59+
static nokprobe_inline int fetch_store_strlen(unsigned long addr);
60+
static nokprobe_inline int
61+
fetch_store_string(unsigned long addr, void *dest, void *base);
62+
static nokprobe_inline int
63+
probe_mem_read(void *dest, void *src, size_t size);
64+
65+
/* From the 2nd stage, routine is same */
66+
static nokprobe_inline int
67+
process_fetch_insn_bottom(struct fetch_insn *code, unsigned long val,
68+
void *dest, void *base)
69+
{
70+
int ret = 0;
71+
72+
/* 2nd stage: dereference memory if needed */
73+
while (code->op == FETCH_OP_DEREF) {
74+
ret = probe_mem_read(&val, (void *)val + code->offset,
75+
sizeof(val));
76+
if (ret)
77+
return ret;
78+
code++;
79+
}
80+
81+
/* 3rd stage: store value to buffer */
82+
if (unlikely(!dest)) {
83+
if (code->op == FETCH_OP_ST_STRING)
84+
return fetch_store_strlen(val + code->offset);
85+
else
86+
return -EILSEQ;
87+
}
88+
89+
switch (code->op) {
90+
case FETCH_OP_ST_RAW:
91+
fetch_store_raw(val, code, dest);
92+
break;
93+
case FETCH_OP_ST_MEM:
94+
probe_mem_read(dest, (void *)val + code->offset, code->size);
95+
break;
96+
case FETCH_OP_ST_STRING:
97+
ret = fetch_store_string(val + code->offset, dest, base);
98+
break;
99+
default:
100+
return -EILSEQ;
101+
}
102+
code++;
103+
104+
/* 4th stage: modify stored value if needed */
105+
if (code->op == FETCH_OP_MOD_BF) {
106+
fetch_apply_bitfield(code, dest);
107+
code++;
108+
}
109+
110+
return code->op == FETCH_OP_END ? ret : -EILSEQ;
111+
}
59112

60113
/* Sum up total data length for dynamic arraies (strings) */
61114
static nokprobe_inline int

‎kernel/trace/trace_uprobe.c‎

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static unsigned long get_user_stack_nth(struct pt_regs *regs, unsigned int n)
101101
* Uprobes-specific fetch functions
102102
*/
103103
static nokprobe_inline int
104-
probe_user_read(void *dest, void *src, size_t size)
104+
probe_mem_read(void *dest, void *src, size_t size)
105105
{
106106
void __user *vaddr = (void __force __user *)src;
107107

@@ -162,7 +162,6 @@ process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest,
162162
void *base)
163163
{
164164
unsigned long val;
165-
int ret = 0;
166165

167166
/* 1st stage: get value from context */
168167
switch (code->op) {
@@ -189,45 +188,7 @@ process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest,
189188
}
190189
code++;
191190

192-
/* 2nd stage: dereference memory if needed */
193-
while (code->op == FETCH_OP_DEREF) {
194-
ret = probe_user_read(&val, (void *)val + code->offset,
195-
sizeof(val));
196-
if (ret)
197-
return ret;
198-
code++;
199-
}
200-
201-
/* 3rd stage: store value to buffer */
202-
if (unlikely(!dest)) {
203-
if (code->op == FETCH_OP_ST_STRING)
204-
return fetch_store_strlen(val + code->offset);
205-
else
206-
return -EILSEQ;
207-
}
208-
209-
switch (code->op) {
210-
case FETCH_OP_ST_RAW:
211-
fetch_store_raw(val, code, dest);
212-
break;
213-
case FETCH_OP_ST_MEM:
214-
probe_kernel_read(dest, (void *)val + code->offset, code->size);
215-
break;
216-
case FETCH_OP_ST_STRING:
217-
ret = fetch_store_string(val + code->offset, dest, base);
218-
break;
219-
default:
220-
return -EILSEQ;
221-
}
222-
code++;
223-
224-
/* 4th stage: modify stored value if needed */
225-
if (code->op == FETCH_OP_MOD_BF) {
226-
fetch_apply_bitfield(code, dest);
227-
code++;
228-
}
229-
230-
return code->op == FETCH_OP_END ? ret : -EILSEQ;
191+
return process_fetch_insn_bottom(code, val, dest, base);
231192
}
232193
NOKPROBE_SYMBOL(process_fetch_insn)
233194

0 commit comments

Comments
 (0)