Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp637511pxb; Thu, 23 Sep 2021 07:41:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuqfP6EZ3aAuc31+JA+IEjehTmJh7qE0jJdYRQKlFR6s6jIxMS0SiSxvf6+zqaT3DzGm9L X-Received: by 2002:a02:2712:: with SMTP id g18mr4272657jaa.115.1632408090420; Thu, 23 Sep 2021 07:41:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632408090; cv=none; d=google.com; s=arc-20160816; b=zLPDoyU9WEGUMr9wfBJi2m7uX4/zZD3vNqYbQgX8e/48gAGwH2f4M0VuMM3TSSdkBi 7bmflYGhh5f/LeMfbMNkpvQz+HHpcleeWMmsiSrTsZVZEYSXPYbqdON3wAWOixlTdbyt Zgil3cnujDDAKnuEa/OgD3qvg2JmV7sr4sAftU42rkIOwZDukfHk6vJqnS6GHmum4kfM h0zMk3JzbXMqPoQNU5YeGqjQqMOtLDabRP96+5NoCOwdS/cIfzU1l+gscK3TbTJKig/z 34hQ4dteLApMOUgvdMP6BotEpG4k8d4/ez8sZIgHg/pAtqk50ut3yCQOQxicbn59TmOj 3uFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=wRRbBHHqeXOx0mHtjb1oI0LsrERNxxTaTNRH7q+8yv4=; b=XP2k/nle6aHSbSCiDLperentIianH3BVUutqoDoLf1+KeyJdMGxPr+Dh1pVDEC0ae4 3g7U9dAxD/VVGOAwd9SVJ2iJPO5L9w8vNzyjtwrDBc6buwVrSDE+WdYzDVaQYAD3ErGS ZlHKCfV74FbpEWRchOnSATdpsTwW4wSWvZrToXwFPCjINI3D8rPtKEOjoHMRkitfxnB7 L1MaKECOTzmOYYbz0Pdnvz3VczUYkRaGvJqYCVdsPTaTEqXK/j5Q69VycXV5jNQpnxmO fs64680XgjduyMhyEtlFvDTA2LzxTqlpLmAZRicXAbazB2CXdzK7N0UmRe0M2VyKvtyA QZSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z22si8336342jan.63.2021.09.23.07.41.18; Thu, 23 Sep 2021 07:41:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241851AbhIWOlW (ORCPT + 99 others); Thu, 23 Sep 2021 10:41:22 -0400 Received: from foss.arm.com ([217.140.110.172]:35350 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241753AbhIWOlJ (ORCPT ); Thu, 23 Sep 2021 10:41:09 -0400 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 D3EBE11FB; Thu, 23 Sep 2021 07:39:37 -0700 (PDT) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A9DFC3F718; Thu, 23 Sep 2021 07:39:36 -0700 (PDT) From: Suzuki K Poulose To: mathieu.poirier@linaro.org, linux-arm-kernel@lists.infradead.org Cc: anshuman.khandual@arm.com, mike.leach@linaro.org, leo.yan@linaro.org, coresight@lists.linaro.org, linux-kernel@vger.kernel.org, Suzuki K Poulose Subject: [PATCH v4 5/5] coresight: trbe: Prohibit trace before disabling TRBE Date: Thu, 23 Sep 2021 15:39:19 +0100 Message-Id: <20210923143919.2944311-6-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20210923143919.2944311-1-suzuki.poulose@arm.com> References: <20210923143919.2944311-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the TRBE generates an IRQ, we stop the TRBE, collect the trace and then reprogram the TRBE with the updated buffer pointers, whenever possible. We might also leave the TRBE disabled, if there is not enough space left in the buffer. However, we do not touch the ETE at all during all of this. This means the ETE is only disabled when the event is disabled later (via irq_work). This is incorrect, as the ETE trace is still ON without actually being captured and may be routed to the ATB (even if it is for a short duration). So, we move the CPU into trace prohibited state always before disabling the TRBE, upon entering the IRQ handler. The state is restored if the TRBE is enabled back. Otherwise the trace remains prohibited. Since, the ETM/ETE driver now controls the TRFCR_EL1 per session, the tracing can be restored/enabled back when the event is rescheduled in. Cc: Anshuman Khandual Cc: Mathieu Poirier Cc: Mike Leach Cc: Leo Yan Reviewed-by: Anshuman Khandual Signed-off-by: Suzuki K Poulose --- .../hwtracing/coresight/coresight-self-hosted-trace.h | 4 +++- drivers/hwtracing/coresight/coresight-trbe.c | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/hwtracing/coresight/coresight-self-hosted-trace.h b/drivers/hwtracing/coresight/coresight-self-hosted-trace.h index 23f05df3f173..53840a2c41f2 100644 --- a/drivers/hwtracing/coresight/coresight-self-hosted-trace.h +++ b/drivers/hwtracing/coresight/coresight-self-hosted-trace.h @@ -21,11 +21,13 @@ static inline void write_trfcr(u64 val) isb(); } -static inline void cpu_prohibit_trace(void) +static inline u64 cpu_prohibit_trace(void) { u64 trfcr = read_trfcr(); /* Prohibit tracing at EL0 & the kernel EL */ write_trfcr(trfcr & ~(TRFCR_ELx_ExTRE | TRFCR_ELx_E0TRE)); + /* Return the original value of the TRFCR */ + return trfcr; } #endif /* __CORESIGHT_SELF_HOSTED_TRACE_H */ diff --git a/drivers/hwtracing/coresight/coresight-trbe.c b/drivers/hwtracing/coresight/coresight-trbe.c index 4174300f1344..a53ee98f312f 100644 --- a/drivers/hwtracing/coresight/coresight-trbe.c +++ b/drivers/hwtracing/coresight/coresight-trbe.c @@ -16,6 +16,7 @@ #define pr_fmt(fmt) DRVNAME ": " fmt #include +#include "coresight-self-hosted-trace.h" #include "coresight-trbe.h" #define PERF_IDX2OFF(idx, buf) ((idx) % ((buf)->nr_pages << PAGE_SHIFT)) @@ -775,6 +776,7 @@ static irqreturn_t arm_trbe_irq_handler(int irq, void *dev) enum trbe_fault_action act; u64 status; bool truncated = false; + u64 trfcr; /* Reads to TRBSR_EL1 is fine when TRBE is active */ status = read_sysreg_s(SYS_TRBSR_EL1); @@ -785,6 +787,8 @@ static irqreturn_t arm_trbe_irq_handler(int irq, void *dev) if (!is_trbe_irq(status)) return IRQ_NONE; + /* 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. @@ -816,9 +820,14 @@ static irqreturn_t arm_trbe_irq_handler(int irq, void *dev) /* * If the buffer was truncated, ensure perf callbacks * have completed, which will disable the event. + * + * Otherwise, restore the trace filter controls to + * allow the tracing. */ if (truncated) irq_work_run(); + else + write_trfcr(trfcr); return IRQ_HANDLED; } -- 2.24.1