lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250319082715.GD2860028@e132581.arm.com>
Date: Wed, 19 Mar 2025 08:27:15 +0000
From: Leo Yan <leo.yan@....com>
To: James Clark <james.clark@...aro.org>
Cc: Suzuki K Poulose <suzuki.poulose@....com>,
	Mike Leach <mike.leach@...aro.org>,
	Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
	Maxime Coquelin <mcoquelin.stm32@...il.com>,
	Alexandre Torgue <alexandre.torgue@...s.st.com>,
	coresight@...ts.linaro.org, linux-arm-kernel@...ts.infradead.org,
	linux-kernel@...r.kernel.org,
	linux-stm32@...md-mailman.stormreply.com
Subject: Re: [PATCH v2 4/8] coresight: Add claim tag warnings and debug
 messages

On Tue, Mar 18, 2025 at 04:21:58PM +0000, James Clark wrote:
> Add a dev_dbg() message so that external debugger conflicts are more
> visible. There are multiple reasons for -EBUSY so a message for this
> particular one could be helpful. Add errors for and enumerate all the
> other cases that are impossible.
> 
> Signed-off-by: James Clark <james.clark@...aro.org>

Reviewed-by: Leo Yan <leo.yan@....com>

> ---
>  drivers/hwtracing/coresight/coresight-core.c | 51 +++++++++++++++++-----------
>  drivers/hwtracing/coresight/coresight-priv.h |  5 ++-
>  2 files changed, 36 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c
> index e39043a9551f..5f08845faf0d 100644
> --- a/drivers/hwtracing/coresight/coresight-core.c
> +++ b/drivers/hwtracing/coresight/coresight-core.c
> @@ -135,16 +135,6 @@ static inline u32 coresight_read_claim_tags(struct coresight_device *csdev)
>  			 csdev_access_relaxed_read32(&csdev->access, CORESIGHT_CLAIMCLR));
>  }
>  
> -static inline bool coresight_is_claimed_self_hosted(struct coresight_device *csdev)
> -{
> -	return coresight_read_claim_tags(csdev) == CORESIGHT_CLAIM_SELF_HOSTED;
> -}
> -
> -static inline bool coresight_is_claimed_any(struct coresight_device *csdev)
> -{
> -	return coresight_read_claim_tags(csdev) != 0;
> -}
> -
>  static inline void coresight_set_self_claim_tag(struct coresight_device *csdev)
>  {
>  	csdev_access_relaxed_write32(&csdev->access, CORESIGHT_CLAIM_SELF_HOSTED,
> @@ -180,18 +170,41 @@ EXPORT_SYMBOL_GPL(coresight_clear_self_claim_tag_unlocked);
>   */
>  int coresight_claim_device_unlocked(struct coresight_device *csdev)
>  {
> +	int tag;
> +	struct csdev_access *csa;
> +
>  	if (WARN_ON(!csdev))
>  		return -EINVAL;
>  
> -	if (coresight_is_claimed_any(csdev))
> +	csa = &csdev->access;
> +	tag = coresight_read_claim_tags(csdev);
> +
> +	switch (tag) {
> +	case CORESIGHT_CLAIM_FREE:
> +		coresight_set_self_claim_tag(csdev);
> +		if (coresight_read_claim_tags(csdev) == CORESIGHT_CLAIM_SELF_HOSTED)
> +			return 0;
> +
> +		/* There was a race setting the tag, clean up and fail */
> +		coresight_clear_self_claim_tag_unlocked(csa);
> +		dev_dbg(&csdev->dev, "Busy: Couldn't set self claim tag");
>  		return -EBUSY;
>  
> -	coresight_set_self_claim_tag(csdev);
> -	if (coresight_is_claimed_self_hosted(csdev))
> -		return 0;
> -	/* There was a race setting the tag, clean up and fail */
> -	coresight_clear_self_claim_tag_unlocked(&csdev->access);
> -	return -EBUSY;
> +	case CORESIGHT_CLAIM_EXTERNAL:
> +		/* External debug is an expected state, so log and report BUSY */
> +		dev_dbg(&csdev->dev, "Busy: Claimed by external debugger");
> +		return -EBUSY;
> +
> +	default:
> +	case CORESIGHT_CLAIM_SELF_HOSTED:
> +	case CORESIGHT_CLAIM_INVALID:
> +		/*
> +		 * Warn here because we clear a lingering self hosted tag
> +		 * on probe, so other tag combinations are impossible.
> +		 */
> +		dev_err_once(&csdev->dev, "Invalid claim tag state: %x", tag);
> +		return -EBUSY;
> +	}
>  }
>  EXPORT_SYMBOL_GPL(coresight_claim_device_unlocked);
>  
> @@ -220,7 +233,7 @@ void coresight_disclaim_device_unlocked(struct coresight_device *csdev)
>  	if (WARN_ON(!csdev))
>  		return;
>  
> -	if (coresight_is_claimed_self_hosted(csdev))
> +	if (coresight_read_claim_tags(csdev) == CORESIGHT_CLAIM_SELF_HOSTED)
>  		coresight_clear_self_claim_tag_unlocked(&csdev->access);
>  	else
>  		/*
> @@ -228,7 +241,7 @@ void coresight_disclaim_device_unlocked(struct coresight_device *csdev)
>  		 * and has manipulated it. Or something else has seriously
>  		 * gone wrong in our driver.
>  		 */
> -		WARN_ON_ONCE(1);
> +		dev_WARN_ONCE(&csdev->dev, 1, "External agent took claim tag");
>  }
>  EXPORT_SYMBOL_GPL(coresight_disclaim_device_unlocked);
>  
> diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
> index 38bb4e8b50ef..6e8cf55aee0a 100644
> --- a/drivers/hwtracing/coresight/coresight-priv.h
> +++ b/drivers/hwtracing/coresight/coresight-priv.h
> @@ -36,7 +36,10 @@ extern const struct device_type coresight_dev_type[];
>   * See PSCI - ARM DEN 0022D, Section: 6.8.1 Debug and Trace save and restore.
>   */
>  #define CORESIGHT_CLAIM_MASK		GENMASK(1, 0)
> -#define CORESIGHT_CLAIM_SELF_HOSTED	BIT(1)
> +#define CORESIGHT_CLAIM_FREE		0
> +#define CORESIGHT_CLAIM_EXTERNAL	1
> +#define CORESIGHT_CLAIM_SELF_HOSTED	2
> +#define CORESIGHT_CLAIM_INVALID		3
>  
>  #define TIMEOUT_US		100
>  #define BMVAL(val, lsb, msb)	((val & GENMASK(msb, lsb)) >> lsb)
> 
> -- 
> 2.34.1
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