linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND] trace_uprobe: support reference counter in fd-based uprobe
@ 2018-09-24 21:12 Song Liu
  2018-09-25  6:26 ` kbuild test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Song Liu @ 2018-09-24 21:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: kernel-team, Song Liu, Masami Hiramatsu, Oleg Nesterov,
	Srikar Dronamraju, Naveen N . Rao, Steven Rostedt

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

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

Signed-off-by: Song Liu <songliubraving@fb.com>
Reviewed-and-tested-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 include/linux/trace_events.h    |  3 +-
 kernel/events/core.c            | 49 ++++++++++++++++++++++++++-------
 kernel/trace/trace_event_perf.c |  7 +++--
 kernel/trace/trace_probe.h      |  3 +-
 kernel/trace/trace_uprobe.c     |  4 ++-
 5 files changed, 50 insertions(+), 16 deletions(-)

diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index 78a010e19ed4..4130a5497d40 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -575,7 +575,8 @@ extern int bpf_get_kprobe_info(const struct perf_event *event,
 			       bool perf_type_tracepoint);
 #endif
 #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 int bpf_get_uprobe_info(const struct perf_event *event,
 			       u32 *fd_type, const char **filename,
diff --git a/kernel/events/core.c b/kernel/events/core.c
index c80549bf82c6..a4ad5235ec9b 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8368,30 +8368,39 @@ static struct pmu perf_tracepoint = {
  *
  * PERF_PROBE_CONFIG_IS_RETPROBE if set, create kretprobe/uretprobe
  *                               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 {
 	PERF_PROBE_CONFIG_IS_RETPROBE = 1U << 0,  /* [k,u]retprobe */
+	PERF_UPROBE_REF_CTR_OFFSET_BITS = 40,
+	PERF_UPROBE_REF_CTR_OFFSET_SHIFT = 64 - PERF_UPROBE_REF_CTR_OFFSET_BITS,
 };

 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,
 	NULL,
 };

-static struct attribute_group probe_format_group = {
+static struct attribute_group kprobe_format_group = {
 	.name = "format",
-	.attrs = probe_attrs,
+	.attrs = kprobe_attrs,
 };

-static const struct attribute_group *probe_attr_groups[] = {
-	&probe_format_group,
+static const struct attribute_group *kprobe_attr_groups[] = {
+	&kprobe_format_group,
 	NULL,
 };
-#endif

-#ifdef CONFIG_KPROBE_EVENTS
 static int perf_kprobe_event_init(struct perf_event *event);
 static struct pmu perf_kprobe = {
 	.task_ctx_nr	= perf_sw_context,
@@ -8401,7 +8410,7 @@ static struct pmu perf_kprobe = {
 	.start		= perf_swevent_start,
 	.stop		= perf_swevent_stop,
 	.read		= perf_swevent_read,
-	.attr_groups	= probe_attr_groups,
+	.attr_groups	= kprobe_attr_groups,
 };

 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 */

 #ifdef CONFIG_UPROBE_EVENTS
+PMU_FORMAT_ATTR(ref_ctr_offset, "config:63-24");
+
+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 struct pmu perf_uprobe = {
 	.task_ctx_nr	= perf_sw_context,
@@ -8442,12 +8469,13 @@ static struct pmu perf_uprobe = {
 	.start		= perf_swevent_start,
 	.stop		= perf_swevent_stop,
 	.read		= perf_swevent_read,
-	.attr_groups	= probe_attr_groups,
+	.attr_groups	= uprobe_attr_groups,
 };

 static int perf_uprobe_event_init(struct perf_event *event)
 {
 	int err;
+	unsigned long ref_ctr_offset;
 	bool is_retprobe;

 	if (event->attr.type != perf_uprobe.type)
@@ -8463,7 +8491,8 @@ static int perf_uprobe_event_init(struct perf_event *event)
 		return -EOPNOTSUPP;

 	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)
 		return err;

diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c
index 69a3fe926e8c..76217bbef815 100644
--- a/kernel/trace/trace_event_perf.c
+++ b/kernel/trace/trace_event_perf.c
@@ -290,7 +290,8 @@ void perf_kprobe_destroy(struct perf_event *p_event)
 #endif /* CONFIG_KPROBE_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;
 	char *path = NULL;
@@ -312,8 +313,8 @@ int perf_uprobe_init(struct perf_event *p_event, bool is_retprobe)
 		goto out;
 	}

-	tp_event = create_local_trace_uprobe(
-		path, p_event->attr.probe_offset, is_retprobe);
+	tp_event = create_local_trace_uprobe(path, p_event->attr.probe_offset,
+					     ref_ctr_offset, is_retprobe);
 	if (IS_ERR(tp_event)) {
 		ret = PTR_ERR(tp_event);
 		goto out;
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index 5f52668e165d..03b10f3201a5 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -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 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);
 #endif
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index 3a7c73c40007..d09638706fe0 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -1405,7 +1405,8 @@ static int unregister_uprobe_event(struct trace_uprobe *tu)

 #ifdef CONFIG_PERF_EVENTS
 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 path path;
@@ -1437,6 +1438,7 @@ create_local_trace_uprobe(char *name, unsigned long offs, bool is_return)

 	tu->offset = offs;
 	tu->path = path;
+	tu->ref_ctr_offset = ref_ctr_offset;
 	tu->filename = kstrdup(name, GFP_KERNEL);
 	init_trace_event_call(tu, &tu->tp.call);

--
2.17.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH RESEND] trace_uprobe: support reference counter in fd-based uprobe
  2018-09-24 21:12 [PATCH RESEND] trace_uprobe: support reference counter in fd-based uprobe Song Liu
@ 2018-09-25  6:26 ` kbuild test robot
  2018-09-25 14:46   ` Song Liu
  2018-09-26 16:06 ` Steven Rostedt
  2018-09-28  7:23 ` Song Liu
  2 siblings, 1 reply; 8+ messages in thread
From: kbuild test robot @ 2018-09-25  6:26 UTC (permalink / raw)
  To: Song Liu
  Cc: kbuild-all, linux-kernel, kernel-team, Song Liu,
	Masami Hiramatsu, Oleg Nesterov, Srikar Dronamraju,
	Naveen N . Rao, Steven Rostedt

[-- Attachment #1: Type: text/plain, Size: 2522 bytes --]

Hi Song,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on tip/perf/core]
[also build test ERROR on v4.19-rc5 next-20180925]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Song-Liu/trace_uprobe-support-reference-counter-in-fd-based-uprobe/20180925-135454
config: i386-randconfig-x005-201838 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   kernel/trace/trace_uprobe.c: In function 'create_local_trace_uprobe':
>> kernel/trace/trace_uprobe.c:1376:4: error: 'struct trace_uprobe' has no member named 'ref_ctr_offset'
     tu->ref_ctr_offset = ref_ctr_offset;
       ^~

vim +1376 kernel/trace/trace_uprobe.c

  1340	
  1341	#ifdef CONFIG_PERF_EVENTS
  1342	struct trace_event_call *
  1343	create_local_trace_uprobe(char *name, unsigned long offs,
  1344				  unsigned long ref_ctr_offset, bool is_return)
  1345	{
  1346		struct trace_uprobe *tu;
  1347		struct path path;
  1348		int ret;
  1349	
  1350		ret = kern_path(name, LOOKUP_FOLLOW, &path);
  1351		if (ret)
  1352			return ERR_PTR(ret);
  1353	
  1354		if (!d_is_reg(path.dentry)) {
  1355			path_put(&path);
  1356			return ERR_PTR(-EINVAL);
  1357		}
  1358	
  1359		/*
  1360		 * local trace_kprobes are not added to probe_list, so they are never
  1361		 * searched in find_trace_kprobe(). Therefore, there is no concern of
  1362		 * duplicated name "DUMMY_EVENT" here.
  1363		 */
  1364		tu = alloc_trace_uprobe(UPROBE_EVENT_SYSTEM, "DUMMY_EVENT", 0,
  1365					is_return);
  1366	
  1367		if (IS_ERR(tu)) {
  1368			pr_info("Failed to allocate trace_uprobe.(%d)\n",
  1369				(int)PTR_ERR(tu));
  1370			path_put(&path);
  1371			return ERR_CAST(tu);
  1372		}
  1373	
  1374		tu->offset = offs;
  1375		tu->path = path;
> 1376		tu->ref_ctr_offset = ref_ctr_offset;
  1377		tu->filename = kstrdup(name, GFP_KERNEL);
  1378		init_trace_event_call(tu, &tu->tp.call);
  1379	
  1380		if (set_print_fmt(&tu->tp, is_ret_probe(tu)) < 0) {
  1381			ret = -ENOMEM;
  1382			goto error;
  1383		}
  1384	
  1385		return &tu->tp.call;
  1386	error:
  1387		free_trace_uprobe(tu);
  1388		return ERR_PTR(ret);
  1389	}
  1390	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 36102 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH RESEND] trace_uprobe: support reference counter in fd-based uprobe
  2018-09-25  6:26 ` kbuild test robot
