Skip to contentSkip to conversation

Fix CPU hotplug state cleanup in Xilinx drivers

PATCH New Prasanna Kumar T S M 1 participant 3 messages Nov 30

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover Fix CPU hotplug state cleanup in Xilinx drivers

Both the ZynqMP IPI mailbox driver and the Xilinx event manager driver pass CPUHP_AP_ONLINE_DYN to cpuhp_remove_state() instead of the dynamically allocated state returned by cpuhp_setup_state(), and ignore cpuhp_setup_state() failures.

This series stores the allocated CPU hotplug state for cleanup and propagates hotplug registration failures during probe in both drivers.

Changes in v2: address v1 review comments.

Link to v1: https://lore.kernel.org/lkml/[email protected]/

Prasanna Kumar T S M (2):
mailbox: zynqmp-ipi: Fix CPU hotplug state cleanup
soc: xilinx: Fix event manager CPU hotplug state cleanup

 drivers/mailbox/zynqmp-ipi-mailbox.c    | 29 +++++++++++++++++++++--------
 drivers/soc/xilinx/xlnx_event_manager.c | 15 +++++++++++----
 2 files changed, 32 insertions(+), 12 deletions(-)
#1 lore raw

PATCH v2 1/2 mailbox: zynqmp-ipi: Fix CPU hotplug state cleanup

On driver removal, the CPUHP_AP_ONLINE_DYN CPU hotplug state is removed instead of its actual state. This can leave the mailbox driver callbacks dangling. Use the actual CPU hotplug state during driver removal.

Hotplug registration failures are also ignored, allowing probe to succeed without the callbacks needed to enable interrupts on CPUs brought online later.

This is found by code inspection.

Fixes 6ffb1635341b ("mailbox: zynqmp: handle SGI for shared IPI")
---
 drivers/mailbox/zynqmp-ipi-mailbox.c | 29 ++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)
drivers/mailbox/zynqmp-ipi-mailbox.c +21 -8
index 42d2583e44ca..843b5ecc905a 100644
@@ -126,6 +126,7 @@ struct zynqmp_ipi_mbox {
  * @method:               IPI SMC or HVC is going to be used
  * @local_id:             local IPI agent ID
  * @virq_sgi:             IRQ number mapped to SGI
+ * @hp_state:             CPU hotplug state for SGI callbacks
  * @num_mboxes:           number of mailboxes of this IPI agent
  * @ipi_mboxes:           IPI mailboxes of this IPI agent
  */
@@ -136,6 +137,7 @@ struct zynqmp_ipi_pdata {
 	unsigned int method;
 	u32 local_id;
 	int virq_sgi;
+	enum cpuhp_state hp_state;
 	int num_mboxes;
 	struct zynqmp_ipi_mbox ipi_mboxes[] __counted_by(num_mboxes);
 };
@@ -863,21 +865,32 @@ static int xlnx_mbox_init_sgi(struct platform_device *pdev,
 	irq_set_status_flags(pdata->virq_sgi, IRQ_PER_CPU);
 
 	/* Setup function for the CPU hot-plug cases */
-	cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mailbox/sgi:starting",
-			  xlnx_mbox_cpuhp_start, xlnx_mbox_cpuhp_down);
+	pdata->hp_state = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
+					    "mailbox/sgi:starting",
+					    xlnx_mbox_cpuhp_start,
+					    xlnx_mbox_cpuhp_down);
+	if (pdata->hp_state < 0) {
+		irq_clear_status_flags(pdata->virq_sgi, IRQ_PER_CPU);
+		free_percpu_irq(pdata->virq_sgi, &per_cpu_pdata);
+		irq_dispose_mapping(pdata->virq_sgi);
+		pdata->virq_sgi = 0;
+		return pdata->hp_state;
+	}
 
 	return ret;
 }
 
 static void xlnx_mbox_cleanup_sgi(struct zynqmp_ipi_pdata *pdata)
 {
-	cpuhp_remove_state(CPUHP_AP_ONLINE_DYN);
-
-	on_each_cpu(xlnx_disable_percpu_irq, NULL, 1);
+	if (pdata->hp_state >= CPUHP_AP_ONLINE_DYN)
+		cpuhp_remove_state(pdata->hp_state);
 
-	irq_clear_status_flags(pdata->virq_sgi, IRQ_PER_CPU);
-	free_percpu_irq(pdata->virq_sgi, &per_cpu_pdata);
-	irq_dispose_mapping(pdata->virq_sgi);
+	if (pdata->virq_sgi) {
+		on_each_cpu(xlnx_disable_percpu_irq, NULL, 1);
+		irq_clear_status_flags(pdata->virq_sgi, IRQ_PER_CPU);
+		free_percpu_irq(pdata->virq_sgi, &per_cpu_pdata);
+		irq_dispose_mapping(pdata->virq_sgi);
+	}
 }
 
 /**
Signature · 1 line
2.49.0
#2 lore raw

PATCH v2 2/2 soc: xilinx: Fix event manager CPU hotplug state cleanup

In reply to Prasanna Kumar T S M

On driver removal, the event manager removes the CPUHP_AP_ONLINE_DYN CPU hotplug state instead of its actual state. This can leave the event manager callbacks dangling. Use the actual CPU hotplug state during driver removal.

Hotplug registration failures are also ignored, allowing probe to succeed without the callbacks needed to enable event interrupts on CPUs brought online later.

This is found by code inspection.

Fixes c7fdb2404f66 ("drivers: soc: xilinx: add xilinx event management driver")
---
 drivers/soc/xilinx/xlnx_event_manager.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/soc/xilinx/xlnx_event_manager.c +11 -4
index f733dc42b3b1..e09a315b65a6 100644
@@ -24,6 +24,7 @@ static DEFINE_PER_CPU_READ_MOSTLY(int, dummy_cpu_number);
 
 static int virq_sgi;
 static int event_manager_availability = -EACCES;
+static enum cpuhp_state hp_state;
 
 /* SGI number used for Event management driver */
 #define XLNX_EVENT_SGI_NUM	(15)
