Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Cristian Marussi <cristian.marussi@arm.com>
To: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org,
	linux-doc@vger.kernel.org
Cc: sudeep.holla@kernel.org, james.quinlan@broadcom.com,
	f.fainelli@gmail.com, vincent.guittot@linaro.org,
	etienne.carriere@st.com, peng.fan@oss.nxp.com,
	michal.simek@amd.com, d-gole@ti.com, jic23@kernel.org,
	elif.topuz@arm.com, lukasz.luba@arm.com, philip.radford@arm.com,
	david@kernel.org, souvik.chakravarty@arm.com, leitao@kernel.org,
	kas@kernel.org, puranjay@kernel.org, usama.arif@linux.dev,
	kernel-team@meta.com, Cristian Marussi <cristian.marussi@arm.com>
Subject: [PATCH v7 02/23] firmware: arm_scmi: Allow registration of unknown-size events/reports
Date: Sun,  2 Aug 2026 15:55:57 +0100	[thread overview]
Message-ID: <20260802145618.1952804-3-cristian.marussi@arm.com> (raw)
In-Reply-To: <20260802145618.1952804-1-cristian.marussi@arm.com>

Allow protocols to register events with build-time unknown sizes: such
events can be declared zero-sized and let the core SCMI stack perform the
needed safe-net boundary checks based on the configured transport size.

Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
v2 --> v3
 - split out of previous patch on protocol notifier
 - use max() instead of max_t()
