All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v2 0/4] tracing: improve symbolic printing
@ 2024-03-26 19:15 Johannes Berg
  2024-03-26 19:15 ` [RFC PATCH v2 1/4] tracing: add __print_sym() to replace __print_symbolic() Johannes Berg
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Johannes Berg @ 2024-03-26 19:15 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-trace-kernel, netdev, linux-wireless

As I mentioned before, it's annoying to see this in dropreason tracing
with trace-cmd:

 irq/65-iwlwifi:-401   [000]    22.790000: kfree_skb:            skbaddr=0x6a89b000 protocol=0 location=ieee80211_rx_handlers_result+0x21a reason: 0x20000

and much nicer to see

 irq/65-iwlwifi:-401   [000]    22.790000: kfree_skb:            skbaddr=0x69142000 protocol=0 location=ieee80211_rx_handlers_result+0x21a reason: RX_DROP_MONITOR

The reason for this is that the __print_symbolic() string in tracing
for trace-cmd to parse it is created at build-time, from the long list
of _core_ drop reasons, but the drop reasons are now more dynamic.

So I came up with __print_sym() which is similar, except it doesn't
build the big list of numbers at build time but rather at runtime,
which is actually a big memory saving too. But building it then, at
the time userspace is recording it, lets us include all the known
reasons.

v2:
 - rebased on 6.9-rc1
 - always search for __print_sym() and get rid of the DYNPRINT flag
   and associated code; I think ideally we'll just remove the older
   __print_symbolic() entirely
 - use ':' as the separator instead of "//" since that makes searching
   for it much easier and it's still not a valid char in an identifier
 - fix RCU

johannes


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

* [RFC PATCH v2 1/4] tracing: add __print_sym() to replace __print_symbolic()
  2024-03-26 19:15 [RFC PATCH v2 0/4] tracing: improve symbolic printing Johannes Berg
@ 2024-03-26 19:15 ` Johannes Berg
  2024-03-27  4:21   ` kernel test robot
                     ` (2 more replies)
  2024-03-26 19:15 ` [RFC PATCH v2 2/4] net: dropreason: use new __print_sym() in tracing Johannes Berg
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 10+ messages in thread
From: Johannes Berg @ 2024-03-26 19:15 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-trace-kernel, netdev, linux-wireless, Johannes Berg

From: Johannes Berg <johannes.berg@intel.com>

The way __print_symbolic() works is limited and inefficient
in multiple ways:
 - you can only use it with a static list of symbols, but
   e.g. the SKB dropreasons are now a dynamic list

 - it builds the list in memory _three_ times, so it takes
   a lot of memory:
   - The print_fmt contains the list (since it's passed to
     the macro there). This actually contains the names
     _twice_, which is fixed up at runtime.
   - TRACE_DEFINE_ENUM() puts a 24-byte struct trace_eval_map
     for every entry, plus the string pointed to by it, which
     cannot be deduplicated with the strings in the print_fmt
   - The in-kernel symbolic printing creates yet another list
     of struct trace_print_flags for trace_print_symbols_seq()

 - it also requires runtime fixup during init, which is a lot
   of string parsing due to the print_fmt fixup

Introduce __print_sym() to - over time - replace the old one.
We can easily extend this also to __print_flags later, but I
cared only about the SKB dropreasons for now, which has only
__print_symbolic().

This new __print_sym() requires only a single list of items,
created by TRACE_DEFINE_SYM_LIST(), or can even use another
already existing list by using TRACE_DEFINE_SYM_FNS() with
lookup and show methods.

Then, instead of doing an init-time fixup, just do this at the
time when userspace reads the print_fmt. This way, dynamically
updated lists are possible.

For userspace, nothing actually changes, because the print_fmt
is shown exactly the same way the old __print_symbolic() was.

This adds about 4k .text in my test builds, but that'll be
more than paid for by the actual conversions.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
v2:
 - fix RCU
 - use ':' as separator to simplify the code, that's
   still not valid in a C identifier
---
 include/asm-generic/vmlinux.lds.h          |  3 +-
 include/linux/module.h                     |  2 +
 include/linux/trace_events.h               |  7 ++
 include/linux/tracepoint.h                 | 20 +++++
 include/trace/stages/init.h                | 54 +++++++++++++
 include/trace/stages/stage2_data_offsets.h |  6 ++
 include/trace/stages/stage3_trace_output.h |  9 +++
 include/trace/stages/stage7_class_define.h |  3 +
 kernel/module/main.c                       |  3 +
 kernel/trace/trace_events.c                | 90 +++++++++++++++++++++-
 kernel/trace/trace_output.c                | 45 +++++++++++
 11 files changed, 239 insertions(+), 3 deletions(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index f7749d0f2562..88de434578a5 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -256,7 +256,8 @@
 #define FTRACE_EVENTS()							\
 	. = ALIGN(8);							\
 	BOUNDED_SECTION(_ftrace_events)					\
-	BOUNDED_SECTION_BY(_ftrace_eval_map, _ftrace_eval_maps)
+	BOUNDED_SECTION_BY(_ftrace_eval_map, _ftrace_eval_maps)		\
+	BOUNDED_SECTION(_ftrace_sym_defs)
 #else
 #define FTRACE_EVENTS()
 #endif
diff --git a/include/linux/module.h b/include/linux/module.h
index 1153b0d99a80..571e5e8f17b6 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -524,6 +524,8 @@ struct module {
 	unsigned int num_trace_events;
 	struct trace_eval_map **trace_evals;
 	unsigned int num_trace_evals;
+	struct trace_sym_def **trace_sym_defs;
+	unsigned int num_trace_sym_defs;
 #endif
 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
 	unsigned int num_ftrace_callsites;
diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index 6f9bdfb09d1d..bc7045d535d0 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -27,6 +27,13 @@ const char *trace_print_flags_seq(struct trace_seq *p, const char *delim,
 const char *trace_print_symbols_seq(struct trace_seq *p, unsigned long val,
 				    const struct trace_print_flags *symbol_array);
 
+const char *trace_print_sym_seq(struct trace_seq *p, unsigned long long val,
+				const char *(*lookup)(unsigned long long val));
+const char *trace_sym_lookup(const struct trace_sym_entry *list,
+			     size_t len, unsigned long long value);
+void trace_sym_show(struct seq_file *m,
+		    const struct trace_sym_entry *list, size_t len);
+
 #if BITS_PER_LONG == 32
 const char *trace_print_flags_seq_u64(struct trace_seq *p, const char *delim,
 		      unsigned long long flags,
diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
index 689b6d71590e..cc3b387953d1 100644
--- a/include/linux/tracepoint.h
+++ b/include/linux/tracepoint.h
@@ -31,6 +31,24 @@ struct trace_eval_map {
 	unsigned long		eval_value;
 };
 
+struct trace_sym_def {
+	const char		*system;
+	const char		*symbol_id;
+	/* may return NULL, called under rcu_read_lock() */
+	const char *		(*lookup)(unsigned long long);
+	/*
+	 * Must print the list: ', { val, "name"}, ...'
+	 * with no trailing comma, but with the leading ', '
+	 * to simplify things:
+	 */
+	void 			(*show)(struct seq_file *);
+};
+
+struct trace_sym_entry {
+	unsigned long long	value;
+	const char		*name;
+};
+
 #define TRACEPOINT_DEFAULT_PRIO	10
 
 extern struct srcu_struct tracepoint_srcu;
@@ -109,6 +127,8 @@ extern void syscall_unregfunc(void);
 
 #define TRACE_DEFINE_ENUM(x)
 #define TRACE_DEFINE_SIZEOF(x)
+#define TRACE_DEFINE_SYM_FNS(...)
+#define TRACE_DEFINE_SYM_LIST(...)
 
 #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
 static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
diff --git a/include/trace/stages/init.h b/include/trace/stages/init.h
index 000bcfc8dd2e..251ab22485d1 100644
--- a/include/trace/stages/init.h
+++ b/include/trace/stages/init.h
@@ -23,6 +23,60 @@ TRACE_MAKE_SYSTEM_STR();
 	__section("_ftrace_eval_map")			\
 	*TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a
 
+/*
+ * Define a symbol for __print_sym by giving lookup and
+ * show functions. See &struct trace_sym_def.
+ */
+#define TRACE_DEFINE_SYM_FNS(_symbol_id, _lookup, _show)		\
+	_TRACE_DEFINE_SYM_FNS(TRACE_SYSTEM, _symbol_id, _lookup, _show)
+#define _TRACE_DEFINE_SYM_FNS(_system, _symbol_id, _lookup, _show)	\
+	__TRACE_DEFINE_SYM_FNS(_system, _symbol_id, _lookup, _show)
+#define __TRACE_DEFINE_SYM_FNS(_system, _symbol_id, _lookup, _show)	\
+	___TRACE_DEFINE_SYM_FNS(_system ## _ ## _symbol_id, _symbol_id,	\
+				_lookup, _show)
+#define ___TRACE_DEFINE_SYM_FNS(_name, _symbol_id, _lookup, _show)	\
+	static struct trace_sym_def					\
+	__trace_sym_def_ ## _name = {					\
+		.system = TRACE_SYSTEM_STRING,				\
+		/* need the ) for later strcmp */			\
+		.symbol_id = #_symbol_id ")",				\
+		.lookup = _lookup,					\
+		.show = _show,						\
+	};								\
+	static struct trace_sym_def 					\
+	__section("_ftrace_sym_defs")					\
+	*__trace_sym_def_p_ ## _name = &__trace_sym_def_ ## _name
+
+/*
+ * Define a symbol for __print_sym by giving lookup and
+ * show functions. See &struct trace_sym_def.
+ */
+#define TRACE_DEFINE_SYM_LIST(_symbol_id, ...)				\
+	_TRACE_DEFINE_SYM_LIST(TRACE_SYSTEM, _symbol_id, __VA_ARGS__)
+#define _TRACE_DEFINE_SYM_LIST(_system, _symbol_id, ...)		\
+	__TRACE_DEFINE_SYM_LIST(_system, _symbol_id, __VA_ARGS__)
+#define __TRACE_DEFINE_SYM_LIST(_system, _symbol_id, ...)		\
+	___TRACE_DEFINE_SYM_LIST(_system ## _ ## _symbol_id, _symbol_id,\
+				 __VA_ARGS__)
+#define ___TRACE_DEFINE_SYM_LIST(_name, _symbol_id, ...)		\
+	static struct trace_sym_entry					\
+	__trace_sym_list_ ## _name[] = { __VA_ARGS__ };			\
+	static const char *						\
+	__trace_sym_lookup_ ## _name(unsigned long long value)		\
+	{								\
+		return trace_sym_lookup(__trace_sym_list_ ## _name,	\
+			ARRAY_SIZE(__trace_sym_list_ ## _name), value);	\
+	}								\
+	static void							\
+	__trace_sym_show_ ## _name(struct seq_file *m)			\
+	{								\
+		trace_sym_show(m, __trace_sym_list_ ## _name,		\
+			       ARRAY_SIZE(__trace_sym_list_ ## _name));	\
+	}								\
+	___TRACE_DEFINE_SYM_FNS(_name, _symbol_id,			\
+				__trace_sym_lookup_ ## _name,		\
+				__trace_sym_show_ ## _name)
+
 #undef TRACE_DEFINE_SIZEOF
 #define TRACE_DEFINE_SIZEOF(a)				\
 	static struct trace_eval_map __used __initdata	\
diff --git a/include/trace/stages/stage2_data_offsets.h b/include/trace/stages/stage2_data_offsets.h
index 8b0cff06d346..5afd9de7deb3 100644
--- a/include/trace/stages/stage2_data_offsets.h
+++ b/include/trace/stages/stage2_data_offsets.h
@@ -5,6 +5,12 @@
 #undef TRACE_DEFINE_ENUM
 #define TRACE_DEFINE_ENUM(a)
 
+#undef TRACE_DEFINE_SYM_FNS
+#define TRACE_DEFINE_SYM_FNS(_symbol_id, _lookup, _show)
+
+#undef TRACE_DEFINE_SYM_LIST
+#define TRACE_DEFINE_SYM_LIST(_symbol_id, ...)
+
 #undef TRACE_DEFINE_SIZEOF
 #define TRACE_DEFINE_SIZEOF(a)
 
diff --git a/include/trace/stages/stage3_trace_output.h b/include/trace/stages/stage3_trace_output.h
index c1fb1355d309..d2c6458b62dc 100644
--- a/include/trace/stages/stage3_trace_output.h
+++ b/include/trace/stages/stage3_trace_output.h
@@ -79,6 +79,15 @@
 		trace_print_symbols_seq(p, value, symbols);		\
 	})
 
+#undef __print_sym
+#define __print_sym(value, symbol_id)					\
+	___print_sym(TRACE_SYSTEM, value, symbol_id)
+#define ___print_sym(sys, value, symbol_id)				\
+	____print_sym(sys, value, symbol_id)
+#define ____print_sym(sys, value, symbol_id)				\
+	trace_print_sym_seq(p, value,					\
+		__trace_sym_def_p_ ## sys ## _ ## symbol_id->lookup)
+
 #undef __print_flags_u64
 #undef __print_symbolic_u64
 #if BITS_PER_LONG == 32
diff --git a/include/trace/stages/stage7_class_define.h b/include/trace/stages/stage7_class_define.h
index bcb960d16fc0..cf552916935f 100644
--- a/include/trace/stages/stage7_class_define.h
+++ b/include/trace/stages/stage7_class_define.h
@@ -25,6 +25,9 @@
 #undef __print_hex_dump
 #undef __get_buf
 
+#undef __print_sym
+#define __print_sym(value, symbol_id)	__print_sym(value:symbol_id)
+
 /*
  * The below is not executed in the kernel. It is only what is
  * displayed in the print format for userspace to parse.
diff --git a/kernel/module/main.c b/kernel/module/main.c
index e1e8a7a9d6c1..babc45cbf1de 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -2161,6 +2161,9 @@ static int find_module_sections(struct module *mod, struct load_info *info)
 	mod->trace_evals = section_objs(info, "_ftrace_eval_map",
 					sizeof(*mod->trace_evals),
 					&mod->num_trace_evals);
+	mod->trace_sym_defs = section_objs(info, "_ftrace_sym_defs",
+					   sizeof(*mod->trace_sym_defs),
+					   &mod->num_trace_sym_defs);
 #endif
 #ifdef CONFIG_TRACING
 	mod->trace_bprintk_fmt_start = section_objs(info, "__trace_printk_fmt",
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 7c364b87352e..24f185836dcc 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1570,6 +1570,93 @@ static void *f_next(struct seq_file *m, void *v, loff_t *pos)
 		return node;
 }
 
+extern struct trace_sym_def *__start_ftrace_sym_defs[];
+extern struct trace_sym_def *__stop_ftrace_sym_defs[];
+
+static void show_sym_list(struct seq_file *m, struct trace_event_call *call,
+			  const char *name)
+{
+	struct trace_sym_def **sym_defs;
+	unsigned int n_sym_defs, i;
+
+	if (call->module) {
+		struct module *mod = call->module;
+
+		sym_defs = mod->trace_sym_defs;
+		n_sym_defs = mod->num_trace_sym_defs;
+	} else {
+		sym_defs = __start_ftrace_sym_defs;
+		n_sym_defs = __stop_ftrace_sym_defs - __start_ftrace_sym_defs;
+	}
+
+	for (i = 0; i < n_sym_defs; i++) {
+		if (!sym_defs[i])
+			continue;
+		if (sym_defs[i]->system != call->class->system)
+			continue;
+		if (strncmp(name, sym_defs[i]->symbol_id,
+			    strlen(sym_defs[i]->symbol_id)))
+			continue;
+		if (sym_defs[i]->show)
+			sym_defs[i]->show(m);
+		break;
+	}
+}
+
+static void show_print_fmt(struct seq_file *m, struct trace_event_call *call)
+{
+	char *ptr = call->print_fmt;
+	bool in_print_sym = false;
+	int quote = 0;
+
+	seq_puts(m, "\nprint fmt: ");
+	while (*ptr) {
+		if (*ptr == '\\') {
+			seq_putc(m, *ptr);
+			ptr++;
+			/* paranoid */
+			if (!*ptr)
+				break;
+			goto next;
+		}
+		if (*ptr == '"') {
+			quote ^= 1;
+			goto next;
+		}
+		if (quote)
+			goto next;
+
+		if (in_print_sym && *ptr != ':')
+			goto next;
+
+		if (in_print_sym && *ptr == ':') {
+			const char *name;
+
+			ptr++;
+			name = ptr;
+			/* skip the name */
+			while (*ptr && *ptr != ')')
+				ptr++;
+			/* and show the actual list inline now */
+			show_sym_list(m, call, name);
+			in_print_sym = false;
+			continue;
+		}
+
+		if (strncmp(ptr, "__print_sym(", 12) == 0) {
+			ptr += 12;
+			seq_puts(m, "__print_symbolic(");
+			in_print_sym = true;
+			continue;
+		}
+next:
+		seq_putc(m, *ptr);
+		ptr++;
+	}
+
+	seq_putc(m, '\n');
+}
+
 static int f_show(struct seq_file *m, void *v)
 {
 	struct trace_event_call *call = event_file_data(m->private);
@@ -1588,8 +1675,7 @@ static int f_show(struct seq_file *m, void *v)
 		return 0;
 
 	case FORMAT_PRINTFMT:
-		seq_printf(m, "\nprint fmt: %s\n",
-			   call->print_fmt);
+		show_print_fmt(m, call);
 		return 0;
 	}
 
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index d8b302d01083..8a3aa661ea46 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -124,6 +124,51 @@ trace_print_symbols_seq(struct trace_seq *p, unsigned long val,
 }
 EXPORT_SYMBOL(trace_print_symbols_seq);
 
+const char *trace_sym_lookup(const struct trace_sym_entry *list,
+			     size_t len, unsigned long long value)
+{
+	size_t i;
+
+	for (i = 0; i < len; i++) {
+		if (list[i].value == value)
+			return list[i].name;
+	}
+	return NULL;
+}
+EXPORT_SYMBOL(trace_sym_lookup);
+
+void trace_sym_show(struct seq_file *m,
+		    const struct trace_sym_entry *list, size_t len)
+{
+	size_t i;
+
+	for (i = 0; i < len; i++)
+		seq_printf(m, ", { %lld, \"%s\" }",
+			   list[i].value, list[i].name);
+}
+EXPORT_SYMBOL(trace_sym_show);
+
+const char *
+trace_print_sym_seq(struct trace_seq *p, unsigned long long val,
+		    const char *(*lookup)(unsigned long long val))
+{
+	const char *ret = trace_seq_buffer_ptr(p);
+	const char *name;
+
+	rcu_read_lock();
+	name = lookup(val);
+	if (name)
+		trace_seq_puts(p, name);
+	else
+		trace_seq_printf(p, "0x%llx", val);
+	rcu_read_unlock();
+
+	trace_seq_putc(p, 0);
+
+	return ret;
+}
+EXPORT_SYMBOL(trace_print_sym_seq);
+
 #if BITS_PER_LONG == 32
 const char *
 trace_print_flags_seq_u64(struct trace_seq *p, const char *delim,
-- 
2.44.0


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

* [RFC PATCH v2 2/4] net: dropreason: use new __print_sym() in tracing
  2024-03-26 19:15 [RFC PATCH v2 0/4] tracing: improve symbolic printing Johannes Berg
  2024-03-26 19:15 ` [RFC PATCH v2 1/4] tracing: add __print_sym() to replace __print_symbolic() Johannes Berg
