Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp8174075rwl; Tue, 10 Jan 2023 09:55:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXvrE1wWKaZ8fnmUSpQxJgM3WQRVF//MeP64qaoe4ql8Nt1HCwuHu3O8ypFdkNyEJuMFsBsm X-Received: by 2002:a05:6a20:4d84:b0:b5:e7b8:3f6e with SMTP id gj4-20020a056a204d8400b000b5e7b83f6emr5884825pzb.15.1673373341617; Tue, 10 Jan 2023 09:55:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673373341; cv=none; d=google.com; s=arc-20160816; b=vkEDzTJ0WcxnRf8L42vZ73fqn4Ev7ZNTCNfaxK+xEC4G2CKT+ghxp/RkXZ17fjnRkc eUssQdMxZjqzng9c20hwzFVJNEp+ADuQ2dvPnZwlV1zOY+FqEdVRcqmw/InfF03iLLqh xvuPwZAN2M7BuhLeNyiLponQQwNnnGBbqoosBmbPRKr6DoNBG2/bALY2BU0sWF7TyAkn V9UpSJ/fBLdGr+8nMG057JtlTGrNdfWQaTU0YpPy7SFvMtF9Jeqebt9u9EW1df2y7Xbw yeDyKs60fu3oZed6RsbG81u5tU+6j9XMgIhhFph7aa7LfXk+a+tAgj6gnAyQ1/wol5Sg Hp2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=R/ahT8jL6pUDznjA96n6U20XBVFpZZ4PTuJ1gDNTLdQ=; b=wKMEuCT/3TTONg/KIY+TktR+DXpsO/LbK2pghVfDeW0QoDD+id2RwL757XQHKUafJ2 yqtrA94V1brRpn9bNewNYYKd/lObKRzVf9Trl5gMzU+EzxlGHN7RTEMNZQCQUdPEO3WW lRKhCM8Nd9fIVVsCxqK1jOXxVYL/5UwsnLQhbT5GSFFf1DnDd91bo2BjOFbt4uk2BDhi CjRLugHkB+K2YUVXC/MDRsTM3TfOprvZkDP8X5ScAWT0ouunOJPISf7xhGjcakVulhp7 LWwXNrre/I/SxzycDPsSRCXy96okFZZJyK24Ab2S7XFd/iBpfsLd7uKVVZEPw6wYwthG qBTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UGF9ErWx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y26-20020aa7943a000000b0057e857295adsi11770073pfo.236.2023.01.10.09.55.34; Tue, 10 Jan 2023 09:55:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UGF9ErWx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232917AbjAJRtC (ORCPT + 55 others); Tue, 10 Jan 2023 12:49:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234709AbjAJRs5 (ORCPT ); Tue, 10 Jan 2023 12:48:57 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6E1C5F4B4 for ; Tue, 10 Jan 2023 09:48:53 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id a30so9439731pfr.6 for ; Tue, 10 Jan 2023 09:48:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=R/ahT8jL6pUDznjA96n6U20XBVFpZZ4PTuJ1gDNTLdQ=; b=UGF9ErWxyig1aP3LUCTwEnhdhMlR0A3zJG/xQfpBmvPfmY/df0BQWvYR9X5HRqgfpz 1VHIkfySYGPadBb7+iiN7rh4NsicY+WBplNflFPGsvv784fmagtTEaD/8g83GGx3IbLd hqLHhO0Fpp5JkFaxosdoto6/zpfThaObLuWUmyVO1gV+8thJT2a5uTzq8rkgqlUT1rMh 8RLIl5qxJn4jdhesJnlBDjynHEW2rJx/H8dsHepTjhBu3GzfLpqu+SyI4BM7yrCI3+IC NF+/7STJMEfXFDfB7cSwHd8MmV6a8Q4lSNY+pQqGpkoWfHq893PhpUCSMarzFlvrYq2X aEdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=R/ahT8jL6pUDznjA96n6U20XBVFpZZ4PTuJ1gDNTLdQ=; b=MaS6zBLnAiUgvZLM5O4k5knXsGkfYpjqJJzGsFcYY3yuKvPgpeiCJPoUc67FSED6zU ZOCJx72Ia/SAEhD4wo8aBwTYdnLedP8+J24JiWBsj9l4pSJdLh7K+AhmXhqxGP6n4Ggb Ofza0QzembAuVa/exdyOV5+Jr0+A9dSmmsHHpT3yb3AzF4QPnKvNv8nY81Mj6C8ifacL IOr/NdOvZ4/Vdqrbn6KN88eH3NVRYsXHWCFujz3lBZH2i1l1L9iDdTSVk5VnrIH+Lw3w DGrejz6aKHVCJsPRmaCKai637fNBv9mHn9H6Gmtdq11U5IQIZl9TKWUoAVsqnDjgCxyV HRBg== X-Gm-Message-State: AFqh2kp3DQwMQM1LVhUA9IHlrxVTjAOlyL5cBpuXBaWMBNOTG30SB8hu ExeWvqduIbX+MTCZ4a292U4dgP0h11vqsZYK+l28Xg== X-Received: by 2002:aa7:9a5d:0:b0:580:984e:6e3f with SMTP id x29-20020aa79a5d000000b00580984e6e3fmr5273650pfj.66.1673372933368; Tue, 10 Jan 2023 09:48:53 -0800 (PST) MIME-Version: 1.0 References: <20230109234312.2870846-1-yabinc@google.com> In-Reply-To: From: Mike Leach Date: Tue, 10 Jan 2023 17:48:42 +0000 Message-ID: Subject: Re: [PATCH] coresight: tmc-etr: Don't enable ETR when it's not ready To: James Clark Cc: Yabin Cui , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mathieu Poirier , Suzuki K Poulose , Leo Yan Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Tue, 10 Jan 2023 at 09:30, James Clark wrote: > > > > On 09/01/2023 23:43, Yabin Cui wrote: > > Otherwise, it may cause error in AXI bus and result in a kernel panic. > > Hi Yabin, > > Thanks for the fix. Do you have a reproducer for this or some more info? > For example is it a regression or has it always been there? And on which > platform. > > Thanks > James > > > > > Signed-off-by: Yabin Cui > > --- > > .../hwtracing/coresight/coresight-tmc-core.c | 4 +++- > > .../hwtracing/coresight/coresight-tmc-etr.c | 18 +++++++++++++++--- > > drivers/hwtracing/coresight/coresight-tmc.h | 2 +- > > 3 files changed, 19 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c > > index 07abf28ad725..c106d142e632 100644 > > --- a/drivers/hwtracing/coresight/coresight-tmc-core.c > > +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c > > @@ -31,7 +31,7 @@ DEFINE_CORESIGHT_DEVLIST(etb_devs, "tmc_etb"); > > DEFINE_CORESIGHT_DEVLIST(etf_devs, "tmc_etf"); > > DEFINE_CORESIGHT_DEVLIST(etr_devs, "tmc_etr"); > > > > -void tmc_wait_for_tmcready(struct tmc_drvdata *drvdata) > > +int tmc_wait_for_tmcready(struct tmc_drvdata *drvdata) > > { > > struct coresight_device *csdev = drvdata->csdev; > > struct csdev_access *csa = &csdev->access; > > @@ -40,7 +40,9 @@ void tmc_wait_for_tmcready(struct tmc_drvdata *drvdata) > > if (coresight_timeout(csa, TMC_STS, TMC_STS_TMCREADY_BIT, 1)) { > > dev_err(&csdev->dev, > > "timeout while waiting for TMC to be Ready\n"); > > + return -EBUSY; > > } > > + return 0; > > } > > > > void tmc_flush_and_stop(struct tmc_drvdata *drvdata) > > diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c > > index 867ad8bb9b0c..2da99dd41ed6 100644 > > --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c > > +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c > > @@ -983,15 +983,21 @@ static void tmc_sync_etr_buf(struct tmc_drvdata *drvdata) > > etr_buf->ops->sync(etr_buf, rrp, rwp); > > } > > > > -static void __tmc_etr_enable_hw(struct tmc_drvdata *drvdata) > > +static int __tmc_etr_enable_hw(struct tmc_drvdata *drvdata) > > { > > u32 axictl, sts; > > struct etr_buf *etr_buf = drvdata->etr_buf; > > + int rc = 0; > > > > CS_UNLOCK(drvdata->base); > > > > /* Wait for TMCSReady bit to be set */ > > - tmc_wait_for_tmcready(drvdata); > > + rc = tmc_wait_for_tmcready(drvdata); > > + if (rc) { > > + dev_err(&drvdata->csdev->dev, "not ready ETR isn't enabled\n"); > > + CS_LOCK(drvdata->base); > > + return rc; > > + } > > > > writel_relaxed(etr_buf->size / 4, drvdata->base + TMC_RSZ); > > writel_relaxed(TMC_MODE_CIRCULAR_BUFFER, drvdata->base + TMC_MODE); > > @@ -1032,6 +1038,7 @@ static void __tmc_etr_enable_hw(struct tmc_drvdata *drvdata) > > tmc_enable_hw(drvdata); > > > > CS_LOCK(drvdata->base); > > + return rc; > > } > > > > static int tmc_etr_enable_hw(struct tmc_drvdata *drvdata, > > @@ -1060,7 +1067,12 @@ static int tmc_etr_enable_hw(struct tmc_drvdata *drvdata, > > rc = coresight_claim_device(drvdata->csdev); > > if (!rc) { > > drvdata->etr_buf = etr_buf; > > - __tmc_etr_enable_hw(drvdata); > > + rc = __tmc_etr_enable_hw(drvdata); > > + if (rc) { > > + drvdata->etr_buf = NULL; > > + coresight_disclaim_device(drvdata->csdev); > > + tmc_etr_disable_catu(drvdata); > > + } > > } > > > > return rc; > > diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h > > index 66959557cf39..01c0382a29c0 100644 > > --- a/drivers/hwtracing/coresight/coresight-tmc.h > > +++ b/drivers/hwtracing/coresight/coresight-tmc.h > > @@ -255,7 +255,7 @@ struct tmc_sg_table { > > }; > > > > /* Generic functions */ > > -void tmc_wait_for_tmcready(struct tmc_drvdata *drvdata); > > +int tmc_wait_for_tmcready(struct tmc_drvdata *drvdata); > > void tmc_flush_and_stop(struct tmc_drvdata *drvdata); > > void tmc_enable_hw(struct tmc_drvdata *drvdata); > > void tmc_disable_hw(struct tmc_drvdata *drvdata); There is no point in waiting for a timeout, and then carrying on even when it is exceeded. As such this patch seems reasonable. We should also apply the same principle to the ETF and ETB devices which use the same tmc_wait_for_tmcready() function. However - the concern is that this appears to be happening on starting the ETR - there should be no outstanding AXI operations that cause the system to not be ready - as we will either be using this the first time after reset, or we should have successfully stopped and flushed the ETR from the previous operation. This warrants further investigation - should we be extending the timeout - which is already at a rather generous 100uS, and do we also need to check the MemErr bit in the status register? As James says, we need details of when and how the problem occurs - as far as I know it has not been seen on any systems we currently use (though could have been missed given the current code) Regards Mike -- Mike Leach Principal Engineer, ARM Ltd. Manchester Design Centre. UK