Skip to contentSkip to conversation

firmware: arm_ffa: Call ffa_rxtx_umap before calling ffa_rxtx_map

PATCH In review Nat Gurumoorthy 2 participants 2 messages Jul 29 Firmware framework for ARMV8-a

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firmware: arm_ffa: Call ffa_rxtx_umap before calling ffa_rxtx_map

In ffa_probe call ffa_rxtx_unmap before calling ffa_rxtx_map. It is possible that crash or a kexec can leave crb_ffa with old mappings. A call to ffa_rxtx_map will fail and leave crb_ffa interface unavalable. The unmap makes crb_ffa forget old mappings and allows new mappings to be set up. In kernels where arm_ffa is built in, module exit routine ffa_exit will never get called during kexec operation. This leaves behind stale mapping. New kernel's ffa_probe call to ffa_rxtx_map will fail and crb_ffa driver will not be available.

---
 drivers/firmware/arm_ffa/driver.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/firmware/arm_ffa/driver.c +5 -0
index 8654b3365c9b..44d095bc8569 100644
@@ -2168,6 +2168,11 @@ static int ffa_probe(struct platform_device *pdev)
 		goto free_pages;
 	}
 
+	/*
+	 * Force unmap before mapping in case previous crash/kexec
+	 * has existing mapping.
+	 */
+	ffa_rxtx_unmap();
 	ret = ffa_rxtx_map(virt_to_phys(drv_info->tx_buffer),
 			   virt_to_phys(drv_info->rx_buffer),
 			   rxtx_bufsz / FFA_PAGE_SIZE);
Signature · 1 line
2.55.0.487.gaf234c4eb3-goog
maintainer
#1 lore raw
Quoted 9 lines · Nat Gurumoorthy

In ffa_probe call ffa_rxtx_unmap before calling ffa_rxtx_map. It is possible that crash or a kexec can leave crb_ffa with old mappings. A call to ffa_rxtx_map will fail and leave crb_ffa interface unavalable. The unmap makes crb_ffa forget old mappings and allows new mappings to be set up. In kernels where arm_ffa is built in, module exit routine ffa_exit will never get called during kexec operation. This leaves behind stale mapping. New kernel's ffa_probe call to ffa_rxtx_map will fail and crb_ffa driver will not be available.

This is not a proper solution, what about the notifications and other states.

Now that we have proper probe and remove, just assign or call remove from shutdown callback which IIRC gets called in kexec. So something like below is a proper fix IMO(not compiled or tested)

Regards,
Sudeep

-->8

firmware: arm_ffa: Tear down driver during shutdown

The platform core invokes a driver's shutdown callback, rather than its remove callback, while preparing devices for a normal kexec. Without a shutdown callback, the FF-A driver leaves notifications, partition devices, and the RX/TX mapping active before the replacement kernel is booted.

Use ffa_remove() for shutdown so the existing cleanup runs before a normal kexec and other orderly system shutdowns.

---
 drivers/firmware/arm_ffa/driver.c | 1 +
 1 file changed, 1 insertion(+)
drivers/firmware/arm_ffa/driver.c +1 -0
index 8654b3365c9b..28abc808fd32 100644
@@ -2225,6 +2225,7 @@ static void ffa_remove(struct platform_device *pdev)
 static struct platform_driver ffa_driver = {
 	.probe = ffa_probe,
 	.remove = ffa_remove,
+	.shutdown = ffa_remove,
 	.driver = {
 		.name = FFA_PLATFORM_NAME,
 	},

--
2.43.0