Skip to contentSkip to conversation

kernel-shark: Handle traces with sched_switch and no sched_waking

PATCH In review John Keeping 2 participants 2 messages Sep 6, 2021 – Sep 8, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel-shark: Handle traces with sched_switch and no sched_waking

plugin_sched_init_context() is careful to make the sched_waking (or sched_wakeup{,_new}) event optional but the initializer blindly dereferences plugin_ctx->sched_waking_event which is null if no waking event is found.

Add the necessary checks to avoid segfaults when (de)initializing the plugin.

---
 src/plugins/sched_events.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
src/plugins/sched_events.c +10 -6
index 83c2520..198ed49 100644
@@ -193,9 +193,11 @@ int KSHARK_PLOT_PLUGIN_INITIALIZER(struct kshark_data_stream *stream)
 				      plugin_ctx->sched_switch_event->id,
 				      plugin_sched_swith_action);
 
-	kshark_register_event_handler(stream,
-				      plugin_ctx->sched_waking_event->id,
-				      plugin_sched_wakeup_action);
+	if (plugin_ctx->sched_waking_event) {
+		kshark_register_event_handler(stream,
+					      plugin_ctx->sched_waking_event->id,
+					      plugin_sched_wakeup_action);
+	}
 
 	kshark_register_draw_handler(stream, plugin_draw);
 
@@ -213,9 +215,11 @@ int KSHARK_PLOT_PLUGIN_DEINITIALIZER(struct kshark_data_stream *stream)
 						plugin_ctx->sched_switch_event->id,
 						plugin_sched_swith_action);
 
-		kshark_unregister_event_handler(stream,
-						plugin_ctx->sched_waking_event->id,
-						plugin_sched_wakeup_action);
+		if (plugin_ctx->sched_waking_event) {
+			kshark_unregister_event_handler(stream,
+							plugin_ctx->sched_waking_event->id,
+							plugin_sched_wakeup_action);
+		}
 
 		kshark_unregister_draw_handler(stream, plugin_draw);
 
Signature · 1 line
2.33.0
#1 lore raw
Quoted 8 lines · John Keeping

plugin_sched_init_context() is careful to make the sched_waking (or sched_wakeup{,_new}) event optional but the initializer blindly dereferences plugin_ctx->sched_waking_event which is null if no waking event is found.

Add the necessary checks to avoid segfaults when (de)initializing the plugin.

Very well spotted. Thanks a lot!
Yordan

Quoted 40 lines
---
  src/plugins/sched_events.c | 16 ++++++++++------
  1 file changed, 10 insertions(+), 6 deletions(-)
src/plugins/sched_events.c +10 -6
index 83c2520..198ed49 100644
@@ -193,9 +193,11 @@ int KSHARK_PLOT_PLUGIN_INITIALIZER(struct kshark_data_stream *stream)
  				      plugin_ctx->sched_switch_event->id,
  				      plugin_sched_swith_action);
 
-	kshark_register_event_handler(stream,
-				      plugin_ctx->sched_waking_event->id,
-				      plugin_sched_wakeup_action);
+	if (plugin_ctx->sched_waking_event) {
+		kshark_register_event_handler(stream,
+					      plugin_ctx->sched_waking_event->id,
+					      plugin_sched_wakeup_action);
+	}
 
  	kshark_register_draw_handler(stream, plugin_draw);
 
@@ -213,9 +215,11 @@ int KSHARK_PLOT_PLUGIN_DEINITIALIZER(struct kshark_data_stream *stream)
  						plugin_ctx->sched_switch_event->id,
  						plugin_sched_swith_action);
 
-		kshark_unregister_event_handler(stream,
-						plugin_ctx->sched_waking_event->id,
-						plugin_sched_wakeup_action);
+		if (plugin_ctx->sched_waking_event) {
+			kshark_unregister_event_handler(stream,
+							plugin_ctx->sched_waking_event->id,
+							plugin_sched_wakeup_action);
+		}
 
  		kshark_unregister_draw_handler(stream, plugin_draw);