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=1796327564; b=pC4tEhdps8vTm90M8Tm3VcNMaG/yeNVZVKZpiZupG6VuyKdVUXuEtEEKvaVn86pJoebv RXq9jb5Wk0PixHiQn0MVFUYCDTnRUxFxMh0gYwtj7jl7aUxWX1RtXfLjVbRKRcdPyqsgn Px7lLyN9msJyYc2WOqlfHsT2mSVbzPXbApKJ+C0GGdEhAh1CcLcC4NNCT33mJAg+oDNRJ F2ABRNP/Cs3H3u7wOqG6su1p9A2/XhzpT1otOzm/oyGMu/eK4QZpEMAgIIh6yQhSUXIQW q5tgBjUaygvZd6pSPIEnF8L6koFnjbY4E1RW5xQbTWNtZG4n6bXzTVE2BLhYHFujqyg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796327564; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=vRslDPUZQeihYK2DV/JzvfxRQbXdD7iodxV0felsk9I=; b=lJuVX8yaJF+Gn43ymScwfta3kG8xY9TFAXyc9MTs7Gbk4V82Co10boEQef402ZethSLt N8k5k365rMpNbt1jdZeTMrBAQA/RPa8codcw1bYsrKTvYv5UKst6eJQ9SxCFgjlSdhvnm 4fIQkgUZEEvOUBU4wdXe6yfJi8g/DnngkLfq894Hu/fMrgtoAbAUdTguYMwM9cILtCC4s PlqR/JpshFrofZ0TFgGWaE0WFZVzDHpOFdhWQZ1UdqURl09RzI4qoA2cWe0CTCdCVT1SX P5eRtbKsjhA3vht8Xe6PIHy7GAhgaRBPd1SdDxCpWjb7E6giVepyKwD6erfSdo9/1lw== 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=JAfdmy3r; 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 390C0606A330 for ; Thu, 3 Dec 2026 19:52:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JAfdmy3r Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06FA21F000CE; Thu, 3 Dec 2026 19:52:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796327564; bh=vRslDPUZQeihYK2DV/JzvfxRQbXdD7iodxV0felsk9I=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=JAfdmy3rraPGw1RbSuWgOcKwyPTarz/A2LQDOFhSy654w9MFGz5zfPA8FCOiPTueE KY1EGhbD8eavvYrjve6HgtSyafcxxBnugYZmGUyexEvMAtghPeyLICuSEHUcWnSqtF oUxKcQg+bxayVEj9AoYtMKerTUa+9w0BiDpt1j1P2AhI19JxnoaYLYWGiY0JyjvRx1 4ocFEwlo9/Rk2FDHtjeeo529tI+zTTavZON5fFGPyaFCab9lTm7m+OSVkFvPdLNzp+ EisYjMcJHWewlpR0AEbirLFIuqPhxRu6YyZGuTFffBaIGoffWAiDGzH+6wS/fR49hw jliY832w2aquw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v10 14/19] tracing/remotes: Add dump_on_panic tracefs file Reply-To: sashiko-reviews@lists.linux.dev To: "Vincent Donnefort" , linux-trace-kernel@vger.kernel.org In-Reply-To: <20261203190007.2431041-15-vdonnefort@google.com> References: <20261203190007.2431041-1-vdonnefort@google.com> <20261203190007.2431041-15-vdonnefort@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 19:52:43 +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 4 potential issues to consider: - [Medium] tracing/remotes: deadlock on reader_lock in trace_remote_panic_handler() - [Medium] tracing/remotes: hotplugged CPUs omitted from trace_remote_panic_handler() - [Medium] tracing/remotes: unbounded dump loop in trace_remote_panic_handler() - [Medium] ring-buffer: IRQ-unsafe reader_lock in ring_buffer_poll_remote() -- commit 2b2612882df3895db81d737752cd2225ff3430b1 Author: Vincent Donnefort tracing/remotes: Add dump_on_panic tracefs file This commit adds a dump_on_panic tracefs attribute for trace remotes that registers a panic notifier and pre-allocates a non-consuming iterator to dump remote ring buffer contents via pr_emerg() when the system panics. > diff --git a/kernel/trace/trace_remote.c b/kernel/trace/trace_remote.c > index c9d2e8731fdc0..a317a417207d8 100644 > --- a/kernel/trace/trace_remote.c > +++ b/kernel/trace/trace_remote.c [ ... ] > @@ -990,6 +1030,113 @@ static int dmesg_show(struct seq_file *s, void *un= used) > } > DEFINE_TRACE_REMOTE_ATTRIBUTE(dmesg); > =20 > +static int trace_remote_panic_handler(struct notifier_block *self, unsig= ned long ev, void *v) > +{ > + struct trace_remote *remote =3D container_of(self, struct trace_remote,= panic_notifier); > + struct trace_remote_iterator *iter =3D smp_load_acquire(&remote->panic_= iter); > + int cpu; > + > + if (!iter) { > + pr_warn("Unexpected error: no panic iterator for the trace remote\n"); > + return NOTIFY_DONE; > + } > + > + for_each_possible_cpu(cpu) > + ring_buffer_iter_reset(iter->rb_iters[cpu]); [Severity: Medium] Can trace_remote_panic_handler() deadlock on cpu_buffer->reader_lock during a non-NMI panic? vpanic() halts all other CPUs via panic_other_cpus_shutdown() before calling panic_notifier_list. ring_buffer_iter_reset(), trace_remote_iter_read_event(), and trace_remote_iter_move() all acquire cpu_buffer->reader_lock via rb_reader_lock(), which only falls back to raw_spin_trylock() when in_nmi() is true and otherwise spins unconditionally without checking panic_in_progress(). CPU0 CPU1 trace_pipe_read() ... raw_spin_lock(&reader_lock) vpanic() panic_other_cpus_shutdown() atomic_notifier_call_chain() trace_remote_panic_handler() ring_buffer_iter_reset() rb_reader_lock() raw_spin_lock(&reader_lock) <-- spins forever The panicking CPU can also self-deadlock if a hypervisor panic occurs while it holds reader_lock in hyp_trace_swap_reader_page(). Because this notifier runs at priority INT_MAX - 1, a deadlock hangs the panic path before remaining panic notifiers, kmsg_dump_desc(), or automatic reboot can run. [Severity: Medium] Does ring_buffer_poll_remote() need raw_spinlock_irqsave for cpu_buffer->reader_lock now that trace_remote_panic_handler() acquires it in panic context? Every other acquisition of cpu_buffer->reader_lock in kernel/trace/ring_buffer.c disables IRQs (including rb_wake_up_waiters() in hardirq context), but ring_buffer_poll_remote() uses guard(raw_spinlock)(&cpu_buffer->reader_lock). ring_buffer_poll_remote() guard(raw_spinlock)(&cpu_buffer->reader_lock) vpanic() atomic_notifier_call_chain() trace_remote_panic_handler() ring_buffer_iter_reset() rb_reader_lock() raw_spin_lock(&cpu_buffer->reader_lock) <-- spins forever With IRQs left enabled, a hardirq panic (such as sysrq-c) preempting ring_buffer_poll_remote() self-deadlocks on the same CPU, and a non-NMI stop IPI can halt the polling CPU while it holds reader_lock. > + > + while (trace_remote_iter_read_event(iter)) { > + trace_seq_init(&iter->seq); > + > + trace_remote_iter_print_event(iter); > + trace_seq_putc(&iter->seq, 0); > + pr_emerg("%s", seq_buf_str(&iter->seq.seq)); > + > + trace_remote_iter_move(iter); > + touch_nmi_watchdog(); > + } [Severity: Medium] Is this dump loop bounded if the remote producer keeps writing during the panic? Unlike ftrace_dump_one(), trace_remote_panic_handler() does not stop the remote writer before dumping, and ring_buffer_iter_empty() re-reads the live commit offset from the shared page on each iteration. If an independent firmware or coprocessor remote continues writing (or an EL2 hypervisor logs console traps from pr_emerg()) and overwrites iter->head_page, rb_iter_head_event() resets iter->head to 0 with the new page timestamp so rb_iter_peek() keeps reading indefinitely. Because touch_nmi_watchdog() runs on every iteration, an active writer can livelock the panic path and suppress watchdog recovery, preventing kmsg_dump_desc() and automatic reboot from completing. Stopping the remote writer or bounding the dump to the current ring buffer size would avoid this. > + > + return NOTIFY_DONE; > +} > + > +static int trace_remote_panic_load(struct trace_remote *remote) > +{ > + struct notifier_block *notifier =3D &remote->panic_notifier; > + struct trace_remote_iterator *iter; > + > + lockdep_assert_held(&remote->lock); > + > + if (remote->panic_iter) > + return 0; > + > + iter =3D trace_remote_iter(remote, RING_BUFFER_ALL_CPUS, TRI_PANIC); > + if (IS_ERR(iter)) > + return PTR_ERR(iter); [Severity: Medium] Will events from CPUs hotplugged online after trace_remote_panic_load() be silently omitted from the panic dump? trace_remote_panic_load() allocates remote->panic_iter once for the loaded lifetime of the remote. In __alloc_ring_buffer_iter(), ring_buffer_read_start() returns NULL for any CPU that is currently offline because it is not yet in buffer->cpumask, leaving iter->rb_iters[cpu] as NULL. When that CPU is later brought online, trace_rb_cpu_prepare() allocates its ring buffer and adds it to buffer->cpumask, but nothing populates remote->panic_iter->rb_iters[cpu]. On panic, __peek_event() sees a NULL iterator and skips that CPU, losing all trace events recorded on the newly onlined CPU. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203190007.2431= 041-1-vdonnefort@google.com?part=3D14