From: sashiko-bot@kernel.org
To: "Praneeth Balasubramanian" <praneethb2002@gmail.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] tracing: Hold trace_event_read_lock() in ftrace_dump() when possible
Date: Fri, 04 Dec 2026 19:31:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-250546@kernel.org> (raw)
In-Reply-To: <20261204184958.1687218-2-praneethb2002@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] tracing: ftrace_dump_one() re-enables IRQs on PREEMPT_RT via
up_read()
- [Medium] tracing: ftrace_dump_one() can self-deadlock in up_read()
wakeup path
--
commit 019975a69522d21b631cf062f9dab7b3f93483ca
Author: Praneeth Balasubramanian <praneethb2002@gmail.com>
tracing: Hold trace_event_read_lock() in ftrace_dump() when possible
This commit adds trace_event_read_trylock() and uses it in
ftrace_dump_one() when in_task() is true to hold trace_event_sem across
the dump loop and release it afterward.
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index abd875bae713c..c7cd21a105a6a 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
[ ... ]
> @@ -9526,6 +9527,15 @@ static void ftrace_dump_one(struct trace_array *tr, enum ftrace_dump_mode dump_m
> */
> tracer_tracing_off(tr);
>
> + /*
> + * print_trace_line() looks up the event of each entry, which needs
> + * trace_event_read_lock() so that the event is not unregistered and
> + * freed meanwhile. A dump must not sleep and can run in any context,
> + * so only try the lock, and only in task context. If it is not
> + * available, dump without it as before.
> + */
> + event_locked = in_task() && trace_event_read_trylock();
> +
> local_irq_save(flags);
>
> /* Simulate the iterator */
> @@ -9593,6 +9603,9 @@ static void ftrace_dump_one(struct trace_array *tr, enum ftrace_dump_mode dump_m
>
> tracer_tracing_enable(tr);
> local_irq_restore(flags);
> +
> + if (event_locked)
> + trace_event_read_unlock();
> }
[Severity: Medium]
On CONFIG_PREEMPT_RT, can trace_event_read_unlock() re-enable hardware
interrupts when ftrace_dump_one() is called with IRQs disabled?
in_task() does not check irqs_disabled(), so it returns true in
IRQ-disabled task contexts such as x86 die() -> oops_begin(), which
disables hard IRQs and takes die_lock before calling ftrace_dump().
If another CPU enters down_write(&trace_event_sem) during the dump,
up_read() takes the __rwbase_read_unlock() slowpath after
local_irq_restore(flags) keeps IRQs disabled. __rwbase_read_unlock()
calls raw_spin_unlock_irq(&rtm->wait_lock) and rt_mutex_wake_up_q().
That unconditionally enables hard IRQs behind the caller's back and
calls preempt_enable(), which can cause IRQ re-entrancy deadlocks or
preempt the oopsing task while it still holds die_lock.
[Severity: Medium]
Can trace_event_read_unlock() self-deadlock in the up_read() wakeup path
when ftrace_dump() is invoked while holding scheduler or rwsem locks?
in_task() returns true even with preemption disabled and raw spinlocks
held, such as when ftrace_dump_probe() is attached to a scheduler
function or an oops happens inside scheduler or rwsem wait_lock code:
CPU0 CPU1
---- ----
<holds rq->__lock>
function_trace_probe_call()
ftrace_dump_probe()
ftrace_dump_one()
trace_event_read_trylock()
down_write(&trace_event_sem)
<queues waiter, blocks>
trace_event_read_unlock()
up_read(&trace_event_sem)
rwsem_wake()
wake_up_q()
try_to_wake_up()
lock(rq->__lock) <-- spins forever
Both rwsem_wake() and PREEMPT_RT's __rwbase_read_unlock() acquire the
rwsem wait_lock and call wake_up_q() -> try_to_wake_up(), which takes
p->pi_lock and rq->__lock. If the dumping CPU already holds any of
those locks, it hangs instead of completing the dump or oops path.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204184958.1687218-1-praneethb2002@gmail.com?part=2
prev parent reply other threads:[~2026-12-04 19:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 18:49 [PATCH 1/2] tracing: Keep an instance alive while ftrace_dump() dumps it Praneeth Balasubramanian
2026-12-04 18:49 ` [PATCH 2/2] tracing: Hold trace_event_read_lock() in ftrace_dump() when possible Praneeth Balasubramanian
2026-12-04 19:31 ` sashiko-bot [this message]
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=sashiko-outbox-250546@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=praneethb2002@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.