mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] spi: qcom-geni: Add shutdown and panic notifier support
@ 2026-08-05 10:42 Praveen Talari
  2026-08-05 10:42 ` [PATCH 1/2] spi: qcom-geni: Add shutdown callback to quiesce hardware on reboot Praveen Talari
  2026-08-05 10:42 ` [PATCH 2/2] spi: qcom-geni: Add panic notifier to suspend controller during panic Praveen Talari
  0 siblings, 2 replies; 7+ messages in thread
From: Praveen Talari @ 2026-08-05 10:42 UTC (permalink / raw)
  To: konrad.dybcio, Mark Brown
  Cc: mukesh.savaliya, linux-arm-msm, linux-spi, linux-kernel,
	chandana.chiluveru, Praveen Talari

On VM-based platforms, if an SPI DMA transfer is in progress when the
guest is torn down (via reboot/shutdown or a panic/crash), the DMA
engine can keep issuing transactions to IOVAs that have already been
invalidated as part of teardown. The SMMU then raises context faults,
which can affect other VMs sharing the same SMMU instance and obscure
the real root cause of the crash.

This series adds two independent quiesce paths for the GENI SPI
controller so that any in-progress transfer is stopped and the DMA
engine is left idle before the IOVA mappings are torn down:

- Patch 1 adds a platform shutdown() callback that suspends the SPI
  controller on a normal reboot/shutdown path.

- Patch 2 registers a panic notifier that suspends the SPI controller
  when the kernel panics, covering the crash path as well.

Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com>
---
Praveen Talari (2):
      spi: qcom-geni: Add shutdown callback to quiesce hardware on reboot
      spi: qcom-geni: Add panic notifier to suspend controller during panic

 drivers/spi/spi-geni-qcom.c | 40 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)
---
base-commit: 9a4cdc958dd79fc6c3b20b51a10debec6ca09fec
change-id: 20260804-add-shutdown-and-panic-notifier-for-spi-fa732be7c7dd

Best regards,
--  
Praveen Talari <praveen.talari@oss.qualcomm.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] spi: qcom-geni: Add shutdown callback to quiesce hardware on reboot
  2026-08-05 10:42 [PATCH 0/2] spi: qcom-geni: Add shutdown and panic notifier support Praveen Talari
@ 2026-08-05 10:42 ` Praveen Talari
  2026-08-12  5:42   ` Mukesh Savaliya
  2026-08-05 10:42 ` [PATCH 2/2] spi: qcom-geni: Add panic notifier to suspend controller during panic Praveen Talari
  1 sibling, 1 reply; 7+ messages in thread
From: Praveen Talari @ 2026-08-05 10:42 UTC (permalink / raw)
  To: konrad.dybcio, Mark Brown
  Cc: mukesh.savaliya, linux-arm-msm, linux-spi, linux-kernel,
	chandana.chiluveru, Praveen Talari

During system reboot, an active SPI transfer can leave the GENI Serial
Engine in an indeterminate state. On VM-based platforms, if a DMA
transfer is in progress when the VM is shut down, the SMMU can raise
context faults as the DMA engine continues to access IOVAs that have
already been invalidated during VM teardown.

Add a shutdown callback to suspend the SPI controller and abort any
in-progress transfer, ensuring the DMA engine is idle and all IOVA
mappings are retired before the system resets.

Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com>
---
 drivers/spi/spi-geni-qcom.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c
index 6566975eb24f..39d67f19244c 100644
--- a/drivers/spi/spi-geni-qcom.c
+++ b/drivers/spi/spi-geni-qcom.c
@@ -1066,6 +1066,13 @@ static int spi_geni_target_abort(struct spi_controller *spi)
 	return 0;
 }
 
+static void spi_geni_shutdown(struct platform_device *pdev)
+{
+	struct spi_controller *spi = platform_get_drvdata(pdev);
+
+	spi_controller_suspend(spi);
+}
+
 static int spi_geni_probe(struct platform_device *pdev)
 {
 	int ret, irq;
@@ -1242,7 +1249,8 @@ static const struct of_device_id spi_geni_dt_match[] = {
 MODULE_DEVICE_TABLE(of, spi_geni_dt_match);
 
 static struct platform_driver spi_geni_driver = {
-	.probe  = spi_geni_probe,
+	.probe    = spi_geni_probe,
+	.shutdown = spi_geni_shutdown,
 	.driver = {
 		.name = "geni_spi",
 		.pm = &spi_geni_pm_ops,

-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/2] spi: qcom-geni: Add panic notifier to suspend controller during panic
  2026-08-05 10:42 [PATCH 0/2] spi: qcom-geni: Add shutdown and panic notifier support Praveen Talari
  2026-08-05 10:42 ` [PATCH 1/2] spi: qcom-geni: Add shutdown callback to quiesce hardware on reboot Praveen Talari
