Skip to contentSkip to conversation

trace_uprobe: Use %lx to display offset

PATCH Superseded Ravi Bangoria 3 participants 9 messages Feb 6, 2018 – Mar 7, 2018 Tracing

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 trace_uprobe: Use %lx to display offset

Kees suggested that, 'offset' is unsigned long, not a pointer, thus %lx should be used to print it, not the %px. Also, I don't see any reason to prepend offset with 0s. Replace %px with %lx.

Before patch:

  # echo "p:probe_a/main /tmp/a.out:0x594" > uprobe_events
  # cat uprobe_events
    p:probe_a/main /tmp/a.out:0x0000000000000594

After patch:

  # echo "p:probe_a/main /tmp/a.out:0x594" > uprobe_events
  # cat uprobe_events
    p:probe_a/main /tmp/a.out:0x594
Fixes 0e4d819d0893 ("trace_uprobe: Display correct offset in uprobe_events")
---
 kernel/trace/trace_uprobe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_uprobe.c +1 -1
index 268029ae1be6..c2c965398893 100644
@@ -608,7 +608,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
 
 	/* Don't print "0x  (null)" when offset is 0 */
 	if (tu->offset) {
-		seq_printf(m, "0x%px", (void *)tu->offset);
+		seq_printf(m, "0x%lx", tu->offset);
 	} else {
 		switch (sizeof(void *)) {
 		case 4:
Signature · 1 line
2.13.6
#1 lore raw

PATCH 2/2 trace_uprobe: Simplify probes_seq_show()

Simplify probes_seq_show() function. We are using %lx to display the offset and we don't prepend unnecessary 0s in the offset.

---
 kernel/trace/trace_uprobe.c | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)
kernel/trace/trace_uprobe.c +3 -18
index c2c965398893..c12a3957e1ee 100644
@@ -602,24 +602,9 @@ static int probes_seq_show(struct seq_file *m, void *v)
 	char c = is_ret_probe(tu) ? 'r' : 'p';
 	int i;
 
-	seq_printf(m, "%c:%s/%s", c, tu->tp.call.class->system,
-			trace_event_name(&tu->tp.call));
-	seq_printf(m, " %s:", tu->filename);
-
-	/* Don't print "0x  (null)" when offset is 0 */
-	if (tu->offset) {
-		seq_printf(m, "0x%lx", tu->offset);
-	} else {
-		switch (sizeof(void *)) {
-		case 4:
-			seq_printf(m, "0x00000000");
-			break;
-		case 8:
-		default:
-			seq_printf(m, "0x0000000000000000");
-			break;
-		}
-	}
+	seq_printf(m, "%c:%s/%s %s:0x%lx", c, tu->tp.call.class->system,
+			trace_event_name(&tu->tp.call), tu->filename,
+			tu->offset);
 
 	for (i = 0; i < tu->tp.nr_args; i++)
 		seq_printf(m, " %s=%s", tu->tp.args[i].name, tu->tp.args[i].comm);
Signature · 1 line
2.13.6
#3 lore raw

Re: [PATCH 2/2] trace_uprobe: Simplify probes_seq_show()

In reply to Ravi Bangoria
Quoted 27 lines · Ravi Bangoria

Simplify probes_seq_show() function. We are using %lx to display the offset and we don't prepend unnecessary 0s in the offset.

---
 kernel/trace/trace_uprobe.c | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)
kernel/trace/trace_uprobe.c +0 -11
index c2c965398893..c12a3957e1ee 100644
@@ -602,24 +602,9 @@ static int probes_seq_show(struct seq_file *m, void *v)
        char c = is_ret_probe(tu) ? 'r' : 'p';
        int i;
 
