From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796412690; b=NlxOWWItA4on1hgKv7HBi+UeBtQKWhFmaiXKXlJViCPuUPI8lpllick1lN4Rz1yqhN7e 7YYHubCnq3SOqLzkxEpjIvHH1WF+8iP5zaD6LxULdm6gU+/Zxxr7nM62Wujg3Xg7CQRQG TK5ZFYjRtwCE6pYqRGRPhOgn80+lsMnLv0osdl2nS+wg9e07fjFnl9yd9KpsTyHpRUF+c uKFWoV0fo5Jwe3FSjKxN8F1bS6SFC8pwvKN3Y2sqsIRnZpCpVIWpIJXLv1THKsASXmtti Nlh/huTdKVCPeNDUNqdA7oWlOGIyzpgQH8dPBqyjPkotG5JXt5gxjK+uNAGpikVhkrA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796412690; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=FNiAs94Y+ME2AshbXdJ2fXCvX/ZD1Yun/gdo/XRBYIg=; b=Wr4qCxoivUl2wFHpyAt4eDQNa35IHac/IdWd5uCutcd54uSTzy0YIwzSp5lgQQr5/ow9 k0u49ryB6qJp6+HuWs9Y2kBEtPQM1Z0O8z6ZM8FzIo6UTvb+650l7gGWwLf4JZ4kAtK/w 1ou6Nf6gx7ghmBWEzgQDiUQzaaweLkNz88EHwVgjfswDDD/cDWPrvDax3NXxVyDSF+h1i V18a5UIA0XapDFO5jxlJbS0E5ytFK+/y89XGFBGxxfU9hLt3D50E1RJ3uqjuXarX5Qb6h LRvoyzMSxr/WEpI/7fGg4r2XSO83hYF1pNdUzHR8E2QP1er6lsjPAvsMMnuw/MLuaDA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lOWltgs7; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8F9E606A322 for ; Fri, 4 Dec 2026 19:31:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lOWltgs7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FAB31F00936; Fri, 4 Dec 2026 19:31:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796412690; bh=FNiAs94Y+ME2AshbXdJ2fXCvX/ZD1Yun/gdo/XRBYIg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=lOWltgs7+lp2WehgwZU4VUbJEhUqZasWDuxgbUtIwK3neXktT/Hpwb5odsweMh/8g 3N1vEVLaPT/7r3OJGq9O1+ehNMV2QZ+6T3A0YwynPFJIm87X/bt2O2sbrTyIQasCEy Z3iC3CVJEbU2ji3+Kpn2XZuMUBPQtVcv1gwu5YDSi9R7dL2tBoPMayhNvJcDTqoKvU 2HteS4bndCpLoFX/AeN8OT27F4TraGYhLuqMqMUO1Qe6ksEf32hwRgJ/5pEbjZP9pb 2k4hnGo6ix8CEzp/pZjielXKEZ8pl/0m5CBdstWAdx+0EdgjiyQ2+1XoyBIB9Vm99l 7zbFat4PYjMpw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/2] tracing: Hold trace_event_read_lock() in ftrace_dump() when possible Reply-To: sashiko-reviews@lists.linux.dev To: "Praneeth Balasubramanian" Cc: linux-trace-kernel@vger.kernel.org In-Reply-To: <20261204184958.1687218-2-praneethb2002@gmail.com> References: <20261204184958.1687218-1-praneethb2002@gmail.com> <20261204184958.1687218-2-praneethb2002@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 19:31:29 +0000 X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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); > =20 > + /* > + * 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 =3D in_task() && trace_event_read_trylock(); > + > local_irq_save(flags); > =20 > /* Simulate the iterator */ > @@ -9593,6 +9603,9 @@ static void ftrace_dump_one(struct trace_array *tr,= enum ftrace_dump_mode dump_m > =20 > 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 ---- ---- __lock> function_trace_probe_call() ftrace_dump_probe() ftrace_dump_one() trace_event_read_trylock() down_write(&trace_event_sem) 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204184958.1687= 218-1-praneethb2002@gmail.com?part=3D2