Skip to contentSkip to conversation

drop_monitor: fix trace_napi_poll_hit()

PATCH Superseded Xiao Guangrong 3 participants 5 messages Aug 27, 2009 – Aug 31, 2009

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 drop_monitor: fix trace_napi_poll_hit()

The net_dev of backlog napi is NULL, like below:

__get_cpu_var(softnet_data).backlog.dev == NULL

So, we should check it in napi tracepoint's probe function

---
 net/core/drop_monitor.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
net/core/drop_monitor.c +2 -1
index 9d66fa9..d311202 100644
@@ -182,7 +182,8 @@ static void trace_napi_poll_hit(struct napi_struct *napi)
 	/*
 	 * Ratelimit our check time to dm_hw_check_delta jiffies
 	 */
-	if (!time_after(jiffies, napi->dev->last_rx + dm_hw_check_delta))
+	if (!napi->dev ||
+	    !time_after(jiffies, napi->dev->last_rx + dm_hw_check_delta))
 		return;
 
 	rcu_read_lock();
Signature · 1 line
1.6.1.2
#1 lore raw

PATCH 2/3 tracing/events: parameter check for __string() and *_str()

If we pass a NULL pointer to __string() and *_str(), kernel will crash, this patch stop it and print the NULL pointer to user, for example:

sshd-2545 [000] 95.588404: napi_poll: ifname=<NULL>

---
 include/trace/ftrace.h             |   11 +++++++----
 kernel/trace/trace_events_filter.c |    2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)
include/trace/ftrace.h +7 -4
index 360a77a..036aa0e 100644
@@ -229,8 +229,9 @@ ftrace_format_##call(struct ftrace_event_call *unused,			\
 #define TP_printk(fmt, args...) fmt "\n", args
 
 #undef __get_dynamic_array
-#define __get_dynamic_array(field)	\
-		((void *)__entry + (__entry->__data_loc_##field & 0xffff))
+#define __get_dynamic_array(field)					\
+	((__entry->__data_loc_##field & 0xffff0000) ?			\
+	((void *)__entry + (__entry->__data_loc_##field & 0xffff)) : NULL)
 
 #undef __get_str
 #define __get_str(field) (char *)__get_dynamic_array(field)
@@ -357,7 +358,8 @@ ftrace_define_fields_##call(struct ftrace_event_call *event_call)	\
 	__data_size += (len) * sizeof(type);
 
 #undef __string
-#define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)       \
+#define __string(item, src)						\
+	__dynamic_array(char, item, src ? strlen(src) + 1 : 0)
 
 #undef TRACE_EVENT
 #define TRACE_EVENT(call, proto, args, tstruct, assign, print)		\
@@ -554,7 +556,8 @@ static void ftrace_profile_disable_##call(struct ftrace_event_call *event_call)\
 
 #undef __assign_str
 #define __assign_str(dst, src)						\
-	strcpy(__get_str(dst), src);
+	if (src) 							\
+		strcpy(__get_str(dst), src);
 
 #undef TRACE_EVENT
 #define TRACE_EVENT(call, proto, args, tstruct, assign, print)		\
kernel/trace/trace_events_filter.c +1 -1
index 9f03082..9f1838a 100644
@@ -196,7 +196,7 @@ static int filter_pred_strloc(struct filter_pred *pred, void *event,
 	char *addr = (char *)(event + str_loc);
 	int cmp, match;
 
-	cmp = strncmp(addr, pred->str_val, str_len);
+	cmp = str_len ? strncmp(addr, pred->str_val, str_len) : -1;
 
 	match = (!cmp) ^ pred->not;
 
Signature · 1 line
1.6.1.2
#2 lore raw

PATCH 3/3 tracing/events: convert NAPI's tracepoint and fix DEFINE_TRACE_FN

In reply to Xiao Guangrong

- Convert NAPI's tracepoint via TRACE_EVENT macro, the output information like below:

   sshd-2503  [000]    71.920846: napi_poll: ifname=eth0 state=0 weigth=16 poll=pcnet32_poll
   sshd-2503  [000]    72.020291: napi_poll: ifname=eth0 state=0 weigth=16 poll=pcnet32_poll
   sshd-2503  [000]    72.020418: napi_poll: ifname=eth0 state=NAPI_STATE_SCHED weigth=16 poll=pcnet32_poll

- Remove the "DECLARE_TRACE" definiens in include/trace/define_trace.h, because TRACE_EVENT not use it

- Undef DEFINE_TRACE_FN after TRACE_EVENT/TRACE_EVENT_FN expanded, then we can include more TRACE_EVENT .h file in one .c file (the .c file has defined CREATE_TRACE_POINTS)

---
 include/trace/define_trace.h |    5 +---
 include/trace/events/napi.h  |   43 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 39 insertions(+), 9 deletions(-)
include/trace/define_trace.h +1 -4
index a89ed59..6158741 100644
@@ -31,10 +31,6 @@
 		assign, print, reg, unreg)			\
 	DEFINE_TRACE_FN(name, reg, unreg)
 
-#undef DECLARE_TRACE
-#define DECLARE_TRACE(name, proto, args)	\
-	DEFINE_TRACE(name)
-
 #undef TRACE_INCLUDE
 #undef __TRACE_INCLUDE
 
@@ -62,6 +58,7 @@
 #endif
 
 #undef TRACE_EVENT
+#undef TRACE_EVENT_FN
 #undef TRACE_HEADER_MULTI_READ
 
 /* Only undef what we defined in this file */
include/trace/events/napi.h +38 -5

49 lines not on this page · raw message

Signature · 1 line
1.6.1.2
maintainer Acked-by on v1 1/3
#3 lore raw
In reply to Xiao Guangrong
Quoted 29 lines · Xiao Guangrong

The net_dev of backlog napi is NULL, like below:

__get_cpu_var(softnet_data).backlog.dev == NULL

So, we should check it in napi tracepoint's probe function

---
 net/core/drop_monitor.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
net/core/drop_monitor.c +2 -1
index 9d66fa9..d311202 100644
@@ -182,7 +182,8 @@ static void trace_napi_poll_hit(struct napi_struct *napi)
 	/*
 	 * Ratelimit our check time to dm_hw_check_delta jiffies
 	 */
-	if (!time_after(jiffies, napi->dev->last_rx + dm_hw_check_delta))
+	if (!napi->dev ||
+	    !time_after(jiffies, napi->dev->last_rx + dm_hw_check_delta))
 		return;
 
 	rcu_read_lock();
Signature · 1 line
1.6.1.2

Thanks!
Neil