๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27042

Re: [PATCH net-next 1/3] dmaengine: qcom: bam_dma: report residue for completed RX transfers

#27042
From: netdev-bot+sashiko
Date: Fri, 04 Dec 2026 17:06
108 lines
12485 bytes
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
Technical Details
Message-ID: <179640396727.3146.6895938404656144166@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377506-linux-kernel-netdev=dewy.ru
References: <20261203-qcom-bam-dmux-qmap-v1-1-abc2e80a03af@oss.qualcomm.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377506-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <179640396727.3146.6895938404656144166@kernel.org>
References: <20261203-qcom-bam-dmux-qmap-v1-1-abc2e80a03af@oss.qualcomm.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2813910"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:+W8snuD2FjThfg6tCUHWBfv/Ha0= sha256:3ONAIg8Q225gHv5ZGUjaZMuC+rbJKQeSdIr0gDsQFWc=
	sha1:+f1cMzxakU8ELqoP/mY1h2vEfr0= sha256:KkT8kPAKMtzvPTrGILOol0UGZCEqSxvpIE/4xTXZc4A=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 2D279117C7B; Fri,  4 Dec 2026 20:06:25 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.541
X-Spam-Status: No, score=-3.541 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 5rRsr8Leb6ei;
	Fri,  4 Dec 2026 20:06:21 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377506-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 18BB2117C0E; Fri,  4 Dec 2026 20:06:12 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 921BC44367; Fri,  4 Dec 2026 17:06:10 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796403970;
	b=ZpIWuxUuLm4VCSzQrAMU6IIs1S8Dh/X4q8ZBNQE8i9mnTSzwouXtZGGeYGbXR562OPsk
	 POvbMwAW/LSbsfP4SPX/1VaMfKSiWDu0wXWboyJhE4DfQXBUhnzYk/MqRBLraNWKv7Wtv
	 pJGNeFCo0u8wDbNFW8u3+YYwJhtiunxALOr/BunYE+wiSrnuyw70sLn/sRvqZR33dSm++
	 1gKQenjnsxMCzF809o10IuFRTAmgufUB34Lb2Z+Dp4co4HZEUSlV0JEYfbJdKoGsi+VCn
	 7frV9wsy7CpDdnuK2z2gjpNrbH76L8QUCl3xfDxg+etXYOAskGXotjpiWL3dN+tqf4A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796403970;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=Wod5ol48sWL4LACMzogKRZspc5XxS3C8asNfEvSYc4U=;
	b=oyJuhQvbXAl3nGBOJKOlA2ZOi11N/E82utl9n5dFvfwYerwOE2jahfNWiu/HKoSky/FP
	 bguCCF4i2Srzqfh1kfWDrjzqJ5TXucXub2t5uhaqfc/ydINyHB2jZp+jJQfO0GCv1fBZf
	 Do9lLXCoGM8kQII4v5kZIgJyN2AjiBTUEgHGtHxJMjY+9/+tyXinBFUxZKO+4A3oZBRga
	 iMzV3VkoQg0/JtxsSRhH/cq0s53gcu3Picdz4DBzh77lFjavOtA4qLeroZ5r/voFh0fev
	 XX/qrsysRdDeNaJUktkMi8OQqiYzAg4zJlZJm+OATpHPg+TwKAQUqnPUClbZPt35V4g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mDVjd7e4;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id F1568606A33A;
	Fri,  4 Dec 2026 17:06:09 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mDVjd7e4
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796403969;
	b=kGpz7e9XVFPCMR/fzqtMj3Nc3eBPRaGI+5joa2syhodv8l3yVEH/t0+qA7FCPcsCHGzd
	 WpaCPOtD7LDo4uI5j97bquP1Kx3F1M3bD/nGGkeLLq7eZMGJ61vNBFQPWDMFXuPT8fvqp
	 dz59ywjEUmZuijZ16zxqsxLUoo+L0yGQMmQOQdJrjr1bUUI+XJEBBSVks93ah0tex048n
	 TgCuXSi348x1mBSriqulQnY4vtmQ5e6Fz4Ad9Yhbxcu3vlpPE+tg21TlERQRNyK6DmFs5
	 qlnCEgK6zR+ZhKNiL9qZEwgquvqlktRDHMY2+r6eW4dvv615zT5M7jC/u1xkrfzqAqA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796403969;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=Wod5ol48sWL4LACMzogKRZspc5XxS3C8asNfEvSYc4U=;
	b=gNBMCEmVmDWTDgKBfatJW3D9mPJIZtxarq0sClGzRKlKLKvLBGQk8BpFCwrX18V4Aeab
	 XGvQMSXqcXdX9EAQsp0Co+8xAHutf9XYTCzhyvWUQyjaD32EzwvXegq9oifbuCJ4DZ38P
	 DAp646r0zS3NmtaxyCBrGueE/i9krDfNA+GiuyxgFodnI/lkOxRSdDvbto2Q9pIHwo7s0
	 nuD8nZ5AdHaDir889tD1+CwJ4BE91IDsFM2WhJiVIqA7UQ/NIkuRGxTU9LeZT9JoCTJw8
	 19tQ4sC1hPEM061yuTJMRis2Mzaj8/q+sy08CvGtkOmbbF3q6GKh3gO/boWXujQFFew==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mDVjd7e4;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C4F8606A322;
	Fri,  4 Dec 2026 17:06:08 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC4471F0093B;
	Fri,  4 Dec 2026 17:06:07 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796403968;
	bh=Wod5ol48sWL4LACMzogKRZspc5XxS3C8asNfEvSYc4U=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=mDVjd7e4SCJCcvThYTr0kiytHGj7UKtAZ3HHZwHreczbcseostkMxouP3MUOIH9BI
	 FS4PZOxc5HNZ5QQHhA5XTIwav7FceBfroVVz1YcxtE9Pgx04QPpqZXrpypdwjUrAgI
	 tGUtQUck5LRdvdyz6Fxq7D3rDxXB8QPR4OmEvUe5QzvDjjmuq65RZVM0csC0t6haEE
	 3kmPB8JwCyIrjmwI+feIxo/6b2KLNdVCzyxxkHVG5mbvB8rnb6i47yWtbbTZW8LU0w
	 Knbs9JYgZ2Knnq2SI6qsLnAsF5RxgbCns9PdWKadFqlETADyvPEIwDj2jQAF7vlwMx
	 rhqLQsxtJzHRA==
X-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
X-In-Reply-To: <20261203-qcom-bam-dmux-qmap-v1-1-abc2e80a03af@oss.qualcomm.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list