Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 05/15] perf debuginfo: Show the debuginfod fetch progress and keys in the TUI
Date: Thu, 17 Sep 2026 16:09:47 +0000	[thread overview]
Message-ID: <20260917160948.4BE121F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260917155528.62607-6-acme@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] perf tui: SLang data race and input corruption during concurrent debuginfod fetch
--

commit 8d18f5ec06006e4e275aaf1773a82812d40a2e7f
Author: Arnaldo Carvalho de Melo <acme@redhat.com>

    perf debuginfo: Show the debuginfod fetch progress and keys in the TUI
    
    The stdio only fetch UI left a TUI fetch in progress with nothing on
    screen, indistinguishable from a stuck perf, with no way out of it.
    Draw a window over the browser with the fetch progress, and drain the
    's'/'d' keys from the TUI input queue, through the new
    ui__key_pending()/ui__key_read()/ui__progress_window()/
    ui__progress_window_end() primitives declared in ui/util.h and
    implemented in ui/tui/util.c, with no-ops for builds without slang:
    slang stays behind the ui/ layer and callers stay free of #ifdefs.

> diff --git a/tools/perf/ui/tui/util.c b/tools/perf/ui/tui/util.c
> index e4d322ce0b54c..280865e980ef5 100644
> --- a/tools/perf/ui/tui/util.c
> +++ b/tools/perf/ui/tui/util.c
[ ... ]
> +void ui__progress_window(const char *title, const char *text,
> +			 u64 fetched, u64 total)
> +{
> +	static char lines[PROGRESS_WINDOW_MAX_LINES][256];
> +	char buf_cur[20], buf_tot[20], bytes[64];
> +	size_t len;
> +	int y, height, nr_lines, inner, i;
> +
> +	if (use_browser != 1)
> +		return;
> +
> +	unit_number__scnprintf(buf_cur, sizeof(buf_cur), fetched);
> +	if (total) {
> +		unit_number__scnprintf(buf_tot, sizeof(buf_tot), total);
> +		scnprintf(bytes, sizeof(bytes), "  %s / %s fetched",
> +			  buf_cur, buf_tot);
> +	} else {
> +		scnprintf(bytes, sizeof(bytes),
> +			  "  %s fetched, size unknown", buf_cur);
> +	}
> +
> +	if (progress_window__shown && !strcmp(bytes, progress_window__bytes))
> +		return;
> +
> +	scnprintf(progress_window__bytes, sizeof(progress_window__bytes),
> +		  "%s", bytes);
> +	progress_window__shown = true;
> +
> +	ui__refresh_dimensions(false);
> +	mutex_lock(&ui__lock);
> +	/*
> +	 * SLsmg_write_nstring() takes the width as an unsigned int, so never
> +	 * let a narrow terminal make it negative.  Clamp it.
> +	 */
> +	inner = SLtt_Screen_Cols - 2;
> +	if (inner < 0)
> +		inner = 0;
> +	else if (inner > 255)
> +		inner = 255;
> +	nr_lines = progress_window__wrap(text, inner, lines);

[Severity: High]
Does this code introduce data races on the static buffers?

The ui__progress_window() function updates static variables like
progress_window__bytes, progress_window__shown, and the static lines array
before acquiring the ui__lock.

Since debuginfod fetch callbacks can execute on the process_thread while the
display_thread is running, can concurrent updates corrupt these buffers and
state flags?

[ ... ]
> +/*
> + * The keys typed while the fetch blocked the browser are in the TUI
> + * input queue: nobody else is reading it, drain them through these.
> + */
> +bool ui__key_pending(void)
> +{
> +	return use_browser == 1 && SLang_input_pending(0) > 0;
> +}

[Severity: High]
Can calling this corrupt the terminal state when debuginfod fetches occur?

This calls SLang_input_pending() directly without synchronization. Since
ui__key_pending() can be triggered via debuginfod__tui_poll_cancel_keys()
from the process_thread during a background fetch, it can race with the
display_thread running ui__getch().

> +
> +int ui__key_read(void)
> +{
> +	return SLang_getkey();
> +}
> diff --git a/tools/perf/util/debuginfo.c b/tools/perf/util/debuginfo.c
> index 0ec11e1ad7508..737dd445d42bb 100644
> --- a/tools/perf/util/debuginfo.c
> +++ b/tools/perf/util/debuginfo.c
[ ... ]
> +/*
> + * The browser thread is the one doing the fetch, so its input queue has
> + * the keys typed while it was busy, drain those.
> + */
> +static void debuginfod__tui_poll_cancel_keys(void)
> +{
> +	while (ui__key_pending())
> +		debuginfod__cancel_key(ui__key_read());
> +}

[Severity: High]
Does this loop silently drop any keystrokes other than 's' or 'd'?

When debuginfod__cancel_key() processes input, it only handles 's' and 'd',
meaning any other keys read from the queue are discarded rather than being
passed back to the TUI.

When this runs on the process_thread, could it drop user input intended for
the display_thread?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260917155528.62607-1-acme@kernel.org?part=5

  reply	other threads:[~2026-09-17 16:09 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 15:55 [PATCH v7 0/15] perf tools: Annotate fixes, stdio progress indication, debuginfo-client in more places Arnaldo Carvalho de Melo
2026-09-17 15:55 ` [PATCH 01/15] perf debuginfo: Fetch debuginfo keyed by build ID using debuginfod Arnaldo Carvalho de Melo
2026-09-17 16:03   ` sashiko-bot
2026-09-17 17:58   ` Ian Rogers
2026-09-17 20:36     ` Arnaldo Carvalho de Melo
2026-09-17 15:55 ` [PATCH 02/15] perf debuginfo: Set DEBUGINFOD_URLS from /etc/debuginfod when unset Arnaldo Carvalho de Melo
2026-09-17 16:07   ` sashiko-bot
2026-09-17 15:55 ` [PATCH 03/15] perf config: Move perf_config__set_variable() to util/config.c Arnaldo Carvalho de Melo
2026-09-17 16:11   ` sashiko-bot
2026-09-17 15:55 ` [PATCH 04/15] perf debuginfo: Let the user skip and disable debuginfod fetches Arnaldo Carvalho de Melo
2026-09-17 16:05   ` sashiko-bot
2026-09-17 15:55 ` [PATCH 05/15] perf debuginfo: Show the debuginfod fetch progress and keys in the TUI Arnaldo Carvalho de Melo
2026-09-17 16:09   ` sashiko-bot [this message]
2026-09-17 15:55 ` [PATCH 06/15] perf symbol: Fall back to fetching the vmlinux by build ID Arnaldo Carvalho de Melo
2026-09-17 16:08   ` sashiko-bot
2026-09-17 15:55 ` [PATCH 07/15] perf annotate-data: Show the sample count in the data-type browser Arnaldo Carvalho de Melo
2026-09-17 16:04   ` sashiko-bot
2026-09-17 15:55 ` [PATCH 08/15] perf report: Add --progress option Arnaldo Carvalho de Melo
2026-09-17 16:02   ` sashiko-bot
2026-09-17 15:55 ` [PATCH 09/15] perf scripts: Add perf-stuck, to tell where a running perf is stuck Arnaldo Carvalho de Melo
2026-09-17 16:04   ` sashiko-bot
2026-09-17 15:55 ` [PATCH 10/15] perf dwarf-aux: Bound the type chases for broken debug info Arnaldo Carvalho de Melo
2026-09-17 16:03   ` sashiko-bot
2026-09-17 15:55 ` [PATCH 11/15] perf dwarf-aux: Add die_same_file() and die_get_type_die() Arnaldo Carvalho de Melo
2026-09-17 16:09   ` sashiko-bot
2026-09-17 15:55 ` [PATCH 12/15] perf annotate-data: Resolve type DIEs in the debug file they came from Arnaldo Carvalho de Melo
2026-09-17 16:09   ` sashiko-bot
2026-09-17 15:55 ` [PATCH 13/15] perf annotate-data: Bound the member nesting recursion Arnaldo Carvalho de Melo
2026-09-17 16:08   ` sashiko-bot
2026-09-17 15:55 ` [PATCH 14/15] perf mem record: Request PERF_SAMPLE_CPU by default Arnaldo Carvalho de Melo
2026-09-17 16:15   ` sashiko-bot
2026-09-17 15:55 ` [PATCH 15/15] perf mem record: Use the IBS swfilt filter when available Arnaldo Carvalho de Melo
2026-09-17 16:09   ` 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=20260917160948.4BE121F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=acme@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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