@ 2018-09-25 14:46   ` Song Liu
  0 siblings, 0 replies; 8+ messages in thread
From: Song Liu @ 2018-09-25 14:46 UTC (permalink / raw)
  To: kbuild test robot
  Cc: kbuild-all, linux-kernel, Kernel Team, Masami Hiramatsu,
	Oleg Nesterov, Srikar Dronamraju, Naveen N . Rao, Steven Rostedt

Hi, 

This patch is based on this branch:

https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git/log/?h=ftrace/core

Thanks,
Song



> On Sep 24, 2018, at 11:26 PM, kbuild test robot <lkp@intel.com> wrote:
> 
> Hi Song,
> 
> Thank you for the patch! Yet something to improve:
> 
> [auto build test ERROR on tip/perf/core]
> [also build test ERROR on v4.19-rc5 next-20180925]
> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
> 
> url:    https://github.com/0day-ci/linux/commits/Song-Liu/trace_uprobe-support-reference-counter-in-fd-based-uprobe/20180925-135454
> config: i386-randconfig-x005-201838 (attached as .config)
> compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
> reproduce:
>        # save the attached .config to linux build tree
>        make ARCH=i386 
> 
> All errors (new ones prefixed by >>):
> 
>   kernel/trace/trace_uprobe.c: In function 'create_local_trace_uprobe':
>>> kernel/trace/trace_uprobe.c:1376:4: error: 'struct trace_uprobe' has no member named 'ref_ctr_offset'
>     tu->ref_ctr_offset = ref_ctr_offset;
>       ^~
> 
> vim +1376 kernel/trace/trace_uprobe.c
> 
>  1340	
>  1341	#ifdef CONFIG_PERF_EVENTS
>  1342	struct trace_event_call *
>  1343	create_local_trace_uprobe(char *name, unsigned long offs,
>  1344				  unsigned long ref_ctr_offset, bool is_return)
>  1345	{
>  1346		struct trace_uprobe *tu;
>  1347		struct path path;
>  1348		int ret;
>  1349	
>  1350		ret = kern_path(name, LOOKUP_FOLLOW, &path);
>  1351		if (ret)
>  1352			return ERR_PTR(ret);
>  1353	
>  1354		if (!d_is_reg(path.dentry)) {
>  1355			path_put(&path);
>  1356			return ERR_PTR(-EINVAL);
>  1357		}
>  1358	
>  1359		/*
>  1360		 * local trace_kprobes are not added to probe_list, so they are never
>  1361		 * searched in find_trace_kprobe(). Therefore, there is no concern of
>  1362		 * duplicated name "DUMMY_EVENT" here.
>  1363		 */
>  1364		tu = alloc_trace_uprobe(UPROBE_EVENT_SYSTEM, "DUMMY_EVENT", 0,
>  1365					is_return);
>  1366	
>  1367		if (IS_ERR(tu)) {
>  1368			pr_info("Failed to allocate trace_uprobe.(%d)\n",
>  1369				(int)PTR_ERR(tu));
>  1370			path_put(&path);
>  1371			return ERR_CAST(tu);
>  1372		}
>  1373	
>  1374		tu->offset = offs;
>  1375		tu->path = path;
>> 1376		tu->ref_ctr_offset = ref_ctr_offset;
>  1377		tu->filename = kstrdup(name, GFP_KERNEL);
>  1378		init_trace_event_call(tu, &tu->tp.call);
>  1379	
>  1380		if (set_print_fmt(&tu->tp, is_ret_probe(tu)) < 0) {
>  1381			ret = -ENOMEM;
>  1382			goto error;
>  1383		}
>  1384	
>  1385		return &tu->tp.call;
>  1386	error:
>  1387		free_trace_uprobe(tu);
>  1388		return ERR_PTR(ret);
>  1389	}
>  1390	
> 
> ---
> 0-DAY kernel test infrastructure                Open Source Technology Center
> https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.01.org_pipermail_kbuild-2Dall&d=DwIBAg&c=5VD0RTtNlTh3ycd41b3MUw&r=i6WobKxbeG3slzHSIOxTVtYIJw7qjCE6S0spDTKL-J4&m=3vAXcNkXYHALEVsIZG7-ToPCNADLh0bCVwEpureyaaw&s=eKJR9UoqZ2KCoTN58CznxX7ipOGdcRwG0zWFLsbzHXc&e=                   Intel Corporation
> <.config.gz>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH RESEND] trace_uprobe: support reference counter in fd-based uprobe
  2018-09-24 21:12 [PATCH RESEND] trace_uprobe: support reference counter in fd-based uprobe Song Liu
  2018-09-25  6:26 ` kbuild test robot
@ 2018-09-26 16:06 ` Steven Rostedt
  2018-09-28  7:18   ` Peter Zijlstra
  2018-09-28  7:23 ` Song Liu
  2 siblings, 1 reply; 8+ messages in thread
From: Steven Rostedt @ 2018-09-26 16:06 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Song Liu, linux-kernel, kernel-team, Masami Hiramatsu,
	Oleg Nesterov, Srikar Dronamraju, Naveen N . Rao

On Mon, 24 Sep 2018 14:12:36 -0700
Song Liu <songliubraving@fb.com> wrote:

> This patch enables uprobes with reference counter in fd-based uprobe.
> Highest 40 bits of perf_event_attr.config is used to stored offset
> of the reference counter (semaphore).
> 
> Format information in /sys/bus/event_source/devices/uprobe/format/ is
> updated to reflect this new feature.
> 
> Signed-off-by: Song Liu <songliubraving@fb.com>
> Reviewed-and-tested-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
> Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
>  include/linux/trace_events.h    |  3 +-
>  kernel/events/core.c            | 49 ++++++++++++++++++++++++++-------
>  kernel/trace/trace_event_perf.c |  7 +++--

Peter,

This is based off of some uprobe code in my tree (which I just finished
testing and need to push to linux-next). But can you give an ack to the
perf parts?

Thanks!

-- Steve


>  kernel/trace/trace_probe.h      |  3 +-
>  kernel/trace/trace_uprobe.c     |  4 ++-
>  5 files changed, 50 insertions(+), 16 deletions(-)
> 
> diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
> index 78a010e19ed4..4130a5497d40 100644
> --- a/include/linux/trace_events.h
> +++ b/include/linux/trace_events.h
> @@ -575,7 +575,8 @@ extern int bpf_get_kprobe_info(const struct perf_event *event,
>  			       bool perf_type_tracepoint);
>  #endif
>  #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 int bpf_get_uprobe_info(const struct perf_event *event,
>  			       u32 *fd_type, const char **filename,
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index c80549bf82c6..a4ad5235ec9b 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -8368,30 +8368,39 @@ static struct pmu perf_tracepoint = {
>   *
>   * PERF_PROBE_CONFIG_IS_RETPROBE if set, create kretprobe/uretprobe
>   *                               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 {
>  	PERF_PROBE_CONFIG_IS_RETPROBE = 1U << 0,  /* [k,u]retprobe */
> +	PERF_UPROBE_REF_CTR_OFFSET_BITS = 40,
> +	PERF_UPROBE_REF_CTR_OFFSET_SHIFT = 64 - PERF_UPROBE_REF_CTR_OFFSET_BITS,
>  };
> 
>  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,
>  	NULL,
>  };
> 
> -static struct attribute_group probe_format_group = {
> +static struct attribute_group kprobe_format_group = {
>  	.name = "format",
> -	.attrs = probe_attrs,
> +	.attrs = kprobe_attrs,
>  };
> 
> -static const struct attribute_group *probe_attr_groups[] = {
> -	&probe_format_group,
> +static const struct attribute_group *kprobe_attr_groups[] = {
> +	&kprobe_format_group,
>  	NULL,
>  };
> -#endif
> 
> -#ifdef CONFIG_KPROBE_EVENTS
>  static int perf_kprobe_event_init(struct perf_event *event);
>  static struct pmu perf_kprobe = {
>  	.task_ctx_nr	= perf_sw_context,
> @@ -8401,7 +8410,7 @@ static struct pmu perf_kprobe = {
>  	.start		= perf_swevent_start,
>  	.stop		= perf_swevent_stop,
>  	.read		= perf_swevent_read,
> -	.attr_groups	= probe_attr_groups,
> +	.attr_groups	= kprobe_attr_groups,
>  };
> 
>  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 */
> 
>  #ifdef CONFIG_UPROBE_EVENTS
> +PMU_FORMAT_ATTR(ref_ctr_offset, "config:63-24");
> +
> +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 struct pmu perf_uprobe = {
>  	.task_ctx_nr	= perf_sw_context,
> @@ -8442,12 +8469,13 @@ static struct pmu perf_uprobe = {
>  	.start		= perf_swevent_start,
>  	.stop		= perf_swevent_stop,
>  	.read		= perf_swevent_read,
> -	.attr_groups	= probe_attr_groups,
> +	.attr_groups	= uprobe_attr_groups,
>  };
> 
>  static int perf_uprobe_event_init(struct perf_event *event)
>  {
>  	int err;
> +	unsigned long ref_ctr_offset;
>  	bool is_retprobe;
> 
>  	if (event->attr.type != perf_uprobe.type)
> @@ -8463,7 +8491,8 @@ static int perf_uprobe_event_init(struct perf_event *event)
>  		return -EOPNOTSUPP;
> 
>  	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)
>  		return err;
> 
> diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c
> index 69a3fe926e8c..76217bbef815 100644
> --- a/kernel/trace/trace_event_perf.c
> +++ b/kernel/trace/trace_event_perf.c
> @@ -290,7 +290,8 @@ void perf_kprobe_destroy(struct perf_event *p_event)
>  #endif /* CONFIG_KPROBE_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;
>  	char *path = NULL;
> @@ -312,8 +313,8 @@ int perf_uprobe_init(struct perf_event *p_event, bool is_retprobe)
>  		goto out;
>  	}
> 
> -	tp_event = create_local_trace_uprobe(
> -		path, p_event->attr.probe_offset, is_retprobe);
> +	tp_event = create_local_trace_uprobe(path, p_event->attr.probe_offset,
> +					     ref_ctr_offset, is_retprobe);
>  	if (IS_ERR(tp_event)) {
>  		ret = PTR_ERR(tp_event);
>  		goto out;
> diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
> index 5f52668e165d..03b10f3201a5 100644
> --- a/kernel/trace/trace_probe.h
> +++ b/kernel/trace/trace_probe.h
> @@ -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 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);
>  #endif
> diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
> index 3a7c73c40007..d09638706fe0 100644
> --- a/kernel/trace/trace_uprobe.c
> +++ b/kernel/trace/trace_uprobe.c
> @@ -1405,7 +1405,8 @@ static int unregister_uprobe_event(struct trace_uprobe *tu)
> 
>  #ifdef CONFIG_PERF_EVENTS
>  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 path path;
> @@ -1437,6 +1438,7 @@ create_local_trace_uprobe(char *name, unsigned long offs, bool is_return)
> 
>  	tu->offset = offs;
>  	tu->path = path;
> +	tu->ref_ctr_offset = ref_ctr_offset;
>  	tu->filename = kstrdup(name, GFP_KERNEL);
>  	init_trace_event_call(tu, &tu->tp.call);
> 
> --
> 2.17.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH RESEND] trace_uprobe: support reference counter in fd-based uprobe
  2018-09-26 16:06 ` Steven Rostedt
