Commit a6ca88b2 authored by Song Liu's avatar Song Liu Committed by Steven Rostedt (VMware)

trace_uprobe: support reference counter in fd-based uprobe

This patch enables uprobes with reference counter in fd-based uprobe.
Highest 32 bits of perf_event_attr.config is used to stored offset
of the reference count (semaphore).

Format information in /sys/bus/event_source/devices/uprobe/format/ is
updated to reflect this new feature.

Link: http://lkml.kernel.org/r/20181002053636.1896903-1-songliubraving@fb.com

Cc: Oleg Nesterov <oleg@redhat.com>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-and-tested-by: default avatarRavi Bangoria <ravi.bangoria@linux.ibm.com>
Signed-off-by: default avatarSong Liu <songliubraving@fb.com>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 5a5e3d3c
...@@ -575,7 +575,8 @@ extern int bpf_get_kprobe_info(const struct perf_event *event, ...@@ -575,7 +575,8 @@ extern int bpf_get_kprobe_info(const struct perf_event *event,
bool perf_type_tracepoint); bool perf_type_tracepoint);
#endif #endif
#ifdef CONFIG_UPROBE_EVENTS #ifdef CONFIG_UPROBE_EVENTS
extern int perf_uprobe_init(struct perf_event *event, bool is_retprobe); extern int perf_uprobe_init(struct perf_event *event,
unsigned long ref_ctr_offset, bool is_retprobe);
extern void perf_uprobe_destroy(struct perf_event *event); extern void perf_uprobe_destroy(struct perf_event *event);
extern int bpf_get_uprobe_info(const struct perf_event *event, extern int bpf_get_uprobe_info(const struct perf_event *event,
u32 *fd_type, const char **filename, u32 *fd_type, const char **filename,
......
...@@ -8368,30 +8368,39 @@ static struct pmu perf_tracepoint = { ...@@ -8368,30 +8368,39 @@ static struct pmu perf_tracepoint = {
* *
* PERF_PROBE_CONFIG_IS_RETPROBE if set, create kretprobe/uretprobe * PERF_PROBE_CONFIG_IS_RETPROBE if set, create kretprobe/uretprobe
* if not set, create kprobe/uprobe * if not set, create kprobe/uprobe
*
* The following values specify a reference counter (or semaphore in the
* terminology of tools like dtrace, systemtap, etc.) Userspace Statically
* Defined Tracepoints (USDT). Currently, we use 40 bit for the offset.
*
* PERF_UPROBE_REF_CTR_OFFSET_BITS # of bits in config as th offset
* PERF_UPROBE_REF_CTR_OFFSET_SHIFT # of bits to shift left
*/ */
enum perf_probe_config { enum perf_probe_config {
PERF_PROBE_CONFIG_IS_RETPROBE = 1U << 0, /* [k,u]retprobe */ PERF_PROBE_CONFIG_IS_RETPROBE = 1U << 0, /* [k,u]retprobe */
PERF_UPROBE_REF_CTR_OFFSET_BITS = 32,
PERF_UPROBE_REF_CTR_OFFSET_SHIFT = 64 - PERF_UPROBE_REF_CTR_OFFSET_BITS,
}; };
PMU_FORMAT_ATTR(retprobe, "config:0"); PMU_FORMAT_ATTR(retprobe, "config:0");
#endif
static struct attribute *probe_attrs[] = { #ifdef CONFIG_KPROBE_EVENTS
static struct attribute *kprobe_attrs[] = {
&format_attr_retprobe.attr, &format_attr_retprobe.attr,
NULL, NULL,
}; };
static struct attribute_group probe_format_group = { static struct attribute_group kprobe_format_group = {
.name = "format", .name = "format",
.attrs = probe_attrs, .attrs = kprobe_attrs,
}; };
static const struct attribute_group *probe_attr_groups[] = { static const struct attribute_group *kprobe_attr_groups[] = {
&probe_format_group, &kprobe_format_group,
NULL, NULL,
}; };
#endif
#ifdef CONFIG_KPROBE_EVENTS
static int perf_kprobe_event_init(struct perf_event *event); static int perf_kprobe_event_init(struct perf_event *event);
static struct pmu perf_kprobe = { static struct pmu perf_kprobe = {
.task_ctx_nr = perf_sw_context, .task_ctx_nr = perf_sw_context,
...@@ -8401,7 +8410,7 @@ static struct pmu perf_kprobe = { ...@@ -8401,7 +8410,7 @@ static struct pmu perf_kprobe = {
.start = perf_swevent_start, .start = perf_swevent_start,
.stop = perf_swevent_stop, .stop = perf_swevent_stop,
.read = perf_swevent_read, .read = perf_swevent_read,
.attr_groups = probe_attr_groups, .attr_groups = kprobe_attr_groups,
}; };
static int perf_kprobe_event_init(struct perf_event *event) static int perf_kprobe_event_init(struct perf_event *event)
...@@ -8433,6 +8442,24 @@ static int perf_kprobe_event_init(struct perf_event *event) ...@@ -8433,6 +8442,24 @@ static int perf_kprobe_event_init(struct perf_event *event)
#endif /* CONFIG_KPROBE_EVENTS */ #endif /* CONFIG_KPROBE_EVENTS */
#ifdef CONFIG_UPROBE_EVENTS #ifdef CONFIG_UPROBE_EVENTS
PMU_FORMAT_ATTR(ref_ctr_offset, "config:32-63");
static struct attribute *uprobe_attrs[] = {
&format_attr_retprobe.attr,
&format_attr_ref_ctr_offset.attr,
NULL,
};
static struct attribute_group uprobe_format_group = {
.name = "format",
.attrs = uprobe_attrs,
};
static const struct attribute_group *uprobe_attr_groups[] = {
&uprobe_format_group,
NULL,
};
static int perf_uprobe_event_init(struct perf_event *event); static int perf_uprobe_event_init(struct perf_event *event);
static struct pmu perf_uprobe = { static struct pmu perf_uprobe = {
.task_ctx_nr = perf_sw_context, .task_ctx_nr = perf_sw_context,
...@@ -8442,12 +8469,13 @@ static struct pmu perf_uprobe = { ...@@ -8442,12 +8469,13 @@ static struct pmu perf_uprobe = {
.start = perf_swevent_start, .start = perf_swevent_start,
.stop = perf_swevent_stop, .stop = perf_swevent_stop,
.read = perf_swevent_read, .read = perf_swevent_read,
.attr_groups = probe_attr_groups, .attr_groups = uprobe_attr_groups,
}; };
static int perf_uprobe_event_init(struct perf_event *event) static int perf_uprobe_event_init(struct perf_event *event)
{ {
int err; int err;
unsigned long ref_ctr_offset;
bool is_retprobe; bool is_retprobe;
if (event->attr.type != perf_uprobe.type) if (event->attr.type != perf_uprobe.type)
...@@ -8463,7 +8491,8 @@ static int perf_uprobe_event_init(struct perf_event *event) ...@@ -8463,7 +8491,8 @@ static int perf_uprobe_event_init(struct perf_event *event)
return -EOPNOTSUPP; return -EOPNOTSUPP;
is_retprobe = event->attr.config & PERF_PROBE_CONFIG_IS_RETPROBE; is_retprobe = event->attr.config & PERF_PROBE_CONFIG_IS_RETPROBE;
err = perf_uprobe_init(event, is_retprobe); ref_ctr_offset = event->attr.config >> PERF_UPROBE_REF_CTR_OFFSET_SHIFT;
err = perf_uprobe_init(event, ref_ctr_offset, is_retprobe);
if (err) if (err)
return err; return err;
......
...@@ -290,7 +290,8 @@ void perf_kprobe_destroy(struct perf_event *p_event) ...@@ -290,7 +290,8 @@ void perf_kprobe_destroy(struct perf_event *p_event)
#endif /* CONFIG_KPROBE_EVENTS */ #endif /* CONFIG_KPROBE_EVENTS */
#ifdef CONFIG_UPROBE_EVENTS #ifdef CONFIG_UPROBE_EVENTS
int perf_uprobe_init(struct perf_event *p_event, bool is_retprobe) int perf_uprobe_init(struct perf_event *p_event,
unsigned long ref_ctr_offset, bool is_retprobe)
{ {
int ret; int ret;
char *path = NULL; char *path = NULL;
...@@ -312,8 +313,8 @@ int perf_uprobe_init(struct perf_event *p_event, bool is_retprobe) ...@@ -312,8 +313,8 @@ int perf_uprobe_init(struct perf_event *p_event, bool is_retprobe)
goto out; goto out;
} }
tp_event = create_local_trace_uprobe( tp_event = create_local_trace_uprobe(path, p_event->attr.probe_offset,
path, p_event->attr.probe_offset, is_retprobe); ref_ctr_offset, is_retprobe);
if (IS_ERR(tp_event)) { if (IS_ERR(tp_event)) {
ret = PTR_ERR(tp_event); ret = PTR_ERR(tp_event);
goto out; goto out;
......
...@@ -412,6 +412,7 @@ create_local_trace_kprobe(char *func, void *addr, unsigned long offs, ...@@ -412,6 +412,7 @@ create_local_trace_kprobe(char *func, void *addr, unsigned long offs,
extern void destroy_local_trace_kprobe(struct trace_event_call *event_call); extern void destroy_local_trace_kprobe(struct trace_event_call *event_call);
extern struct trace_event_call * extern struct trace_event_call *
create_local_trace_uprobe(char *name, unsigned long offs, bool is_return); create_local_trace_uprobe(char *name, unsigned long offs,
unsigned long ref_ctr_offset, bool is_return);
extern void destroy_local_trace_uprobe(struct trace_event_call *event_call); extern void destroy_local_trace_uprobe(struct trace_event_call *event_call);
#endif #endif
...@@ -1405,7 +1405,8 @@ static int unregister_uprobe_event(struct trace_uprobe *tu) ...@@ -1405,7 +1405,8 @@ static int unregister_uprobe_event(struct trace_uprobe *tu)
#ifdef CONFIG_PERF_EVENTS #ifdef CONFIG_PERF_EVENTS
struct trace_event_call * struct trace_event_call *
create_local_trace_uprobe(char *name, unsigned long offs, bool is_return) create_local_trace_uprobe(char *name, unsigned long offs,
unsigned long ref_ctr_offset, bool is_return)
{ {
struct trace_uprobe *tu; struct trace_uprobe *tu;
struct path path; struct path path;
...@@ -1437,6 +1438,7 @@ create_local_trace_uprobe(char *name, unsigned long offs, bool is_return) ...@@ -1437,6 +1438,7 @@ create_local_trace_uprobe(char *name, unsigned long offs, bool is_return)
tu->offset = offs; tu->offset = offs;
tu->path = path; tu->path = path;
tu->ref_ctr_offset = ref_ctr_offset;
tu->filename = kstrdup(name, GFP_KERNEL); tu->filename = kstrdup(name, GFP_KERNEL);
init_trace_event_call(tu, &tu->tp.call); init_trace_event_call(tu, &tu->tp.call);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment