From nobody Wed Oct 8 07:28:51 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B312279DC9 for ; Tue, 1 Jul 2025 14:54:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751381645; cv=none; b=IyFDuyXIKdn6gMlsV2TA9FOCT6/nnyG3Zca+a1ZuRC8pSbCEEYxktivyUa7yF5DHGouUaHj8kkZu3iRwv7imGiZY7mZqH6pFnwz6xhLDxBMduevjCgrRuv02eMhfjGbDE9Evrj+o8T5RBV8HMrl62drYAiymCzuMslLLY9LpcVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751381645; c=relaxed/simple; bh=A0yKAWVcMgCyrm81uThCxgUMLlA16noJqO4Jd+RAcRw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Et8w8JBrtre4OyHCyM8sGRDG3Jh2AlkSqMOyKyIvkc1JtCri4DyoQJZaLHlAW/R7Ddhcgn2MG/9TKPizdF3oK1a5NIG6rV6qW7ofMk2FKShJPfrzhNLiypvMob60254vmKNacW4R1+5Roy24c9V5Wh6PLqDC4eYG61A312oWuA4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9316812FC; Tue, 1 Jul 2025 07:53:48 -0700 (PDT) Received: from e132581.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D86223F66E; Tue, 1 Jul 2025 07:54:01 -0700 (PDT) From: Leo Yan Date: Tue, 01 Jul 2025 15:53:31 +0100 Subject: [PATCH v2 06/28] coresight: etm4x: Add context synchronization before enabling trace Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250701-arm_cs_pm_fix_v3-v2-6-23ebb864fcc1@arm.com> References: <20250701-arm_cs_pm_fix_v3-v2-0-23ebb864fcc1@arm.com> In-Reply-To: <20250701-arm_cs_pm_fix_v3-v2-0-23ebb864fcc1@arm.com> To: Suzuki K Poulose , Mike Leach , James Clark , Levi Yun , Greg Kroah-Hartman , Alexander Shishkin , Yabin Cui , Keita Morisaki , Yuanfang Zhang Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Leo Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1751381627; l=3229; i=leo.yan@arm.com; s=20250604; h=from:subject:message-id; bh=A0yKAWVcMgCyrm81uThCxgUMLlA16noJqO4Jd+RAcRw=; b=X0m9T17TpD4msrfEyJDpSWwEvXKj3cky95dLHbG6w/zWzRn67fIG21uGnY47VqPmEHuyRULuY T8e5f2rxl4NC4+l/iKJVET/kahAf8ibQSolKLMlJf592+nxhwiHqYTk X-Developer-Key: i=leo.yan@arm.com; a=ed25519; pk=k4BaDbvkCXzBFA7Nw184KHGP5thju8lKqJYIrOWxDhI= According to the software usage PKLXF in Arm ARM (ARM DDI 0487 L.a), a Context synchronization event is required before enabling the trace unit. An ISB is added to meet this requirement. Improved the barrier comments to provide more accurate information by specifying which section of the document the requirement comes from and clarifying its intended purpose. Fixes: 1ab3bb9df5e3 ("coresight: etm4x: Add necessary synchronization for s= ysreg access") Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-etm4x-core.c | 37 ++++++++++++++++++= +--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/h= wtracing/coresight/coresight-etm4x-core.c index af9d3b2319c5f49ccd40dfa0ccf0f694ce9e2f4f..e3a73718d0c903ee9c72b97028b= 56565f5ee1053 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -445,13 +445,37 @@ static int etm4_enable_trace_unit(struct etmv4_drvdat= a *drvdata) etm4x_relaxed_write32(csa, TRCRSR_TA, TRCRSR); =20 etm4x_allow_trace(drvdata); + + /* + * According to software usage PKLXF in Arm ARM (ARM DDI 0487 L.a), + * execute a Context synchronization event to guarantee the trace unit + * will observe the new values of the System registers. + */ + if (!csa->io_mem) + isb(); + /* Enable the trace unit */ etm4x_relaxed_write32(csa, 1, TRCPRGCTLR); =20 - /* Synchronize the register updates for sysreg access */ + /* + * As recommended by section 4.3.7 ("Synchronization when using system + * instructions to progrom the trace unit") of ARM IHI 0064H.b, the + * self-hosted trace analyzer must perform a Context synchronization + * event between writing to the TRCPRGCTLR and reading the TRCSTATR. + */ if (!csa->io_mem) isb(); =20 + /* + * For the memory-mapped interface, the registers are mapped as Device + * type (Device-nGnRE). As described in section 4.3.7 ("Synchronization + * of register updates") of ARM IHI0064H.b, read back the value of any + * register in the trace unit to ensure writes have completed. + * + * Therefore, polling on TRCSTATR ensures that the writing TRCPRGCTLR + * is complete. + */ + /* wait for TRCSTATR.IDLE to go back down to '0' */ if (etm4x_wait_status(csa, TRCSTATR_IDLE_BIT, 0)) { dev_err(etm_dev, @@ -931,11 +955,16 @@ static void etm4_disable_trace_unit(struct etmv4_drvd= ata *drvdata) */ etm4x_prohibit_trace(drvdata); /* - * Make sure everything completes before disabling, as recommended - * by section 7.3.77 ("TRCVICTLR, ViewInst Main Control Register, - * SSTATUS") of ARM IHI 0064D + * Prevent being speculative at the point of disabling the trace unit, + * as recommended by section 7.3.77 ("TRCVICTLR, ViewInst Main Control + * Register, SSTATUS") of ARM IHI 0064D */ dsb(sy); + /* + * According to software usage VKHHY in Arm ARM (ARM DDI 0487 L.a), + * execute a Context synchronization event to guarantee no new + * program-flow trace is generated. + */ isb(); /* Trace synchronization barrier, is a nop if not supported */ tsb_csync(); --=20 2.34.1