public inbox for linux-trace-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	Ian Rogers <irogers@google.com>
Subject: Re: [PATCH v14 5/5] ring-buffer: Add persistent ring buffer selftest
Date: Mon, 30 Mar 2026 16:24:19 -0400	[thread overview]
Message-ID: <20260330162419.5e4708fb@gandalf.local.home> (raw)
In-Reply-To: <177487502763.3463592.7901517545360137050.stgit@mhiramat.tok.corp.google.com>

On Mon, 30 Mar 2026 21:50:27 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:

> @@ -2558,12 +2577,64 @@ static void rb_free_cpu_buffer(struct ring_buffer_per_cpu *cpu_buffer)
>  	kfree(cpu_buffer);
>  }
>  
> +#ifdef CONFIG_RING_BUFFER_PERSISTENT_INJECT
> +static void rb_test_inject_invalid_pages(struct trace_buffer *buffer)
> +{
> +	struct ring_buffer_per_cpu *cpu_buffer;
> +	struct ring_buffer_cpu_meta *meta;
> +	struct buffer_data_page *dpage;
> +	u32 entry_bytes = 0;
> +	unsigned long ptr;
> +	int subbuf_size;
> +	int invalid = 0;
> +	int cpu;
> +	int i;
> +
> +	if (!(buffer->flags & RB_FL_TESTING))
> +		return;
> +
> +	guard(preempt)();
> +	cpu = smp_processor_id();
> +
> +	cpu_buffer = buffer->buffers[cpu];
> +	meta = cpu_buffer->ring_meta;
> +	ptr = (unsigned long)rb_subbufs_from_meta(meta);
> +	subbuf_size = meta->subbuf_size;
> +
> +	for (i = 0; i < meta->nr_subbufs; i++) {
> +		int idx = meta->buffers[i];
> +
> +		dpage = (void *)(ptr + idx * subbuf_size);
> +		/* Skip unused pages */
> +		if (!local_read(&dpage->commit))
> +			continue;
> +
> +		/* Invalidate even pages. */
> +		if (!(i & 0x1)) {
> +			local_add(subbuf_size + 1, &dpage->commit);
> +			invalid++;
> +		} else {
> +			/* Count total commit bytes. */
> +			entry_bytes += local_read(&dpage->commit);
> +		}
> +	}
> +
> +	pr_info("Inject invalidated %d pages on CPU%d, total size: %ld\n",
> +		invalid, cpu, (long)entry_bytes);

This is only enabled when testing. Let's make that a pr_warn() as we really
do want to be able to see it. And it should warn that it is invalidating pages!
(warn as in pr_warn, it doesn't need a warn as in WARN()).

-- Steve


> +	meta->nr_invalid = invalid;
> +	meta->entry_bytes = entry_bytes;
> +}
> +#else /* !CONFIG_RING_BUFFER_PERSISTENT_INJECT */
> +#define rb_test_inject_invalid_pages(buffer)	do { } while (0)
> +#endif
> +
>  /* Stop recording on a persistent buffer and flush cache if needed. */
>  static int rb_flush_buffer_cb(struct notifier_block *nb, unsigned long event, void *data)
>  {
>  	struct trace_buffer *buffer = container_of(nb, struct trace_buffer, flush_nb);
>  
>  	ring_buffer_record_off(buffer);
> +	rb_test_inject_invalid_pages(buffer);
>  	arch_ring_buffer_flush_range(buffer->range_addr_start, buffer->range_addr_end);
>  	return NOTIFY_DONE;
>  }

  reply	other threads:[~2026-03-30 20:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-30 12:49 [PATCH v14 0/5] ring-buffer: Making persistent ring buffers robust Masami Hiramatsu (Google)
2026-03-30 12:49 ` [PATCH v14 1/5] ring-buffer: Flush and stop persistent ring buffer on panic Masami Hiramatsu (Google)
2026-03-30 17:54   ` Steven Rostedt
2026-03-31  0:29     ` Masami Hiramatsu
2026-03-30 12:50 ` [PATCH v14 2/5] ring-buffer: Skip invalid sub-buffers when validating persistent ring buffer Masami Hiramatsu (Google)
2026-03-30 20:22   ` Steven Rostedt
2026-03-30 20:28     ` Steven Rostedt
2026-03-31  1:24       ` Masami Hiramatsu
2026-03-30 12:50 ` [PATCH v14 3/5] ring-buffer: Skip invalid sub-buffers when rewinding " Masami Hiramatsu (Google)
2026-03-30 12:50 ` [PATCH v14 4/5] ring-buffer: Reset RB_MISSED_* flags on " Masami Hiramatsu (Google)
2026-03-30 18:36   ` Steven Rostedt
2026-03-31  1:43     ` Masami Hiramatsu
2026-03-30 12:50 ` [PATCH v14 5/5] ring-buffer: Add persistent ring buffer selftest Masami Hiramatsu (Google)
2026-03-30 20:24   ` Steven Rostedt [this message]
2026-03-31  4:12     ` Masami Hiramatsu

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=20260330162419.5e4708fb@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    /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