public inbox for linux-trace-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix trace remotes read with an offline CPU
@ 2026-04-01  2:50 Vincent Donnefort
  2026-04-01  2:50 ` [PATCH 1/2] tracing: Non-consuming read for trace remotes " Vincent Donnefort
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Vincent Donnefort @ 2026-04-01  2:50 UTC (permalink / raw)
  To: rostedt, mhiramat, mathieu.desnoyers, linux-trace-kernel, maz
  Cc: kernel-team, linux-kernel, Vincent Donnefort

This small series is fixing non-consuming read of a trace remote when the
trace_buffer is created after a CPU is offline.

It also extends hotplug testing coverage to include this test case.

I have based this series on top of kvmarm/next which contains the hypervisor
tracing patches.

Vincent Donnefort (2):
  tracing: Non-consuming read for trace remotes with an offline CPU
  tracing: selftests: Extend hotplug testing for trace remotes

 kernel/trace/trace_remote.c                   | 21 ++++-
 .../selftests/ftrace/test.d/remotes/functions | 15 +++-
 .../ftrace/test.d/remotes/hotplug.tc          | 86 +++++++++++++++++++
 .../test.d/remotes/hypervisor/hotplug.tc      | 11 +++
 .../selftests/ftrace/test.d/remotes/trace.tc  | 27 +-----
 .../ftrace/test.d/remotes/trace_pipe.tc       | 25 ------
 6 files changed, 129 insertions(+), 56 deletions(-)
 create mode 100644 tools/testing/selftests/ftrace/test.d/remotes/hotplug.tc
 create mode 100644 tools/testing/selftests/ftrace/test.d/remotes/hypervisor/hotplug.tc


base-commit: 5ad2ff071b5980f072a85c8114649218971c586e
-- 
2.53.0.1118.gaef5881109-goog


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] tracing: Non-consuming read for trace remotes with an offline CPU
  2026-04-01  2:50 [PATCH 0/2] Fix trace remotes read with an offline CPU Vincent Donnefort
@ 2026-04-01  2:50 ` Vincent Donnefort
  2026-04-01  2:50 ` [PATCH 2/2] tracing: selftests: Extend hotplug testing for trace remotes Vincent Donnefort
  2026-04-01 14:31 ` [PATCH 0/2] Fix trace remotes read with an offline CPU Steven Rostedt
  2 siblings, 0 replies; 6+ messages in thread
From: Vincent Donnefort @ 2026-04-01  2:50 UTC (permalink / raw)
  To: rostedt, mhiramat, mathieu.desnoyers, linux-trace-kernel, maz
  Cc: kernel-team, linux-kernel, Vincent Donnefort

When a trace_buffer is created while a CPU is offline, this CPU is
cleared from the trace_buffer CPU mask, preventing the creation of a
non-consuming iterator (ring_buffer_iter). For trace remotes, it means
the iterator fails to be allocated (-ENOMEM) even though there are
available ring buffers in the trace_buffer.

For non-consuming reads of trace remotes, skip missing ring_buffer_iter
to allow reading the available ring buffers.

Signed-off-by: Vincent Donnefort <vdonnefort@google.com>

diff --git a/kernel/trace/trace_remote.c b/kernel/trace/trace_remote.c
index 0d78e5f5fe98..39d5414c1723 100644
--- a/kernel/trace/trace_remote.c
+++ b/kernel/trace/trace_remote.c
@@ -282,6 +282,14 @@ static void trace_remote_put(struct trace_remote *remote)
 	trace_remote_try_unload(remote);
 }
 
