From: Mike Leach <mike.leach@linaro.org>
To: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Cc: suzuki.poulose@arm.com, leo.yan@arm.com, james.clark@linaro.org,
Mike Leach <mike.leach@linaro.org>
Subject: [PATCH] coresight: tmc: Prevent sysfs parameter changes if sink in use
Date: Thu, 6 Nov 2025 17:04:59 +0000 [thread overview]
Message-ID: <20251106170459.2348-1-mike.leach@linaro.org> (raw)
The sysfs files that change the operational parameters for TMC buffer_size,
stop_on_flush and trigger_cntr are writable when the TMC is in use.
The new values will have no effect and be silently ignored.
Alter the sysfs functions to return -EBUSY if the TMC is currently
in use, and also protect the write values using the spinlock.
Signed-off-by: Mike Leach <mike.leach@linaro.org>
---
.../hwtracing/coresight/coresight-tmc-core.c | 41 ++++++++++++++++---
1 file changed, 35 insertions(+), 6 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c
index 36599c431be6..a1216a1f9681 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-core.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
@@ -489,15 +489,24 @@ static ssize_t trigger_cntr_store(struct device *dev,
const char *buf, size_t size)
{
int ret;
- unsigned long val;
+ unsigned long val, flags;
struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent);
ret = kstrtoul(buf, 16, &val);
if (ret)
return ret;
+ /* do not permit write if the sink is currently in use */
+ raw_spin_lock_irqsave(&drvdata->spinlock, flags);
+ if (coresight_get_mode(drvdata->csdev) != CS_MODE_DISABLED) {
+ ret = -EBUSY;
+ goto out;
+ }
drvdata->trigger_cntr = val;
- return size;
+ ret = size;
+out:
+ raw_spin_unlock_irqrestore(&drvdata->spinlock, flags);
+ return ret;
}
static DEVICE_ATTR_RW(trigger_cntr);
@@ -514,7 +523,7 @@ static ssize_t buffer_size_store(struct device *dev,
const char *buf, size_t size)
{
int ret;
- unsigned long val;
+ unsigned long val, flags;
struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent);
/* Only permitted for TMC-ETRs */
@@ -527,8 +536,18 @@ static ssize_t buffer_size_store(struct device *dev,
/* The buffer size should be page aligned */
if (val & (PAGE_SIZE - 1))
return -EINVAL;
+
+ /* do not permit write if the sink is currently in use */
+ raw_spin_lock_irqsave(&drvdata->spinlock, flags);
+ if (coresight_get_mode(drvdata->csdev) != CS_MODE_DISABLED) {
+ ret = -EBUSY;
+ goto out;
+ }
drvdata->size = val;
- return size;
+ ret = size;
+out:
+ raw_spin_unlock_irqrestore(&drvdata->spinlock, flags);
+ return ret;
}
static DEVICE_ATTR_RW(buffer_size);
@@ -547,17 +566,27 @@ static ssize_t stop_on_flush_store(struct device *dev,
{
int ret;
u8 val;
+ unsigned long flags;
struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent);
ret = kstrtou8(buf, 0, &val);
if (ret)
return ret;
+
+ /* do not permit write if the sink is currently in use */
+ raw_spin_lock_irqsave(&drvdata->spinlock, flags);
+ if (coresight_get_mode(drvdata->csdev) != CS_MODE_DISABLED) {
+ ret = -EBUSY;
+ goto out;
+ }
if (val)
drvdata->stop_on_flush = true;
else
drvdata->stop_on_flush = false;
-
- return size;
+ ret = size;
+out:
+ raw_spin_unlock_irqrestore(&drvdata->spinlock, flags);
+ return ret;
}
static DEVICE_ATTR_RW(stop_on_flush);
--
2.32.0
reply other threads:[~2025-11-06 17:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20251106170459.2348-1-mike.leach@linaro.org \
--to=mike.leach@linaro.org \
--cc=coresight@lists.linaro.org \
--cc=james.clark@linaro.org \
--cc=leo.yan@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=suzuki.poulose@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;
as well as URLs for NNTP newsgroup(s).