Re: [PATCH] x86/tracing: Flush persistent ring buffer cache on panic
From: Masami Hiramatsu (Google)
Date: Wed Dec 02 2026 - 21:07:46 EST
On Wed, 2 Dec 2026 08:50:57 -0500, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> On Wed, 2 Dec 2026 14:34:40 +0900
> "Masami Hiramatsu (Google)" <mhiramat@xxxxxxxxxx> wrote:
>
> > Persistent ring buffers (configured via reserve_mem= and
> > trace_instance=...@...) are mapped as write-back (WB) cached memory.
> > While x86-TSO keeps caches coherent across CPUs during normal
> > operation, it does not guarantee that dirty cache lines are written back
> > to DRAM before a hard reset triggered on panic (for example,
> > emergency_restart() via acpi_reboot() writing to port 0xcf9, where
> > neither stop_this_cpu() on normal WB memory nor acpi_reboot() flushes
> > CPU caches).
> >
> > Currently arch/x86/include/asm/Kbuild falls back to
> > asm-generic/ring_buffer.h, leaving arch_ring_buffer_flush_range() as a
> > no-op on x86. On real x86 hardware, a panic-triggered reboot therefore
> > loses dirty cache lines in L1/L2/LLC for the persistent ring buffer: on
> > the next boot, rb_validate_buffer() either detects inconsistent pages
> > ("Ring buffer meta [N] invalid buffer page") and discards the affected
> > CPU buffer, or validates up to a stale commit pointer in DRAM and
> > silently drops the last several milliseconds of trace events immediately
> > preceding the panic.
> >
> > Implement arch_ring_buffer_flush_range() for x86 using
> > clflush_cache_range() (chunked by SZ_2G to accommodate unsigned long
> > ranges against clflush_cache_range()'s unsigned int size parameter),
> > falling back to wbinvd() if X86_FEATURE_CLFLUSH is not available.
> > Because CLFLUSH/CLFLUSHOPT broadcast across the cache coherence domain
> > and require no IPIs, locks, or sleeping, the panicking CPU can safely
> > write back dirty lines from all halted CPUs in panic/NMI context.
> >
> > Tested on an x86_64 Intel system with repeated sysrq-c panic reboots:
> > without this change, 0/5 runs preserved a trace_marker written
> > immediately before panic and 1-4 CPUs per reboot reported invalid buffer
> > pages; with this change, 5/5 runs preserved the final pre-panic
> > trace_marker with 0 invalid buffer pages across all 8 CPUs.
> >
> > Fixes: a494d3c8d539 ("ring-buffer: Flush and stop persistent ring buffer on panic")
> > Cc: stable@xxxxxxxxxxxxxxx
> > Signed-off-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
>
> Reviewed-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
Thanks! BTW, should we ask x86 maintainers to pick this via -tip tree?
Thank you,
>
> -- Steve
>
>
--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>