Skip to content

Commit 5c14f38

Browse files
cris-masudeep-holla
authored andcommitted
firmware: arm_scmi: Account for SHMEM memory overhead
Transports using shared memory have to consider the overhead due to the layout area when determining the area effectively available for messages. Till now, such definitions were ambiguos across the SCMI stack and the overhead layout area was not considered at all. Add proper checks in the shmem layer to validate the provided max_msg_size against the effectively available memory area, less the layout. Signed-off-by: Cristian Marussi <[email protected]> Message-Id: <[email protected]> Signed-off-by: Sudeep Holla <[email protected]>
1 parent 2cd7f3d commit 5c14f38

File tree

6 files changed

+18
-8
lines changed

6 files changed

+18
-8
lines changed

drivers/firmware/arm_scmi/common.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
#define SCMI_MAX_RESPONSE_TIMEOUT (2 * MSEC_PER_SEC)
3333

34+
#define SCMI_SHMEM_MAX_PAYLOAD_SIZE 104
35+
3436
enum scmi_error_codes {
3537
SCMI_SUCCESS = 0, /* Success */
3638
SCMI_ERR_SUPPORT = -1, /* Not supported */
@@ -165,6 +167,7 @@ void scmi_protocol_release(const struct scmi_handle *handle, u8 protocol_id);
165167
* channel
166168
* @is_p2a: A flag to identify a channel as P2A (RX)
167169
* @rx_timeout_ms: The configured RX timeout in milliseconds.
170+
* @max_msg_size: Maximum size of message payload.
168171
* @handle: Pointer to SCMI entity handle
169172
* @no_completion_irq: Flag to indicate that this channel has no completion
170173
* interrupt mechanism for synchronous commands.
@@ -177,6 +180,7 @@ struct scmi_chan_info {
177180
struct device *dev;
178181
bool is_p2a;
179182
unsigned int rx_timeout_ms;
183+
unsigned int max_msg_size;
180184
struct scmi_handle *handle;
181185
bool no_completion_irq;
182186
void *transport_info;
@@ -224,7 +228,7 @@ struct scmi_transport_ops {
224228
* @max_msg: Maximum number of messages for a channel type (tx or rx) that can
225229
* be pending simultaneously in the system. May be overridden by the
226230
* get_max_msg op.
227-
* @max_msg_size: Maximum size of data per message that can be handled.
231+
* @max_msg_size: Maximum size of data payload per message that can be handled.
228232
* @force_polling: Flag to force this whole transport to use SCMI core polling
229233
* mechanism instead of completion interrupts even if available.
230234
* @sync_cmds_completed_on_ret: Flag to indicate that the transport assures

drivers/firmware/arm_scmi/driver.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,6 +2645,7 @@ static int scmi_chan_setup(struct scmi_info *info, struct device_node *of_node,
26452645

26462646
cinfo->is_p2a = !tx;
26472647
cinfo->rx_timeout_ms = info->desc->max_rx_timeout_ms;
2648+
cinfo->max_msg_size = info->desc->max_msg_size;
26482649

26492650
/* Create a unique name for this transport device */
26502651
snprintf(name, 32, "__scmi_transport_device_%s_%02X",

drivers/firmware/arm_scmi/shmem.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include "common.h"
1818

19+
#define SCMI_SHMEM_LAYOUT_OVERHEAD 24
20+
1921
/*
2022
* SCMI specification requires all parameters, message headers, return
2123
* arguments or any protocol data to be expressed in little endian
@@ -221,6 +223,11 @@ static void __iomem *shmem_setup_iomap(struct scmi_chan_info *cinfo,
221223
}
222224

223225
size = resource_size(res);
226+
if (cinfo->max_msg_size + SCMI_SHMEM_LAYOUT_OVERHEAD > size) {
227+
dev_err(dev, "misconfigured SCMI shared memory\n");
228+
return IOMEM_ERR_PTR(-ENOSPC);
229+
}
230+
224231
addr = devm_ioremap(dev, res->start, size);
225232
if (!addr) {
226233
dev_err(dev, "failed to ioremap SCMI %s shared memory\n", desc);

drivers/firmware/arm_scmi/transports/mailbox.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static struct scmi_desc scmi_mailbox_desc = {
371371
.ops = &scmi_mailbox_ops,
372372
.max_rx_timeout_ms = 30, /* We may increase this if required */
373373
.max_msg = 20, /* Limited by MBOX_TX_QUEUE_LEN */
374-
.max_msg_size = 128,
374+
.max_msg_size = SCMI_SHMEM_MAX_PAYLOAD_SIZE,
375375
};
376376

377377
static const struct of_device_id scmi_of_match[] = {

drivers/firmware/arm_scmi/transports/optee.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
#include "../common.h"
1919

20-
#define SCMI_OPTEE_MAX_MSG_SIZE 128
21-
2220
enum scmi_optee_pta_cmd {
2321
/*
2422
* PTA_SCMI_CMD_CAPABILITIES - Get channel capabilities
@@ -299,7 +297,7 @@ static int invoke_process_msg_channel(struct scmi_optee_channel *channel, size_t
299297

300298
param[2].attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT;
301299
param[2].u.memref.shm = channel->tee_shm;
302-
param[2].u.memref.size = SCMI_OPTEE_MAX_MSG_SIZE;
300+
param[2].u.memref.size = SCMI_SHMEM_MAX_PAYLOAD_SIZE;
303301

304302
ret = tee_client_invoke_func(scmi_optee_private->tee_ctx, &arg, param);
305303
if (ret < 0 || arg.ret) {
@@ -332,7 +330,7 @@ static void scmi_optee_clear_channel(struct scmi_chan_info *cinfo)
332330

333331
static int setup_dynamic_shmem(struct device *dev, struct scmi_optee_channel *channel)
334332
{
335-
const size_t msg_size = SCMI_OPTEE_MAX_MSG_SIZE;
333+
const size_t msg_size = SCMI_SHMEM_MAX_PAYLOAD_SIZE;
336334
void *shbuf;
337335

338336
channel->tee_shm = tee_shm_alloc_kernel_buf(scmi_optee_private->tee_ctx, msg_size);
@@ -519,7 +517,7 @@ static struct scmi_desc scmi_optee_desc = {
519517
.ops = &scmi_optee_ops,
520518
.max_rx_timeout_ms = 30,
521519
.max_msg = 20,
522-
.max_msg_size = SCMI_OPTEE_MAX_MSG_SIZE,
520+
.max_msg_size = SCMI_SHMEM_MAX_PAYLOAD_SIZE,
523521
.sync_cmds_completed_on_ret = true,
524522
};
525523

drivers/firmware/arm_scmi/transports/smc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static struct scmi_desc scmi_smc_desc = {
282282
.ops = &scmi_smc_ops,
283283
.max_rx_timeout_ms = 30,
284284
.max_msg = 20,
285-
.max_msg_size = 128,
285+
.max_msg_size = SCMI_SHMEM_MAX_PAYLOAD_SIZE,
286286
/*
287287
* Setting .sync_cmds_atomic_replies to true for SMC assumes that,
288288
* once the SMC instruction has completed successfully, the issued

0 commit comments

Comments
 (0)