-       seq_printf(m, "%c:%s/%s", c, tu->tp.call.class->system,
-                       trace_event_name(&tu->tp.call));
-       seq_printf(m, " %s:", tu->filename);
-
-       /* Don't print "0x  (null)" when offset is 0 */
-       if (tu->offset) {
-               seq_printf(m, "0x%lx", tu->offset);
-       } else {
-               switch (sizeof(void *)) {
-               case 4:
-                       seq_printf(m, "0x00000000");

kernel/trace/trace_uprobe.c static int probes_seq_show(struct seq_file *m, void *v) · line 607

Quoted 10 lines
kernel/trace/trace_uprobe.c +3 -7
-                       break;
-               case 8:
-               default:
-                       seq_printf(m, "0x0000000000000000");
-                       break;
-               }
-       }
+       seq_printf(m, "%c:%s/%s %s:0x%lx", c, tu->tp.call.class->system,
+                       trace_event_name(&tu->tp.call), tu->filename,
+                       tu->offset);

To keep the prepended zeros (and avoid the redundant 0x prefix):

"...%#0*lx...", ... sizeof(void *) * 2, tu->offset);

As in:

+ seq_printf(m, "%c:%s/%s %s:%#0*lx", c, tu->tp.call.class->system,
+ trace_event_name(&tu->tp.call), tu->filename,
+ sizeof(void *) * 2, tu->offset);

-Kees

Quoted 6 lines
kernel/trace/trace_uprobe.c +0 -1
        for (i = 0; i < tu->tp.nr_args; i++)
                seq_printf(m, " %s=%s", tu->tp.args[i].name, tu->tp.args[i].comm);
--

2.13.6

Signature · 2 lines
Kees Cook
Pixel Security
#4 lore raw

Re: [PATCH 2/2] trace_uprobe: Simplify probes_seq_show()

Quoted 45 lines · Kees Cook
Quoted 27 lines · Ravi Bangoria

Simplify probes_seq_show() function. We are using %lx to display the offset and we don't prepend unnecessary 0s in the offset.

---
 kernel/trace/trace_uprobe.c | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)
kernel/trace/trace_uprobe.c +0 -11
index c2c965398893..c12a3957e1ee 100644
@@ -602,24 +602,9 @@ static int probes_seq_show(struct seq_file *m, void *v)
        char c = is_ret_probe(tu) ? 'r' : 'p';
        int i;
 
-       seq_printf(m, "%c:%s/%s", c, tu->tp.call.class->system,
-                       trace_event_name(&tu->tp.call));
-       seq_printf(m, " %s:", tu->filename);
-
-       /* Don't print "0x  (null)" when offset is 0 */
-       if (tu->offset) {
-               seq_printf(m, "0x%lx", tu->offset);
-       } else {
-               switch (sizeof(void *)) {
-               case 4:
-                       seq_printf(m, "0x00000000");

kernel/trace/trace_uprobe.c static int probes_seq_show(struct seq_file *m, void *v) · line 607

Quoted 10 lines
kernel/trace/trace_uprobe.c +3 -7
-                       break;
-               case 8:
-               default:
-                       seq_printf(m, "0x0000000000000000");
-                       break;
-               }
-       }
+       seq_printf(m, "%c:%s/%s %s:0x%lx", c, tu->tp.call.class->system,
+                       trace_event_name(&tu->tp.call), tu->filename,
+                       tu->offset);

To keep the prepended zeros (and avoid the redundant 0x prefix):

"...%#0*lx...", ... sizeof(void *) * 2, tu->offset);

As in:

Review

Quoted 3 lines
(quoted diff) +3 -0
+       seq_printf(m, "%c:%s/%s %s:%#0*lx", c, tu->tp.call.class->system,
+                       trace_event_name(&tu->tp.call), tu->filename,
+                       sizeof(void *) * 2, tu->offset);

This is useful, thanks Kees.

@Wang, Do we really need those 0s? Won't just 0x0 should suffice? Here is the sample output...

  # echo "p:probe_a/main /tmp/a.out:0x0" > uprobe_events

Before patch:

  # cat uprobe_events
    p:probe_a/main /tmp/a.out:0x0000000000000000

After patch:

  # cat uprobe_events
    p:probe_a/main /tmp/a.out:0x0

Thanks,
Ravi

Quoted 9 lines

-Kees

Quoted 5 lines
kernel/trace/trace_uprobe.c +0 -1
        for (i = 0; i < tu->tp.nr_args; i++)
                seq_printf(m, " %s=%s", tu->tp.args[i].name, tu->tp.args[i].comm);
--

2.13.6

#5 lore raw

Re: [PATCH 2/2] trace_uprobe: Simplify probes_seq_show()

Quoted 57 lines · Ravi Bangoria
Quoted 45 lines · Kees Cook
Quoted 27 lines · Ravi Bangoria

Simplify probes_seq_show() function. We are using %lx to display the offset and we don't prepend unnecessary 0s in the offset.

---
 kernel/trace/trace_uprobe.c | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)
kernel/trace/trace_uprobe.c +0 -11
index c2c965398893..c12a3957e1ee 100644
@@ -602,24 +602,9 @@ static int probes_seq_show(struct seq_file *m, void *v)
        char c = is_ret_probe(tu) ? 'r' : 'p';
        int i;
 
-       seq_printf(m, "%c:%s/%s", c, tu->tp.call.class->system,
-                       trace_event_name(&tu->tp.call));
-       seq_printf(m, " %s:", tu->filename);
-
-       /* Don't print "0x  (null)" when offset is 0 */
-       if (tu->offset) {
-               seq_printf(m, "0x%lx", tu->offset);
-       } else {
-               switch (sizeof(void *)) {
-               case 4:
-                       seq_printf(m, "0x00000000");

kernel/trace/trace_uprobe.c static int probes_seq_show(struct seq_file *m, void *v) · line 607

Quoted 10 lines
kernel/trace/trace_uprobe.c +3 -7
-                       break;
-               case 8:
-               default:
-                       seq_printf(m, "0x0000000000000000");
-                       break;
-               }
-       }
+       seq_printf(m, "%c:%s/%s %s:0x%lx", c, tu->tp.call.class->system,
+                       trace_event_name(&tu->tp.call), tu->filename,
+                       tu->offset);

To keep the prepended zeros (and avoid the redundant 0x prefix):

"...%#0*lx...", ... sizeof(void *) * 2, tu->offset);

As in:

Review

Quoted 3 lines
(quoted diff) +3 -0
+       seq_printf(m, "%c:%s/%s %s:%#0*lx", c, tu->tp.call.class->system,
+                       trace_event_name(&tu->tp.call), tu->filename,
+                       sizeof(void *) * 2, tu->offset);

This is useful, thanks Kees.

@Wang, Do we really need those 0s? Won't just 0x0 should suffice? Here is the sample output...

  # echo "p:probe_a/main /tmp/a.out:0x0" > uprobe_events
Quoted 7 lines

Before patch:

  # cat uprobe_events
    p:probe_a/main /tmp/a.out:0x0000000000000000

After patch:

  # cat uprobe_events
    p:probe_a/main /tmp/a.out:0x0

Wang, ping :)

Kees, I don't hear back from Wang and no one has reported any issues with the patches yet. Can I have your Acked-by?

Thanks,
Ravi

#6 lore raw

Re: [PATCH 2/2] trace_uprobe: Simplify probes_seq_show()

Quoted 64 lines · Ravi Bangoria
Quoted 61 lines · Ravi Bangoria
Quoted 45 lines · Kees Cook
Quoted 27 lines · Ravi Bangoria

Simplify probes_seq_show() function. We are using %lx to display the offset and we don't prepend unnecessary 0s in the offset.

---
 kernel/trace/trace_uprobe.c | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)
kernel/trace/trace_uprobe.c +0 -11
index c2c965398893..c12a3957e1ee 100644
@@ -602,24 +602,9 @@ static int probes_seq_show(struct seq_file *m, void *v)
        char c = is_ret_probe(tu) ? 'r' : 'p';
        int i;
 
