Skip to contentSkip to conversation

tracing/synthetic: Fix order of struct trace_dynamic_info

PATCH RESEND In review Steven Rostedt 3 participants 4 messages Sep 8, 2023 – Sep 12, 2023 Tracing

lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH RESEND 1/1 tracing/synthetic: Fix order of struct trace_dynamic_info

From: "Steven Rostedt (Google)" <[email protected]>

To make handling BIG and LITTLE endian better the offset/len of dynamic fields of the synthetic events was changed into a structure of:

struct trace_dynamic_info {

 #ifdef CONFIG_CPU_BIG_ENDIAN
	u16	offset;
	u16	len;
 #else
	u16	len;
	u16	offset;

#endif
};

to replace the manual changes of:

data_offset = offset & 0xffff;
data_offest = len << 16;

But if you look closely, the above is:

<len> << 16 | offset

Which in little endian would be in memory:

offset_lo offset_hi len_lo len_hi

and in big endian:

len_hi len_lo offset_hi offset_lo

Which if broken into a structure would be:

struct trace_dynamic_info {

 #ifdef CONFIG_CPU_BIG_ENDIAN
	u16	len;
	u16	offset;
 #else
	u16	offset;
	u16	len;

#endif
};

Which is the opposite of what was defined.

Fix this and just to be safe also add "__packed".

Fixes ddeea494a16f3 ("tracing/synthetic: Use union instead of casts")

---

[ Resending to the correct mailing list this time :-p ]

 include/linux/trace_events.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/trace_events.h +3 -3
index 12f875e9e69a..21ae37e49319 100644
@@ -62,13 +62,13 @@ void trace_event_printf(struct trace_iterator *iter, const char *fmt, ...);
 /* Used to find the offset and length of dynamic fields in trace events */
 struct trace_dynamic_info {
 #ifdef CONFIG_CPU_BIG_ENDIAN
-	u16	offset;
 	u16	len;
+	u16	offset;
 #else
-	u16	len;
 	u16	offset;
+	u16	len;
 #endif
-};
+} __packed;
 
 /*
  * The trace entry - the most basic unit of tracing. This is what
Signature · 1 line
2.40.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 41 lines · On Fri, 8 Sep 2023 16:39:29 -0400 Steven Rostedt <[email protected]> wrote:

From: "Steven Rostedt (Google)" <[email protected]>

To make handling BIG and LITTLE endian better the offset/len of dynamic fields of the synthetic events was changed into a structure of:

struct trace_dynamic_info {

 #ifdef CONFIG_CPU_BIG_ENDIAN
	u16	offset;
	u16	len;
 #else
	u16	len;
	u16	offset;

#endif
};

to replace the manual changes of:

data_offset = offset & 0xffff;
data_offest = len << 16;

But if you look closely, the above is:

<len> << 16 | offset

Which in little endian would be in memory:

offset_lo offset_hi len_lo len_hi

and in big endian:

len_hi len_lo offset_hi offset_lo

Which if broken into a structure would be:

struct trace_dynamic_info {

 #ifdef CONFIG_CPU_BIG_ENDIAN
	u16	len;
	u16	offset;
 #else
	u16	offset;
	u16	len;
Quoted 8 lines

#endif
};

Which is the opposite of what was defined.

Fix this and just to be safe also add "__packed".

Good catch! I'm not sure why this worked. Maybe we don't have any testcase for this feature?

Thank you,

Quoted 35 lines
Fixes ddeea494a16f3 ("tracing/synthetic: Use union instead of casts")

---

[ Resending to the correct mailing list this time :-p ]

 include/linux/trace_events.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/trace_events.h +3 -3
index 12f875e9e69a..21ae37e49319 100644
@@ -62,13 +62,13 @@ void trace_event_printf(struct trace_iterator *iter, const char *fmt, ...);
 /* Used to find the offset and length of dynamic fields in trace events */
 struct trace_dynamic_info {
 #ifdef CONFIG_CPU_BIG_ENDIAN
-	u16	offset;
 	u16	len;
+	u16	offset;
 #else
-	u16	len;
 	u16	offset;
+	u16	len;
 #endif
-};
+} __packed;
 
 /*
  * The trace entry - the most basic unit of tracing. This is what
Signature · 1 line
2.40.1
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
author maintainer
#2 lore raw
Quoted 6 lines · On Mon, 11 Sep 2023 09:26:12 +0900 Masami Hiramatsu (Google)…
Quoted 3 lines

Fix this and just to be safe also add "__packed".

Good catch! I'm not sure why this worked. Maybe we don't have any testcase for this feature?

We have a test case, it was broken by a change in the README :-p

I noticed issues with it, and then looked at the tests, fixed the test and it failed. Before that, it was just reporting "unsupported", which is why I included that fix with this queue.

https://lore.kernel.org/linux-trace-kernel/[email protected]/

Quoted 2 lines

Thanks!

-- Steve

Tested-by on v1 1/1
#3 lore raw
In reply to Steven Rostedt

Hi Steven,

Quoted 71 lines · Steven Rostedt

From: "Steven Rostedt (Google)" <[email protected]>

To make handling BIG and LITTLE endian better the offset/len of dynamic fields of the synthetic events was changed into a structure of:

struct trace_dynamic_info {

 #ifdef CONFIG_CPU_BIG_ENDIAN
	u16	offset;
	u16	len;
 #else
	u16	len;
	u16	offset;

#endif
};

to replace the manual changes of:

data_offset = offset & 0xffff;
data_offest = len << 16;

But if you look closely, the above is:

<len> << 16 | offset

Which in little endian would be in memory:

offset_lo offset_hi len_lo len_hi

and in big endian:

len_hi len_lo offset_hi offset_lo

Which if broken into a structure would be:

struct trace_dynamic_info {

 #ifdef CONFIG_CPU_BIG_ENDIAN
	u16	len;
	u16	offset;
 #else
	u16	offset;
	u16	len;

#endif
};

Which is the opposite of what was defined.

Fix this and just to be safe also add "__packed".

Fixes ddeea494a16f3 ("tracing/synthetic: Use union instead of casts")

---

[ Resending to the correct mailing list this time :-p ]

 include/linux/trace_events.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/trace_events.h +1 -1
index 12f875e9e69a..21ae37e49319 100644
@@ -62,13 +62,13 @@ void trace_event_printf(struct trace_iterator *iter, const char *fmt, ...);
 /* Used to find the offset and length of dynamic fields in trace events */
 struct trace_dynamic_info {
 #ifdef CONFIG_CPU_BIG_ENDIAN
-	u16	offset;
 	u16	len;
+	u16	offset;

include/linux/trace_events.h void trace_event_printf(struct trace_iterator *iter, const char *fmt, ...); · line 74

Quoted 10 lines
include/linux/trace_events.h +2 -2
 #else
-	u16	len;
 	u16	offset;
+	u16	len;
 #endif
-};
+} __packed;
 
 /*
  * The trace entry - the most basic unit of tracing. This is what

This issue was also present on BE, but as you noted "covered" by the broken test case. With this patch everything works as expected. So: