Skip to contentSkip to conversation

tracing: devlink: Use static array for string in devlink_trap_report even

PATCH In review Steven Rostedt 3 participants 3 messages Jul 12, 2022 – Jul 13, 2022

Subsystems (3)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH v2 1/1 tracing: devlink: Use static array for string in devlink_trap_report even

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

The trace event devlink_trap_report uses the __dynamic_array() macro to determine the size of the input_dev_name field. This is because it needs to test the dev field for NULL, and will use "NULL" if it is. But it also has the size of the dynamic array as a fixed IFNAMSIZ bytes. This defeats the purpose of the dynamic array, as this will reserve that amount of bytes on the ring buffer, and to make matters worse, it will even save that size in the event as the event expects it to be dynamic (for which it is not).

Since IFNAMSIZ is just 16 bytes, just make it a static array and this will remove the meta data from the event that records the size.

Cc Jakub Kicinski <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc Jiri Pirko <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Paolo Abeni <[email protected]>

---
Changes since v1: https://lkml.kernel.org/r/[email protected]

- The old version tried to do the same logic in the __dynamic_array() to calculate the size of the string, but actually failed to by not using the correct variable. Just use __array() instead, as IFNAMSIZ is just 16 bytes anyway.

- Cc'd more maintainers by running get_maintainers.pl from the call of the tracepoint and not just the include/trace/events file.

 include/trace/events/devlink.h | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
include/trace/events/devlink.h +3 -4
index 2814f188d98c..24969184c534 100644
@@ -186,7 +186,7 @@ TRACE_EVENT(devlink_trap_report,
 		__string(driver_name, devlink_to_dev(devlink)->driver->name)
 		__string(trap_name, metadata->trap_name)
 		__string(trap_group_name, metadata->trap_group_name)
-		__dynamic_array(char, input_dev_name, IFNAMSIZ)
+		__array(char, input_dev_name, IFNAMSIZ)
 	),
 
 	TP_fast_assign(
@@ -197,15 +197,14 @@ TRACE_EVENT(devlink_trap_report,
 		__assign_str(driver_name, devlink_to_dev(devlink)->driver->name);
 		__assign_str(trap_name, metadata->trap_name);
 		__assign_str(trap_group_name, metadata->trap_group_name);
-		__assign_str(input_dev_name,
-			     (input_dev ? input_dev->name : "NULL"));
+		strscpy(__entry->input_dev_name, input_dev ? input_dev->name : "NULL", IFNAMSIZ);
 	),
 
 	TP_printk("bus_name=%s dev_name=%s driver_name=%s trap_name=%s "
 		  "trap_group_name=%s input_dev_name=%s", __get_str(bus_name),
 		  __get_str(dev_name), __get_str(driver_name),
 		  __get_str(trap_name), __get_str(trap_group_name),
-		  __get_str(input_dev_name))
+		  __entry->input_dev_name)
 );
 
 #endif /* _TRACE_DEVLINK_H */
Signature · 1 line
2.35.1
Reviewed-by Tested-by on v2 1/1
#1 lore raw
Quoted 14 lines · Steven Rostedt

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

The trace event devlink_trap_report uses the __dynamic_array() macro to determine the size of the input_dev_name field. This is because it needs to test the dev field for NULL, and will use "NULL" if it is. But it also has the size of the dynamic array as a fixed IFNAMSIZ bytes. This defeats the purpose of the dynamic array, as this will reserve that amount of bytes on the ring buffer, and to make matters worse, it will even save that size in the event as the event expects it to be dynamic (for which it is not).

Since IFNAMSIZ is just 16 bytes, just make it a static array and this will remove the meta data from the event that records the size.

Quoted 8 lines
Cc Jakub Kicinski <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc Jiri Pirko <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Paolo Abeni <[email protected]>
maintainer Acked-by on v2 1/1
#2 lore raw
In reply to Steven Rostedt
Quoted 11 lines · On Tue, 12 Jul 2022 18:58:20 -0400 Steven Rostedt wrote:

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

The trace event devlink_trap_report uses the __dynamic_array() macro to determine the size of the input_dev_name field. This is because it needs to test the dev field for NULL, and will use "NULL" if it is. But it also has the size of the dynamic array as a fixed IFNAMSIZ bytes. This defeats the purpose of the dynamic array, as this will reserve that amount of bytes on the ring buffer, and to make matters worse, it will even save that size in the event as the event expects it to be dynamic (for which it is not).

Quoted 4 lines

Since IFNAMSIZ is just 16 bytes, just make it a static array and this will remove the meta data from the event that records the size.

Cc Jakub Kicinski <[email protected]>