@ 2018-09-28  7:18   ` Peter Zijlstra
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Zijlstra @ 2018-09-28  7:18 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Song Liu, linux-kernel, kernel-team, Masami Hiramatsu,
	Oleg Nesterov, Srikar Dronamraju, Naveen N . Rao

On Wed, Sep 26, 2018 at 12:06:23PM -0400, Steven Rostedt wrote:
> On Mon, 24 Sep 2018 14:12:36 -0700
> Song Liu <songliubraving@fb.com> wrote:
> 
> > This patch enables uprobes with reference counter in fd-based uprobe.
> > Highest 40 bits of perf_event_attr.config is used to stored offset
> > of the reference counter (semaphore).
> > 
> > Format information in /sys/bus/event_source/devices/uprobe/format/ is
> > updated to reflect this new feature.
> > 
> > Signed-off-by: Song Liu <songliubraving@fb.com>
> > Reviewed-and-tested-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
> > Cc: Masami Hiramatsu <mhiramat@kernel.org>
> > Cc: Oleg Nesterov <oleg@redhat.com>
> > Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
> > Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> > Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
> > ---
> >  include/linux/trace_events.h    |  3 +-
> >  kernel/events/core.c            | 49 ++++++++++++++++++++++++++-------
> >  kernel/trace/trace_event_perf.c |  7 +++--
> 
> Peter,
> 
> This is based off of some uprobe code in my tree (which I just finished
> testing and need to push to linux-next). But can you give an ack to the
> perf parts?

> > diff --git a/kernel/events/core.c b/kernel/events/core.c
> > index c80549bf82c6..a4ad5235ec9b 100644
> > --- a/kernel/events/core.c
> > +++ b/kernel/events/core.c
> > @@ -8368,30 +8368,39 @@ static struct pmu perf_tracepoint = {
> >   *
> >   * PERF_PROBE_CONFIG_IS_RETPROBE if set, create kretprobe/uretprobe
> >   *                               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 {
> >  	PERF_PROBE_CONFIG_IS_RETPROBE = 1U << 0,  /* [k,u]retprobe */
> > +	PERF_UPROBE_REF_CTR_OFFSET_BITS = 40,
> > +	PERF_UPROBE_REF_CTR_OFFSET_SHIFT = 64 - PERF_UPROBE_REF_CTR_OFFSET_BITS,
> >  };
> > 
> >  PMU_FORMAT_ATTR(retprobe, "config:0");

There's a PMU_FORMAT_ATTR() missing for the new part.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH RESEND] trace_uprobe: support reference counter in fd-based uprobe
  2018-09-24 21:12 [PATCH RESEND] trace_uprobe: support reference counter in fd-based uprobe Song Liu
  2018-09-25  6:26 ` kbuild test robot
  2018-09-26 16:06 ` Steven Rostedt
@ 2018-09-28  7:23 ` Song Liu
  2018-09-28  7:52   ` Peter Zijlstra
  2 siblings, 1 reply; 8+ messages in thread
From: Song Liu @ 2018-09-28  7:23 UTC (permalink / raw)
  To: lkml, Peter Zijlstra
  Cc: Kernel Team, Masami Hiramatsu, Oleg Nesterov, Srikar Dronamraju,
	Naveen N . Rao, Steven Rostedt

Hi Peter,


> On Sep 24, 2018, at 2:12 PM, Song Liu <songliubraving@fb.com> wrote:
> 
> This patch enables uprobes with reference counter in fd-based uprobe.
> Highest 40 bits of perf_event_attr.config is used to stored offset
> of the reference counter (semaphore).
> 
> Format information in /sys/bus/event_source/devices/uprobe/format/ is
> updated to reflect this new feature.
> 
> Signed-off-by: Song Liu <songliubraving@fb.com>
> Reviewed-and-tested-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
> Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
> include/linux/trace_events.h    |  3 +-
> kernel/events/core.c            | 49 ++++++++++++++++++++++++++-------
> kernel/trace/trace_event_perf.c |  7 +++--
> kernel/trace/trace_probe.h      |  3 +-
> kernel/trace/trace_uprobe.c     |  4 ++-
> 5 files changed, 50 insertions(+), 16 deletions(-)
> 
> diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
> index 78a010e19ed4..4130a5497d40 100644
> --- a/include/linux/trace_events.h
> +++ b/include/linux/trace_events.h
> @@ -575,7 +575,8 @@ extern int bpf_get_kprobe_info(const struct perf_event *event,
> 			       bool perf_type_tracepoint);
> #endif
> #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 int bpf_get_uprobe_info(const struct perf_event *event,
> 			       u32 *fd_type, const char **filename,
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index c80549bf82c6..a4ad5235ec9b 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -8368,30 +8368,39 @@ static struct pmu perf_tracepoint = {
>  *
>  * PERF_PROBE_CONFIG_IS_RETPROBE if set, create kretprobe/uretprobe
>  *                               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 {
> 	PERF_PROBE_CONFIG_IS_RETPROBE = 1U << 0,  /* [k,u]retprobe */
> +	PERF_UPROBE_REF_CTR_OFFSET_BITS = 40,
> +	PERF_UPROBE_REF_CTR_OFFSET_SHIFT = 64 - PERF_UPROBE_REF_CTR_OFFSET_BITS,
> };
> 
> 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,
> 	NULL,
> };
> 
> -static struct attribute_group probe_format_group = {
> +static struct attribute_group kprobe_format_group = {
> 	.name = "format",
> -	.attrs = probe_attrs,
> +	.attrs = kprobe_attrs,
> };
> 
> -static const struct attribute_group *probe_attr_groups[] = {
> -	&probe_format_group,
> +static const struct attribute_group *kprobe_attr_groups[] = {
> +	&kprobe_format_group,
> 	NULL,
> };
> -#endif
> 
> -#ifdef CONFIG_KPROBE_EVENTS
> static int perf_kprobe_event_init(struct perf_event *event);
> static struct pmu perf_kprobe = {
> 	.task_ctx_nr	= perf_sw_context,
> @@ -8401,7 +8410,7 @@ static struct pmu perf_kprobe = {
> 	.start		= perf_swevent_start,
> 	.stop		= perf_swevent_stop,
> 	.read		= perf_swevent_read,
> -	.attr_groups	= probe_attr_groups,
> +	.attr_groups	= kprobe_attr_groups,
> };
> 
> 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 */
> 
> #ifdef CONFIG_UPROBE_EVENTS
> +PMU_FORMAT_ATTR(ref_ctr_offset, "config:63-24");

I guess you meant this part? This is for uprobe only, so I put
it here. 

Thanks,
Song

> +
> +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 struct pmu perf_uprobe = {
> 	.task_ctx_nr	= perf_sw_context,
> @@ -8442,12 +8469,13 @@ static struct pmu perf_uprobe = {
> 	.start		= perf_swevent_start,
> 	.stop		= perf_swevent_stop,
> 	.read		= perf_swevent_read,
> -	.attr_groups	= probe_attr_groups,
> +	.attr_groups	= uprobe_attr_groups,
> };
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH RESEND] trace_uprobe: support reference counter in fd-based uprobe
  2018-09-28  7:23 ` Song Liu