@ 2024-03-26 19:15 ` Johannes Berg
  2024-03-26 19:15 ` [RFC PATCH v2 3/4] net: drop_monitor: use drop_reason_lookup() Johannes Berg
  2024-03-26 19:15 ` [RFC PATCH v2 4/4] tracing/timer: use __print_sym() Johannes Berg
  3 siblings, 0 replies; 10+ messages in thread
From: Johannes Berg @ 2024-03-26 19:15 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-trace-kernel, netdev, linux-wireless, Johannes Berg

From: Johannes Berg <johannes.berg@intel.com>

The __print_symbolic() could only ever print the core
drop reasons, since that's the way the infrastructure
works. Now that we have __print_sym() with all the
advantages mentioned in that commit, convert to that
and get all the drop reasons from all subsystems. As
we already have a list of them, that's really easy.

This is a little bit of .text (~100 bytes in my build)
and saves a lot of .data (~17k).

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 include/net/dropreason.h   |  5 +++++
 include/trace/events/skb.h | 16 +++-----------
 net/core/skbuff.c          | 43 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/include/net/dropreason.h b/include/net/dropreason.h
index 56cb7be92244..c157070b5303 100644
--- a/include/net/dropreason.h
+++ b/include/net/dropreason.h
@@ -42,6 +42,11 @@ struct drop_reason_list {
 extern const struct drop_reason_list __rcu *
 drop_reasons_by_subsys[SKB_DROP_REASON_SUBSYS_NUM];
 
+#ifdef CONFIG_TRACEPOINTS
+const char *drop_reason_lookup(unsigned long long value);
+void drop_reason_show(struct seq_file *m);
+#endif
+
 void drop_reasons_register_subsys(enum skb_drop_reason_subsys subsys,
 				  const struct drop_reason_list *list);
 void drop_reasons_unregister_subsys(enum skb_drop_reason_subsys subsys);
diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h
index 07e0715628ec..8a1a63f9e796 100644
--- a/include/trace/events/skb.h
+++ b/include/trace/events/skb.h
@@ -8,15 +8,9 @@
 #include <linux/skbuff.h>
 #include <linux/netdevice.h>
 #include <linux/tracepoint.h>
+#include <net/dropreason.h>
 
-#undef FN
-#define FN(reason)	TRACE_DEFINE_ENUM(SKB_DROP_REASON_##reason);
-DEFINE_DROP_REASON(FN, FN)
-
-#undef FN
-#undef FNe
-#define FN(reason)	{ SKB_DROP_REASON_##reason, #reason },
-#define FNe(reason)	{ SKB_DROP_REASON_##reason, #reason }
+TRACE_DEFINE_SYM_FNS(drop_reason, drop_reason_lookup, drop_reason_show);
 
 /*
  * Tracepoint for free an sk_buff:
@@ -44,13 +38,9 @@ TRACE_EVENT(kfree_skb,
 
 	TP_printk("skbaddr=%p protocol=%u location=%pS reason: %s",
 		  __entry->skbaddr, __entry->protocol, __entry->location,
-		  __print_symbolic(__entry->reason,
-				   DEFINE_DROP_REASON(FN, FNe)))
+		  __print_sym(__entry->reason, drop_reason ))
 );
 
-#undef FN
-#undef FNe
-
 TRACE_EVENT(consume_skb,
 
 	TP_PROTO(struct sk_buff *skb, void *location),
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index b99127712e67..012b48da8810 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -147,6 +147,49 @@ drop_reasons_by_subsys[SKB_DROP_REASON_SUBSYS_NUM] = {
 };
 EXPORT_SYMBOL(drop_reasons_by_subsys);
 
+#ifdef CONFIG_TRACEPOINTS
+const char *drop_reason_lookup(unsigned long long value)
+{
+	unsigned long long subsys_id = value >> SKB_DROP_REASON_SUBSYS_SHIFT;
+	u32 reason = value & ~SKB_DROP_REASON_SUBSYS_MASK;
+	const struct drop_reason_list *subsys;
+
+	if (subsys_id >= SKB_DROP_REASON_SUBSYS_NUM)
+		return NULL;
+
+	subsys = rcu_dereference(drop_reasons_by_subsys[subsys_id]);
+	if (!subsys)
+		return NULL;
+	if (reason >= subsys->n_reasons)
+		return NULL;
+	return subsys->reasons[reason];
+}
+
+void drop_reason_show(struct seq_file *m)
+{
+	u32 subsys_id;
+
+	rcu_read_lock();
+	for (subsys_id = 0; subsys_id < SKB_DROP_REASON_SUBSYS_NUM; subsys_id++) {
+		const struct drop_reason_list *subsys;
+		u32 i;
+
+		subsys = rcu_dereference(drop_reasons_by_subsys[subsys_id]);
+		if (!subsys)
+			continue;
+
+		for (i = 0; i < subsys->n_reasons; i++) {
+			if (!subsys->reasons[i])
+				continue;
+			seq_printf(m, ", { %u, \"%s\" }",
+				   (subsys_id << SKB_DROP_REASON_SUBSYS_SHIFT) | i,
+				   subsys->reasons[i]);
+		}
+	}
+	rcu_read_unlock();
+}
+#endif
+
 /**
  * drop_reasons_register_subsys - register another drop reason subsystem
  * @subsys: the subsystem to register, must not be the core
-- 
2.44.0


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

* [RFC PATCH v2 3/4] net: drop_monitor: use drop_reason_lookup()
  2024-03-26 19:15 [RFC PATCH v2 0/4] tracing: improve symbolic printing Johannes Berg
  2024-03-26 19:15 ` [RFC PATCH v2 1/4] tracing: add __print_sym() to replace __print_symbolic() Johannes Berg
  2024-03-26 19:15 ` [RFC PATCH v2 2/4] net: dropreason: use new __print_sym() in tracing Johannes Berg
@ 2024-03-26 19:15 ` Johannes Berg
  2024-03-27  4:21   ` kernel test robot
  2024-03-26 19:15 ` [RFC PATCH v2 4/4] tracing/timer: use __print_sym() Johannes Berg
  3 siblings, 1 reply; 10+ messages in thread
