DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jyothi Kumar Seerapu" <jyothi.seerapu@oss.qualcomm.com>
Cc: dmaengine@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org, vkoul@kernel.org,
	Frank.Li@kernel.org
Subject: Re: [PATCH v2 1/6] spi: spi-geni-qcom: Add transfer_one_message() support
Date: Tue, 24 Nov 2026 12:30:41 +0000	[thread overview]
Message-ID: <sashiko-outbox-231139@kernel.org> (raw)
In-Reply-To: <20261124-qspi_qup_upstream-v2-1-cd69894107c8@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] spi: spi-geni-qcom: unreset started flag in
  spi_geni_transfer_one_message()
- [Medium] spi: spi-geni-qcom: double handle_se_timeout() call on target
  abort
--

commit 6aec5a29fbc76295782ba681ed33e86a4939fdbf
Author: Jyothi Kumar Seerapu <jyothi.seerapu@oss.qualcomm.com>

spi: spi-geni-qcom: Add transfer_one_message() support

This commit introduces a custom transfer_one_message() callback to manage
SPI message sequencing, transfer completion, DMA buffer synchronization,
and GPIO chip-select handling directly in the GENI SPI driver.

> diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c
> index e239c4333055b..0a15e75051d86 100644
> --- a/drivers/spi/spi-geni-qcom.c
> +++ b/drivers/spi/spi-geni-qcom.c
[ ... ]
> @@ -939,18 +945,209 @@ static int spi_geni_transfer_one(struct spi_controller *spi,
[ ... ]
> +static int spi_geni_transfer_one_message(struct spi_controller *spi,
> +					 struct spi_message *msg)
> +{
> +	struct spi_geni_master *mas = spi_controller_get_devdata(spi);
> +	struct spi_device *spi_slv = msg->spi;
> +	struct spi_transfer *xfer, *next_xfer;
> +	bool keep_cs = false;
> +	bool dma_synced = false;
> +	bool started = false;
> +	int ret = 0;
> +
> +	xfer = list_first_entry(&msg->transfers, struct spi_transfer, transfer_list);
> +	spi_geni_set_cs(spi_slv, !xfer->cs_off);
> +
> +	list_for_each_entry(xfer, &msg->transfers, transfer_list) {
> +		if ((xfer->tx_buf || xfer->rx_buf) && xfer->len) {
> +			reinit_completion(&mas->xfer_done);
> +
> +			/* Synchronize buffers only for DMA; the SE FIFO path uses CPU access. */
> +			dma_synced = mas->cur_xfer_mode == GENI_GPI_DMA ||
> +				     ((xfer->tx_sg.nents || xfer->rx_sg.nents) &&
> +				      xfer->tx_sg.nents <= 1 && xfer->rx_sg.nents <= 1);
> +			if (dma_synced)
> +				spi_geni_dma_sync(spi, xfer, true);
> +
> +			ret = spi_geni_transfer_one(spi, spi_slv, xfer);
> +			if (ret < 0) {
> +				dev_err(mas->dev, "Transfer failed: %d\n", ret);
> +				goto out_err;
> +			}
> +			started = true;
> +
> +			ret = spi_geni_wait_for_xfer(spi, xfer);
> +			if (ret)
> +				goto out_err;
> +
> +			/* DMA errors and target aborts are reported through msg->status. */
> +			if (msg->status != -EINPROGRESS) {
> +				ret = msg->status;
> +				goto out_err;
> +			}
> +			if (dma_synced) {
> +				spi_geni_dma_sync(spi, xfer, false);
> +				dma_synced = false;
> +			}
> +		} else if (xfer->len) {
> +			dev_err(&spi_slv->dev,
> +				"Bufferless transfer has length %u\n", xfer->len);
> +			ret = -EINVAL;
> +			goto out_err;
> +		}
[ ... ]
> +out_err:
> +	if (!ret && msg->status != -EINPROGRESS)
> +		ret = msg->status;
> +
> +	if (ret && started)
> +		spi_geni_handle_err(spi, msg);

[Severity: Medium]
Should started be reset to false once a transfer completes?

Unlike dma_synced, started stays true across iterations of
msg->transfers.  If one transfer finishes normally and a subsequent
transfer in the same message fails before starting hardware (for example,
failing the bufferless transfer check or clk set_rate() in
setup_se_xfer()), out_err runs spi_geni_handle_err() on an idle
controller.  In GENI_SE_FIFO or GENI_SE_DMA mode, handle_se_timeout()
then issues cancel and abort commands with no active command, waiting up
to 2 seconds for completion timeouts and setting mas->abort_failed = true,
which causes future transfers to fail with -EBUSY.

[ ... ]

> @@ -1065,11 +1263,14 @@ static irqreturn_t geni_spi_isr(int irq, void *data)
>  
>  static int spi_geni_target_abort(struct spi_controller *spi)
>  {
> +	struct spi_geni_master *mas = spi_controller_get_devdata(spi);
> +
>  	if (!spi->cur_msg)
>  		return 0;
>  
> +	spi->cur_msg->status = -ECANCELED;
>  	handle_se_timeout(spi);
> -	spi_finalize_current_transfer(spi);
> +	complete(&mas->xfer_done);
>  
>  	return 0;
>  }

[Severity: Medium]
Does setting spi->cur_msg->status = -ECANCELED here cause
handle_se_timeout() to run twice on a target abort?

After complete(&mas->xfer_done) wakes spi_geni_wait_for_xfer(),
spi_geni_transfer_one_message() sees msg->status != -EINPROGRESS, sets
ret = -ECANCELED, and jumps to out_err with started == true.  That calls
spi_geni_handle_err() -> handle_se_timeout() a second time on an already
aborted and idle serial engine, timing out after 1 second on
mas->abort_done and setting mas->abort_failed = true.

In addition, because spi_target_abort() runs without spi->io_mutex, if
wait_for_completion_interruptible() in spi_geni_wait_for_xfer() is
interrupted by a signal at the same time as spi_geni_target_abort(), both
threads call handle_se_timeout() concurrently without serialization on
mas->abort_done, mas->tx_reset_done, and mas->rx_reset_done.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-qspi_qup_upstream-v2-0-cd69894107c8@oss.qualcomm.com?part=1

  reply	other threads:[~2026-11-24 12:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 12:15 [PATCH v2 0/6] spi: qcom-geni: Add QSPI support over GPI DMA Jyothi Kumar Seerapu
2026-11-24 12:15 ` [PATCH v2 1/6] spi: spi-geni-qcom: Add transfer_one_message() support Jyothi Kumar Seerapu
2026-11-24 12:30   ` sashiko-bot [this message]
2026-11-24 12:15 ` [PATCH v2 2/6] dt-bindings: dma: qcom-gpi: Add QSPI protocol identifier Jyothi Kumar Seerapu
2026-11-24 12:15 ` [PATCH v2 3/6] dt-bindings: spi: qcom,spi-geni-qcom: Document QSPI support Jyothi Kumar Seerapu
2026-11-24 12:15 ` [PATCH v2 4/6] soc: qcom: geni-se: Define the QSPI firmware protocol Jyothi Kumar Seerapu
2026-11-24 12:15 ` [PATCH v2 5/6] dmaengine: qcom: gpi: Add QSPI protocol support Jyothi Kumar Seerapu
2026-11-24 12:15 ` [PATCH v2 6/6] spi: spi-geni-qcom: Add QSPI support over GPI DMA Jyothi Kumar Seerapu

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-231139@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=jyothi.seerapu@oss.qualcomm.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /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