@ 2026-08-05 10:42 ` Praveen Talari
  2026-08-11 14:36   ` Mark Brown
  2026-08-12  5:46   ` Mukesh Savaliya
  1 sibling, 2 replies; 7+ messages in thread
From: Praveen Talari @ 2026-08-05 10:42 UTC (permalink / raw)
  To: konrad.dybcio, Mark Brown
  Cc: mukesh.savaliya, linux-arm-msm, linux-spi, linux-kernel,
	chandana.chiluveru, Praveen Talari

When a VM crashes with an active SPI DMA transfer in progress, the
SMMU raises context faults as the DMA engine continues to access
IOVAs that are invalidated when the VM's memory context is torn down.
These faults can affect other VMs sharing the same SMMU instance and
obscure the root cause of the crash.

Register a panic notifier to suspend the SPI controller, stopping the
transfer queue and preventing the DMA engine from issuing further
transactions to invalidated IOVAs.

Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com>
---
 drivers/spi/spi-geni-qcom.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c
index 39d67f19244c..dfd87428e84f 100644
--- a/drivers/spi/spi-geni-qcom.c
+++ b/drivers/spi/spi-geni-qcom.c
@@ -14,6 +14,7 @@
 #include <linux/io.h>
 #include <linux/log2.h>
 #include <linux/module.h>
+#include <linux/panic_notifier.h>
 #include <linux/platform_device.h>
 #include <linux/pm_opp.h>
 #include <linux/pm_runtime.h>
@@ -115,6 +116,7 @@ struct spi_geni_master {
 	struct dma_chan *rx;
 	int cur_xfer_mode;
 	const struct geni_spi_desc *dev_data;
+	struct notifier_block panic_nb;
 };
 
 static void spi_slv_setup(struct spi_geni_master *mas)
@@ -1073,6 +1075,23 @@ static void spi_geni_shutdown(struct platform_device *pdev)
 	spi_controller_suspend(spi);
 }
 
+static int spi_geni_panic_notifier(struct notifier_block *nb,
+				   unsigned long action, void *data)
+{
+	struct spi_geni_master *mas = container_of(nb, struct spi_geni_master, panic_nb);
+	struct spi_controller *spi = dev_get_drvdata(mas->dev);
+
+	spi_controller_suspend(spi);
+	return NOTIFY_OK;
+}
+
+static void spi_geni_unregister_notifiers(void *data)
+{
+	struct spi_geni_master *mas = data;
+
+	atomic_notifier_chain_unregister(&panic_notifier_list, &mas->panic_nb);
+}
+
 static int spi_geni_probe(struct platform_device *pdev)
 {
 	int ret, irq;
@@ -1161,7 +1180,16 @@ static int spi_geni_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	return devm_spi_register_controller(dev, spi);
+	ret = devm_spi_register_controller(dev, spi);
+	if (ret)
+		return ret;
+
+	mas->panic_nb.notifier_call = spi_geni_panic_notifier;
+	ret = atomic_notifier_chain_register(&panic_notifier_list, &mas->panic_nb);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev, spi_geni_unregister_notifiers, mas);
 }
 
 static int __maybe_unused spi_geni_runtime_suspend(struct device *dev)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] spi: qcom-geni: Add panic notifier to suspend controller during panic
  2026-08-05 10:42 ` [PATCH 2/2] spi: qcom-geni: Add panic notifier to suspend controller during panic Praveen Talari
