BPF List
 help / color / mirror / Atom feed
From: Matt Turner <mattst88@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Arnaldo Carvalho de Melo <acme@kernel.org>,
	 Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	 Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	 Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	 Adrian Hunter <adrian.hunter@intel.com>,
	 James Clark <james.clark@linaro.org>
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	 bpf@vger.kernel.org, Matt Turner <mattst88@gmail.com>
Subject: [PATCH v4 3/3] perf tools: fix GTK4 leftover show/hide calls and error-loop list race
Date: Sun, 06 Sep 2026 13:18:06 -0400	[thread overview]
Message-ID: <20260906-perf-gtk2-v4-3-97e92ee07214@gmail.com> (raw)
In-Reply-To: <20260906-perf-gtk2-v4-0-97e92ee07214@gmail.com>

Sashiko AI review of the GTK2-to-GTK4 port flagged two real issues:

- gtk_widget_show()/gtk_widget_hide() were removed in GTK4 but three
  call sites were missed during the port. Replace with
  gtk_widget_set_visible(), adding a small wrapper for the
  info-bar "response" signal callback since gtk_widget_hide() no
  longer exists to pass directly.

- perf_gtk__error_loops is updated with g_slist_prepend()/
  g_slist_remove() in perf_gtk__error(), but perf_gtk__quit_error_dialog()
  walks the same list from a signal handler (perf_gtk__signal() ->
  perf_gtk__exit()) that can fire mid-update, corrupting the list.
  Block the relevant signals around the two list updates.
---
 tools/perf/ui/gtk/browser.c | 10 ++++++++--
 tools/perf/ui/gtk/util.c    | 27 ++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c
index e1d286945832..40a413787192 100644
--- a/tools/perf/ui/gtk/browser.c
+++ b/tools/perf/ui/gtk/browser.c
@@ -74,6 +74,12 @@ const char *perf_gtk__get_percent_color(double percent)
 	return NULL;
 }
 
+static void perf_gtk__hide_widget(GtkWidget *widget, gint response_id __maybe_unused,
+				   gpointer data __maybe_unused)
+{
+	gtk_widget_set_visible(widget, FALSE);
+}
+
 GtkWidget *perf_gtk__setup_info_bar(void)
 {
 	GtkWidget *info_bar;
@@ -83,14 +89,14 @@ GtkWidget *perf_gtk__setup_info_bar(void)
 	gtk_widget_set_visible(info_bar, FALSE);
 
 	label = gtk_label_new("");
-	gtk_widget_show(label);
+	gtk_widget_set_visible(label, TRUE);
 
 	gtk_info_bar_add_child(GTK_INFO_BAR(info_bar), label);
 
 	gtk_info_bar_add_button(GTK_INFO_BAR(info_bar), "_OK",
 				GTK_RESPONSE_OK);
 	g_signal_connect(info_bar, "response",
-			 G_CALLBACK(gtk_widget_hide), NULL);
+			 G_CALLBACK(perf_gtk__hide_widget), NULL);
 
 	pgctx->info_bar = info_bar;
 	pgctx->message_label = label;
diff --git a/tools/perf/ui/gtk/util.c b/tools/perf/ui/gtk/util.c
index 8a922851257e..f1dbd96e2370 100644
--- a/tools/perf/ui/gtk/util.c
+++ b/tools/perf/ui/gtk/util.c
@@ -2,6 +2,7 @@
 #include "../util.h"
 #include "gtk.h"
 
+#include <signal.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -48,6 +49,25 @@ void perf_gtk__quit_error_dialog(void)
 	g_slist_foreach(perf_gtk__error_loops, perf_gtk__quit_loop, NULL);
 }
 
+/*
+ * perf_gtk__signal() runs perf_gtk__quit_error_dialog() from a signal
+ * handler, which can preempt perf_gtk__error() while it is updating
+ * perf_gtk__error_loops below. Block those signals around the update so
+ * the list is never traversed half-modified.
+ */
+static void perf_gtk__block_exit_signals(sigset_t *old_set)
+{
+	sigset_t set;
+
+	sigemptyset(&set);
+	sigaddset(&set, SIGSEGV);
+	sigaddset(&set, SIGFPE);
+	sigaddset(&set, SIGINT);
+	sigaddset(&set, SIGQUIT);
+	sigaddset(&set, SIGTERM);
+	sigprocmask(SIG_BLOCK, &set, old_set);
+}
+
 static void perf_gtk__dialog_response(GtkDialog *dialog,
 				      gint response_id __maybe_unused,
 				      gpointer data __maybe_unused)
@@ -61,6 +81,7 @@ static int perf_gtk__error(const char *format, va_list args)
 	GtkWidget *dialog;
 	GMainLoop *loop;
 	va_list args_copy;
+	sigset_t old_set;
 
 	va_copy(args_copy, args);
 	if (!perf_gtk__is_active_context(pgctx) ||
@@ -86,7 +107,9 @@ static int perf_gtk__error(const char *format, va_list args)
 	 * outlive the dialog and hang.
 	 */
 	loop = g_main_loop_new(NULL, FALSE);
+	perf_gtk__block_exit_signals(&old_set);
 	perf_gtk__error_loops = g_slist_prepend(perf_gtk__error_loops, loop);
+	sigprocmask(SIG_SETMASK, &old_set, NULL);
 	g_signal_connect(dialog, "response",
 			 G_CALLBACK(perf_gtk__dialog_response), NULL);
 	g_signal_connect_swapped(dialog, "destroy",
@@ -94,7 +117,9 @@ static int perf_gtk__error(const char *format, va_list args)
 
 	gtk_widget_set_visible(dialog, TRUE);
 	g_main_loop_run(loop);
+	perf_gtk__block_exit_signals(&old_set);
 	perf_gtk__error_loops = g_slist_remove(perf_gtk__error_loops, loop);
+	sigprocmask(SIG_SETMASK, &old_set, NULL);
 	g_main_loop_unref(loop);
 
 	free(msg);
@@ -120,7 +145,7 @@ static int perf_gtk__warning_info_bar(const char *format, va_list args)
 	gtk_label_set_text(GTK_LABEL(pgctx->message_label), msg);
 	gtk_info_bar_set_message_type(GTK_INFO_BAR(pgctx->info_bar),
 				      GTK_MESSAGE_WARNING);
-	gtk_widget_show(pgctx->info_bar);
+	gtk_widget_set_visible(pgctx->info_bar, TRUE);
 
 	free(msg);
 	return 0;

-- 
2.54.0


  parent reply	other threads:[~2026-09-06 17:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-06 17:18 [PATCH v4 0/3] perf tools: port UI from GTK2 to GTK4 Matt Turner
2026-09-06 17:18 ` [PATCH v4 1/3] tools: port perf ui from GTK 2 to GTK 4 Matt Turner
2026-09-06 17:27   ` sashiko-bot
2026-09-06 17:18 ` [PATCH v4 2/3] perf tools: make the GTK4 report browser actually loadable at runtime Matt Turner
2026-09-06 17:27   ` sashiko-bot
2026-09-06 17:18 ` Matt Turner [this message]
2026-09-06 17:29   ` [PATCH v4 3/3] perf tools: fix GTK4 leftover show/hide calls and error-loop list race sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260906-perf-gtk2-v4-3-97e92ee07214@gmail.com \
    --to=mattst88@gmail.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=bpf@vger.kernel.org \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox