diff mbox series

firmware: arm_scmi: Fix chan_free cleanup on SMC

Message ID 20230719173533.2739319-1-cristian.marussi@arm.com (mailing list archive)
State New, archived
Headers show
Series firmware: arm_scmi: Fix chan_free cleanup on SMC | expand

Commit Message

Cristian Marussi July 19, 2023, 5:35 p.m. UTC
SCMI transport based on SMC can optionally use an additional IRQ to signal
message completion; the associated ISR is currently allocated using devres
but the core SCMI stack, on shutdown, will call .chan_free() well before
any managed cleanup is invoked by devres and, as a consequence, the arrival
of a late reply to an in-flight pending transaction could still trigger the
ISR well after the SCMI core has cleaned up the channels, with unpleasant
results.

Inhibit further message processing on the IRQ path by explicitly freeing
the IRQ inside .chan_free() callback itself.

Fixes: dd820ee21d5e ("firmware: arm_scmi: Augment SMC/HVC to allow optional interrupt")
Reported-by: Bjorn Andersson <andersson@kernel.org>
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
Just compile tested, dont have a platform to test it.
---
 drivers/firmware/arm_scmi/smc.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Comments

Bjorn Andersson July 22, 2023, 2:43 a.m. UTC | #1
On Wed, Jul 19, 2023 at 06:35:33PM +0100, Cristian Marussi wrote:
> SCMI transport based on SMC can optionally use an additional IRQ to signal
> message completion; the associated ISR is currently allocated using devres
> but the core SCMI stack, on shutdown, will call .chan_free() well before
> any managed cleanup is invoked by devres and, as a consequence, the arrival
> of a late reply to an in-flight pending transaction could still trigger the
> ISR well after the SCMI core has cleaned up the channels, with unpleasant
> results.
> 
> Inhibit further message processing on the IRQ path by explicitly freeing
> the IRQ inside .chan_free() callback itself.
> 
> Fixes: dd820ee21d5e ("firmware: arm_scmi: Augment SMC/HVC to allow optional interrupt")
> Reported-by: Bjorn Andersson <andersson@kernel.org>
> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
> ---

Reviewed-by: Bjorn Andersson <andersson@kernel.org>

Regards,
Bjorn
Sudeep Holla July 22, 2023, 8:07 a.m. UTC | #2
On Wed, 19 Jul 2023 18:35:33 +0100, Cristian Marussi wrote:
> SCMI transport based on SMC can optionally use an additional IRQ to signal
> message completion; the associated ISR is currently allocated using devres
> but the core SCMI stack, on shutdown, will call .chan_free() well before
> any managed cleanup is invoked by devres and, as a consequence, the arrival
> of a late reply to an in-flight pending transaction could still trigger the
> ISR well after the SCMI core has cleaned up the channels, with unpleasant
> results.
> 
> [...]

Applied to sudeep.holla/linux (for-next/scmi/fixes), thanks!

[1/1] firmware: arm_scmi: Fix chan_free cleanup on SMC
      https://git.kernel.org/sudeep.holla/c/d1ff11d7ad87
--
Regards,
Sudeep
diff mbox series

Patch

diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
index 621c37efe3ec..c8c2fb172079 100644
--- a/drivers/firmware/arm_scmi/smc.c
+++ b/drivers/firmware/arm_scmi/smc.c
@@ -40,6 +40,7 @@ 
 /**
  * struct scmi_smc - Structure representing a SCMI smc transport
  *
+ * @irq: An optional IRQ for completion
  * @cinfo: SCMI channel info
  * @shmem: Transmit/Receive shared memory area
  * @shmem_lock: Lock to protect access to Tx/Rx shared memory area.
@@ -52,6 +53,7 @@ 
  */
 
 struct scmi_smc {
+	int irq;
 	struct scmi_chan_info *cinfo;
 	struct scmi_shared_mem __iomem *shmem;
 	/* Protect access to shmem area */
@@ -127,7 +129,7 @@  static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 	struct resource res;
 	struct device_node *np;
 	u32 func_id;
-	int ret, irq;
+	int ret;
 
 	if (!tx)
 		return -ENODEV;
@@ -167,11 +169,10 @@  static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 	 * completion of a message is signaled by an interrupt rather than by
 	 * the return of the SMC call.
 	 */
-	irq = of_irq_get_byname(cdev->of_node, "a2p");
-	if (irq > 0) {
-		ret = devm_request_irq(dev, irq, smc_msg_done_isr,
-				       IRQF_NO_SUSPEND,
-				       dev_name(dev), scmi_info);
+	scmi_info->irq = of_irq_get_byname(cdev->of_node, "a2p");
+	if (scmi_info->irq > 0) {
+		ret = request_irq(scmi_info->irq, smc_msg_done_isr,
+				  IRQF_NO_SUSPEND, dev_name(dev), scmi_info);
 		if (ret) {
 			dev_err(dev, "failed to setup SCMI smc irq\n");
 			return ret;
@@ -193,6 +194,10 @@  static int smc_chan_free(int id, void *p, void *data)
 	struct scmi_chan_info *cinfo = p;
 	struct scmi_smc *scmi_info = cinfo->transport_info;
 
+	/* Ignore any possible further reception on the IRQ path */
+	if (scmi_info->irq > 0)
+		free_irq(scmi_info->irq, scmi_info);
+
 	cinfo->transport_info = NULL;
 	scmi_info->cinfo = NULL;