@ 2026-08-11 14:36   ` Mark Brown
  2026-08-18  5:34     ` Praveen Talari
  2026-08-12  5:46   ` Mukesh Savaliya
  1 sibling, 1 reply; 7+ messages in thread
From: Mark Brown @ 2026-08-11 14:36 UTC (permalink / raw)
  To: Praveen Talari
  Cc: konrad.dybcio, mukesh.savaliya, linux-arm-msm, linux-spi,
	linux-kernel, chandana.chiluveru

[-- Attachment #1: Type: text/plain, Size: 1304 bytes --]

On Wed, Aug 05, 2026 at 04:12:10PM +0530, Praveen Talari wrote:
> When a VM crashes with an active SPI DMA transfer in progress, the
> SMMU raises context faults as the DMA engine continues to access
> IOVAs that are invalidated when the VM's memory context is torn down.
> These faults can affect other VMs sharing the same SMMU instance and
> obscure the root cause of the crash.

> +static int spi_geni_panic_notifier(struct notifier_block *nb,
> +				   unsigned long action, void *data)
> +{
> +	struct spi_geni_master *mas = container_of(nb, struct spi_geni_master, panic_nb);
> +	struct spi_controller *spi = dev_get_drvdata(mas->dev);
> +
> +	spi_controller_suspend(spi);

This will take locks - are you sure that's OK in a panic handler?

> -	return devm_spi_register_controller(dev, spi);
> +	ret = devm_spi_register_controller(dev, spi);
> +	if (ret)
> +		return ret;
> +
> +	mas->panic_nb.notifier_call = spi_geni_panic_notifier;
> +	ret = atomic_notifier_chain_register(&panic_notifier_list, &mas->panic_nb);
> +	if (ret)
> +		return ret;
> +
> +	return devm_add_action_or_reset(dev, spi_geni_unregister_notifiers, mas);

Should we have the notifier in place before registation, what happens if
we panic while probing a SPI device which is probing as a result of
registering the controller?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] spi: qcom-geni: Add shutdown callback to quiesce hardware on reboot
  2026-08-05 10:42 ` [PATCH 1/2] spi: qcom-geni: Add shutdown callback to quiesce hardware on reboot Praveen Talari
@ 2026-08-12  5:42   ` Mukesh Savaliya
  0 siblings, 0 replies; 7+ messages in thread
From: Mukesh Savaliya @ 2026-08-12  5:42 UTC (permalink / raw)
  To: Praveen Talari, konrad.dybcio, Mark Brown
  Cc: linux-arm-msm, linux-spi, linux-kernel, chandana.chiluveru



On 8/5/2026 4:12 PM, Praveen Talari wrote:
> During system reboot, an active SPI transfer can leave the GENI Serial
> Engine in an indeterminate state. On VM-based platforms, if a DMA
> transfer is in progress when the VM is shut down, the SMMU can raise
> context faults as the DMA engine continues to access IOVAs that have
> already been invalidated during VM teardown.
> 
> Add a shutdown callback to suspend the SPI controller and abort any
> in-progress transfer, ensuring the DMA engine is idle and all IOVA
> mappings are retired before the system resets.
> 
> Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com>
> ---

Reviewed-by : Mukesh Savaliya <mukesh.savaliya@oss.qualcomm.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] spi: qcom-geni: Add panic notifier to suspend controller during panic
  2026-08-05 10:42 ` [PATCH 2/2] spi: qcom-geni: Add panic notifier to suspend controller during panic Praveen Talari
  2026-08-11 14:36   ` Mark Brown
@ 2026-08-12  5:46   ` Mukesh Savaliya
  1 sibling, 0 replies; 7+ messages in thread
From: Mukesh Savaliya @ 2026-08-12  5:46 UTC (permalink / raw)
  To: Praveen Talari, konrad.dybcio, Mark Brown
  Cc: linux-arm-msm, linux-spi, linux-kernel, chandana.chiluveru



On 8/5/2026 4:12 PM, Praveen Talari wrote:

