Blame SOURCES/0002-extensions-trace-Rename-trace_buffer-to-array_buffer.patch

085f43
From c4cdbe3c18bca496dc6b4af17e2637379528ad02 Mon Sep 17 00:00:00 2001
085f43
From: Valentin Schneider <valentin.schneider@arm.com>
085f43
Date: Thu, 3 Sep 2020 21:28:46 +0100
085f43
Subject: [PATCH 2/3] extensions/trace: Rename trace_buffer to array_buffer
085f43
085f43
This renaming is present from Linux v5.6 upwards, and was introduced by
085f43
commit:
085f43
085f43
  1c5eb4481e01 ("tracing: Rename trace_buffer to array_buffer")
085f43
085f43
Rename the internal references from trace_buffer to array_buffer. Backwards
085f43
compatibility with older kernels is provided by checking whether struct
085f43
trace_array has an array_buffer field - should that not be the case, the
085f43
old naming scheme is used instead.
085f43
085f43
Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
085f43
---
085f43
 trace.c | 53 +++++++++++++++++++++++++++++++++++------------------
085f43
 1 file changed, 35 insertions(+), 18 deletions(-)
085f43
085f43
diff --git a/trace.c b/trace.c
085f43
index c26b6c7ec475..2cea5b2d650a 100644
085f43
--- a/trace.c
085f43
+++ b/trace.c
085f43
@@ -31,9 +31,9 @@ static int per_cpu_buffer_sizes;
085f43
  */
085f43
 static int encapsulated_current_trace;
085f43
 /*
085f43
- * trace_buffer is supported
085f43
+ * array_buffer (trace_buffer pre v5.6) is supported
085f43
  */
085f43
-static int trace_buffer_available;
085f43
+static int array_buffer_available;
085f43
 /*
085f43
  * max_buffer is supported
085f43
  */
085f43
@@ -51,9 +51,9 @@ static int buffer_page_real_end_available;
085f43
 #define koffset(struct, member) struct##_##member##_offset
085f43
 
085f43
 static int koffset(trace_array, current_trace);
085f43
-static int koffset(trace_array, trace_buffer);
085f43
+static int koffset(trace_array, array_buffer);
085f43
 static int koffset(trace_array, max_buffer);
085f43
-static int koffset(trace_buffer, buffer);
085f43
+static int koffset(array_buffer, buffer);
085f43
 static int koffset(trace_array, buffer);
085f43
 static int koffset(tracer, name);
085f43
 
085f43
@@ -117,7 +117,7 @@ static ulong max_tr_trace;
085f43
 
085f43
 struct trace_instance {
085f43
 	char name[NAME_MAX + 1];
085f43
-	ulong trace_buffer;
085f43
+	ulong array_buffer;
085f43
 	ulong max_buffer;
085f43
 	ulong ring_buffer;
085f43
 	unsigned pages;
085f43
@@ -174,8 +174,7 @@ static int write_and_check(int fd, void *data, size_t size)
085f43
 
085f43
 static int init_offsets(void)
085f43
 {
085f43
-#define init_offset(struct, member) do {				\
085f43
-		koffset(struct, member) = MEMBER_OFFSET(#struct, #member);\
085f43
+#define check_offset(struct, member) do { \
085f43
 		if (koffset(struct, member) < 0) {			\
085f43
 			fprintf(fp, "failed to init the offset, struct:"\
085f43
 				#struct ", member:" #member);		\
085f43
@@ -184,12 +183,29 @@ static int init_offsets(void)
085f43
 		}							\
085f43
 	} while (0)
085f43
 
085f43
+#define init_offset(struct, member) do {				\
085f43
+		koffset(struct, member) = MEMBER_OFFSET(#struct, #member); \
085f43
+		check_offset(struct, member);				\
085f43
+	} while (0)
085f43
+
085f43
+#define init_offset_alternative(struct, member, alt_struct, alt_member) do {	\
085f43
+		koffset(struct, member) = MEMBER_OFFSET(#alt_struct, #alt_member); \
085f43
+		check_offset(struct, member);				\
085f43
+	} while (0)
085f43
+
085f43
 	if (encapsulated_current_trace)
085f43
 		init_offset(trace_array, current_trace);
085f43
 
085f43
-	if (trace_buffer_available) {
085f43
-		init_offset(trace_array, trace_buffer);
085f43
-		init_offset(trace_buffer, buffer);
085f43
+	if (array_buffer_available) {
085f43
+		if (MEMBER_EXISTS("trace_array", "array_buffer")) {
085f43
+			init_offset(trace_array, array_buffer);
085f43
+			init_offset(array_buffer, buffer);
085f43
+		} else {
085f43
+			init_offset_alternative(trace_array, array_buffer,
085f43
+						trace_array, trace_buffer);
085f43
+			init_offset_alternative(array_buffer, buffer,
085f43
+						trace_buffer, buffer);
085f43
+		}
085f43
 
085f43
 		if (max_buffer_available)
085f43
 			init_offset(trace_array, max_buffer);
085f43
@@ -486,17 +502,17 @@ out_fail:
085f43
 
085f43
 static int ftrace_init_trace(struct trace_instance *ti, ulong instance_addr)
085f43
 {
085f43
-	if (trace_buffer_available) {
085f43
-		ti->trace_buffer = instance_addr +
085f43
-				koffset(trace_array, trace_buffer);
085f43
-		read_value(ti->ring_buffer, ti->trace_buffer,
085f43
-				trace_buffer, buffer);
085f43
+	if (array_buffer_available) {
085f43
+		ti->array_buffer = instance_addr +
085f43
+				koffset(trace_array, array_buffer);
085f43
+		read_value(ti->ring_buffer, ti->array_buffer,
085f43
+			   array_buffer, buffer);
085f43
 
085f43
 		if (max_buffer_available) {
085f43
 			ti->max_buffer = instance_addr +
085f43
 					koffset(trace_array, max_buffer);
085f43
 			read_value(ti->max_tr_ring_buffer, ti->max_buffer,
085f43
-					trace_buffer, buffer);
085f43
+					array_buffer, buffer);
085f43
 		}
085f43
 	} else {
085f43
 		read_value(ti->ring_buffer, instance_addr, trace_array, buffer);
085f43
@@ -683,8 +699,9 @@ static int ftrace_init(void)
085f43
 		current_trace = sym_current_trace->value;
085f43
 	}
085f43
 
085f43
-	if (MEMBER_EXISTS("trace_array", "trace_buffer")) {
085f43
-		trace_buffer_available = 1;
085f43
+	if (MEMBER_EXISTS("trace_array", "array_buffer") ||
085f43
+	    MEMBER_EXISTS("trace_array", "trace_buffer")) {
085f43
+		array_buffer_available = 1;
085f43
 
085f43
 		if (MEMBER_EXISTS("trace_array", "max_buffer"))
085f43
 			max_buffer_available = 1;
085f43
-- 
085f43
2.17.1
085f43