-       seq_printf(m, "%c:%s/%s", c, tu->tp.call.class->system,
-                       trace_event_name(&tu->tp.call));
-       seq_printf(m, " %s:", tu->filename);
-
-       /* Don't print "0x  (null)" when offset is 0 */
-       if (tu->offset) {
-               seq_printf(m, "0x%lx", tu->offset);
-       } else {
-               switch (sizeof(void *)) {
-               case 4:
-                       seq_printf(m, "0x00000000");

kernel/trace/trace_uprobe.c static int probes_seq_show(struct seq_file *m, void *v) · line 607

Quoted 10 lines
kernel/trace/trace_uprobe.c +3 -7
-                       break;
-               case 8:
-               default:
-                       seq_printf(m, "0x0000000000000000");
-                       break;
-               }
-       }
+       seq_printf(m, "%c:%s/%s %s:0x%lx", c, tu->tp.call.class->system,
+                       trace_event_name(&tu->tp.call), tu->filename,
+                       tu->offset);

To keep the prepended zeros (and avoid the redundant 0x prefix):

"...%#0*lx...", ... sizeof(void *) * 2, tu->offset);

As in:

Review

Quoted 3 lines
(quoted diff) +3 -0
+       seq_printf(m, "%c:%s/%s %s:%#0*lx", c, tu->tp.call.class->system,
+                       trace_event_name(&tu->tp.call), tu->filename,
+                       sizeof(void *) * 2, tu->offset);

This is useful, thanks Kees.

@Wang, Do we really need those 0s? Won't just 0x0 should suffice? Here is the sample output...

  # echo "p:probe_a/main /tmp/a.out:0x0" > uprobe_events

Before patch:

  # cat uprobe_events
    p:probe_a/main /tmp/a.out:0x0000000000000000
Quoted 8 lines
Quoted 3 lines

After patch:

  # cat uprobe_events
    p:probe_a/main /tmp/a.out:0x0

Wang, ping :)

Kees, I don't hear back from Wang and no one has reported any issues with the patches yet. Can I have your Acked-by?

I didn't see a v2 of these patches with the output fixed?

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
#7 lore raw

Re: [PATCH 2/2] trace_uprobe: Simplify probes_seq_show()

Quoted 9 lines · Kees Cook
Quoted 6 lines · Ravi Bangoria
Quoted 4 lines · Ravi Bangoria

Wang, ping :)

Kees, I don't hear back from Wang and no one has reported any issues with the patches yet. Can I have your Acked-by?

I didn't see a v2 of these patches with the output fixed?

Kees, I didn't send v2 because those 0s seems unnecessary to me.

Please let me know if you still wants to show them. Will re-spin :)

Thanks,
Ravi

PS: Changing Masami's email address in cc.

#8 lore raw

Re: [PATCH 2/2] trace_uprobe: Simplify probes_seq_show()

Quoted 6 lines · Ravi Bangoria
Quoted 3 lines · Kees Cook
Quoted 1 line · Ravi Bangoria
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines · Ravi Bangoria
Quoted 4 lines

Wang, ping :)

Kees, I don't hear back from Wang and no one has reported any issues with the patches yet. Can I have your Acked-by?

I didn't see a v2 of these patches with the output fixed?

Kees, I didn't send v2 because those 0s seems unnecessary to me.

Oh, okay. I don't care either way. That's up to whoever consumes that output. Usually it's bad form to change formatting for a userspace API, but if nothing cares, then sure. :)

Quoted 1 line

Please let me know if you still wants to show them. Will re-spin :)

AIUI, it's "safer" to include them since that's what it did before.

-Kees

Quoted 6 lines

Thanks,
Ravi

PS: Changing Masami's email address in cc.

Signature · 2 lines
Kees Cook
Pixel Security