tracing: improve symbolic printing
Subsystems (9)
v8 cover tracing: improve symbolic printing
Hi,
This new version just updates the samples to have the old way (marking it as deprecated) and fully fleshes out the sample for both new ways.
v2 was:
- 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
v3:
- fix #undef issues
- fix drop_monitor default
- rebase on linux-trace/for-next (there were no conflicts)
- move net patches to 3/4
- clarify symbol name matching logic (and remove ")" from it)
v4:
- fix non-module build and possibly dynamic event handling
v5: (https://lore.kernel.org/all/[email protected]/)
- fix build warning in non-module build
v6: (https://lore.kernel.org/linux-trace-kernel/[email protected]/)
- rebase
- fix nit from Paolo (I hope, I don't remember changing it
but it looks fixed!)
- fix crash due to wrong data placement
v7: (https://lore.kernel.org/lkml/[email protected]/)
- update ovs selftest
- don't ifdef drop_reason_lookup() prototype
- fix section alignment
v8: (this version)
- sample updates
To recap, it's annoying to have
irq/65-iwlwifi:-401 [000] 22.790000: kfree_skb: ... reason: 0x20000
and much nicer to see
irq/65-iwlwifi:-401 [000] 22.790000: kfree_skb: ... reason: RX_DROP_MONITOR
but this doesn't work now because __print_symbolic() can only deal with a hard-coded list (which is actually really big.)
So here's __print_sym() which doesn't build the list into the kernel image, but creates it at runtime. For userspace, it will look the same as __print_symbolic() (it literally shows __print_symbolic() to userspace) so no changes are needed, but the actual list of values exposed to userspace in there is built dynamically. For SKB drop reasons, this then has all the reasons known when userspace queries the trace format.
I guess patches 3/4 should go through net-next, so not sure how to handle this patch series. Or perhaps, as this will likely not cause conflicts (in fact I've been rebasing it for years now), go through tracing anyway with an Ack from netdev? But I can also just wait for the trace patch(es) to land and resubmit the net patches after, seeing how even at v8 I didn't get an ACK yet :)
Thanks,
johannes
PATCH v8 1/4 tracing: add __print_sym() to replace __print_symbolic()
From: Johannes Berg <[email protected]>
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.
---
v8: fix it to use TRACE_SYM_VAR, add a sample
v7: address sashiko's alignment concern
v6: don't place data needed at runtime in .init sections,
fixing the crash Steven reported with v1:
https://lore.kernel.org/r/[email protected]/
(yes, it's been over 2 years ... my bad)
--- include/asm-generic/vmlinux.lds.h | 4 + include/linux/module.h | 2 + include/linux/trace_events.h | 7 ++ include/linux/tracepoint.h | 20 +++++ include/trace/stages/init.h | 55 ++++++++++++ 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 | 99 +++++++++++++++++++++- kernel/trace/trace_output.c | 45 ++++++++++ samples/trace_events/trace-events-sample.c | 30 +++++++ samples/trace_events/trace-events-sample.h | 47 +++++++++- 13 files changed, 327 insertions(+), 3 deletions(-)
include/asm-generic/vmlinux.lds.h +4 -0
@@ -275,9 +275,12 @@#define FTRACE_EVENTS () \ . = ALIGN(8); \ BOUNDED_SECTION(_ftrace_events) \ + . = ALIGN(8); \ BOUNDED_SECTION_BY(_ftrace_eval_map, _ftrace_eval_maps) +#define FTRACE_SYM_DEFS () BOUNDED_SECTION(_ftrace_sym_defs)#else #define FTRACE_EVENTS () +#define FTRACE_SYM_DEFS ()#endif #ifdef CONFIG_TRACING
@@ -391,6 +394,7 @@ TRACE_PRINTKS() \ BPF_RAW_TP() \ TRACEPOINT_STR() \ + FTRACE_SYM_DEFS() \KUNIT_TABLE ()/*
include/linux/module.h +2 -0
@@ -520,6 +520,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_DYNAMIC_FTRACE unsigned int num_ftrace_callsites;
include/linux/trace_events.h +7 -0
@@ -29,6 +29,13 @@ const char *trace_print_symbols_seq(struct trace_seq *p, unsigned long val,const struct trace_print_flags *symbol_array, size_t symbol_array_size); +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,
include/linux/tracepoint.h +20 -0
@@ -32,6 +32,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 int
@@ -163,6 +181,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)
include/trace/stages/init.h +55 -0
61 lines not on this page · raw message
include/trace/stages/stage2_data_offsets.h +6 -0
@@ -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)
include/trace/stages/stage3_trace_output.h +9 -0
@@ -79,6 +79,15 @@trace_print_symbols_seq (p, value, symbols,ARRAY_SIZE (symbols)); \ }) +#undef __print_sym +#define __print_sym (value, symbol_id) \ + ___print_sym(TRACE_SYSTEM_VAR, 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
include/trace/stages/stage7_class_define.h +3 -0
@@ -45,6 +45,9 @@#define __event_in_softirq () (REC->common_flags & 0x10)#define __event_in_irq () (REC->common_flags & 0x18) +#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.
kernel/module/main.c +3 -0
@@ -2751,6 +2751,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",
kernel/trace/trace_events.c +97 -2
111 lines not on this page · raw message
kernel/trace/trace_output.c +45 -0
51 lines not on this page · raw message
samples/trace_events/trace-events-sample.c +30 -0
@@ -11,6 +11,36 @@#define CREATE_TRACE_POINTS #include "trace-events-sample.h" +/* functions for the dynamic __print_sym() example */ +static const struct { +unsigned long val; +char *name; +} print_sym_dynamic_names[] = { + {0 ,"zero" }, + {TRACE_SAMPLE_FOO ,"TWO" }, + {TRACE_SAMPLE_BAR ,"FOUR" }, + {TRACE_SAMPLE_ZOO ,"EIGHT" }, + {10 ,"TEN" } +}; + +const char *sample_names_dynamic_lookup (unsigned long long value) +{ +for (int i =0 ; i <ARRAY_SIZE (print_sym_dynamic_names); i++) { +if (print_sym_dynamic_names[i].val == value) +return print_sym_dynamic_names[i].name; + } + +return NULL ; +} + +void sample_names_dynamic_show (struct seq_file *m) +{ +for (int i =0 ; i <ARRAY_SIZE (print_sym_dynamic_names); i++) +seq_printf (m,", { %lu, \"%s\" }" , + print_sym_dynamic_names[i].val, + print_sym_dynamic_names[i].name); +} +static const char *random_strings[] = {"Mother Goose" ,"Snoopy" ,
samples/trace_events/trace-events-sample.h +46 -1
71 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH v8 2/4 tracing/timer: use __print_sym()
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
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.
--- include/trace/events/timer.h | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
include/trace/events/timer.h +5 -13
@@ -441,26 +441,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); +#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 } -TICK_DEP_NAMES +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 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 } -#define show_tick_dep_name (val) \ - __print_symbolic(val, TICK_DEP_NAMES) + __print_sym(val, tick_dep_names) TRACE_EVENT(tick_stop,
Signature · 1 line
2.56.1
PATCH v8 3/4 net: dropreason: use new __print_sym() in tracing
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
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).
---
v7: update the selftest accordingly
--- include/net/dropreason.h | 5 +++ include/trace/events/skb.h | 13 ++---- net/core/skbuff.c | 43 +++++++++++++++++++ .../selftests/net/openvswitch/openvswitch.sh | 17 ++------ 4 files changed, 55 insertions(+), 23 deletions(-)
include/net/dropreason.h +5 -0
@@ -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);
include/trace/events/skb.h +3 -10
@@ -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:
@@ -47,8 +41,7 @@ TRACE_EVENT(kfree_skb,TP_printk ("skbaddr=%p rx_sk=%p protocol=%u location=%pS reason: %s" , __entry->skbaddr, __entry->rx_sk, __entry->protocol, __entry->location, -__print_symbolic (__entry->reason, -DEFINE_DROP_REASON (FN , FNe))) +__print_sym (__entry->reason, drop_reason)) );#undef FN
net/core/skbuff.c +43 -0
49 lines not on this page · raw message
tools/testing/selftests/net/openvswitch/openvswitch.sh +4 -13
@@ -236,7 +236,7 @@ ovs_drop_reason_count() local reason=$1 local perf_output=`perf script -i ${ovs_dir}/perf.data -F trace:event,trace` - local pattern="skb:kfree_skb:.*reason: $reason" + local pattern="skb:kfree_skb:.*reason: $reason$" return `echo "$perf_output" | grep "$pattern" | wc -l` }
@@ -900,15 +900,6 @@ test_psample() { # - drop packets and verify the right drop reason is reported test_drop_reason() { which perf >/dev/null 2>&1 || return $ksft_skip - which pahole >/dev/null 2>&1 || return $ksft_skip - - ovs_drop_subsys=$(pahole -C skb_drop_reason_subsys | - awk '/OPENVSWITCH/ { print $3; }' | - tr -d ,) - if [ -z "$ovs_drop_subsys" ]; then - info "failed to get OVS drop subsys ID" - return $ksft_skip - fi sbx_add "test_drop_reason" || return $?
@@ -952,7 +943,7 @@ test_drop_reason() { "in_port(2),eth(),eth_type(0x0800),ipv4(src=172.31.110.20,proto=1),icmp()" 'drop' ovs_drop_record_and_run "test_drop_reason" ip netns exec client ping -c 2 172.31.110.20 - ovs_drop_reason_count 0x${ovs_drop_subsys}0001 # OVS_DROP_FLOW_ACTION + ovs_drop_reason_count OVS_DROP_LAST_ACTION if [[ "$?" -ne "2" ]]; then info "Did not detect expected drops: $?" return 1
@@ -969,7 +960,7 @@ test_drop_reason() { ovs_drop_record_and_run \ "test_drop_reason" ip netns exec client nc -i 1 -zuv 172.31.110.20 6000 - ovs_drop_reason_count 0x${ovs_drop_subsys}0004 # OVS_DROP_EXPLICIT_ACTION_ERROR + ovs_drop_reason_count OVS_DROP_EXPLICIT_WITH_ERROR if [[ "$?" -ne "1" ]]; then info "Did not detect expected explicit error drops: $?" return 1
@@ -977,7 +968,7 @@ test_drop_reason() { ovs_drop_record_and_run \ "test_drop_reason" ip netns exec client nc -i 1 -zuv 172.31.110.20 7000 - ovs_drop_reason_count 0x${ovs_drop_subsys}0003 # OVS_DROP_EXPLICIT_ACTION + ovs_drop_reason_count OVS_DROP_EXPLICIT if [[ "$?" -ne "1" ]]; then info "Did not detect expected explicit drops: $?" return 1
Signature · 1 line
2.56.1
Re: [PATCH v8 3/4] net: dropreason: use new __print_sym() in tracing
Quoted 21 lines · Johannes Berg
From: Johannes Berg <[email protected]>
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 <[email protected]>---
v7: update the selftest accordingly--- include/net/dropreason.h | 5 +++ include/trace/events/skb.h | 13 ++---- net/core/skbuff.c | 43 +++++++++++++++++++ .../selftests/net/openvswitch/openvswitch.sh | 17 ++------ 4 files changed, 55 insertions(+), 23 deletions(-)
[...]
Quoted 48 lines
tools/testing/selftests/net/openvswitch/openvswitch.sh +3
-12@@ -236,7 +236,7 @@ ovs_drop_reason_count() local reason=$1 local perf_output=`perf script -i ${ovs_dir}/perf.data -F trace:event,trace` - local pattern="skb:kfree_skb:.*reason: $reason" + local pattern="skb:kfree_skb:.*reason: $reason$" return `echo "$perf_output" | grep "$pattern" | wc -l` }@@ -900,15 +900,6 @@ test_psample() { # - drop packets and verify the right drop reason is reported test_drop_reason() { which perf >/dev/null 2>&1 || return $ksft_skip - which pahole >/dev/null 2>&1 || return $ksft_skip - - ovs_drop_subsys=$(pahole -C skb_drop_reason_subsys | - awk '/OPENVSWITCH/ { print $3; }' | - tr -d ,) - if [ -z "$ovs_drop_subsys" ]; then - info "failed to get OVS drop subsys ID" - return $ksft_skip - fi sbx_add "test_drop_reason" || return $?@@ -952,7 +943,7 @@ test_drop_reason() { "in_port(2),eth(),eth_type(0x0800),ipv4(src=172.31.110.20,proto=1),icmp()" 'drop' ovs_drop_record_and_run "test_drop_reason" ip netns exec client ping -c 2 172.31.110.20 - ovs_drop_reason_count 0x${ovs_drop_subsys}0001 # OVS_DROP_FLOW_ACTION + ovs_drop_reason_count OVS_DROP_LAST_ACTION if [[ "$?" -ne "2" ]]; then info "Did not detect expected drops: $?" return 1@@ -969,7 +960,7 @@ test_drop_reason() { ovs_drop_record_and_run \ "test_drop_reason" ip netns exec client nc -i 1 -zuv 172.31.110.20 6000 - ovs_drop_reason_count 0x${ovs_drop_subsys}0004 # OVS_DROP_EXPLICIT_ACTION_ERROR + ovs_drop_reason_count OVS_DROP_EXPLICIT_WITH_ERROR if [[ "$?" -ne "1" ]]; then info "Did not detect expected explicit error drops: $?" return 1
tools/testing/selftests/net/openvswitch/openvswitch.sh test_drop_reason() { · line 974
Quoted 8 lines
tools/testing/selftests/net/openvswitch/openvswitch.sh +1
-1@@ -977,7 +968,7 @@ test_drop_reason() { ovs_drop_record_and_run \ "test_drop_reason" ip netns exec client nc -i 1 -zuv 172.31.110.20 7000 - ovs_drop_reason_count 0x${ovs_drop_subsys}0003 # OVS_DROP_EXPLICIT_ACTION + ovs_drop_reason_count OVS_DROP_EXPLICIT if [[ "$?" -ne "1" ]]; then info "Did not detect expected explicit drops: $?" return 1
For the OVS test part:
PATCH v8 4/4 net: drop_monitor: use drop_reason_lookup()
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
Now that we have drop_reason_lookup(), we can just use it for drop_monitor as well, rather than exporting the list itself.
---
v7: don't hide drop_reason_show() prototype (sashiko,
but it got it the wrong way around)
--- include/net/dropreason.h | 5 +---- net/core/drop_monitor.c | 20 +++++--------------- net/core/skbuff.c | 6 +++--- 3 files changed, 9 insertions(+), 22 deletions(-)
include/net/dropreason.h +1 -4
@@ -38,12 +38,9 @@ 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 ]; +const char *drop_reason_lookup (unsigned long long value);#ifdef CONFIG_TRACEPOINTS -const char *drop_reason_lookup (unsigned long long value);void drop_reason_show (struct seq_file *m);#endif
net/core/drop_monitor.c +5 -15
@@ -611,9 +611,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;
@@ -631,19 +630,10 @@ 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 (unlikely (!reason_str)) + reason_str =drop_reason_lookup (SKB_DROP_REASON_NOT_SPECIFIED ); +if (nla_put_string (msg,NET_DM_ATTR_REASON , reason_str)) {rcu_read_unlock (); goto nla_put_failure; }
net/core/skbuff.c +3 -3
@@ -149,13 +149,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 ;
@@ -172,7 +170,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;
Signature · 1 line
2.56.1