Skip to contentSkip to conversation

perf_events: fix ordering bug in perf_output_sample()

PATCH NAK Stephane Eranian 2 participants 4 messages Mar 18, 2010 – Mar 19, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf_events: fix ordering bug in perf_output_sample()

In order to parse a sample correctly based on the information requested via sample_type, the kernel needs to save each component in a known order. There is no type value saved with each component. The current convention is that each component is saved according to the order in enum perf_event_sample_format. But perf_output_sample() was not completely following this convention, thereby making samples impossible to parse without internal kernel knowledge.

This patch puts things in the right order.

--

 perf_event.c |   24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
kernel/perf_event.c +12 -12
index 455393e..b35df1d 100644
@@ -3167,18 +3167,6 @@ void perf_output_sample(struct perf_output_handle *handle,
 	if (sample_type & PERF_SAMPLE_ADDR)
 		perf_output_put(handle, data->addr);
 
-	if (sample_type & PERF_SAMPLE_ID)
-		perf_output_put(handle, data->id);
-
-	if (sample_type & PERF_SAMPLE_STREAM_ID)
-		perf_output_put(handle, data->stream_id);
-
-	if (sample_type & PERF_SAMPLE_CPU)
-		perf_output_put(handle, data->cpu_entry);
-
-	if (sample_type & PERF_SAMPLE_PERIOD)
-		perf_output_put(handle, data->period);
-
 	if (sample_type & PERF_SAMPLE_READ)
 		perf_output_read(handle, event);
 
@@ -3198,6 +3186,18 @@ void perf_output_sample(struct perf_output_handle *handle,
 		}
 	}
 
+	if (sample_type & PERF_SAMPLE_ID)
+		perf_output_put(handle, data->id);
+
+	if (sample_type & PERF_SAMPLE_CPU)
+		perf_output_put(handle, data->cpu_entry);
+
+	if (sample_type & PERF_SAMPLE_STREAM_ID)
+		perf_output_put(handle, data->stream_id);
+
+	if (sample_type & PERF_SAMPLE_PERIOD)
+		perf_output_put(handle, data->period);
+
 	if (sample_type & PERF_SAMPLE_RAW) {
 		if (data->raw) {
 			perf_output_put(handle, data->raw->size);
#1 lore raw
Quoted 9 lines · Stephane Eranian

In order to parse a sample correctly based on the information requested via sample_type, the kernel needs to save each component in a known order. There is no type value saved with each component. The current convention is that each component is saved according to the order in enum perf_event_sample_format. But perf_output_sample() was not completely following this convention, thereby making samples impossible to parse without internal kernel knowledge.

This patch puts things in the right order.

NAK, not so actually, its in the order specified in the PERF_RECORD_SAMPLE comment.

#2 lore raw
Quoted 9 lines · Peter Zijlstra
Quoted 8 lines · Stephane Eranian

      In order to parse a sample correctly based on the information requested via sample_type, the kernel needs to save each component in a known order. There is no type value saved with each component. The current convention is that each component is saved according to the order in enum perf_event_sample_format. But perf_output_sample() was not completely following this convention, thereby making samples impossible to parse without internal kernel knowledge.

Quoted 5 lines
Quoted 1 line

      This patch puts things in the right order.

NAK, not so actually, its in the order specified in the PERF_RECORD_SAMPLE comment.

And why is that order different than the one in the enum?

#3 lore raw
Quoted 10 lines · Stephane Eranian
Quoted 9 lines · Peter Zijlstra
Quoted 8 lines · Stephane Eranian

In order to parse a sample correctly based on the information requested via sample_type, the kernel needs to save each component in a known order. There is no type value saved with each component. The current convention is that each component is saved according to the order in enum perf_event_sample_format. But perf_output_sample() was not completely following this convention, thereby making samples impossible to parse without internal kernel knowledge.

Quoted 6 lines
Quoted 5 lines
Quoted 1 line

This patch puts things in the right order.

NAK, not so actually, its in the order specified in the PERF_RECORD_SAMPLE comment.

And why is that order different than the one in the enum?

Because I tried to keep the simple elements before the complex ones, but in any case its too late to change any ordering there now, as its ABI.