@@ -625,8 +626,6 @@ static int xlnx_event_init_sgi(struct platform_device *pdev)
 
 static void xlnx_event_cleanup_sgi(struct platform_device *pdev)
 {
-	cpuhp_remove_state(CPUHP_AP_ONLINE_DYN);
-
 	on_each_cpu(xlnx_disable_percpu_irq, NULL, 1);
 
 	irq_clear_status_flags(virq_sgi, IRQ_PER_CPU);
@@ -660,8 +659,14 @@ static int xlnx_event_manager_probe(struct platform_device *pdev)
 	}
 
 	/* Setup function for the CPU hot-plug cases */
-	cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "soc/event:starting",
-			  xlnx_event_cpuhp_start, xlnx_event_cpuhp_down);
+	hp_state = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
+				     "soc/event:starting",
+				     xlnx_event_cpuhp_start,
+				     xlnx_event_cpuhp_down);
+	if (hp_state < 0) {
+		xlnx_event_cleanup_sgi(pdev);
+		return hp_state;
+	}
 
 	ret = zynqmp_pm_register_sgi(sgi_num, 0);
 	if (ret) {
@@ -670,6 +675,7 @@ static int xlnx_event_manager_probe(struct platform_device *pdev)
 		else
 			dev_err(&pdev->dev, "SGI %d registration failed, err %d\n", sgi_num, ret);
 
+		cpuhp_remove_state(hp_state);
 		xlnx_event_cleanup_sgi(pdev);
 		return ret;
 	}
@@ -704,6 +710,7 @@ static void xlnx_event_manager_remove(struct platform_device *pdev)
 	if (ret)
 		dev_err(&pdev->dev, "SGI unregistration over TF-A failed with %d\n", ret);
 
+	cpuhp_remove_state(hp_state);
 	xlnx_event_cleanup_sgi(pdev);
 
 	event_manager_availability = -EACCES;
Signature · 1 line
2.49.0