From: Praveen Talari <praveen.talari@oss.qualcomm.com>
To: Jyothi Kumar Seerapu <jyothi.seerapu@oss.qualcomm.com>,
konrad.dybcio@oss.qualcomm.com, Mark Brown <broonie@kernel.org>
Cc: mukesh.savaliya@oss.qualcomm.com, linux-arm-msm@vger.kernel.org,
linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
chandana.chiluveru@oss.qualcomm.com
Subject: Re: [PATCH v3 2/2] spi: qcom-geni: Add panic notifier to cancel and reset DMA during panic
Date: Fri, 21 Aug 2026 21:21:56 +0530 [thread overview]
Message-ID: <9b1b7f13-51a1-4846-a030-99f9b1cb439d@oss.qualcomm.com> (raw)
In-Reply-To: <720c8c7f-532c-41e2-a4b4-60ab0edbb280@oss.qualcomm.com>
Hi Jyothi,
Thank you for review.
On 21-08-2026 16:19, Jyothi Kumar Seerapu wrote:
>
>
> On 8/18/2026 6:58 PM, 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.
>>
>> Register a panic notifier that cancels (or aborts, if cancel doesn't
>> complete) the in-flight command and resets the TX/RX DMA FSMs, so the
>> DMA engine stops issuing transactions against invalidated IOVAs
>> before the system halts. For GPI DMA mode, the DMA channels are
>> terminated directly via dmaengine_terminate_async().
>>
>> The notifier bails out early if the device is not runtime-active or
>> if there's no active GENI command, avoiding unnecessary register
>> accesses while the SE is clock-gated or idle.
>>
>> Since panic notifiers run with IRQs and preemption disabled,
>> completion-based waits used by the regular error-handling path
>> (handle_se_timeout()) cannot be reused here. Instead, the relevant
>> status registers are polled directly with
>> readl_poll_timeout_atomic(), which is safe to call in this context.
>>
>> Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com>
>> ---
>> drivers/spi/spi-geni-qcom.c | 68
>> +++++++++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 68 insertions(+)
>>
>> diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c
>> index c65c1788325d..f272bd0cb640 100644
>> --- a/drivers/spi/spi-geni-qcom.c
>> +++ b/drivers/spi/spi-geni-qcom.c
>> @@ -12,8 +12,10 @@
>> #include <linux/dma/qcom-gpi-dma.h>
>> #include <linux/interrupt.h>
>> #include <linux/io.h>
>> +#include <linux/iopoll.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 +117,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 +1076,62 @@ 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);
>> + struct geni_se *se = &mas->se;
>> + u32 val;
>> +
>> + if (!pm_runtime_active(mas->dev))
>> + return NOTIFY_OK;
>> +
>> + if (mas->cur_xfer_mode == GENI_GPI_DMA) {
>> + dmaengine_terminate_async(mas->tx);
>> + dmaengine_terminate_async(mas->rx);
>> + return NOTIFY_OK;
>> + }
>> +
>> + if (!(readl_relaxed(se->base + SE_GENI_STATUS) &
>> M_GENI_CMD_ACTIVE))
>> + return NOTIFY_OK;
>> +
>> + if (!spi->target) {
>> + geni_se_cancel_m_cmd(se);
>> + if (!readl_poll_timeout_atomic(se->base +
>> SE_GENI_M_IRQ_STATUS, val,
>> + val & M_CMD_CANCEL_EN, 10, 50000)) {
>> + writel_relaxed(M_CMD_CANCEL_EN, se->base +
>> SE_GENI_M_IRQ_CLEAR);
>> + return NOTIFY_OK;
> Looks like a successful cancel here returns NOTIFY_OK directly,
> skipping the FSM reset block below it entirely. Is that the correct
> expectation ?> + }
If the cancel operation succeeds, an FSM reset is not required. If it
fails, the driver proceeds with an abort sequence followed by an FSM reset.
Thanks,
Praveen Talari
>> + }
>> +
>> + geni_se_abort_m_cmd(se);
>> + if (!readl_poll_timeout_atomic(se->base + SE_GENI_M_IRQ_STATUS,
>> val,
>> + val & M_CMD_ABORT_EN, 10, 50000))
>> + writel_relaxed(M_CMD_ABORT_EN, se->base + SE_GENI_M_IRQ_CLEAR);
>> +
>> + if (mas->cur_xfer_mode == GENI_SE_DMA) {
>> + writel_relaxed(1, se->base + SE_DMA_TX_FSM_RST);
>> + readl_poll_timeout_atomic(se->base + SE_DMA_TX_IRQ_STAT, val,
>> + val & TX_RESET_DONE, 10, 50000);
>> + writel_relaxed(val, se->base + SE_DMA_TX_IRQ_CLR);
>> +
>> + writel_relaxed(1, se->base + SE_DMA_RX_FSM_RST);
>> + readl_poll_timeout_atomic(se->base + SE_DMA_RX_IRQ_STAT, val,
>> + val & RX_RESET_DONE, 10, 50000);
>> + writel_relaxed(val, se->base + SE_DMA_RX_IRQ_CLR);
>> + }
>> +
>> + 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,6 +1220,15 @@ static int spi_geni_probe(struct
>> platform_device *pdev)
>> 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;
>> +
>> + ret = devm_add_action_or_reset(dev,
>> spi_geni_unregister_notifiers, mas);
>> + if (ret)
>> + return ret;
>> +
>> return devm_spi_register_controller(dev, spi);
>> }
>>
>
next prev parent reply other threads:[~2026-08-21 15:52 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 13:28 [PATCH v3 0/2] spi: qcom-geni: Add shutdown and panic notifier support Praveen Talari
2026-08-18 13:28 ` [PATCH v3 1/2] spi: qcom-geni: Add shutdown callback to quiesce hardware on reboot Praveen Talari
2026-08-19 18:46 ` Mukesh Savaliya
2026-08-21 10:29 ` Jyothi Kumar Seerapu
2026-08-21 15:56 ` Praveen Talari
2026-08-18 13:28 ` [PATCH v3 2/2] spi: qcom-geni: Add panic notifier to cancel and reset DMA during panic Praveen Talari
2026-08-19 19:32 ` Mukesh Savaliya
2026-08-21 9:55 ` Praveen Talari
2026-08-21 10:49 ` Jyothi Kumar Seerapu
2026-08-21 15:51 ` Praveen Talari [this message]
2026-09-04 17:02 ` [PATCH v3 0/2] spi: qcom-geni: Add shutdown and panic notifier support Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9b1b7f13-51a1-4846-a030-99f9b1cb439d@oss.qualcomm.com \
--to=praveen.talari@oss.qualcomm.com \
--cc=broonie@kernel.org \
--cc=chandana.chiluveru@oss.qualcomm.com \
--cc=jyothi.seerapu@oss.qualcomm.com \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=mukesh.savaliya@oss.qualcomm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®