[...]
> @@ -1073,6 +1075,23 @@ static void spi_geni_shutdown(struct platform_device *pdev)
>   	spi_controller_suspend(spi);
>   }
>   
> +static int spi_geni_panic_notifier(struct notifier_block *nb,
> +				   unsigned long action, void *data)
> +{
> +	struct spi_geni_master *mas = container_of(nb, struct spi_geni_master, panic_nb);
> +	struct spi_controller *spi = dev_get_drvdata(mas->dev);
> +
> +	spi_controller_suspend(spi);

Add a line space before return

> +	return NOTIFY_OK;
> +}
> +
> +static void spi_geni_unregister_notifiers(void *data)
> +{
> +	struct spi_geni_master *mas = data;
> +
> +	atomic_notifier_chain_unregister(&panic_notifier_list, &mas->panic_nb);
> +}
> +
>   static int spi_geni_probe(struct platform_device *pdev)
>   {
>   	int ret, irq;
> @@ -1161,7 +1180,16 @@ static int spi_geni_probe(struct platform_device *pdev)
>   	if (ret)
>   		return ret;
>   
> -	return devm_spi_register_controller(dev, spi);
> +	ret = devm_spi_register_controller(dev, spi);
> +	if (ret)
Can you add a trace log here and below where ever you get error ?
Hope that will help in case of issue.
> +		return ret;
> +
> +	mas->panic_nb.notifier_call = spi_geni_panic_notifier;
> +	ret = atomic_notifier_chain_register(&panic_notifier_list, &mas->panic_nb);
> +	if (ret)
same here, add trace log
> +		return ret;
> +
> +	return devm_add_action_or_reset(dev, spi_geni_unregister_notifiers, mas);
>   }
>   
>   static int __maybe_unused spi_geni_runtime_suspend(struct device *dev)
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] spi: qcom-geni: Add panic notifier to suspend controller during panic
  2026-08-11 14:36   ` Mark Brown
@ 2026-08-18  5:34     ` Praveen Talari
  0 siblings, 0 replies; 7+ messages in thread
From: Praveen Talari @ 2026-08-18  5:34 UTC (permalink / raw)
  To: Mark Brown
  Cc: konrad.dybcio, mukesh.savaliya, linux-arm-msm, linux-spi,
	linux-kernel, chandana.chiluveru

Hi Mark,

On 11-08-2026 20:06, Mark Brown wrote:
> On Wed, Aug 05, 2026 at 04:12:10PM +0530, Praveen Talari wrote:
>> When a VM crashes with an active SPI DMA transfer in progress, the
>> SMMU raises context faults as the DMA engine continues to access
>> IOVAs that are invalidated when the VM's memory context is torn down.
>> These faults can affect other VMs sharing the same SMMU instance and
>> obscure the root cause of the crash.
>> +static int spi_geni_panic_notifier(struct notifier_block *nb,
>> +				   unsigned long action, void *data)
>> +{
>> +	struct spi_geni_master *mas = container_of(nb, struct spi_geni_master, panic_nb);
>> +	struct spi_controller *spi = dev_get_drvdata(mas->dev);
>> +
>> +	spi_controller_suspend(spi);
> This will take locks - are you sure that's OK in a panic handler?
Good point. I hadn't considered the locking requirements of
spi_controller_suspend(). Looking at the implementation, it can take
locks and is therefore not suitable for panic context.

I'll rework this to avoid invoking the SPI core suspend path from the
panic notifier and instead use a panic-safe mechanism that directly
quiesces the controller without taking sleeping locks.
>
>> -	return devm_spi_register_controller(dev, spi);
>> +	ret = devm_spi_register_controller(dev, spi);
>> +	if (ret)
>> +		return ret;
>> +
>> +	mas->panic_nb.notifier_call = spi_geni_panic_notifier;
>> +	ret = atomic_notifier_chain_register(&panic_notifier_list, &mas->panic_nb);
>> +	if (ret)
>> +		return ret;
>> +
>> +	return devm_add_action_or_reset(dev, spi_geni_unregister_notifiers, mas);
> Should we have the notifier in place before registation, what happens if
> we panic while probing a SPI device which is probing as a result of
> registering the controller?
You're right. There is a window between
devm_spi_register_controller() and notifier registration where a panic
could occur while a child SPI device is probing and issuing transfers.

I'll move the notifier registration before controller registration so
that panic handling is active before any client device can start using

the controller.


Thanks,

Praveen Talari

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-08-18  5:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-05 10:42 [PATCH 0/2] spi: qcom-geni: Add shutdown and panic notifier support Praveen Talari
2026-08-05 10:42 ` [PATCH 1/2] spi: qcom-geni: Add shutdown callback to quiesce hardware on reboot Praveen Talari
2026-08-12  5:42   ` Mukesh Savaliya
2026-08-05 10:42 ` [PATCH 2/2] spi: qcom-geni: Add panic notifier to suspend controller during panic Praveen Talari
2026-08-11 14:36   ` Mark Brown
2026-08-18  5:34     ` Praveen Talari
2026-08-12  5:46   ` Mukesh Savaliya

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®