From: Johannes Berg @ 2024-03-26 19:15 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-trace-kernel, netdev, linux-wireless, Johannes Berg

From: Johannes Berg <johannes.berg@intel.com>

Now that we have drop_reason_lookup(), we can just use it for
drop_monitor as well, rather than exporting the list itself.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 include/net/dropreason.h |  4 ----
 net/core/drop_monitor.c  | 18 +++---------------
 net/core/skbuff.c        |  6 +++---
 3 files changed, 6 insertions(+), 22 deletions(-)

diff --git a/include/net/dropreason.h b/include/net/dropreason.h
index c157070b5303..0e2195ccf2cd 100644
--- a/include/net/dropreason.h
+++ b/include/net/dropreason.h
@@ -38,10 +38,6 @@ struct drop_reason_list {
 	size_t n_reasons;
 };
 
-/* Note: due to dynamic registrations, access must be under RCU */
-extern const struct drop_reason_list __rcu *
-drop_reasons_by_subsys[SKB_DROP_REASON_SUBSYS_NUM];
-
 #ifdef CONFIG_TRACEPOINTS
 const char *drop_reason_lookup(unsigned long long value);
 void drop_reason_show(struct seq_file *m);
diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c
index b0f221d658be..185c43e5b501 100644
--- a/net/core/drop_monitor.c
+++ b/net/core/drop_monitor.c
@@ -610,9 +610,8 @@ static int net_dm_packet_report_fill(struct sk_buff *msg, struct sk_buff *skb,
 				     size_t payload_len)
 {
 	struct net_dm_skb_cb *cb = NET_DM_SKB_CB(skb);
-	const struct drop_reason_list *list = NULL;
-	unsigned int subsys, subsys_reason;
 	char buf[NET_DM_MAX_SYMBOL_LEN];
+	const char *reason_str;
 	struct nlattr *attr;
 	void *hdr;
 	int rc;
@@ -630,19 +629,8 @@ static int net_dm_packet_report_fill(struct sk_buff *msg, struct sk_buff *skb,
 		goto nla_put_failure;
 
 	rcu_read_lock();
-	subsys = u32_get_bits(cb->reason, SKB_DROP_REASON_SUBSYS_MASK);
-	if (subsys < SKB_DROP_REASON_SUBSYS_NUM)
-		list = rcu_dereference(drop_reasons_by_subsys[subsys]);
-	subsys_reason = cb->reason & ~SKB_DROP_REASON_SUBSYS_MASK;
-	if (!list ||
-	    subsys_reason >= list->n_reasons ||
-	    !list->reasons[subsys_reason] ||
-	    strlen(list->reasons[subsys_reason]) > NET_DM_MAX_REASON_LEN) {
-		list = rcu_dereference(drop_reasons_by_subsys[SKB_DROP_REASON_SUBSYS_CORE]);
-		subsys_reason = SKB_DROP_REASON_NOT_SPECIFIED;
-	}
-	if (nla_put_string(msg, NET_DM_ATTR_REASON,
-			   list->reasons[subsys_reason])) {
+	reason_str = drop_reason_lookup(cb->reason);
+	if (nla_put_string(msg, NET_DM_ATTR_REASON, reason_str)) {
 		rcu_read_unlock();
 		goto nla_put_failure;
 	}
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 012b48da8810..a8065c40a270 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -141,13 +141,11 @@ static const struct drop_reason_list drop_reasons_core = {
 	.n_reasons = ARRAY_SIZE(drop_reasons),
 };
 
-const struct drop_reason_list __rcu *
+static const struct drop_reason_list __rcu *
 drop_reasons_by_subsys[SKB_DROP_REASON_SUBSYS_NUM] = {
 	[SKB_DROP_REASON_SUBSYS_CORE] = RCU_INITIALIZER(&drop_reasons_core),
 };
-EXPORT_SYMBOL(drop_reasons_by_subsys);
 
-#ifdef CONFIG_TRACEPOINTS
 const char *drop_reason_lookup(unsigned long long value)
 {
 	unsigned long long subsys_id = value >> SKB_DROP_REASON_SUBSYS_SHIFT;
@@ -164,7 +162,9 @@ const char *drop_reason_lookup(unsigned long long value)
 		return NULL;
 	return subsys->reasons[reason];
 }
+EXPORT_SYMBOL(drop_reason_lookup);
 
+#ifdef CONFIG_TRACEPOINTS
 void drop_reason_show(struct seq_file *m)
 {
 	u32 subsys_id;
-- 
2.44.0


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

* [RFC PATCH v2 4/4] tracing/timer: use __print_sym()
  2024-03-26 19:15 [RFC PATCH v2 0/4] tracing: improve symbolic printing Johannes Berg
                   ` (2 preceding siblings ...)
  2024-03-26 19:15 ` [RFC PATCH v2 3/4] net: drop_monitor: use drop_reason_lookup() Johannes Berg
@ 2024-03-26 19:15 ` Johannes Berg
  3 siblings, 0 replies; 10+ messages in thread
From: Johannes Berg @ 2024-03-26 19:15 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-trace-kernel, netdev, linux-wireless, Johannes Berg

From: Johannes Berg <johannes.berg@intel.com>

Use the new __print_sym() in the timer tracing, just to show
how to convert something. This adds ~80 bytes of .text for a
saving of ~1.5K of data in my builds.

Note the format changes from

print fmt: "success=%d dependency=%s", REC->success, __print_symbolic(REC->dependency, { 0, "NONE" }, { (1 << 0), "POSIX_TIMER" }, { (1 << 1), "PERF_EVENTS" }, { (1 << 2), "SCHED" }, { (1 << 3), "CLOCK_UNSTABLE" }, { (1 << 4), "RCU" }, { (1 << 5), "RCU_EXP" })

to

print fmt: "success=%d dependency=%s", REC->success, __print_symbolic(REC->dependency, { 0, "NONE" }, { 1, "POSIX_TIMER" }, { 2, "PERF_EVENTS" }, { 4, "SCHED" }, { 8, "CLOCK_UNSTABLE" }, { 16, "RCU" }, { 32, "RCU_EXP" })

Since the values are now just printed in the show function as
pure decimal values.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 include/trace/events/timer.h | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/include/trace/events/timer.h b/include/trace/events/timer.h
index 1ef58a04fc57..d483abffed78 100644
--- a/include/trace/events/timer.h
+++ b/include/trace/events/timer.h
@@ -402,26 +402,18 @@ TRACE_EVENT(itimer_expire,
 #undef tick_dep_mask_name
 #undef tick_dep_name_end
 
-/* The MASK will convert to their bits and they need to be processed too */
-#define tick_dep_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \
-	TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
-#define tick_dep_name_end(sdep)  TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \
-	TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
-/* NONE only has a mask defined for it */
-#define tick_dep_mask_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
-
-TICK_DEP_NAMES
-
-#undef tick_dep_name
-#undef tick_dep_mask_name
-#undef tick_dep_name_end
-
 #define tick_dep_name(sdep) { TICK_DEP_MASK_##sdep, #sdep },
 #define tick_dep_mask_name(sdep) { TICK_DEP_MASK_##sdep, #sdep },
 #define tick_dep_name_end(sdep) { TICK_DEP_MASK_##sdep, #sdep }
 
+TRACE_DEFINE_SYM_LIST(tick_dep_names, TICK_DEP_NAMES);
+
+#undef tick_dep_name
+#undef tick_dep_mask_name
+#undef tick_dep_name_end
+
 #define show_tick_dep_name(val)				\
-	__print_symbolic(val, TICK_DEP_NAMES)
+	__print_sym(val, tick_dep_names)
 
 TRACE_EVENT(tick_stop,
 
-- 
2.44.0


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

* Re: [RFC PATCH v2 1/4] tracing: add __print_sym() to replace __print_symbolic()
  2024-03-26 19:15 ` [RFC PATCH v2 1/4] tracing: add __print_sym() to replace __print_symbolic() Johannes Berg
@ 2024-03-27  4:21   ` kernel test robot
  2024-03-27  5:34   ` kernel test robot
  2024-03-27 21:11   ` Simon Horman
  2 siblings, 0 replies; 10+ messages in thread
From: kernel test robot @ 2024-03-27  4:21 UTC (permalink / raw)
  To: Johannes Berg; +Cc: llvm, oe-kbuild-all

Hi Johannes,

[This is a private test report for your RFC patch.]
kernel test robot noticed the following build warnings:

[auto build test WARNING on mcgrof/modules-next]
[also build test WARNING on arnd-asm-generic/master tip/timers/core net/main net-next/main linus/master horms-ipvs/master v6.9-rc1 next-20240326]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Johannes-Berg/tracing-add-__print_sym-to-replace-__print_symbolic/20240327-032437
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git modules-next
patch link:    https://lore.kernel.org/r/20240326202131.9d261d5bb667.I9bd2617499f0d170df58471bc51379742190f92d%40changeid
patch subject: [RFC PATCH v2 1/4] tracing: add __print_sym() to replace __print_symbolic()
config: s390-defconfig (https://download.01.org/0day-ci/archive/20240327/202403271216.iazgC6LR-lkp@intel.com/config)
compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 23de3862dce582ce91c1aa914467d982cb1a73b4)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240327/202403271216.iazgC6LR-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202403271216.iazgC6LR-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from lib/maple_tree.c:65:
   In file included from include/trace/events/maple_tree.h:123:
   In file included from include/trace/define_trace.h:102:
   In file included from include/trace/trace_events.h:27:
>> include/trace/stages/init.h:30:9: warning: 'TRACE_DEFINE_SYM_FNS' macro redefined [-Wmacro-redefined]
      30 | #define TRACE_DEFINE_SYM_FNS(_symbol_id, _lookup, _show)                \
         |         ^
   include/linux/tracepoint.h:130:9: note: previous definition is here
     130 | #define TRACE_DEFINE_SYM_FNS(...)
         |         ^
   In file included from lib/maple_tree.c:65:
   In file included from include/trace/events/maple_tree.h:123:
   In file included from include/trace/define_trace.h:102:
   In file included from include/trace/trace_events.h:27:
>> include/trace/stages/init.h:54:9: warning: 'TRACE_DEFINE_SYM_LIST' macro redefined [-Wmacro-redefined]
      54 | #define TRACE_DEFINE_SYM_LIST(_symbol_id, ...)                          \
         |         ^
   include/linux/tracepoint.h:131:9: note: previous definition is here
     131 | #define TRACE_DEFINE_SYM_LIST(...)
         |         ^
   2 warnings generated.
--
   In file included from lib/maple_tree.c:65:
   In file included from include/trace/events/maple_tree.h:9:
   In file included from include/linux/tracepoint.h:22:
   In file included from include/linux/static_call.h:135:
   In file included from include/linux/cpu.h:17:
   In file included from include/linux/node.h:18:
   In file included from include/linux/device.h:32:
   In file included from include/linux/device/driver.h:21:
   In file included from include/linux/module.h:19:
   In file included from include/linux/elf.h:6:
   In file included from arch/s390/include/asm/elf.h:173:
   In file included from arch/s390/include/asm/mmu_context.h:11:
   In file included from arch/s390/include/asm/pgalloc.h:18:
   In file included from include/linux/mm.h:2188:
   include/linux/vmstat.h:508:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     508 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     509 |                            item];
         |                            ~~~~
   include/linux/vmstat.h:515:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     515 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     516 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   include/linux/vmstat.h:522:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     522 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
   include/linux/vmstat.h:527:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     527 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     528 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   include/linux/vmstat.h:536:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     536 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     537 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   In file included from lib/maple_tree.c:65:
   In file included from include/trace/events/maple_tree.h:123:
   In file included from include/trace/define_trace.h:102:
   In file included from include/trace/trace_events.h:27:
>> include/trace/stages/init.h:30:9: warning: 'TRACE_DEFINE_SYM_FNS' macro redefined [-Wmacro-redefined]
      30 | #define TRACE_DEFINE_SYM_FNS(_symbol_id, _lookup, _show)                \
         |         ^
   include/linux/tracepoint.h:130:9: note: previous definition is here
     130 | #define TRACE_DEFINE_SYM_FNS(...)
         |         ^
   In file included from lib/maple_tree.c:65:
   In file included from include/trace/events/maple_tree.h:123:
   In file included from include/trace/define_trace.h:102:
   In file included from include/trace/trace_events.h:27:
>> include/trace/stages/init.h:54:9: warning: 'TRACE_DEFINE_SYM_LIST' macro redefined [-Wmacro-redefined]
      54 | #define TRACE_DEFINE_SYM_LIST(_symbol_id, ...)                          \
         |         ^
   include/linux/tracepoint.h:131:9: note: previous definition is here
     131 | #define TRACE_DEFINE_SYM_LIST(...)
         |         ^
   lib/maple_tree.c:351:21: warning: unused function 'mte_set_full' [-Wunused-function]
     351 | static inline void *mte_set_full(const struct maple_enode *node)
         |                     ^~~~~~~~~~~~
   lib/maple_tree.c:356:21: warning: unused function 'mte_clear_full' [-Wunused-function]
     356 | static inline void *mte_clear_full(const struct maple_enode *node)
         |                     ^~~~~~~~~~~~~~
   lib/maple_tree.c:361:20: warning: unused function 'mte_has_null' [-Wunused-function]
     361 | static inline bool mte_has_null(const struct maple_enode *node)
         |                    ^~~~~~~~~~~~
   10 warnings generated.


vim +/TRACE_DEFINE_SYM_FNS +30 include/trace/stages/init.h

    12	
    13	#undef TRACE_DEFINE_ENUM
    14	#define TRACE_DEFINE_ENUM(a)				\
    15		static struct trace_eval_map __used __initdata	\
    16		__##TRACE_SYSTEM##_##a =			\
    17		{						\
    18			.system = TRACE_SYSTEM_STRING,		\
    19			.eval_string = #a,			\
    20			.eval_value = a				\
    21		};						\
    22		static struct trace_eval_map __used		\
    23		__section("_ftrace_eval_map")			\
    24		*TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a
    25	
    26	/*
    27	 * Define a symbol for __print_sym by giving lookup and
    28	 * show functions. See &struct trace_sym_def.
    29	 */
  > 30	#define TRACE_DEFINE_SYM_FNS(_symbol_id, _lookup, _show)		\
    31		_TRACE_DEFINE_SYM_FNS(TRACE_SYSTEM, _symbol_id, _lookup, _show)
    32	#define _TRACE_DEFINE_SYM_FNS(_system, _symbol_id, _lookup, _show)	\
    33		__TRACE_DEFINE_SYM_FNS(_system, _symbol_id, _lookup, _show)
    34	#define __TRACE_DEFINE_SYM_FNS(_system, _symbol_id, _lookup, _show)	\
    35		___TRACE_DEFINE_SYM_FNS(_system ## _ ## _symbol_id, _symbol_id,	\
    36					_lookup, _show)
    37	#define ___TRACE_DEFINE_SYM_FNS(_name, _symbol_id, _lookup, _show)	\
    38		static struct trace_sym_def					\
    39		__trace_sym_def_ ## _name = {					\
    40			.system = TRACE_SYSTEM_STRING,				\
    41			/* need the ) for later strcmp */			\
    42			.symbol_id = #_symbol_id ")",				\
    43			.lookup = _lookup,					\
    44			.show = _show,						\
    45		};								\
    46		static struct trace_sym_def 					\
    47		__section("_ftrace_sym_defs")					\
    48		*__trace_sym_def_p_ ## _name = &__trace_sym_def_ ## _name
    49	
    50	/*
    51	 * Define a symbol for __print_sym by giving lookup and
    52	 * show functions. See &struct trace_sym_def.
    53	 */
  > 54	#define TRACE_DEFINE_SYM_LIST(_symbol_id, ...)				\
    55		_TRACE_DEFINE_SYM_LIST(TRACE_SYSTEM, _symbol_id, __VA_ARGS__)
    56	#define _TRACE_DEFINE_SYM_LIST(_system, _symbol_id, ...)		\
    57		__TRACE_DEFINE_SYM_LIST(_system, _symbol_id, __VA_ARGS__)
    58	#define __TRACE_DEFINE_SYM_LIST(_system, _symbol_id, ...)		\
    59		___TRACE_DEFINE_SYM_LIST(_system ## _ ## _symbol_id, _symbol_id,\
    60					 __VA_ARGS__)
    61	#define ___TRACE_DEFINE_SYM_LIST(_name, _symbol_id, ...)		\
    62		static struct trace_sym_entry					\
    63		__trace_sym_list_ ## _name[] = { __VA_ARGS__ };			\
    64		static const char *						\
    65		__trace_sym_lookup_ ## _name(unsigned long long value)		\
    66		{								\
    67			return trace_sym_lookup(__trace_sym_list_ ## _name,	\
    68				ARRAY_SIZE(__trace_sym_list_ ## _name), value);	\
    69		}								\
    70		static void							\
    71		__trace_sym_show_ ## _name(struct seq_file *m)			\
    72		{								\
    73			trace_sym_show(m, __trace_sym_list_ ## _name,		\
    74				       ARRAY_SIZE(__trace_sym_list_ ## _name));	\
    75		}								\
    76		___TRACE_DEFINE_SYM_FNS(_name, _symbol_id,			\
    77					__trace_sym_lookup_ ## _name,		\
    78					__trace_sym_show_ ## _name)
    79	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [RFC PATCH v2 3/4] net: drop_monitor: use drop_reason_lookup()
  2024-03-26 19:15 ` [RFC PATCH v2 3/4] net: drop_monitor: use drop_reason_lookup() Johannes Berg
@ 2024-03-27  4:21   ` kernel test robot
  0 siblings, 0 replies; 10+ messages in thread
From: kernel test robot @ 2024-03-27  4:21 UTC (permalink / raw)
  To: Johannes Berg; +Cc: oe-kbuild-all

Hi Johannes,

[This is a private test report for your RFC patch.]
kernel test robot noticed the following build warnings:

[auto build test WARNING on mcgrof/modules-next]
[also build test WARNING on arnd-asm-generic/master tip/timers/core net/main net-next/main linus/master v6.9-rc1 next-20240326]
[cannot apply to horms-ipvs/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Johannes-Berg/tracing-add-__print_sym-to-replace-__print_symbolic/20240327-032437
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git modules-next
patch link:    https://lore.kernel.org/r/20240326202131.3ca898497886.Idc122c3395bea9652f34ccaa678e918bfd4fae75%40changeid
patch subject: [RFC PATCH v2 3/4] net: drop_monitor: use drop_reason_lookup()
config: openrisc-defconfig (https://download.01.org/0day-ci/archive/20240327/202403271245.NkUQBP1L-lkp@intel.com/config)
compiler: or1k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240327/202403271245.NkUQBP1L-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202403271245.NkUQBP1L-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> net/core/skbuff.c:135:13: warning: no previous prototype for 'drop_reason_lookup' [-Wmissing-prototypes]
     135 | const char *drop_reason_lookup(unsigned long long value)
         |             ^~~~~~~~~~~~~~~~~~


vim +/drop_reason_lookup +135 net/core/skbuff.c

071c0fc6fb919d Johannes Berg 2023-04-19  134  
c983b2007bc00c Johannes Berg 2024-03-26 @135  const char *drop_reason_lookup(unsigned long long value)
c983b2007bc00c Johannes Berg 2024-03-26  136  {
c983b2007bc00c Johannes Berg 2024-03-26  137  	unsigned long long subsys_id = value >> SKB_DROP_REASON_SUBSYS_SHIFT;
c983b2007bc00c Johannes Berg 2024-03-26  138  	u32 reason = value & ~SKB_DROP_REASON_SUBSYS_MASK;
c983b2007bc00c Johannes Berg 2024-03-26  139  	const struct drop_reason_list *subsys;
c983b2007bc00c Johannes Berg 2024-03-26  140  
c983b2007bc00c Johannes Berg 2024-03-26  141  	if (subsys_id >= SKB_DROP_REASON_SUBSYS_NUM)
c983b2007bc00c Johannes Berg 2024-03-26  142  		return NULL;
c983b2007bc00c Johannes Berg 2024-03-26  143  
c983b2007bc00c Johannes Berg 2024-03-26  144  	subsys = rcu_dereference(drop_reasons_by_subsys[subsys_id]);
c983b2007bc00c Johannes Berg 2024-03-26  145  	if (!subsys)
c983b2007bc00c Johannes Berg 2024-03-26  146  		return NULL;
c983b2007bc00c Johannes Berg 2024-03-26  147  	if (reason >= subsys->n_reasons)
c983b2007bc00c Johannes Berg 2024-03-26  148  		return NULL;
c983b2007bc00c Johannes Berg 2024-03-26  149  	return subsys->reasons[reason];
c983b2007bc00c Johannes Berg 2024-03-26  150  }
076117b5a29931 Johannes Berg 2024-03-26  151  EXPORT_SYMBOL(drop_reason_lookup);
c983b2007bc00c Johannes Berg 2024-03-26  152  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [RFC PATCH v2 1/4] tracing: add __print_sym() to replace __print_symbolic()
  2024-03-26 19:15 ` [RFC PATCH v2 1/4] tracing: add __print_sym() to replace __print_symbolic() Johannes Berg
  2024-03-27  4:21   ` kernel test robot
@ 2024-03-27  5:34   ` kernel test robot
  2024-03-27 21:11   ` Simon Horman
  2 siblings, 0 replies; 10+ messages in thread
From: kernel test robot @ 2024-03-27  5:34 UTC (permalink / raw)
  To: Johannes Berg; +Cc: oe-kbuild-all

Hi Johannes,

[This is a private test report for your RFC patch.]
kernel test robot noticed the following build warnings:

[auto build test WARNING on mcgrof/modules-next]
[also build test WARNING on arnd-asm-generic/master tip/timers/core net/main net-next/main linus/master horms-ipvs/master v6.9-rc1 next-20240326]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Johannes-Berg/tracing-add-__print_sym-to-replace-__print_symbolic/20240327-032437
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git modules-next
patch link:    https://lore.kernel.org/r/20240326202131.9d261d5bb667.I9bd2617499f0d170df58471bc51379742190f92d%40changeid
patch subject: [RFC PATCH v2 1/4] tracing: add __print_sym() to replace __print_symbolic()
config: sh-defconfig (https://download.01.org/0day-ci/archive/20240327/202403271340.X3uVZhs3-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240327/202403271340.X3uVZhs3-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202403271340.X3uVZhs3-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from include/trace/trace_events.h:27,
                    from include/trace/define_trace.h:102,
                    from include/trace/events/filemap.h:118,
                    from mm/filemap.c:54:
>> include/trace/stages/init.h:30: warning: "TRACE_DEFINE_SYM_FNS" redefined
      30 | #define TRACE_DEFINE_SYM_FNS(_symbol_id, _lookup, _show)                \
         | 
   In file included from include/trace/syscall.h:5,
                    from include/linux/syscalls.h:93,
                    from mm/filemap.c:25:
   include/linux/tracepoint.h:130: note: this is the location of the previous definition
     130 | #define TRACE_DEFINE_SYM_FNS(...)
         | 
>> include/trace/stages/init.h:54: warning: "TRACE_DEFINE_SYM_LIST" redefined
      54 | #define TRACE_DEFINE_SYM_LIST(_symbol_id, ...)                          \
         | 
   include/linux/tracepoint.h:131: note: this is the location of the previous definition
     131 | #define TRACE_DEFINE_SYM_LIST(...)
         | 
--
   In file included from include/trace/trace_events.h:27,
                    from include/trace/define_trace.h:102,
                    from include/trace/events/tlb.h:62,
                    from mm/rmap.c:82:
>> include/trace/stages/init.h:30: warning: "TRACE_DEFINE_SYM_FNS" redefined
      30 | #define TRACE_DEFINE_SYM_FNS(_symbol_id, _lookup, _show)                \
         | 
   In file included from include/trace/events/tlb.h:9:
   include/linux/tracepoint.h:130: note: this is the location of the previous definition
     130 | #define TRACE_DEFINE_SYM_FNS(...)
         | 
>> include/trace/stages/init.h:54: warning: "TRACE_DEFINE_SYM_LIST" redefined
      54 | #define TRACE_DEFINE_SYM_LIST(_symbol_id, ...)                          \
         | 
   include/linux/tracepoint.h:131: note: this is the location of the previous definition
     131 | #define TRACE_DEFINE_SYM_LIST(...)
         | 
   In file included from include/trace/trace_events.h:27,
                    from include/trace/define_trace.h:102,
                    from include/trace/events/migrate.h:146,
                    from mm/rmap.c:83:
>> include/trace/stages/init.h:30: warning: "TRACE_DEFINE_SYM_FNS" redefined
      30 | #define TRACE_DEFINE_SYM_FNS(_symbol_id, _lookup, _show)                \
         | 
   In file included from include/trace/trace_events.h:112:
   include/trace/stages/stage2_data_offsets.h:9: note: this is the location of the previous definition
       9 | #define TRACE_DEFINE_SYM_FNS(_symbol_id, _lookup, _show)
         | 
>> include/trace/stages/init.h:54: warning: "TRACE_DEFINE_SYM_LIST" redefined
      54 | #define TRACE_DEFINE_SYM_LIST(_symbol_id, ...)                          \
         | 
   include/trace/stages/stage2_data_offsets.h:12: note: this is the location of the previous definition
      12 | #define TRACE_DEFINE_SYM_LIST(_symbol_id, ...)
         | 


vim +/TRACE_DEFINE_SYM_FNS +30 include/trace/stages/init.h

    12	
    13	#undef TRACE_DEFINE_ENUM
    14	#define TRACE_DEFINE_ENUM(a)				\
    15		static struct trace_eval_map __used __initdata	\
    16		__##TRACE_SYSTEM##_##a =			\
    17		{						\
    18			.system = TRACE_SYSTEM_STRING,		\
    19			.eval_string = #a,			\
    20			.eval_value = a				\
    21		};						\
    22		static struct trace_eval_map __used		\
    23		__section("_ftrace_eval_map")			\
    24		*TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a
    25	
    26	/*
    27	 * Define a symbol for __print_sym by giving lookup and
    28	 * show functions. See &struct trace_sym_def.
    29	 */
  > 30	#define TRACE_DEFINE_SYM_FNS(_symbol_id, _lookup, _show)		\
    31		_TRACE_DEFINE_SYM_FNS(TRACE_SYSTEM, _symbol_id, _lookup, _show)
    32	#define _TRACE_DEFINE_SYM_FNS(_system, _symbol_id, _lookup, _show)	\
    33		__TRACE_DEFINE_SYM_FNS(_system, _symbol_id, _lookup, _show)
    34	#define __TRACE_DEFINE_SYM_FNS(_system, _symbol_id, _lookup, _show)	\
    35		___TRACE_DEFINE_SYM_FNS(_system ## _ ## _symbol_id, _symbol_id,	\
    36					_lookup, _show)
    37	#define ___TRACE_DEFINE_SYM_FNS(_name, _symbol_id, _lookup, _show)	\
    38		static struct trace_sym_def					\
    39		__trace_sym_def_ ## _name = {					\
    40			.system = TRACE_SYSTEM_STRING,				\
    41			/* need the ) for later strcmp */			\
    42			.symbol_id = #_symbol_id ")",				\
    43			.lookup = _lookup,					\
    44			.show = _show,						\
    45		};								\
    46		static struct trace_sym_def 					\
    47		__section("_ftrace_sym_defs")					\
    48		*__trace_sym_def_p_ ## _name = &__trace_sym_def_ ## _name
    49	
    50	/*
    51	 * Define a symbol for __print_sym by giving lookup and
    52	 * show functions. See &struct trace_sym_def.
    53	 */
  > 54	#define TRACE_DEFINE_SYM_LIST(_symbol_id, ...)				\
    55		_TRACE_DEFINE_SYM_LIST(TRACE_SYSTEM, _symbol_id, __VA_ARGS__)
    56	#define _TRACE_DEFINE_SYM_LIST(_system, _symbol_id, ...)		\
    57		__TRACE_DEFINE_SYM_LIST(_system, _symbol_id, __VA_ARGS__)
    58	#define __TRACE_DEFINE_SYM_LIST(_system, _symbol_id, ...)		\
    59		___TRACE_DEFINE_SYM_LIST(_system ## _ ## _symbol_id, _symbol_id,\
    60					 __VA_ARGS__)
    61	#define ___TRACE_DEFINE_SYM_LIST(_name, _symbol_id, ...)		\
    62		static struct trace_sym_entry					\
    63		__trace_sym_list_ ## _name[] = { __VA_ARGS__ };			\
    64		static const char *						\
    65		__trace_sym_lookup_ ## _name(unsigned long long value)		\
    66		{								\
    67			return trace_sym_lookup(__trace_sym_list_ ## _name,	\
    68				ARRAY_SIZE(__trace_sym_list_ ## _name), value);	\
    69		}								\
    70		static void							\
    71		__trace_sym_show_ ## _name(struct seq_file *m)			\
    72		{								\
    73			trace_sym_show(m, __trace_sym_list_ ## _name,		\
    74				       ARRAY_SIZE(__trace_sym_list_ ## _name));	\
    75		}								\
    76		___TRACE_DEFINE_SYM_FNS(_name, _symbol_id,			\
    77					__trace_sym_lookup_ ## _name,		\
    78					__trace_sym_show_ ## _name)
    79	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [RFC PATCH v2 1/4] tracing: add __print_sym() to replace __print_symbolic()
  2024-03-26 19:15 ` [RFC PATCH v2 1/4] tracing: add __print_sym() to replace __print_symbolic() Johannes Berg
  2024-03-27  4:21   ` kernel test robot
  2024-03-27  5:34   ` kernel test robot
@ 2024-03-27 21:11   ` Simon Horman
  2024-03-27 21:24     ` Johannes Berg
  2 siblings, 1 reply; 10+ messages in thread
From: Simon Horman @ 2024-03-27 21:11 UTC (permalink / raw)
  To: Johannes Berg
  Cc: linux-kernel, linux-trace-kernel, netdev, linux-wireless,
	Johannes Berg

On Tue, Mar 26, 2024 at 08:15:56PM +0100, Johannes Berg wrote:
> From: Johannes Berg <johannes.berg@intel.com>
> 
> The way __print_symbolic() works is limited and inefficient
> in multiple ways:
>  - you can only use it with a static list of symbols, but
>    e.g. the SKB dropreasons are now a dynamic list
> 
>  - it builds the list in memory _three_ times, so it takes
>    a lot of memory:
>    - The print_fmt contains the list (since it's passed to
>      the macro there). This actually contains the names
>      _twice_, which is fixed up at runtime.
>    - TRACE_DEFINE_ENUM() puts a 24-byte struct trace_eval_map
>      for every entry, plus the string pointed to by it, which
>      cannot be deduplicated with the strings in the print_fmt
>    - The in-kernel symbolic printing creates yet another list
>      of struct trace_print_flags for trace_print_symbols_seq()
> 
>  - it also requires runtime fixup during init, which is a lot
>    of string parsing due to the print_fmt fixup
> 
> Introduce __print_sym() to - over time - replace the old one.
> We can easily extend this also to __print_flags later, but I
> cared only about the SKB dropreasons for now, which has only
> __print_symbolic().
> 
> This new __print_sym() requires only a single list of items,
> created by TRACE_DEFINE_SYM_LIST(), or can even use another
> already existing list by using TRACE_DEFINE_SYM_FNS() with
> lookup and show methods.
> 
> Then, instead of doing an init-time fixup, just do this at the
> time when userspace reads the print_fmt. This way, dynamically
> updated lists are possible.
> 
> For userspace, nothing actually changes, because the print_fmt
> is shown exactly the same way the old __print_symbolic() was.
> 
> This adds about 4k .text in my test builds, but that'll be
> more than paid for by the actual conversions.
> 
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>

Hi Johannes,

I'm seeing some allmodconfig build problems with this applied on top of
net-next.

In file included from ./include/trace/trace_events.h:27,
                 from ./include/trace/define_trace.h:102,
                 from ./include/trace/events/module.h:134,
                 from kernel/module/main.c:64:
./include/trace/stages/init.h:30: warning: "TRACE_DEFINE_SYM_FNS" redefined
   30 | #define TRACE_DEFINE_SYM_FNS(_symbol_id, _lookup, _show)                \
      |
In file included from ./include/linux/trace_events.h:11,
                 from kernel/module/main.c:14:
./include/linux/tracepoint.h:130: note: this is the location of the previous definition
  130 | #define TRACE_DEFINE_SYM_FNS(...)
      |
./include/trace/stages/init.h:54: warning: "TRACE_DEFINE_SYM_LIST" redefined
   54 | #define TRACE_DEFINE_SYM_LIST(_symbol_id, ...)                          \
      |
./include/linux/tracepoint.h:131: note: this is the location of the previous definition
  131 | #define TRACE_DEFINE_SYM_LIST(...)
      |


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

* Re: [RFC PATCH v2 1/4] tracing: add __print_sym() to replace __print_symbolic()
  2024-03-27 21:11   ` Simon Horman
@ 2024-03-27 21:24     ` Johannes Berg
  0 siblings, 0 replies; 10+ messages in thread
From: Johannes Berg @ 2024-03-27 21:24 UTC (permalink / raw)
  To: Simon Horman; +Cc: linux-kernel, linux-trace-kernel, netdev, linux-wireless

On Wed, 2024-03-27 at 21:11 +0000, Simon Horman wrote:
> 
> I'm seeing some allmodconfig build problems with this applied on top of
> net-next.

> ./include/trace/stages/init.h:30: warning: "TRACE_DEFINE_SYM_FNS" redefined

> ./include/trace/stages/init.h:54: warning: "TRACE_DEFINE_SYM_LIST" redefined

Yeah, the 0-day bot reported that too, sorry about that. It needs two
lines to #undef these in init.h before their definition, just like all
other macros there. Not sure why my builds didn't show that, maybe it
doesn't affect all users.

johannes

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

end of thread, other threads:[~2024-03-27 21:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-26 19:15 [RFC PATCH v2 0/4] tracing: improve symbolic printing Johannes Berg
2024-03-26 19:15 ` [RFC PATCH v2 1/4] tracing: add __print_sym() to replace __print_symbolic() Johannes Berg
2024-03-27  4:21   ` kernel test robot
2024-03-27  5:34   ` kernel test robot
2024-03-27 21:11   ` Simon Horman
2024-03-27 21:24     ` Johannes Berg
2024-03-26 19:15 ` [RFC PATCH v2 2/4] net: dropreason: use new __print_sym() in tracing Johannes Berg
2024-03-26 19:15 ` [RFC PATCH v2 3/4] net: drop_monitor: use drop_reason_lookup() Johannes Berg
2024-03-27  4:21   ` kernel test robot
2024-03-26 19:15 ` [RFC PATCH v2 4/4] tracing/timer: use __print_sym() Johannes Berg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.