Re: [PATCH 05/19] coresight: trbe: Refactor status clearing

From: Leo Yan

Date: Tue Dec 09 2025 - 10:29:19 EST


On Thu, Dec 04, 2025 at 06:27:27PM +0530, Anshuman Khandual wrote:
> On 01/12/25 4:51 PM, Leo Yan wrote:
> > If the driver does not clear the status when disabling the trace buffer
> > unit, stale state will carry over to the next enable, though the driver
> > clears it again on enable.
>
> There is no problem now ! Because trbe_enable_hw() calls clr_trbe_status().
>
> >
> > Explicitly clear status after the trace is disabled in the interrupt
> > handling and when a perf session ends. Keep the status for spurious
> > interrupts for continuous tracing.
>
> But is not that the behaviour already without this change ?
>
> clr_trbe_status() in trbe_enable_hw() ensures that no TRBE session can be
> started without first clearing the existing status. Still wondering what
> is the purpose of this change ?

It is about the driver's sanity.

The driver should clear the status immediately when the trace unit is
disabled, rather than waiting until the next enable. This avoids
unexpected behaviour, such as a spurious TRBE interrupt.

Consider an edge case: if TRBE is being disabled at the same moment it
is about to raise an interrupt, arm_trbe_update_buffer() may miss the
IRQ bit due to latency. If arm_trbe_disable() does not clear that bit,
arm_trbe_irq_handler() will still run after the perf event has been
stopped. The interrupt handler then retrieves the trbe_buf pointer
from the perf output handle, which is dangerous because the perf
session has already ended.

Thanks,
Leo