@ 2018-09-28  7:52   ` Peter Zijlstra
  2018-09-28 14:50     ` Song Liu
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Zijlstra @ 2018-09-28  7:52 UTC (permalink / raw)
  To: Song Liu
  Cc: lkml, Kernel Team, Masami Hiramatsu, Oleg Nesterov,
	Srikar Dronamraju, Naveen N . Rao, Steven Rostedt

On Fri, Sep 28, 2018 at 07:23:20AM +0000, Song Liu wrote:
> Hi Peter,
> > #ifdef CONFIG_UPROBE_EVENTS
> > +PMU_FORMAT_ATTR(ref_ctr_offset, "config:63-24");
> 
> I guess you meant this part? This is for uprobe only, so I put
> it here. 

Ah,.. right you are.

You seem to have the bitfield backwards, does that mean we should write
the bits in backwards too? Seems a tad loopy if you ask me.

Did you instead mean: "config:24-63" ? Also, why 40 bits? 32 seems like
a much more natural amount.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH RESEND] trace_uprobe: support reference counter in fd-based uprobe
  2018-09-28  7:52   ` Peter Zijlstra
@ 2018-09-28 14:50     ` Song Liu
  0 siblings, 0 replies; 8+ messages in thread
From: Song Liu @ 2018-09-28 14:50 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: lkml, Kernel Team, Masami Hiramatsu, Oleg Nesterov,
	Srikar Dronamraju, Naveen N . Rao, Steven Rostedt



> On Sep 28, 2018, at 12:52 AM, Peter Zijlstra <peterz@infradead.org> wrote:
> 
> On Fri, Sep 28, 2018 at 07:23:20AM +0000, Song Liu wrote:
>> Hi Peter,
>>> #ifdef CONFIG_UPROBE_EVENTS
>>> +PMU_FORMAT_ATTR(ref_ctr_offset, "config:63-24");
>> 
>> I guess you meant this part? This is for uprobe only, so I put
>> it here. 
> 
> Ah,.. right you are.
> 
> You seem to have the bitfield backwards, does that mean we should write
> the bits in backwards too? Seems a tad loopy if you ask me.
> 
> Did you instead mean: "config:24-63" ? Also, why 40 bits? 32 seems like
> a much more natural amount.

I guess it should be "config:24-63". I didn't realize the bit order here. 
I picked 40 bits files up to 1 TB. 32 bits should be also be enough for 
most cases. Let me fix these in v2. 

Thanks,
Song


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-09-28 14:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-24 21:12 [PATCH RESEND] trace_uprobe: support reference counter in fd-based uprobe Song Liu
2018-09-25  6:26 ` kbuild test robot
2018-09-25 14:46   ` Song Liu
2018-09-26 16:06 ` Steven Rostedt
2018-09-28  7:18   ` Peter Zijlstra
2018-09-28  7:23 ` Song Liu
2018-09-28  7:52   ` Peter Zijlstra
2018-09-28 14:50     ` Song Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).