Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3417273pxb; Mon, 4 Oct 2021 01:47:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEIU4TZr55JiOV4HNkfL6FL0d5x5FXhLcYfrMLubON9146lxNHCHfjYQlYs2OYtj6fH8EU X-Received: by 2002:a17:906:269a:: with SMTP id t26mr16335684ejc.20.1633337270411; Mon, 04 Oct 2021 01:47:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633337270; cv=none; d=google.com; s=arc-20160816; b=xpPHrAKB0eOdspUAiU0hUMGf7pqYGF7nrFFEGVV0gh0AVWIYVBS6BFUusjrEh6FDgi MPh2Y1JH2f1P2tK+0T43YfgmlDbj6x4ix5TLWIxlpKfo4lAYN0kDV0Z4TnjvhbNj6sve uFYujBpbi1fC5q3ctcGbHGXGCAz92uwV4afiDZEjNA3EJsdZS7JHuHG+PUXERQoH4QgH WhtUtpNkaq7d+MbsJAx7TrvwQ8U+BQrh16B6YdhpoICJie+d7ndPq94FDogReh9dsZXW K/ZJryEyCWEPDVQUdXhmp2W0yRPPE9mnAG4E8qkTe3k3zKXMB8q6XDXgD2IF/uCeyD6v YC4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=26GhHoArbURfbDanKsn9PwUfs1LkzPAyXxspfRlBH+U=; b=r8e1R0RjgE3g44W8uDF8xSZhRmrLLkfkOPpjmIFm67T6bOQHS6mJjk6Tq+enO12GyS J19/9obz95D1BhVjOuoRieii2qSZsO5aT/TzhvYOOQUQeKwk6dpuXtaoAjCYKCjamuSo f01O6lGRI71+yhwvV84N99g16c2B0oj05yXipQjKrVnA+HZwKXuyqVGnXq2HOD0s8OG+ DuqUkAvb9R3cEJ+IeKO4OfkYLDX4OlZqesfEibUrAU2u66Ys2eLkjZrWCwi+lVZM4f1g L5Aslx/uC09Z/6fNA0+AaTMrA6k9XUfD1TzxISWuSq6ms6GKVGBP9sRg8s/7pL9jRw1K 5oHA== 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 y97si17037364ede.520.2021.10.04.01.47.26; Mon, 04 Oct 2021 01:47:50 -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 S229716AbhJDIsB (ORCPT + 99 others); Mon, 4 Oct 2021 04:48:01 -0400 Received: from foss.arm.com ([217.140.110.172]:50132 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbhJDIsA (ORCPT ); Mon, 4 Oct 2021 04:48:00 -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 B5EA4101E; Mon, 4 Oct 2021 01:46:11 -0700 (PDT) Received: from [10.57.72.173] (unknown [10.57.72.173]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BD6323F66F; Mon, 4 Oct 2021 01:46:09 -0700 (PDT) Subject: Re: [PATCH v2 09/17] coresight: trbe: Workaround TRBE errata overwrite in FILL mode To: Mathieu Poirier Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, maz@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, james.morse@arm.com, anshuman.khandual@arm.com, leo.yan@linaro.org, mike.leach@linaro.org, will@kernel.org, lcherian@marvell.com, coresight@lists.linaro.org References: <20210921134121.2423546-1-suzuki.poulose@arm.com> <20210921134121.2423546-10-suzuki.poulose@arm.com> <20211001171522.GB3148492@p14s> From: Suzuki K Poulose Message-ID: <085e398c-767c-1b9b-0780-bed830d936fb@arm.com> Date: Mon, 4 Oct 2021 09:46:07 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <20211001171522.GB3148492@p14s> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mathieu On 01/10/2021 18:15, Mathieu Poirier wrote: > On Tue, Sep 21, 2021 at 02:41:13PM +0100, Suzuki K Poulose wrote: >> ARM Neoverse-N2 (#2139208) and Cortex-A710(##2119858) suffers from >> an erratum, which when triggered, might cause the TRBE to overwrite >> the trace data already collected in FILL mode, in the event of a WRAP. >> i.e, the TRBE doesn't stop writing the data, instead wraps to the base >> and could write upto 3 cache line size worth trace. Thus, this could >> corrupt the trace at the "BASE" pointer. >> >> The workaround is to program the write pointer 256bytes from the >> base, such that if the erratum is triggered, it doesn't overwrite >> the trace data that was captured. This skipped region could be >> padded with ignore packets at the end of the session, so that >> the decoder sees a continuous buffer with some padding at the >> beginning. The trace data written at the base is considered >> lost as the limit could have been in the middle of the perf >> ring buffer, and jumping to the "base" is not acceptable. >> We set the flags already to indicate that some amount of trace >> was lost during the FILL event IRQ. So this is fine. >> >> One important change with the work around is, we program the >> TRBBASER_EL1 to current page where we are allowed to write. >> Otherwise, it could overwrite a region that may be consumed >> by the perf. Towards this, we always make sure that the >> "handle->head" and thus the trbe_write is PAGE_SIZE aligned, >> so that we can set the BASE to the PAGE base and move the >> TRBPTR to the 256bytes offset. >> >> Cc: Mike Leach >> Cc: Mathieu Poirier >> Cc: Anshuman Khandual >> Cc: Leo Yan >> Signed-off-by: Suzuki K Poulose >> --- >> Change since v1: >> - Updated comment with ASCII art >> - Add _BYTES suffix for the space to skip for the work around. >> --- >> drivers/hwtracing/coresight/coresight-trbe.c | 144 +++++++++++++++++-- >> 1 file changed, 132 insertions(+), 12 deletions(-) >> >> diff --git a/drivers/hwtracing/coresight/coresight-trbe.c b/drivers/hwtracing/coresight/coresight-trbe.c >> index f569010c672b..983dd5039e52 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 >> #include >> >> #include "coresight-self-hosted-trace.h" >> @@ -84,9 +85,17 @@ struct trbe_buf { >> * per TRBE instance, we keep track of the list of errata that >> * affects the given instance of the TRBE. >> */ >> -#define TRBE_ERRATA_MAX 0 >> +#define TRBE_WORKAROUND_OVERWRITE_FILL_MODE 0 >> +#define TRBE_ERRATA_MAX 1 >> + >> +/* >> + * Safe limit for the number of bytes that may be overwritten >> + * when the erratum is triggered. >> + */ >> +#define TRBE_WORKAROUND_OVERWRITE_FILL_MODE_SKIP_BYTES 256 >> >> static unsigned long trbe_errata_cpucaps[TRBE_ERRATA_MAX] = { >> + [TRBE_WORKAROUND_OVERWRITE_FILL_MODE] = ARM64_WORKAROUND_TRBE_OVERWRITE_FILL_MODE, >> }; >> >> /* >> @@ -519,10 +528,13 @@ static void trbe_enable_hw(struct trbe_buf *buf) >> set_trbe_limit_pointer_enabled(buf->trbe_limit); >> } >> >> -static enum trbe_fault_action trbe_get_fault_act(u64 trbsr) >> +static enum trbe_fault_action trbe_get_fault_act(struct perf_output_handle *handle, >> + u64 trbsr) >> { >> int ec = get_trbe_ec(trbsr); >> int bsc = get_trbe_bsc(trbsr); >> + struct trbe_buf *buf = etm_perf_sink_config(handle); >> + struct trbe_cpudata *cpudata = buf->cpudata; >> >> WARN_ON(is_trbe_running(trbsr)); >> if (is_trbe_trg(trbsr) || is_trbe_abort(trbsr)) >> @@ -531,10 +543,16 @@ static enum trbe_fault_action trbe_get_fault_act(u64 trbsr) >> if ((ec == TRBE_EC_STAGE1_ABORT) || (ec == TRBE_EC_STAGE2_ABORT)) >> return TRBE_FAULT_ACT_FATAL; >> >> - if (is_trbe_wrap(trbsr) && (ec == TRBE_EC_OTHERS) && (bsc == TRBE_BSC_FILLED)) { >> - if (get_trbe_write_pointer() == get_trbe_base_pointer()) >> - return TRBE_FAULT_ACT_WRAP; >> - } >> + /* >> + * If the trbe is affected by TRBE_WORKAROUND_OVERWRITE_FILL_MODE, >> + * it might write data after a WRAP event in the fill mode. >> + * Thus the check TRBPTR == TRBBASER will not be honored. >> + */ >> + if ((is_trbe_wrap(trbsr) && (ec == TRBE_EC_OTHERS) && (bsc == TRBE_BSC_FILLED)) && >> + (trbe_has_erratum(cpudata, TRBE_WORKAROUND_OVERWRITE_FILL_MODE) || >> + get_trbe_write_pointer() == get_trbe_base_pointer())) >> + return TRBE_FAULT_ACT_WRAP; >> + > > I'm very perplexed by the trbe_has_erratum() infrastructure... Since this is a > TRBE the code will always run on the CPU it is associated with, and if > I'm correct here we could call this_cpu_has_cap() directly with the same > outcome. I doubt that all divers using the cpucaps subsystem carry a shadow > structure to keep the same information. Very valid question. Of course, we can use the this_cpu_has_cap() helper. Unlike the cpus_have_*_cap() - which gives you the system wide status of the erratum - the cpucap doesn't keep a cache of which CPUs are affected by a given erratum. Thus this_cpu_has_cap() would involve running the detection on the current CPU everytime we call it. i.e, scanning the MIDR of the CPU through the list of affected MIDRs for the given erratum. This is a bit of overhead. Given that we already have CPU specific information in trbe_cpudata, I chose to cache the affected errata locally. This gives us quick access to the erratum for individual TRBE instances. Of course this list is initialised at TRBE probe and thus avoids us having to do the costly check, each time we need it. I could make this clear in the patch which introduces the framework. Thanks for the review Suzuki > Thanks, > Mathieu