From: James Clark <james.clark@linaro.org>
To: Leo Yan <leo.yan@arm.com>
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, coresight@lists.linaro.org,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Mike Leach <mike.leach@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Anshuman Khandual <anshuman.khandual@arm.com>,
Tamas Petz <tamas.petz@arm.com>,
Tamas Zsoldos <tamas.zsoldos@arm.com>,
Suyash Mahar <smahar@meta.com>, Amir Ayupov <aaupov@fb.com>
Subject: Re: [PATCH v2 21/23] coresight: trbe: Read TRBSR after prohibiting and flushing trace
Date: Tue, 10 Nov 2026 15:24:21 +0000 [thread overview]
Message-ID: <52f2c3c3-b67b-497f-9b21-1ed08842d9d4@linaro.org> (raw)
In-Reply-To: <20261016-trbe_enable_disable_irq_handle_refactor-v2-21-3f57cf3199b1@arm.com>
On 16/10/2026 17:55, Leo Yan wrote:
> The IRQ handler needs a stable TRBSR_EL1 value before classifying the
> interrupt. If the PE can still generate trace, or if pending trace has
> not been flushed, TRBSR can still change while the handler is sampling
> it. This is especially important for TRBSR.S bit, which is used to
> decide whether the TRBE has stopped.
>
> Move the drain buffer into arm_trbe_prohibit_trace(), so the handler
> first prohibits trace and flushes trace before reading TRBSR_EL1. Once
> this has been done, the IRQ path no longer needs the unconditional
> trbe_drain_and_disable_local(); it only needs to disable TRBE before
> handling the stopped-buffer status.
>
> Refactor the IRQ exit path accordingly: restore TRFCR on non-truncated
> exits, while the truncated path still runs the perf IRQ work to shut
> down the event.
>
> Signed-off-by: Leo Yan <leo.yan@arm.com>
> ---
> drivers/hwtracing/coresight/coresight-trbe.c | 40 +++++++++++++++++++---------
> 1 file changed, 28 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/hwtracing/coresight/coresight-trbe.c b/drivers/hwtracing/coresight/coresight-trbe.c
> index c83c440d4ac13c346bc2a7f9093951c186c90157..36f143a15e680b28aa6ca6a43ad7d3ee134693be 100644
> --- a/drivers/hwtracing/coresight/coresight-trbe.c
> +++ b/drivers/hwtracing/coresight/coresight-trbe.c
> @@ -1207,24 +1207,34 @@ static bool is_perf_trbe(struct perf_output_handle *handle)
> return true;
> }
>
> -static u64 cpu_prohibit_trace(void)
> +static u64 arm_trbe_prohibit_trace(void)
> {
> u64 trfcr = read_trfcr();
>
> /* Prohibit tracing at EL0 & the kernel EL */
> write_trfcr(trfcr & ~(TRFCR_EL1_ExTRE | TRFCR_EL1_E0TRE));
> +
> + /* Ensure the program-flow trace is flushed */
> + trbe_drain_buffer();
> +
> /* Return the original value of the TRFCR */
> return trfcr;
> }
>
> +static void arm_trbe_allow_trace(u64 trfcr)
> +{
> + /* Allow tracing at EL0 & the kernel EL */
> + write_trfcr(trfcr);
> +}
> +
> static irqreturn_t arm_trbe_irq_handler(int irq, void *dev)
> {
> struct trbe_cpudata *cpudata = dev;
> struct perf_output_handle *handle = cpudata->handle;
> enum trbe_fault_action act;
> - u64 status;
> bool truncated = false;
> - u64 trfcr;
> + u64 status, trfcr;
> + irqreturn_t ret;
>
> if (!handle || !perf_get_aux(handle))
> return IRQ_NONE;
> @@ -1232,22 +1242,25 @@ static irqreturn_t arm_trbe_irq_handler(int irq, void *dev)
> if (!is_perf_trbe(handle))
> return IRQ_NONE;
>
> + /* Prohibit the CPU from tracing before we disable the TRBE */
> + trfcr = arm_trbe_prohibit_trace();
> +
> /* Reads to TRBSR_EL1 is fine when TRBE is active */
> status = read_sysreg_s(SYS_TRBSR_EL1);
I think sashiko is right, you need an isb() between
arm_trbe_prohibit_trace() and the status read, otherwise it can still be
stale.
> /*
> * If the pending IRQ was handled by update_buffer callback
> * we have nothing to do here.
> */
> - if (!is_trbe_irq(status))
> - return IRQ_NONE;
> + if (!is_trbe_irq(status)) {
> + ret = IRQ_NONE;
> + goto out;
> + }
>
> - /* Prohibit the CPU from tracing before we disable the TRBE */
> - trfcr = cpu_prohibit_trace();
> /*
> * Ensure the trace is visible to the CPUs and
> * any external aborts have been resolved.
> */
> - trbe_drain_and_disable_local(cpudata);
> + set_trbe_disabled(cpudata);
> clr_trbe_irq();
> isb();
>
> @@ -1272,12 +1285,15 @@ static irqreturn_t arm_trbe_irq_handler(int irq, void *dev)
> * Otherwise, restore the trace filter controls to
> * allow the tracing.
> */
> - if (truncated)
> + if (truncated) {
> irq_work_run();
> - else
> - write_trfcr(trfcr);
> + return IRQ_HANDLED;
> + }
>
> - return IRQ_HANDLED;
> + ret = IRQ_HANDLED;
> +out:
> + arm_trbe_allow_trace(trfcr);
> + return ret;
> }
>
> static int arm_trbe_save(struct coresight_device *csdev)
>
next prev parent reply other threads:[~2026-11-10 15:24 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 16:54 [PATCH v2 00/23] coresight: trbe: Refactor buffer and IRQ handling Leo Yan
2026-10-16 16:54 ` [PATCH v2 01/23] arm64/sysreg: Define TRBSR_EL1.EC event classes Leo Yan
2026-11-10 15:28 ` James Clark
2026-10-16 16:55 ` [PATCH v2 02/23] coresight: trbe: Make watermark range check overflow safe in __trbe_normal_offset() Leo Yan
2026-11-10 15:28 ` James Clark
2026-10-16 16:55 ` [PATCH v2 03/23] coresight: trbe: Use helpers for checking errata Leo Yan
2026-11-10 15:29 ` James Clark
2026-10-16 16:55 ` [PATCH v2 04/23] coresight: trbe: Check the buffer association before IRQ validation Leo Yan
2026-11-10 15:29 ` James Clark
2026-10-16 16:55 ` [PATCH v2 05/23] coresight: trbe: Validate perf handle before using sink data Leo Yan
2026-11-10 15:29 ` James Clark
2026-10-16 16:55 ` [PATCH v2 06/23] coresight: trbe: Drop redundant disable from enable path Leo Yan
2026-11-09 16:27 ` James Clark
2026-10-16 16:55 ` [PATCH v2 07/23] coresight: trbe: Publish the session after successful enable Leo Yan
2026-11-10 15:30 ` James Clark
2026-10-16 16:55 ` [PATCH v2 08/23] coresight: trbe: Clear stale external abort status Leo Yan
2026-11-10 15:30 ` James Clark
2026-10-16 16:55 ` [PATCH v2 09/23] coresight: trbe: Clear TRBSR status at stop sites Leo Yan
2026-11-09 16:40 ` James Clark
2026-11-09 16:51 ` James Clark
2026-11-09 22:51 ` Suzuki K Poulose
2026-11-10 8:48 ` Leo Yan
2026-11-10 15:25 ` Suzuki K Poulose
2026-10-16 16:55 ` [PATCH v2 10/23] coresight: trbe: Drop redundant disables Leo Yan
2026-11-10 15:31 ` James Clark
2026-10-16 16:55 ` [PATCH v2 11/23] coresight: trbe: Assign the perf handle in enable and disable Leo Yan
2026-11-10 15:31 ` James Clark
2026-10-16 16:55 ` [PATCH v2 12/23] coresight: trbe: Decode TRBSR status codes Leo Yan
2026-11-10 15:32 ` James Clark
2026-10-16 16:55 ` [PATCH v2 13/23] coresight: trbe: Simplify wrap status handling Leo Yan
2026-11-10 15:32 ` James Clark
2026-10-16 16:55 ` [PATCH v2 14/23] coresight: trbe: Treat access not allowed stops as fatal Leo Yan
2026-11-10 15:33 ` James Clark
2026-10-16 16:55 ` [PATCH v2 15/23] coresight: trbe: Report truncated trace on buffer update errors Leo Yan
2026-11-10 15:33 ` James Clark
2026-10-16 16:55 ` [PATCH v2 16/23] coresight: trbe: Always classify TRBSR when updating buffer Leo Yan
2026-11-10 15:34 ` James Clark
2026-10-16 16:55 ` [PATCH v2 17/23] coresight: trbe: Calculate trace size across buffer wrap Leo Yan
2026-11-10 15:34 ` James Clark
2026-10-16 16:55 ` [PATCH v2 18/23] coresight: trbe: Keep the perf handle in per-CPU data Leo Yan
2026-11-10 15:34 ` James Clark
2026-10-16 16:55 ` [PATCH v2 19/23] coresight: trbe: Reload the AUX buffer on overflow restart Leo Yan
2026-11-10 15:12 ` James Clark
2026-10-16 16:55 ` [PATCH v2 20/23] coresight: trbe: Add fault action argument to trbe_handle_overflow() Leo Yan
2026-11-10 15:34 ` James Clark
2026-10-16 16:55 ` [PATCH v2 21/23] coresight: trbe: Read TRBSR after prohibiting and flushing trace Leo Yan
2026-11-10 15:24 ` James Clark [this message]
2026-10-16 16:55 ` [PATCH v2 22/23] coresight: trbe: Restart trace source for stopped buffers Leo Yan
2026-11-10 15:35 ` James Clark
2026-10-16 16:55 ` [PATCH v2 23/23] coresight: trbe: Report trace gaps with PARTIAL instead of COLLISION Leo Yan
2026-11-10 15:35 ` James Clark
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=52f2c3c3-b67b-497f-9b21-1ed08842d9d4@linaro.org \
--to=james.clark@linaro.org \
--cc=aaupov@fb.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=anshuman.khandual@arm.com \
--cc=coresight@lists.linaro.org \
--cc=leo.yan@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mike.leach@arm.com \
--cc=smahar@meta.com \
--cc=suzuki.poulose@arm.com \
--cc=tamas.petz@arm.com \
--cc=tamas.zsoldos@arm.com \
/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
all inboxes | Powered by JetHome®