public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: Anshuman Khandual <anshuman.khandual@arm.com>,
	linux-arm-kernel@lists.infradead.org
Cc: Lorenzo Pieralisi <lpieralisi@kernel.org>,
	Sudeep Holla <sudeep.holla@arm.com>,
	Mike Leach <mike.leach@linaro.org>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
	coresight@lists.linaro.org,
	linux-stm32@st-md-mailman.stormreply.com
Subject: Re: [PATCH V4 03/11] coresight: tmc: Extract device properties from AMBA pid based table lookup
Date: Wed, 14 Feb 2024 10:16:56 +0000	[thread overview]
Message-ID: <653d8ae0-4eed-4fa4-b7ac-0668af93c030@arm.com> (raw)
In-Reply-To: <14d4c862-0880-408c-bc4e-5047c7eace87@arm.com>

On 14/02/2024 03:35, Anshuman Khandual wrote:
> 
> 
> On 2/13/24 16:02, Suzuki K Poulose wrote:
>> On 13/02/2024 03:13, Anshuman Khandual wrote:
>>>
>>>
>>> On 2/12/24 17:43, Suzuki K Poulose wrote:
>>>> On 23/01/2024 05:46, Anshuman Khandual wrote:
>>>>> This extracts device properties from AMBA pid based table lookup. This also
>>>>> defers tmc_etr_setup_caps() after the coresight device has been initialized
>>>>> so that PID value can be read.
>>>>>
>>>>> Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
>>>>> Cc: Mike Leach <mike.leach@linaro.org>
>>>>> Cc: James Clark <james.clark@arm.com>
>>>>> Cc: coresight@lists.linaro.org
>>>>> Cc: linux-arm-kernel@lists.infradead.org
>>>>> Cc: linux-kernel@vger.kernel.org
>>>>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>>>>> ---
>>>>>     .../hwtracing/coresight/coresight-tmc-core.c  | 19 +++++++++++++------
>>>>>     1 file changed, 13 insertions(+), 6 deletions(-)
>>>>>
>>>>> diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c
>>>>> index 7ec5365e2b64..e71db3099a29 100644
>>>>> --- a/drivers/hwtracing/coresight/coresight-tmc-core.c
>>>>> +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
>>>>> @@ -370,16 +370,24 @@ static inline bool tmc_etr_has_non_secure_access(struct tmc_drvdata *drvdata)
>>>>>         return (auth & TMC_AUTH_NSID_MASK) == 0x3;
>>>>>     }
>>>>>     +#define TMC_AMBA_MASK 0xfffff
>>>>> +
>>>>> +static const struct amba_id tmc_ids[];
>>>>> +
>>>>>     /* Detect and initialise the capabilities of a TMC ETR */
>>>>> -static int tmc_etr_setup_caps(struct device *parent, u32 devid, void *dev_caps)
>>>>> +static int tmc_etr_setup_caps(struct device *parent, u32 devid)
>>>>>     {
>>>>>         int rc;
>>>>> -    u32 dma_mask = 0;
>>>>> +    u32 tmc_pid, dma_mask = 0;
>>>>>         struct tmc_drvdata *drvdata = dev_get_drvdata(parent);
>>>>> +    void *dev_caps;
>>>>>           if (!tmc_etr_has_non_secure_access(drvdata))
>>>>>             return -EACCES;
>>>>>     +    tmc_pid = coresight_get_pid(&drvdata->csdev->access) & TMC_AMBA_MASK;
>>>>> +    dev_caps = coresight_get_uci_data_from_amba(tmc_ids, tmc_pid);
>>>>> +
>>>>>         /* Set the unadvertised capabilities */
>>>>>         tmc_etr_init_caps(drvdata, (u32)(unsigned long)dev_caps);
>>>>>     @@ -497,10 +505,6 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
>>>>>             desc.type = CORESIGHT_DEV_TYPE_SINK;
>>>>>             desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM;
>>>>>             desc.ops = &tmc_etr_cs_ops;
>>>>> -        ret = tmc_etr_setup_caps(dev, devid,
>>>>> -                     coresight_get_uci_data(id));
>>>>> -        if (ret)
>>>>> -            goto out;
>>>>>             idr_init(&drvdata->idr);
>>>>>             mutex_init(&drvdata->idr_mutex);
>>>>>             dev_list = &etr_devs;
>>>>> @@ -539,6 +543,9 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
>>>>>             goto out;
>>>>>         }
>>>>>     +    if (drvdata->config_type == TMC_CONFIG_TYPE_ETR)
>>>>> +        ret = tmc_etr_setup_caps(dev, devid);
>>>>> +
>>>>
>>>> With this change, we silently accept an ETR that may only have "SECURE" access only and crash later while we try to enable tracing. You could
>>>> pass in the "access" (which is already in 'desc.access' in the original
>>>> call site and deal with it ?
>>>
>>> Just wondering, if something like the following will help ? A failed tmc_etr_setup_caps()
>>> because of failed tmc_etr_has_non_secure_access(), will unregister the coresight device
>>> before returning.
>>>
>>> --- a/drivers/hwtracing/coresight/coresight-tmc-core.c
>>> +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
>>> @@ -538,8 +538,13 @@ static int __tmc_probe(struct device *dev, struct resource *res)
>>>                   goto out;
>>>           }
>>>    -       if (drvdata->config_type == TMC_CONFIG_TYPE_ETR)
>>> +       if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) {
>>>                   ret = tmc_etr_setup_caps(dev, devid);
>>> +               if (ret) {
>>> +                       coresight_unregister(drvdata->csdev);
>>> +                       goto out;
>>> +               }
>>> +       }
>>
>> Why do we move the tmc_etr_setup_caps() in the first place ? We could retain where that was and pass "desc.access" parameter rather than registering the csdev and then relying csdev->access ?
> 
> Agreed, and after implementing the changes suggested above, the entire patch
> will look something like the following. Please do confirm if this looks good
> enough.
> 
> --- a/drivers/hwtracing/coresight/coresight-tmc-core.c
> +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
> @@ -370,16 +370,25 @@ static inline bool tmc_etr_has_non_secure_access(struct tmc_drvdata *drvdata)
>          return (auth & TMC_AUTH_NSID_MASK) == 0x3;
>   }
>   
> +#define TMC_AMBA_MASK 0xfffff
> +
> +static const struct amba_id tmc_ids[];
> +
>   /* Detect and initialise the capabilities of a TMC ETR */
> -static int tmc_etr_setup_caps(struct device *parent, u32 devid, void *dev_caps)
> +static int tmc_etr_setup_caps(struct device *parent, u32 devid,
> +                             struct csdev_access *access)
>   {
>          int rc;
> -       u32 dma_mask = 0;
> +       u32 tmc_pid, dma_mask = 0;
>          struct tmc_drvdata *drvdata = dev_get_drvdata(parent);
> +       void *dev_caps;
>   
>          if (!tmc_etr_has_non_secure_access(drvdata))
>                  return -EACCES;
>   
> +       tmc_pid = coresight_get_pid(access) & TMC_AMBA_MASK;
> +       dev_caps = coresight_get_uci_data_from_amba(tmc_ids, tmc_pid);
> +
>          /* Set the unadvertised capabilities */
>          tmc_etr_init_caps(drvdata, (u32)(unsigned long)dev_caps);
>   
> @@ -497,8 +506,7 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
>                  desc.type = CORESIGHT_DEV_TYPE_SINK;
>                  desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM;
>                  desc.ops = &tmc_etr_cs_ops;
> -               ret = tmc_etr_setup_caps(dev, devid,
> -                                        coresight_get_uci_data(id));
> +               ret = tmc_etr_setup_caps(dev, devid, &desc.access);
>                  if (ret)
>                          goto out;
>                  idr_init(&drvdata->idr);
> 

That looks much better. Thanks

Suzuki


  reply	other threads:[~2024-02-14 10:17 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-23  5:45 [PATCH V4 00/11] coresight: Move remaining AMBA ACPI devices into platform driver Anshuman Khandual
2024-01-23  5:45 ` [PATCH V4 01/11] coresight: etm4x: Fix unbalanced pm_runtime_enable() Anshuman Khandual
2024-02-15 11:04   ` Suzuki K Poulose
2024-02-22  4:45     ` Anshuman Khandual
2024-01-23  5:45 ` [PATCH V4 02/11] coresight: stm: Extract device name from AMBA pid based table lookup Anshuman Khandual
2024-02-15 10:55   ` Suzuki K Poulose
2024-02-22  5:33     ` Anshuman Khandual
2024-01-23  5:46 ` [PATCH V4 03/11] coresight: tmc: Extract device properties " Anshuman Khandual
2024-02-12 12:13   ` Suzuki K Poulose
2024-02-13  3:13     ` Anshuman Khandual
2024-02-13 10:32       ` Suzuki K Poulose
2024-02-14  3:35         ` Anshuman Khandual
2024-02-14 10:16           ` Suzuki K Poulose [this message]
2024-01-23  5:46 ` [PATCH V4 04/11] coresight: Add helpers registering/removing both AMBA and platform drivers Anshuman Khandual
2024-01-23  5:46 ` [PATCH V4 05/11] coresight: replicator: Move ACPI support from AMBA driver to platform driver Anshuman Khandual
2024-02-15 11:23   ` Suzuki K Poulose
2024-02-15 11:25     ` Suzuki K Poulose
2024-02-19  2:52       ` Anshuman Khandual
2024-01-23  5:46 ` [PATCH V4 06/11] coresight: funnel: " Anshuman Khandual
2024-01-23  5:46 ` [PATCH V4 07/11] coresight: catu: " Anshuman Khandual
2024-01-23  5:46 ` [PATCH V4 08/11] coresight: tpiu: " Anshuman Khandual
2024-01-23  5:46 ` [PATCH V4 09/11] coresight: tmc: " Anshuman Khandual
2024-01-23  5:46 ` [PATCH V4 10/11] coresight: stm: " Anshuman Khandual
2024-01-23  5:46 ` [PATCH V4 11/11] coresight: debug: " Anshuman Khandual
2024-02-12 12:02 ` [PATCH V4 00/11] coresight: Move remaining AMBA ACPI devices into " James Clark

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=653d8ae0-4eed-4fa4-b7ac-0668af93c030@arm.com \
    --to=suzuki.poulose@arm.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=anshuman.khandual@arm.com \
    --cc=coresight@lists.linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=lpieralisi@kernel.org \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=mike.leach@linaro.org \
    --cc=sudeep.holla@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox