mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yeoreum Yun <yeoreum.yun@arm.com>
To: sashiko-reviews@lists.linux.dev
Cc: Yeoreum Yun <yeoreum.yun@arm.com>,
	linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v10 3/8] coresight: etm3x: change drvdata->spinlock type to raw_spin_lock_t
Date: Fri, 11 Sep 2026 12:52:04 +0100	[thread overview]
Message-ID: <aqPrZD-NLo7gZr55@e129823.arm.com> (raw)
In-Reply-To: <20260911111736.EBA341F000FF@smtp.kernel.org>

[...]

> 
> > diff --git a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
> > index b3c67e96a82a4..0701edc094581 100644
> > --- a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
> > +++ b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
> > @@ -49,13 +49,13 @@ static ssize_t etmsr_show(struct device *dev,
> >  	struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
> >  
> >  	pm_runtime_get_sync(dev->parent);
> > -	spin_lock_irqsave(&drvdata->spinlock, flags);
> > +	raw_spin_lock_irqsave(&drvdata->spinlock, flags);
> >  	CS_UNLOCK(drvdata->csa.base);
> >  
> >  	val = etm_readl(drvdata, ETMSR);
> 
> [Severity: High]
> This is a pre-existing issue, but could this code cause a synchronous
> external abort if the device fails to resume?
> 
> If pm_runtime_get_sync() returns a negative error code (e.g., if the device
> is suspended and its clocks or power domains remain gated), the code proceeds
> unconditionally to dereference drvdata->csa.base in etm_readl(). 
> 
> Accessing unclocked or unpowered CoreSight registers on ARM can result in a
> kernel panic. Should the return value of pm_runtime_get_sync() be checked
> before accessing the hardware?

Valid. might in another patchset.

> 
> [Severity: High]
> This is another pre-existing issue, but can this sysfs read silently break
> concurrent hardware enablement?
> 
> Concurrent sysfs readers like etmsr_show() use drvdata->spinlock to serialize
> their own hardware accesses, issuing CS_UNLOCK and CS_LOCK. However,
> etm_enable_hw() executes via smp_call_function_single() and does not hold
> drvdata->spinlock while issuing its own register writes and CS_LOCK.
> 
> If a sysfs read occurs concurrently with etm_enable_hw():
> 
> Sysfs thread                           etm_enable_hw()
> etmsr_show()
>   raw_spin_lock_irqsave()
>   CS_UNLOCK()
>                                        CS_UNLOCK()
>                                        write to registers...
>   CS_LOCK()                            
>                                        write to more registers... (ignored)
>                                        CS_LOCK()
> 
> Will the sysfs read's CS_LOCK lock the CoreSight Lock Access Register (LAR)
> in the middle of etm_enable_hw()'s configuration sequence, causing
> subsequent register writes in etm_enable_hw() to be silently ignored?
> 
> [ ... ]
> 
> > @@ -76,7 +76,7 @@ static ssize_t reset_store(struct device *dev,
> >  		return ret;
> >  
> >  	if (val) {
> > -		spin_lock(&drvdata->spinlock);
> > +		raw_spin_lock(&drvdata->spinlock);
> >  		memset(config, 0, sizeof(struct etm_config));
> >  		config->mode = ETM_MODE_EXCLUDE;
> >  		config->trigger_event = ETM_DEFAULT_EVENT_VAL;
> > @@ -86,7 +86,7 @@ static ssize_t reset_store(struct device *dev,
> >  
> >  		etm_set_default(config);
> >  		etm_release_trace_id(drvdata);
> > -		spin_unlock(&drvdata->spinlock);
> > +		raw_spin_unlock(&drvdata->spinlock);
> 
> [Severity: High]
> This isn't a bug introduced by this patch, but can this cause a trace ID
> use-after-free and corrupt the trace stream?
> 
> This resets the staging configuration and unconditionally calls
> etm_release_trace_id() without checking if the tracer is currently active
> (e.g., via coresight_get_mode()). 
> 
> If writing to this reset attribute happens while a tracing session is running,
> the trace ID is returned to the pool and can be reallocated to another
> CoreSight component while this device continues to emit hardware packets using
> the freed ID.
> 

I think we should allow the reset when coresight_get_mode() == DISABLE
only. @Leo?

> > @@ -722,9 +722,9 @@ static ssize_t cntr_val_show(struct device *dev,
> >  	struct etm_config *config = &drvdata->config;
> >  
> >  	if (!coresight_get_mode(drvdata->csdev)) {
> > -		spin_lock(&drvdata->spinlock);
> > +		raw_spin_lock(&drvdata->spinlock);
> >  		val = config->cntr_val[config->cntr_idx];
> > -		spin_unlock(&drvdata->spinlock);
> > +		raw_spin_unlock(&drvdata->spinlock);
> >  	} else {
> >  		val = etm_readl(drvdata, ETMCNTVRn(config->cntr_idx));
> 
> [Severity: High]
> This is a pre-existing issue, but can this race with a concurrent power down
> and cause a synchronous external abort?
> 
> The check for coresight_get_mode() bypasses both the spinlock and
> pm_runtime_get_sync(). If the device is active during the check, it jumps
> to the else branch to read the hardware register. 
> 
> If another thread disables the device (which calls pm_runtime_put() and
> powers down the hardware) concurrently, this will read from powered-off
> hardware.
> 
> Additionally, is it safe to read config->cntr_idx here without a lock?
> 
> [ ... ]
> 
> > @@ -940,13 +940,13 @@ static ssize_t seq_curr_state_show(struct device *dev,
> >  	}
> >  
> >  	pm_runtime_get_sync(dev->parent);
> > -	spin_lock_irqsave(&drvdata->spinlock, flags);
> > +	raw_spin_lock_irqsave(&drvdata->spinlock, flags);
> >  
> >  	CS_UNLOCK(drvdata->csa.base);
> >  	val = (etm_readl(drvdata, ETMSQR) & ETM_SQR_MASK);
> 
> [Severity: High]
> This is a pre-existing issue, but as with etmsr_show() earlier, could this
> cause a synchronous external abort if the device fails to resume?
> 
> If pm_runtime_get_sync() returns a negative error, accessing the unclocked
> hardware register will cause a kernel panic.

@Leo, I think both of direct read from sysfs interface should be
synchronized via IPI. What do you think?

-- 
Sincerely,
Yeoreum Yun

  reply	other threads:[~2026-09-11 11:52 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11 10:55 [PATCH v10 0/8] fix several inconsistencies with sysfs configuration in etmX Yeoreum Yun
2026-09-11 10:56 ` [PATCH v10 1/8] coresight: etm4x: fix inconsistencies with sysfs configuration Yeoreum Yun
2026-09-11 11:21   ` sashiko-bot
2026-09-11 11:29     ` Yeoreum Yun
2026-09-11 10:56 ` [PATCH v10 2/8] coresight: etm3x: " Yeoreum Yun
2026-09-11 11:07   ` sashiko-bot
2026-09-11 11:28     ` Yeoreum Yun
2026-09-11 10:56 ` [PATCH v10 3/8] coresight: etm3x: change drvdata->spinlock type to raw_spin_lock_t Yeoreum Yun
2026-09-11 11:17   ` sashiko-bot
2026-09-11 11:52     ` Yeoreum Yun [this message]
2026-09-11 10:56 ` [PATCH v10 4/8] coresight: etm3x: remove redundant cpu online check on etm_enable_sysfs() Yeoreum Yun
2026-09-11 10:56 ` [PATCH v10 5/8] coresight: etm4x: introduce struct etm4_caps Yeoreum Yun
2026-09-11 11:20   ` sashiko-bot
2026-09-11 11:31     ` Yeoreum Yun
2026-09-11 10:56 ` [PATCH v10 6/8] coresight: etm4x: exclude ss_status from drvdata->config Yeoreum Yun
2026-09-11 11:12   ` sashiko-bot
2026-09-11 10:56 ` [PATCH v10 7/8] coresight: etm4x: remove s_ex_level from config Yeoreum Yun
2026-09-11 10:56 ` [PATCH v10 8/8] coresight: etm3x: introduce struct etm_caps Yeoreum Yun
2026-09-11 11:20   ` sashiko-bot
2026-09-11 11:42     ` Yeoreum Yun

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=aqPrZD-NLo7gZr55@e129823.arm.com \
    --to=yeoreum.yun@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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

all inboxes | Powered by JetHome®