mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Amir Ayupov <aaupov@fb.com>
To: James Clark <james.clark@linaro.org>, Leo Yan <leo.yan@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Mike Leach <mike.leach@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Daniel Pereira <danielmaraboo@gmail.com>,
	<coresight@lists.linaro.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-perf-users@vger.kernel.org>, <linux-doc@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH v6 2/4] coresight: etm4x: Skip features requiring unavailable events
Date: Fri, 20 Nov 2026 10:54:32 -0800	[thread overview]
Message-ID: <af7838ccf521e6317dbc3ef706dd4b8c979740fa.1795196854.git.aaupov@fb.com> (raw)
In-Reply-To: <cover.1795196854.git.aaupov@fb.com>

Feature register mappings accept TRCEVENTCTL0R without checking which
event fields the trace unit implements. A feature that drives EVENT1 can
therefore load on a trace unit with only EVENT0 and silently produce no
pulses.

Validate the descriptors before checking their requested EVENT fields
against the decoded event count. Parameterized writes are checked against
every writable field because parameter values may change after loading.
Let the configuration manager treat -EOPNOTSUPP as a per-device skip and
release the unlinked feature instance, while malformed descriptions and
other errors still abort loading.

Suggested-by: Mike Leach <mike.leach@arm.com>
Assisted-by: Devmate:GPT-6.1-Sol
Signed-off-by: Amir Ayupov <aaupov@fb.com>
---
 .../hwtracing/coresight/coresight-config.h    |  3 ++
 .../hwtracing/coresight/coresight-etm4x-cfg.c | 47 +++++++++++++++++--
 .../hwtracing/coresight/coresight-syscfg.c    |  7 +++
 3 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-config.h b/drivers/hwtracing/coresight/coresight-config.h