+static bool trace_remote_has_cpu(struct trace_remote *remote, int cpu)
+{
+	if (cpu == RING_BUFFER_ALL_CPUS)
+		return true;
+
+	return ring_buffer_poll_remote(remote->trace_buffer, cpu) == 0;
+}
+
 static void __poll_remote(struct work_struct *work)
 {
 	struct delayed_work *dwork = to_delayed_work(work);
@@ -324,6 +332,10 @@ static int __alloc_ring_buffer_iter(struct trace_remote_iterator *iter, int cpu)
 		iter->rb_iters[cpu] = ring_buffer_read_start(iter->remote->trace_buffer, cpu,
 							     GFP_KERNEL);
 		if (!iter->rb_iters[cpu]) {
+			/* This CPU isn't part of trace_buffer. Skip it */
+			if (!trace_remote_has_cpu(iter->remote, cpu))
+				continue;
+
 			__free_ring_buffer_iter(iter, RING_BUFFER_ALL_CPUS);
 			return -ENOMEM;
 		}
@@ -347,10 +359,10 @@ static struct trace_remote_iterator
 	if (ret)
 		return ERR_PTR(ret);
 
-	/* Test the CPU */
-	ret = ring_buffer_poll_remote(remote->trace_buffer, cpu);
-	if (ret)
+	if (!trace_remote_has_cpu(remote, cpu)) {
+		ret = -ENODEV;
 		goto err;
+	}
 
 	iter = kzalloc_obj(*iter);
 	if (iter) {
@@ -476,6 +488,9 @@ __peek_event(struct trace_remote_iterator *iter, int cpu, u64 *ts, unsigned long
 		return ring_buffer_peek(iter->remote->trace_buffer, cpu, ts, lost_events);
 	case TRI_NONCONSUMING:
 		rb_iter = __get_rb_iter(iter, cpu);
+		if (!rb_iter)
+			return NULL;
+
 		rb_evt = ring_buffer_iter_peek(rb_iter, ts);
 		if (!rb_evt)
 			return NULL;
-- 
2.53.0.1118.gaef5881109-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] tracing: selftests: Extend hotplug testing for trace remotes
  2026-04-01  2:50 [PATCH 0/2] Fix trace remotes read with an offline CPU Vincent Donnefort
  2026-04-01  2:50 ` [PATCH 1/2] tracing: Non-consuming read for trace remotes " Vincent Donnefort
@ 2026-04-01  2:50 ` Vincent Donnefort
  2026-04-01 14:31 ` [PATCH 0/2] Fix trace remotes read with an offline CPU Steven Rostedt
  2 siblings, 0 replies; 6+ messages in thread
From: Vincent Donnefort @ 2026-04-01  2:50 UTC (permalink / raw)
  To: rostedt, mhiramat, mathieu.desnoyers, linux-trace-kernel, maz
  Cc: kernel-team, linux-kernel, Vincent Donnefort

The hotplug testing only tries reading a trace remote buffer, loaded
before a CPU is offline. Extend this testing to cover:

  * A trace remote buffer loaded after a CPU is offline.
  * A trace remote buffer loaded before a CPU is online.

Because of these added test cases, move the hotplug testing into a
separate hotplug.tc file.

Signed-off-by: Vincent Donnefort <vdonnefort@google.com>

diff --git a/tools/testing/selftests/ftrace/test.d/remotes/functions b/tools/testing/selftests/ftrace/test.d/remotes/functions
index 97a09d564a34..ca531a0336dc 100644
--- a/tools/testing/selftests/ftrace/test.d/remotes/functions
+++ b/tools/testing/selftests/ftrace/test.d/remotes/functions
@@ -32,6 +32,15 @@ assert_unloaded()
 	grep -q "(unloaded)" buffer_size_kb
 }
 
+reload_remote()
+{
+	echo 0 > tracing_on
+	clear_trace
+	assert_unloaded
+	echo 1 > tracing_on
+	assert_loaded
+}
+
 dump_trace_pipe()
 {
     output=$(mktemp $TMPDIR/remote_test.XXXXXX)
@@ -79,10 +88,12 @@ get_cpu_ids()
     sed -n 's/^processor\s*:\s*\([0-9]\+\).*/\1/p' /proc/cpuinfo
 }
 
-get_page_size() {
+get_page_size()
+{
     sed -ne 's/^.*data.*size:\([0-9][0-9]*\).*/\1/p' events/header_page
 }
 
-get_selftest_event_size() {
+get_selftest_event_size()
+{
     sed -ne 's/^.*field:.*;.*size:\([0-9][0-9]*\);.*/\1/p' events/*/selftest/format | awk '{s+=$1} END {print s}'
 }
diff --git a/tools/testing/selftests/ftrace/test.d/remotes/hotplug.tc b/tools/testing/selftests/ftrace/test.d/remotes/hotplug.tc
new file mode 100644
index 000000000000..86b55824d631
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/remotes/hotplug.tc
@@ -0,0 +1,86 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Test trace remote read with an offline CPU
+# requires: remotes/test
+
+. $TEST_DIR/remotes/functions
+
+hotunplug_one_cpu()
+{
+	[ "$(get_cpu_ids | wc -l)" -ge 2 ] || return 1
+
+	for cpu in $(get_cpu_ids); do
+		echo 0 > /sys/devices/system/cpu/cpu$cpu/online || return 1
+		break
+	done
+
+	echo $cpu
+}
+
+# Check non-consuming and consuming read
+check_read()
+{
+    for i in $(seq 1 8); do
+        echo $i > write_event
+    done
+
+    check_trace 1 8 trace
+
+    output=$(dump_trace_pipe)
+    check_trace 1 8 $output
+    rm $output
+}
+
+test_hotplug()
+{
+    echo 0 > trace
+    assert_loaded
+
+    #
+    # Test a trace buffer containing an offline CPU
+    #
+
+    cpu=$(hotunplug_one_cpu) || exit_unsupported
+
+    check_read
+
+    #
+    # Test a trace buffer with a missing CPU
+    #
+
+    reload_remote
+
+    check_read
+
+    #
+    # Test a trace buffer with a CPU added later
+    #
+
+    echo 1 > /sys/devices/system/cpu/cpu$cpu/online
+    assert_loaded
+
+    check_read
+
+    # Test if the ring-buffer for the newly added CPU is both writable and
+    # readable
+    for i in $(seq 1 8); do
+        taskset -c $cpu echo $i > write_event
+    done
+
+    cd per_cpu/cpu$cpu/
+
+    check_trace 1 8 trace
+
+    output=$(dump_trace_pipe)
+    check_trace 1 8 $output
+    rm $output
+
+    cd -
+}
+
+if [ -z "$SOURCE_REMOTE_TEST" ]; then
+    set -e
+
+    setup_remote_test
+    test_hotplug
+fi
diff --git a/tools/testing/selftests/ftrace/test.d/remotes/hypervisor/hotplug.tc b/tools/testing/selftests/ftrace/test.d/remotes/hypervisor/hotplug.tc
new file mode 100644
index 000000000000..580ec32c8f81
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/remotes/hypervisor/hotplug.tc
@@ -0,0 +1,11 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Test hypervisor trace read with an offline CPU
+# requires: remotes/hypervisor/write_event
+
+SOURCE_REMOTE_TEST=1
+. $TEST_DIR/remotes/hotplug.tc
+
+set -e
+setup_remote "hypervisor"
+test_hotplug
diff --git a/tools/testing/selftests/ftrace/test.d/remotes/trace.tc b/tools/testing/selftests/ftrace/test.d/remotes/trace.tc
index 170f7648732a..bc9377a70e8d 100644
--- a/tools/testing/selftests/ftrace/test.d/remotes/trace.tc
+++ b/tools/testing/selftests/ftrace/test.d/remotes/trace.tc
@@ -58,11 +58,7 @@ test_trace()
     #
 
     # Ensure the writer is not on the reader page by reloading the buffer
-    echo 0 > tracing_on
-    echo 0 > trace
-    assert_unloaded
-    echo 1 > tracing_on
-    assert_loaded
+    reload_remote
 
     # Ensure ring-buffer overflow by emitting events from the same CPU
     for cpu in $(get_cpu_ids); do
@@ -96,27 +92,6 @@ test_trace()
 
         cd - > /dev/null
     done
-
-    #
-    # Test with hotplug
-    #
-
-    [ "$(get_cpu_ids | wc -l)" -ge 2 ] || return 0
-
-    echo 0 > trace
-
-    for cpu in $(get_cpu_ids); do
-        echo 0 > /sys/devices/system/cpu/cpu$cpu/online || return 0
-        break
-    done
-
-    for i in $(seq 1 8); do
-        echo $i > write_event
-    done
-
-    check_trace 1 8 trace
-
-    echo 1 > /sys/devices/system/cpu/cpu$cpu/online
 }
 
 if [ -z "$SOURCE_REMOTE_TEST" ]; then
diff --git a/tools/testing/selftests/ftrace/test.d/remotes/trace_pipe.tc b/tools/testing/selftests/ftrace/test.d/remotes/trace_pipe.tc
index 669a7288ed7c..7f7b7b79c490 100644
--- a/tools/testing/selftests/ftrace/test.d/remotes/trace_pipe.tc
+++ b/tools/testing/selftests/ftrace/test.d/remotes/trace_pipe.tc
@@ -92,31 +92,6 @@ test_trace_pipe()
         rm $output
         cd - > /dev/null
     done
-
-    #
-    # Test interaction with hotplug
-    #
-
-    [ "$(get_cpu_ids | wc -l)" -ge 2 ] || return 0
-
-    echo 0 > trace
-
-    for cpu in $(get_cpu_ids); do
-        echo 0 > /sys/devices/system/cpu/cpu$cpu/online || return 0
-        break
-    done
-
-    for i in $(seq 1 8); do
-        echo $i > write_event
-    done
-
-    output=$(dump_trace_pipe)
-
-    check_trace 1 8 $output
-
-    rm $output
-
-    echo 1 > /sys/devices/system/cpu/cpu$cpu/online
 }
 
 if [ -z "$SOURCE_REMOTE_TEST" ]; then
-- 
2.53.0.1118.gaef5881109-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] Fix trace remotes read with an offline CPU
  2026-04-01  2:50 [PATCH 0/2] Fix trace remotes read with an offline CPU Vincent Donnefort
  2026-04-01  2:50 ` [PATCH 1/2] tracing: Non-consuming read for trace remotes " Vincent Donnefort
  2026-04-01  2:50 ` [PATCH 2/2] tracing: selftests: Extend hotplug testing for trace remotes Vincent Donnefort
@ 2026-04-01 14:31 ` Steven Rostedt
  2026-04-01 15:08   ` Marc Zyngier
  2 siblings, 1 reply; 6+ messages in thread
From: Steven Rostedt @ 2026-04-01 14:31 UTC (permalink / raw)
  To: Vincent Donnefort
  Cc: mhiramat, mathieu.desnoyers, linux-trace-kernel, maz, kernel-team,
	linux-kernel

On Wed,  1 Apr 2026 03:50:01 +0100
Vincent Donnefort <vdonnefort@google.com> wrote:

> This small series is fixing non-consuming read of a trace remote when the
> trace_buffer is created after a CPU is offline.
> 
> It also extends hotplug testing coverage to include this test case.
> 
> I have based this series on top of kvmarm/next which contains the hypervisor
> tracing patches.
> 
> Vincent Donnefort (2):
>   tracing: Non-consuming read for trace remotes with an offline CPU
>   tracing: selftests: Extend hotplug testing for trace remotes

This looks fine to me. Since they only affect the new remote code and will
not conflict with anything I'm doing, they can go on top of the KVM patches
in the arm64 tree.

Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>

for the series.

Thanks,

-- Steve

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] Fix trace remotes read with an offline CPU
  2026-04-01 14:31 ` [PATCH 0/2] Fix trace remotes read with an offline CPU Steven Rostedt
@ 2026-04-01 15:08   ` Marc Zyngier
  2026-04-01 15:16     ` Steven Rostedt
  0 siblings, 1 reply; 6+ messages in thread
From: Marc Zyngier @ 2026-04-01 15:08 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Vincent Donnefort, mhiramat, mathieu.desnoyers,
	linux-trace-kernel, kernel-team, linux-kernel

On Wed, 01 Apr 2026 15:31:59 +0100,
Steven Rostedt <rostedt@goodmis.org> wrote:
> 
> On Wed,  1 Apr 2026 03:50:01 +0100
> Vincent Donnefort <vdonnefort@google.com> wrote:
> 
> > This small series is fixing non-consuming read of a trace remote when the
> > trace_buffer is created after a CPU is offline.
> > 
> > It also extends hotplug testing coverage to include this test case.
> > 
> > I have based this series on top of kvmarm/next which contains the hypervisor
> > tracing patches.
> > 
> > Vincent Donnefort (2):
> >   tracing: Non-consuming read for trace remotes with an offline CPU
> >   tracing: selftests: Extend hotplug testing for trace remotes
> 
> This looks fine to me. Since they only affect the new remote code and will
> not conflict with anything I'm doing, they can go on top of the KVM patches
> in the arm64 tree.
> 
> Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> 
> for the series.

Do you want to look at v2 [1], which was sent two hours later?

	M.

[1] https://lore.kernel.org/r/20260401045100.3394299-1-vdonnefort@google.com

-- 
Without deviation from the norm, progress is not possible.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] Fix trace remotes read with an offline CPU
  2026-04-01 15:08   ` Marc Zyngier
@ 2026-04-01 15:16     ` Steven Rostedt
  0 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2026-04-01 15:16 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: Vincent Donnefort, mhiramat, mathieu.desnoyers,
	linux-trace-kernel, kernel-team, linux-kernel

On Wed, 01 Apr 2026 16:08:41 +0100
Marc Zyngier <maz@kernel.org> wrote:

> Do you want to look at v2 [1], which was sent two hours later?

Yeah I saw that right after I sent my ack.

Yep, my ack still stands, please add it to them.

Thanks,

-- Steve

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-04-01 15:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-01  2:50 [PATCH 0/2] Fix trace remotes read with an offline CPU Vincent Donnefort
2026-04-01  2:50 ` [PATCH 1/2] tracing: Non-consuming read for trace remotes " Vincent Donnefort
2026-04-01  2:50 ` [PATCH 2/2] tracing: selftests: Extend hotplug testing for trace remotes Vincent Donnefort
2026-04-01 14:31 ` [PATCH 0/2] Fix trace remotes read with an offline CPU Steven Rostedt
2026-04-01 15:08   ` Marc Zyngier
2026-04-01 15:16     ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox