Hi Sai, On Tue, 2 Jun 2020 at 08:30, Sai Prakash Ranjan <saiprakash.ranjan@xxxxxxxxxxxxxx> wrote: > > Hi Mathieu, > > Thanks for taking your time for review. > > On 2020-06-02 02:58, Mathieu Poirier wrote: > > Hi Sai, > > > > On top of the comments already privided by Mike, I have the following: > > > > On Mon, Jun 01, 2020 at 01:32:26PM +0530, Sai Prakash Ranjan wrote: > >> Implement a shutdown callback to ensure ETR/ETF hardware is > >> properly shutdown in reboot/shutdown path. This is required > >> for ETR/ETF which has SMMU address translation enabled like > >> on SC7180 SoC and few others. If the hardware is still accessing > >> memory after SMMU translation is disabled as part of SMMU > >> shutdown callback in system reboot or shutdown path, then > >> IOVAs(I/O virtual address) which it was using will go on the bus > >> as the physical addresses which might result in unknown crashes > >> (NoC/interconnect errors). So we make sure from this shutdown > >> callback that the ETR/ETF is shutdown before SMMU translation is > >> disabled and device_link in SMMU driver will take care of ordering > >> of shutdown callbacks such that SMMU shutdown callback is not > >> called before any of its consumer shutdown callbacks. > >> > >> Signed-off-by: Sai Prakash Ranjan <saiprakash.ranjan@xxxxxxxxxxxxxx> > >> --- > >> .../hwtracing/coresight/coresight-tmc-etf.c | 4 +-- > >> .../hwtracing/coresight/coresight-tmc-etr.c | 2 +- > >> drivers/hwtracing/coresight/coresight-tmc.c | 29 > >> +++++++++++++++++++ > >> drivers/hwtracing/coresight/coresight-tmc.h | 3 ++ > >> 4 files changed, 35 insertions(+), 3 deletions(-) > >> > >> diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c > >> b/drivers/hwtracing/coresight/coresight-tmc-etf.c > >> index 36cce2bfb744..cba3e7592820 100644 > >> --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c > >> +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c > >> @@ -85,7 +85,7 @@ static void __tmc_etb_disable_hw(struct tmc_drvdata > >> *drvdata) > >> CS_LOCK(drvdata->base); > >> } > >> > >> -static void tmc_etb_disable_hw(struct tmc_drvdata *drvdata) > >> +void tmc_etb_disable_hw(struct tmc_drvdata *drvdata) > >> { > >> __tmc_etb_disable_hw(drvdata); > >> coresight_disclaim_device(drvdata->base); > >> @@ -118,7 +118,7 @@ static int tmc_etf_enable_hw(struct tmc_drvdata > >> *drvdata) > >> return 0; > >> } > >> > >> -static void tmc_etf_disable_hw(struct tmc_drvdata *drvdata) > >> +void tmc_etf_disable_hw(struct tmc_drvdata *drvdata) > >> { > >> CS_UNLOCK(drvdata->base); > >> > > > > Why do we care about ETB and ETF when they both use RAM internal to the > > device? > > Moreover, the system RAM they use is not dedicated and as such falls > > back to the > > kernel's memory pool. > > > > Actually we don't, I added the disable for ETF/ETB for completeness > since we are > adding shutdown callback for TMC devices and not just ETR although this > issue applies > only for ETR and it doesn't hurt to disable these devices in shutdown > path. > If they don't affect the issue you are fixing, there are good reasons for leaving ETB./ETF running. If a system is not completely powered down, then the static ram in these devices can sometimes be used for post-mortem diagnosis after re-start. > >> diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c > >> b/drivers/hwtracing/coresight/coresight-tmc-etr.c > >> index 625882bc8b08..b29c2db94d96 100644 > >> --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c > >> +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c > >> @@ -1110,7 +1110,7 @@ static void __tmc_etr_disable_hw(struct > >> tmc_drvdata *drvdata) > >> > >> } > >> > >> -static void tmc_etr_disable_hw(struct tmc_drvdata *drvdata) > >> +void tmc_etr_disable_hw(struct tmc_drvdata *drvdata) > >> { > >> __tmc_etr_disable_hw(drvdata); > >> /* Disable CATU device if this ETR is connected to one */ > >> diff --git a/drivers/hwtracing/coresight/coresight-tmc.c > >> b/drivers/hwtracing/coresight/coresight-tmc.c > >> index 5a271ebc4585..7e687a356fe0 100644 > >> --- a/drivers/hwtracing/coresight/coresight-tmc.c > >> +++ b/drivers/hwtracing/coresight/coresight-tmc.c > >> @@ -540,6 +540,34 @@ static int tmc_probe(struct amba_device *adev, > >> const struct amba_id *id) > >> return ret; > >> } > >> > >> +static void tmc_shutdown(struct amba_device *adev) > >> +{ > >> + struct tmc_drvdata *drvdata = amba_get_drvdata(adev); > >> + > >> + if (!drvdata->enable) > >> + goto out; > >> + > >> + /* > >> + * We do not care about the active trace sessions here > >> + * since the system is going down unlike remove callback, > >> + * just make sure that the hardware is shutdown. > >> + */ > >> + switch (drvdata->config_type) { > >> + case TMC_CONFIG_TYPE_ETB: > >> + tmc_etb_disable_hw(drvdata); > >> + break; > >> + case TMC_CONFIG_TYPE_ETF: > >> + tmc_etf_disable_hw(drvdata); > >> + break; > >> + case TMC_CONFIG_TYPE_ETR: > >> + tmc_etr_disable_hw(drvdata); > >> + } > >> + > >> +out: > >> + misc_deregister(&drvdata->miscdev); > >> + coresight_unregister(drvdata->csdev); > > > > If a session is active when tmc_shutdown() is called, unregistering the > > ETF/ETR > > will result in a kernel crash if the session is stopped before the > > kernel has > > had the opportunity to shutdown. It is the problem as trying to make > > coresight > > drivers modular. > > > > For this to really work the ongoing session would need to be stopped. > > That > > would teardown the path and stop the sink. > > I have tested this with and without active trace sessions multiple times > on 2 devices > and did not observe a single crash. The crash should be easily triggered > as per > what you are saying if we have active sessions but I do not see any > crash. > > > > > That being said I'm sure that dependencies on an IOMMU isn't a problem > > confined > > to coresight. I am adding Robin Murphy, who added this commit [1], to > > the thread > > in the hope that he can provide guidance on the right way to do this. > > > > SMMU/IOMMU won't be able to do much here as it is the client's > responsiblity to > properly shutdown and SMMU device link just makes sure that > SMMU(supplier) shutdown is > called only after its consumers shutdown callbacks are called. I think this use case can be handled slightly differently than the general requirements for modular CoreSight drivers. What is needed here is a way of stopping the underlying ETR hardware from issuing data to the SMMU, until the entire device has been shut down, in a way that does not remove the driver, breaking existing references and causing a system crash. We could introduce a new mode to the ETR driver - e.g. CS_MODE_SHUTDOWN. At the end of the block tmc_shutdown(struct amba_device *adev), set drvdata->mode to CS_MODE_SHUTDOWN & remove the coresight_unregister(). This new mode can be used to prevent the underlying hardware from being able to restart until the device is re-powered. This mode can be detected in the code that enables / disables the ETR and handled appropriately (updates to tmc_enable_etr_sink and tmc_disable_etr_sink). This mode will persist until the device is re-started - but because we are on the device shutdown path this is not an issue. This should leave the CoreSight infrastructure stable until the drivers are shut down normally as part of the device power down process. Regards Mike > > Thanks, > Sai > > -- > QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a > member > of Code Aurora Forum, hosted by The Linux Foundation -- Mike Leach Principal Engineer, ARM Ltd. Manchester Design Centre. UK