index ae6295e3081319..8f3c37b0421e24 100644
--- a/drivers/hwtracing/coresight/coresight-config.h
+++ b/drivers/hwtracing/coresight/coresight-config.h
@@ -245,6 +245,9 @@ struct cscfg_config_csdev {
  *
  * @load_feat:	Pass a feature descriptor into the device and create the
  *		loaded feature instance (struct cscfg_feature_csdev).
+ *		Return -EOPNOTSUPP if the device lacks required resources; the
+ *		manager skips that device. Other errors abort loading. An
+ *		unsupported feature must leave device state unchanged.
  */
 struct cscfg_csdev_feat_ops {
 	int (*load_feat)(struct coresight_device *csdev,
diff --git a/drivers/hwtracing/coresight/coresight-etm4x-cfg.c b/drivers/hwtracing/coresight/coresight-etm4x-cfg.c
index 52cb036bb04b96..278329075f380d 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x-cfg.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x-cfg.c
@@ -127,6 +127,28 @@ static int etm4_cfg_map_reg_offset(struct etmv4_drvdata *drvdata,
 	return err;
 }
 
+static int etm4_cfg_check_eventctl0_support(const struct cscfg_regval_desc *reg_desc,
+					    unsigned int nr_event)
+{
+	u32 requested;
+
+	if (reg_desc->offset != TRCEVENTCTL0R)
+		return 0;
+
+	/* Parameters can change after loading, so check all writable fields. */
+	if (reg_desc->type & CS_CFG_REG_TYPE_VAL_PARAM)
+		requested = reg_desc->type & CS_CFG_REG_TYPE_VAL_MASK ?
+			    reg_desc->mask32 : U32_MAX;
+	else
+		requested = reg_desc->type & CS_CFG_REG_TYPE_VAL_MASK ?
+			    reg_desc->val32 & reg_desc->mask32 : reg_desc->val32;
+
+	/* Four events use the full register: do not shift a u32 by 32. */
+	if (nr_event < 4 && (requested >> (8 * nr_event)))
+		return -EOPNOTSUPP;
+	return 0;
+}
+
 /**
  * etm4_cfg_load_feature - load a feature into a device instance.
  *
@@ -149,6 +171,7 @@ static int etm4_cfg_load_feature(struct coresight_device *csdev,
 	struct device *dev = csdev->dev.parent;
 	struct etmv4_drvdata *drvdata = dev_get_drvdata(dev);
 	const struct cscfg_feature_desc *feat_desc = feat_csdev->feat_desc;
+	const struct cscfg_regval_desc *reg_desc;
 	u32 offset;
 	int i = 0, err = 0;
 
@@ -162,12 +185,28 @@ static int etm4_cfg_load_feature(struct coresight_device *csdev,
 	 */
 	feat_csdev->drv_spinlock = NULL;
 
-	/* process the register descriptions */
-	for (i = 0; i < feat_csdev->nr_regs && !err; i++) {
-		offset = feat_desc->regs_desc[i].offset;
+	/* Validate every description before deciding whether to skip a device. */
+	for (i = 0; i < feat_csdev->nr_regs; i++) {
+		reg_desc = &feat_desc->regs_desc[i];
+		offset = reg_desc->offset;
+		if ((reg_desc->type & CS_CFG_REG_TYPE_VAL_PARAM) &&
+		    reg_desc->param_idx >= (u32)feat_csdev->nr_params)
+			return -EINVAL;
+		if (offset == TRCEVENTCTL0R &&
+		    (reg_desc->type & CS_CFG_REG_TYPE_VAL_64BIT))
+			return -EINVAL;
 		err = etm4_cfg_map_reg_offset(drvdata, &feat_csdev->regs_csdev[i], offset);
+		if (err)
+			return err;
 	}
-	return err;
+
+	for (i = 0; i < feat_csdev->nr_regs; i++) {
+		err = etm4_cfg_check_eventctl0_support(&feat_desc->regs_desc[i],
+						       drvdata->caps.nr_event);
+		if (err)
+			return err;
+	}
+	return 0;
 }
 
 /* match information when loading configurations */
diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c
index 2bfdd7b45e49c8..11946e5718fc5e 100644
--- a/drivers/hwtracing/coresight/coresight-syscfg.c
+++ b/drivers/hwtracing/coresight/coresight-syscfg.c
@@ -176,6 +176,7 @@ static int cscfg_load_feat_csdev(struct coresight_device *csdev,
 				 struct cscfg_feature_desc *feat_desc,
 				 struct cscfg_csdev_feat_ops *ops)
 {
+	struct device *dev = csdev->dev.parent;
 	struct cscfg_feature_csdev *feat_csdev;
 	unsigned long flags;
 	int err;
@@ -189,6 +190,12 @@ static int cscfg_load_feat_csdev(struct coresight_device *csdev,
 
 	/* load the feature into the device */
 	err = ops->load_feat(csdev, feat_csdev);
+	if (err == -EOPNOTSUPP) {
+		devm_kfree(dev, feat_csdev->regs_csdev);
+		devm_kfree(dev, feat_csdev->params_csdev);
+		devm_kfree(dev, feat_csdev);
+		return 0;
+	}
 	if (err)
 		return err;
 
-- 
2.52.1


  parent reply	other threads:[~2026-11-20 18:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 18:54 [PATCH v6 0/4] coresight: Pulse an ETM external output for a PMU event Amir Ayupov
2026-11-20 18:54 ` [PATCH v6 1/4] coresight: etm4x: Fix event count decoding Amir Ayupov
2026-11-20 18:54 ` Amir Ayupov [this message]
2026-11-20 18:54 ` [PATCH v6 3/4] coresight: perf: Filter sources lacking the selected configuration Amir Ayupov
2026-11-20 18:54 ` [PATCH v6 4/4] coresight: Add pmu_pulse/extout_pulse Amir Ayupov

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=af7838ccf521e6317dbc3ef706dd4b8c979740fa.1795196854.git.aaupov@fb.com \
    --to=aaupov@fb.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=corbet@lwn.net \
    --cc=coresight@lists.linaro.org \
    --cc=danielmaraboo@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=james.clark@linaro.org \
    --cc=leo.yan@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=mike.leach@arm.com \
    --cc=rdunlap@infradead.org \
    --cc=skhan@linuxfoundation.org \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    /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®