DMA Engine development
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: vishnu.santhosh@oss.qualcomm.com
Cc: vkoul@kernel.org, Frank.Li@kernel.org, stephan@gerhold.net,
	loic.poulain@oss.qualcomm.com, ryazanov.s.a@gmail.com,
	johannes@sipsolutions.net, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, linux-arm-msm@vger.kernel.org,
	dmaengine@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, deepak.singh@oss.qualcomm.com
Subject: Re: [PATCH net-next 1/3] dmaengine: qcom: bam_dma: report residue for completed RX transfers
Date: Fri, 04 Dec 2026 17:06:07 +0000	[thread overview]
Message-ID: <179640396727.3146.6895938404656144166@kernel.org> (raw)
In-Reply-To: <20261203-qcom-bam-dmux-qmap-v1-1-abc2e80a03af@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] dmaengine: qcom: bam_dma: dma_rmb() does not order MMIO
  readl_relaxed()

--

> diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
> --- a/drivers/dma/qcom/bam_dma.c
> +++ b/drivers/dma/qcom/bam_dma.c
> @@ -834,6 +834,57 @@ static int bam_resume(struct dma_chan *chan)
>  	return 0;
>  }
>  
> +/**
> + * bam_update_rx_result - account for bytes received by completed descriptors
> + * @bchan: bam channel
> + * @async_desc: descriptor whose hardware descriptors have completed
> + *
> + * On a producer pipe the BAM writes the number of bytes it transferred back
> + * into the size field of each completed descriptor in the FIFO. Report the
> + * unused part of the buffers as residue, so that clients using
> + * callback_result know how much data was received. Only the last descriptor
> + * of a transfer may be short, otherwise the transfer is marked as aborted.
> + * Clients that rely on the residue should therefore use a single buffer of
> + * at most BAM_FIFO_SIZE bytes per transfer. The residue is undefined if the
> + * result is not DMA_TRANS_NOERROR.
> + */
> +static void bam_update_rx_result(struct bam_chan *bchan,
> +				 struct bam_async_desc *async_desc)
> +{
> +	struct bam_desc_hw *fifo = PTR_ALIGN(bchan->fifo_virt,
> +					    sizeof(struct bam_desc_hw));
> +	u32 i;
> +
> +	if (async_desc->dir != DMA_DEV_TO_MEM)
> +		return;
> +
> +	/* Read the written back sizes only after reading BAM_P_SW_OFSTS */
> +	dma_rmb();
> +
> +	for (i = 0; i < async_desc->xfer_len; i++) {
> +		u16 expected = le16_to_cpu(async_desc->curr_desc[i].size);
> +		u16 received = le16_to_cpu(fifo[(bchan->head + i) %
> +						 MAX_DESCRIPTORS].size);
> +
> +		if (received > expected) {
> +			async_desc->vd.tx_result.result = DMA_TRANS_WRITE_FAILED;
> +			async_desc->vd.tx_result.residue += expected;
> +			continue;
> +		}
> +
> +		/*
> +		 * The next descriptor writes from its own address, so a short
> +		 * write before the last one leaves a hole in the buffer that
> +		 * cannot be described by the residue.
> +		 */
> +		if (received < expected && i != async_desc->num_desc - 1 &&
> +		    async_desc->vd.tx_result.result == DMA_TRANS_NOERROR)
> +			async_desc->vd.tx_result.result = DMA_TRANS_ABORTED;
> +
> +		async_desc->vd.tx_result.residue += expected - received;
> +	}
> +}
> +
>  /**
>   * process_channel_irqs - processes the channel interrupts
>   * @bdev: bam controller

[Severity: Medium]
The comment says the FIFO size fields must be read only after the
BAM_P_SW_OFSTS read. That read in process_channel_irqs() is a
readl_relaxed(), and dma_rmb() is not specified to order MMIO accesses
against normal memory.

Documentation/memory-barriers.txt says the dma_*() barriers give no
ordering guarantees for MMIO. It also says readX() is what you need
when a device status read must complete before you look at a buffer
the device has written.

This matters on the platforms that use bam-dmux. On 32-bit ARMv7
(msm8974, msm8226 and friends) readl() ends in rmb(), which is a dsb.
dma_rmb() is only dmb(osh). So nothing guarantees the CPU won't see a
stale pre-transfer size in fifo_virt. It would then compute a wrong
residue, which for qcom_bam_dmux means a wrong packet length. arm64
happens to be fine because its __io_ar() is dma_rmb() anyway.

As a side effect, placing the barrier in bam_update_rx_result() issues
it once per completed async_desc rather than once per interrupt.

Would it be simpler to switch the BAM_P_SW_OFSTS read in
process_channel_irqs() to readl() and drop the dma_rmb() here? That
gives the right ordering on both arm and arm64 and costs only one
barrier per channel per IRQ. An rmb() right after the readl_relaxed()
would also work, if you prefer to keep the relaxed accessor.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-qcom-bam-dmux-qmap-v1-0-abc2e80a03af%40oss.qualcomm.com

  parent reply	other threads:[~2026-12-04 17:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 16:10 [PATCH net-next 0/3] net: wwan: qcom_bam_dmux: Add QMAP support Vishnu Santhosh
2026-12-03 16:10 ` [PATCH net-next 1/3] dmaengine: qcom: bam_dma: report residue for completed RX transfers Vishnu Santhosh
2026-12-03 16:19   ` Frank Li
2026-12-04 10:10   ` Stephan Gerhold
2026-12-04 11:18     ` Nickolay Goppen
2026-12-04 11:31     ` Nickolay Goppen
2026-12-04 16:11   ` sashiko-bot
2026-12-04 17:06   ` netdev-bot+sashiko [this message]
2026-12-03 16:10 ` [PATCH net-next 2/3] net: wwan: qcom_bam_dmux: use DMA transfer size for RX packets Vishnu Santhosh
2026-12-04 10:14   ` Stephan Gerhold
2026-12-04 17:06   ` netdev-bot+sashiko
2026-12-03 16:10 ` [PATCH net-next 3/3] net: wwan: qcom_bam_dmux: enable QMAP if supported by the modem Vishnu Santhosh
2026-12-03 19:22   ` Loic Poulain
2026-12-04 10:42   ` Stephan Gerhold
2026-12-04 16:11   ` sashiko-bot
2026-12-04 17:06   ` netdev-bot+sashiko

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=179640396727.3146.6895938404656144166@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=deepak.singh@oss.qualcomm.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=edumazet@kernel.org \
    --cc=johannes@sipsolutions.net \
    --cc=kuba@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loic.poulain@oss.qualcomm.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ryazanov.s.a@gmail.com \
    --cc=stephan@gerhold.net \
    --cc=vishnu.santhosh@oss.qualcomm.com \
    --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