Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Paul Cercueil" <paul.cercueil@bootlin.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v6 3/4] spi: cadence-xspi: Add support for panic writes
Date: Thu, 03 Dec 2026 09:37:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-247484@kernel.org> (raw)
In-Reply-To: <20261203091112.9449-4-paul.cercueil@bootlin.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] spi: cadence-xspi: stale INTR_STATUS bits and missed SDMA
  errors in poll mode
- [Medium] spi: cadence-xspi: cdns_xspi_supports_op() takes devtree_lock
  in panic write
--

commit eea24ee8b207103bf755dc8e3c7be6db03c744ea
Author: Tanmay Jagdale <tanmay@marvell.com>

spi: cadence-xspi: Add support for panic writes

This commit advertises panic_write support on the Cadence XSPI controller
and updates STIG command execution and polling helpers to run without
interrupts, DMA, or sleeping when op->panic_write is set.

> diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c
> index 1738a5983f054..974dd78518e39 100644
> --- a/drivers/spi/spi-cadence-xspi.c
> +++ b/drivers/spi/spi-cadence-xspi.c

[ ... ]

> @@ -684,13 +689,13 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi,
>  	int ret;
>  	int dummybytes = op->dummy.nbytes;
>  
> -	ret = cdns_xspi_set_stig_mode(cdns_xspi);
> +	ret = cdns_xspi_set_stig_mode(cdns_xspi, !op->panic_write);
>  	if (ret)
>  		return ret;
>  
>  	reinit_completion(&cdns_xspi->cmd_complete);
>  	reinit_completion(&cdns_xspi->sdma_complete);
> -	if (cdns_xspi->irq >= 0)
> +	if (cdns_xspi->irq >= 0 && !op->panic_write)
>  		cdns_xspi->set_interrupts_handler(cdns_xspi, true);
>  	cdns_xspi->sdma_error = false;
>  
> @@ -720,16 +725,16 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi,
>  
>  		cdns_xspi_trigger_command(cdns_xspi, cmd_regs);
>  
> -		if (cdns_xspi->irq >= 0) {
> +		if (cdns_xspi->irq >= 0 && !op->panic_write) {
>  			wait_for_completion(&cdns_xspi->sdma_complete);
>  			if (cdns_xspi->sdma_error) {
>  				cdns_xspi->set_interrupts_handler(cdns_xspi, false);
>  				return -EIO;
>  			}
> -		} else if (!cdns_xspi_is_sdma_ready(cdns_xspi, true)) {
> +		} else if (!cdns_xspi_is_sdma_ready(cdns_xspi, !op->panic_write)) {
>  			return -EIO;
>  		}
> -		ret = cdns_xspi->sdma_handler(cdns_xspi);
> +		ret = cdns_xspi->sdma_handler(cdns_xspi, !op->panic_write);
>  		if (ret || cdns_xspi->sdma_error) {
>  			if (cdns_xspi->irq >= 0)
>  				cdns_xspi->set_interrupts_handler(cdns_xspi, false);

[Severity: Medium]
Can stale CDNS_XSPI_SDMA_TRIGGER or CDNS_XSPI_SDMA_ERROR bits in
CDNS_XSPI_INTR_STATUS_REG break polling and panic_write commands here?

Nothing clears CDNS_XSPI_INTR_STATUS_REG before triggering the STIG command
when set_interrupts_handler() is skipped (and cdns_xspi_set_interrupts()
never clears it either).  In addition, cdns_xspi->sdma_error is only set by
cdns_xspi_irq_handler(), so an SDMA error raised during sdma_handler() in
polling or panic_write mode goes undetected and stays latched in
CDNS_XSPI_INTR_STATUS_REG.

On the next data-phase STIG command, cdns_xspi_is_sdma_ready() then observes
the stale bit immediately and either aborts with -EIO (leaving the STIG
engine busy) or runs sdma_handler() prematurely against stale SDMA registers.

Clearing CDNS_XSPI_INTR_STATUS_REG before triggering the command and checking
it for CDNS_XSPI_SDMA_ERROR after sdma_handler() in polling mode would avoid
this.

[ ... ]

> @@ -1550,6 +1555,7 @@ static int cdns_xspi_probe(struct platform_device *pdev)
>  	}
>  
>  	host->num_chipselect = 1 << cdns_xspi->hw_num_banks;
> +	host->mem_caps = &cdns_xspi_mem_caps;
>  
>  	ret = devm_spi_register_controller(dev, host);
>  	if (ret) {

[Severity: Medium]
Can advertising panic_write deadlock on devtree_lock during a kernel panic?

When CONFIG_ACPI is enabled (such as arm64 defconfig), both
cadence_xspi_mem_ops and marvell_xspi_mem_ops install cdns_xspi_supports_op()
even on Device Tree booted systems.  spi_mem_exec_op() calls supports_op()
unconditionally before exec_op(), including when op->panic_write is set.

cdns_xspi_supports_op() calls device_property_read_u32() for
spi-tx-bus-width and spi-rx-bus-width, which on OF-backed devices reaches
of_find_property() and acquires devtree_lock via raw_spin_lock_irqsave():

CPU0                              CPU1
of_find_property()
  raw_spin_lock_irqsave(&devtree_lock)
                                  vpanic()
                                    panic_other_cpus_shutdown()
  <NMI stop while holding lock>
                                    kmsg_dump_desc(KMSG_DUMP_PANIC, ...)
                                      spi_mem_exec_op()
                                        cdns_xspi_supports_op()
                                          device_property_read_u32()
                                            ...
                                              of_find_property()
                                                raw_spin_lock_irqsave(
                                                  &devtree_lock)
                                                <-- spins forever

If devtree_lock is held by the panicking CPU or an NMI-stopped CPU, the panic
dump hangs permanently before writing the log or rebooting.  Skipping the
property lookups in cdns_xspi_supports_op() when op->panic_write is set (or
when !has_acpi_companion(dev)) would avoid taking devtree_lock in panic
context.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203091112.9449-1-paul.cercueil@bootlin.com?part=3

  reply	other threads:[~2026-12-03  9:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  9:11 [PATCH v6 0/4] spi: cadence-xspi: Add support for panic mem writes Paul Cercueil
2026-12-03  9:11 ` [PATCH v6 1/4] spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() Paul Cercueil
2026-12-03  9:28   ` sashiko-bot
2026-12-03  9:11 ` [PATCH v6 2/4] spi: cadence-xspi: Add irq-less support Paul Cercueil
2026-12-03  9:36   ` sashiko-bot
2026-12-03  9:11 ` [PATCH v6 3/4] spi: cadence-xspi: Add support for panic writes Paul Cercueil
2026-12-03  9:37   ` sashiko-bot [this message]
2026-12-03  9:11 ` [PATCH v6 4/4] spi: dt-bindings: cadence: Make XSPI's IRQ line optional Paul Cercueil
2026-12-03  9:20   ` sashiko-bot

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=sashiko-outbox-247484@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=paul.cercueil@bootlin.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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