Re: [PATCH v17 04/34] firmware: arm_scmi: Add centralized detection of truncated replies
From: Jonathan Cameron
Date: Tue Nov 24 2026 - 18:35:38 EST
On Tue, 24 Nov 2026 19:48:10 +0000
Cristian Marussi <cristian.marussi@xxxxxxx> wrote:
> When an xfer is allocated with a very well known fixed reply size by
> providing a non-zero rx_size parameter to xfer_get_init(), it becomes
> possible to verify if the effectively received reply was truncated.
>
> Add the logic to detect and report truncated replies.
>
> Signed-off-by: Cristian Marussi <cristian.marussi@xxxxxxx>
A suggestion to perhaps move this to a different layer.
I don't feel that strongly about it though, so whilst that is my preference
this is fine if not.
Reviewed-by: Jonathan Cameron <jonathan.cameron@xxxxxxxxxxxxxxxx>
> ---
> v16 --> v17
> - use %zu
> - consider expected_size when reset_rx_to_max
> ---
> drivers/firmware/arm_scmi/driver.c | 14 +++++++++++++-
> drivers/firmware/arm_scmi/protocols.h | 8 ++++++++
> drivers/firmware/arm_scmi/raw_mode.c | 1 +
> 3 files changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
> index 6dd249c08f5f..35adee6a7a15 100644
> --- a/drivers/firmware/arm_scmi/driver.c
> +++ b/drivers/firmware/arm_scmi/driver.c
> @@ -1356,6 +1356,16 @@ static int scmi_wait_for_reply(struct device *dev, const struct scmi_desc *desc,
> }
> }
>
> + /* Check for truncated messages..it will be logged by the caller */
> + if (!ret && !xfer->hdr.status && xfer->expected_rx_len &&
> + xfer->expected_rx_len != xfer->rx.len) {
> + dev_dbg(dev,
> + "Truncated reply - HDR:%08X expected:%zu received:%zu\n",
> + pack_scmi_header(&xfer->hdr), xfer->expected_rx_len,
> + xfer->rx.len);
> + xfer->hdr.status = SCMI_ERR_COMMS;
> + }
The check is good but it's the only validation done in this function and
the naming doesn't suggest any validation would be done in here.
There are only two call chains to this, so maybe it makes more sense
to move it up to do_xfer() / scmi_xfer_raw_worker()?
Small amount of duplication but in a place I think feels a little more natural.
> +
> return ret;
> }
>
> @@ -1508,7 +1518,7 @@ static void reset_rx_to_maxsz(const struct scmi_protocol_handle *ph,
> const struct scmi_protocol_instance *pi = ph_to_pi(ph);
> struct scmi_info *info = handle_to_scmi_info(pi->handle);
>
> - xfer->rx.len = info->desc->max_msg_size;
> + xfer->rx.len = xfer->expected_rx_len ?: info->desc->max_msg_size;
> }
>
> /**
> @@ -1616,6 +1626,8 @@ static int xfer_get_init(const struct scmi_protocol_handle *ph,
>
> xfer->tx.len = tx_size;
> xfer->rx.len = rx_size ? : info->desc->max_msg_size;
> + /* When a specific rx_size was specified, check for truncation */
> + xfer->expected_rx_len = rx_size ? : 0;
> xfer->hdr.type = MSG_TYPE_COMMAND;
> xfer->hdr.id = msg_id;
> xfer->hdr.poll_completion = false;
> diff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_scmi/protocols.h
> index c15ec188291a..50b89c56e309 100644
> --- a/drivers/firmware/arm_scmi/protocols.h
> +++ b/drivers/firmware/arm_scmi/protocols.h
> @@ -106,6 +106,13 @@ struct scmi_msg_hdr {
> * @rx: Receive message, the buffer should be pre-allocated to store
> * message. If request-ACK protocol is used, we can reuse the same
> * buffer for the rx path as we use for the tx path.
> + * @expected_rx_len: The expected length of the payload in the reply, excluding
> + * the status field. When set to a non-zero value this is used
> + * to evaluate if a reply had been possibly truncated due to a
> + * misconfigured transport: it is only set to some meaningful
> + * non-zero value for replies having a very well known fixed
> + * size, definitely not for variable-sized xfers with an RX
> + * len initialized to max_msg_size.
> * @done: command message transmit completion event
> * @async_done: pointer to delayed response message received event completion,
> * or NULL when no delayed response is expected. Protected by
> @@ -139,6 +146,7 @@ struct scmi_xfer {
> struct scmi_msg_hdr hdr;
> struct scmi_msg tx;
> struct scmi_msg rx;
> + size_t expected_rx_len;
> struct completion done;
> struct completion *async_done;
> bool pending;
> diff --git a/drivers/firmware/arm_scmi/raw_mode.c b/drivers/firmware/arm_scmi/raw_mode.c
> index 7e42dd6cc2af..45206edff446 100644
> --- a/drivers/firmware/arm_scmi/raw_mode.c
> +++ b/drivers/firmware/arm_scmi/raw_mode.c
> @@ -574,6 +574,7 @@ static int scmi_xfer_raw_get_init(struct scmi_raw_mode_info *raw, void *buf,
> xfer->hdr.status = SCMI_SUCCESS;
> xfer->tx.len = tx_size;
> xfer->rx.len = raw->desc->max_msg_size;
> + xfer->expected_rx_len = 0;
> /* Clear the whole TX buffer */
> memset(xfer->tx.buf, 0x00, raw->desc->max_msg_size);
> if (xfer->tx.len)