---
 drivers/firmware/arm_scmi/notify.c | 24 +++++++++++++++++++-----
 drivers/firmware/arm_scmi/notify.h |  8 ++++++--
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/drivers/firmware/arm_scmi/notify.c b/drivers/firmware/arm_scmi/notify.c
index 0a192cf2deab..8995dd1b12aa 100644
--- a/drivers/firmware/arm_scmi/notify.c
+++ b/drivers/firmware/arm_scmi/notify.c
@@ -595,7 +595,13 @@ int scmi_notify(const struct scmi_handle *handle, u8 proto_id, u8 evt_id,
 	if (!r_evt)
 		return -EINVAL;
 
-	if (len > r_evt->evt->max_payld_sz) {
+	/*
+	 * Events with a zero max_payld_sz are sized to be of the maximum
+	 * size allowed by the transport: no need to be size-checked here
+	 * since the transport layer would have already dropped such
+	 * over-sized messages.
+	 */
+	if (r_evt->evt->max_payld_sz && len > r_evt->evt->max_payld_sz) {
 		dev_err(handle->dev, "discard badly sized message\n");
 		return -EINVAL;
 	}
@@ -754,7 +760,7 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,
 				  const struct scmi_protocol_handle *ph,
 				  const struct scmi_protocol_events *ee)
 {
-	int i;
+	int i, max_msg_sz;
 	unsigned int num_sources;
 	size_t payld_sz = 0;
 	struct scmi_registered_events_desc *pd;
@@ -769,6 +775,8 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,
 	if (!ni)
 		return -ENOMEM;
 
+	max_msg_sz = ph->hops->get_max_msg_size(ph);
+
 	/* num_sources cannot be <= 0 */
 	if (ee->num_sources) {
 		num_sources = ee->num_sources;
@@ -781,8 +789,13 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,
 	}
 
 	evt = ee->evts;
-	for (i = 0; i < ee->num_events; i++)
-		payld_sz = max_t(size_t, payld_sz, evt[i].max_payld_sz);
+	for (i = 0; i < ee->num_events; i++) {
+		if (evt[i].max_payld_sz == 0) {
+			payld_sz = max_msg_sz;
+			break;
+		}
+		payld_sz = max(payld_sz, evt[i].max_payld_sz);
+	}
 	payld_sz += sizeof(struct scmi_event_header);
 
 	pd = scmi_allocate_registered_events_desc(ni, proto_id, ee->queue_sz,
@@ -811,7 +824,8 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,
 		mutex_init(&r_evt->sources_mtx);
 
 		r_evt->report = devm_kzalloc(ni->handle->dev,
-					     evt->max_report_sz, GFP_KERNEL);
+					     evt->max_report_sz ?: max_msg_sz,
+					     GFP_KERNEL);
 		if (!r_evt->report)
 			return -ENOMEM;
 
diff --git a/drivers/firmware/arm_scmi/notify.h b/drivers/firmware/arm_scmi/notify.h
index 76758a736cf4..ecfa4b746487 100644
--- a/drivers/firmware/arm_scmi/notify.h
+++ b/drivers/firmware/arm_scmi/notify.h
@@ -18,8 +18,12 @@
 /**
  * struct scmi_event  - Describes an event to be supported
  * @id: Event ID
- * @max_payld_sz: Max possible size for the payload of a notification message
- * @max_report_sz: Max possible size for the report of a notification message
+ * @max_payld_sz: Max possible size for the payload of a notification message.
+ *		  Set to zero to use the maximum payload size allowed by the
+ *		  transport.
+ * @max_report_sz: Max possible size for the report of a notification message.
+ *		  Set to zero to use the maximum payload size allowed by the
+ *		  transport.
  *
  * Each SCMI protocol, during its initialization phase, can describe the events
  * it wishes to support in a few struct scmi_event and pass them to the core
-- 
2.54.0



  parent reply	other threads:[~2026-08-02 14:57 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-02 14:55 [PATCH v7 00/23] Introduce SCMI Telemetry support Cristian Marussi
2026-08-02 14:55 ` [PATCH v7 01/23] firmware: arm_scmi: Add new SCMIv4.0 error codes definitions Cristian Marussi
2026-08-02 14:55 ` Cristian Marussi [this message]
2026-08-02 14:55 ` [PATCH v7 03/23] firmware: arm_scmi: Introduce protocol instance notifiers Cristian Marussi
2026-08-02 14:55 ` [PATCH v7 04/23] dt-bindings: firmware: arm,scmi: Add support for telemetry protocol Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 05/23] include: trace: Add Telemetry trace events Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 06/23] firmware: arm_scmi: Add basic Telemetry support Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 07/23] firmware: arm_scmi: Add support to parse SHMTIs areas Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 08/23] firmware: arm_scmi: Add Telemetry configuration operations Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 09/23] firmware: arm_scmi: Add Telemetry DataEvent read capabilities Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 10/23] firmware: arm_scmi: Add support for Telemetry reset Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 11/23] firmware: arm_scmi: Add Telemetry notification support Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 12/23] firmware: arm_scmi: Add support for boot-on Telemetry Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 13/23] firmware: arm-scmi: Add telemetry generic event support Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 14/23] firmware: arm_scmi: Add Telemetry generation counter event Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 15/23] firmware: arm_scmi: Add common per-protocol debugfs support Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 16/23] firmware: arm_scmi: Add Telemetry debugfs SHMTI dump support Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 17/23] firmware: arm_scmi: Add Telemetry debugfs ABI documentation Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 18/23] firmware: arm_scmi: Expose per-instance identifier Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 19/23] uapi: Add ARM SCMI Telemetry definitions Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 20/23] firmware: arm_scmi: Add System Telemetry driver Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 21/23] docs: ioctl-number: Add SCMI Ioctls Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 22/23] [RFC] Documentation: Add SCMI System Telemetry documentation Cristian Marussi
2026-08-02 14:56 ` [PATCH v7 23/23] [RFC] tools/scmi: Add SCMI Telemetry testing tool Cristian Marussi
2026-08-05  5:21 ` [PATCH v7 00/23] Introduce SCMI Telemetry support Subrahmanya Lingappa
2026-08-05  6:14   ` David Hildenbrand (Arm)
2026-08-05 11:06     ` Subrahmanya Lingappa
     [not found] <<20260802145618.1952804-20-cristian.marussi@arm.com>
2026-08-03 22:25 ` [PATCH v7 19/23] uapi: Add ARM SCMI Telemetry definitions Fayssal Benmlih
2026-08-04 10:39   ` Cristian Marussi

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=20260802145618.1952804-3-cristian.marussi@arm.com \
    --to=cristian.marussi@arm.com \
    --cc=arm-scmi@vger.kernel.org \
    --cc=d-gole@ti.com \
    --cc=david@kernel.org \
    --cc=elif.topuz@arm.com \
    --cc=etienne.carriere@st.com \
    --cc=f.fainelli@gmail.com \
    --cc=james.quinlan@broadcom.com \
    --cc=jic23@kernel.org \
    --cc=kas@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=leitao@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=michal.simek@amd.com \
    --cc=peng.fan@oss.nxp.com \
    --cc=philip.radford@arm.com \
    --cc=puranjay@kernel.org \
    --cc=souvik.chakravarty@arm.com \
    --cc=sudeep.holla@kernel.org \
    --cc=usama.arif@linux.dev \
    --cc=vincent.guittot@linaro.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