Netdev List
 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 2/3] net: wwan: qcom_bam_dmux: use DMA transfer size for RX packets
Date: Fri, 04 Dec 2026 17:06:08 +0000	[thread overview]
Message-ID: <179640396883.3146.15360849304828602379@kernel.org> (raw)
In-Reply-To: <20261203-qcom-bam-dmux-qmap-v1-2-abc2e80a03af@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] Undisclosed hard dependency on the bam_dma residue patch, plus a
  requested Fixes: tag.
- [Low] The 0xffff length derivation ignores hdr->pad.

Pre-existing issues:
- [Low] Zero-length DATA packet handling in bam_dmux_cmd_data().

--

net: wwan: qcom_bam_dmux: use DMA transfer size for RX packets

The RX DMA callback now uses the dmaengine result variant, so the driver
knows how many bytes were received. It drops failed or too-short
transfers. For DATA frames whose header length is 0xffff, it takes the
payload length from the DMA transfer size. The old check against the
buffer size is replaced with a check against the received size.

> diff --git a/drivers/net/wwan/qcom_bam_dmux.c b/drivers/net/wwan/qcom_bam_dmux.c
> index e1cc3038a724e..a7d05b1b8b123 100644
> --- a/drivers/net/wwan/qcom_bam_dmux.c
> +++ b/drivers/net/wwan/qcom_bam_dmux.c

[ ... ]

> @@ -500,21 +502,23 @@ static bool bam_dmux_skb_dma_queue_rx(struct bam_dmux_skb_dma *skb_dma, gfp_t gf
>  	       bam_dmux_skb_dma_submit_rx(skb_dma);
>  }
>  
> -static void bam_dmux_cmd_data(struct bam_dmux_skb_dma *skb_dma)
> +static void bam_dmux_cmd_data(struct bam_dmux_skb_dma *skb_dma,
> +			      unsigned int rx_len)
>  {
>  	struct bam_dmux *dmux = skb_dma->dmux;
>  	struct sk_buff *skb = skb_dma->skb;
>  	struct bam_dmux_hdr *hdr = (struct bam_dmux_hdr *)skb->data;
>  	struct net_device *netdev = dmux->netdevs[hdr->ch];
> +	unsigned int avail = rx_len - sizeof(*hdr);

[ ... ]

> -	if (hdr->len > BAM_DMUX_MAX_DATA_SIZE) {
> -		dev_err(dmux->dev, "Data larger than buffer? (%u > %u)\n",
> -			hdr->len, (u16)BAM_DMUX_MAX_DATA_SIZE);
> +	if (hdr->len > avail) {
> +		dev_err(dmux->dev, "Data larger than received? (%u > %u)\n",
> +			hdr->len, avail);
>  		return;
>  	}

[Severity: Low]
This issue is pre-existing and was not introduced by this patch. Now that
this check is being changed, though, what happens when hdr->len is 0?

The check passes because 0 > avail is false. The rest of
bam_dmux_cmd_data() then does:

	skb_pull(skb, sizeof(*hdr));
	skb_trim(skb, hdr->len);
	skb->dev = netdev;

	/* Only Raw-IP/QMAP is supported by this driver */
	switch (skb->data[0] & 0xf0) {

After skb_trim(skb, 0), skb->len is 0. So skb->data[0] is a byte that
was not received in this transfer. It is either stale data from a
recycled RX buffer or uninitialised memory from __netdev_alloc_skb().
The zero-length skb is then passed to netif_receive_skb().

On the baseline the modem could already send len 0 directly. This patch
adds a second route to the same state. A 0xffff DATA frame whose transfer
is exactly sizeof(struct bam_dmux_hdr) bytes passes the new check in
bam_dmux_rx_callback(), which only rejects rx_len < sizeof(*hdr). The
rewrite then computes hdr->len = 0.

Downstream consumers appear to drop such packets:
rmnet_map_validate_packet_len() rejects short skbs, and
ip_rcv()/ipv6_rcv() fail pskb_may_pull(). The effect is therefore limited
to reading one stale byte, which KMSAN could flag.

Would it make sense to reject hdr->len == 0 here as well?

[ ... ]

> @@ -574,15 +578,29 @@ static void bam_dmux_cmd_close(struct bam_dmux *dmux, struct bam_dmux_hdr *hdr)
>  		netif_device_detach(netdev);
>  }
>  
> -static void bam_dmux_rx_callback(void *data)
> +static void bam_dmux_rx_callback(void *data,
> +				 const struct dmaengine_result *result)
>  {
>  	struct bam_dmux_skb_dma *skb_dma = data;
>  	struct bam_dmux *dmux = skb_dma->dmux;
>  	struct sk_buff *skb = skb_dma->skb;
>  	struct bam_dmux_hdr *hdr = (struct bam_dmux_hdr *)skb->data;
> +	unsigned int rx_len;
>  
>  	bam_dmux_skb_dma_unmap(skb_dma, DMA_FROM_DEVICE);
>  
> +	if (result->result != DMA_TRANS_NOERROR || result->residue > skb->len) {
> +		dev_err(dmux->dev, "RX DMA failed: %d (residue %u)\n",
> +			result->result, result->residue);
> +		goto out;
> +	}
> +
> +	rx_len = skb->len - result->residue;

[Severity: Low]
This calculation is only correct if bam_dma fills in residue. That comes
from the earlier patch in the series, "dmaengine: qcom: bam_dma: report
residue for completed RX transfers", which adds bam_update_rx_result().

Without that patch, dmaengine_desc_callback_invoke() passes its dummy
result to the callback:

	struct dmaengine_result dummy_result = { .result = DMA_TRANS_NOERROR, .residue = 0 };

Every RX buffer would then look like a full 2048-byte transfer. A 0xffff
DATA frame would be delivered as 2040 bytes, including bytes the modem
never wrote in that transfer. The client has no way to tell that the
provider did not report a residue.

Within the series the order is correct. 0xffff frames are also only
expected after the QMAP-enable patch, so a Fixes: tag does not seem
needed.

Could the commit message state the dependency on the bam_dma patch, so
the dmaengine and net patches land together or in the right order?

> +	if (rx_len < sizeof(*hdr)) {
> +		dev_err(dmux->dev, "RX shorter than header: %u\n", rx_len);
> +		goto out;
> +	}
> +
>  	if (hdr->magic != BAM_DMUX_HDR_MAGIC) {
>  		dev_err(dmux->dev, "Invalid magic in header: %#x\n", hdr->magic);
>  		goto out;
> @@ -593,9 +611,13 @@ static void bam_dmux_rx_callback(void *data)
>  		goto out;
>  	}
>  
> +	/* The remote side may leave it to us to use the DMA transfer size */
> +	if (hdr->cmd == BAM_DMUX_CMD_DATA && hdr->len == BAM_DMUX_LEN_FROM_DMA)
> +		hdr->len = rx_len - sizeof(*hdr);

[Severity: Low]
Should hdr->pad be accounted for here?

The driver's own TX path in bam_dmux_tx_prepare_skb() defines the wire
format as header + payload + pad. There, hdr->len excludes the padding:

	hdr->pad = pad;
	hdr->ch = bndev->ch;
	hdr->len = skb->len - sizeof(*hdr);
	if (pad)
		skb_put_zero(skb, pad);

If the modem sets a non-zero hdr->pad on 0xffff frames, the pad bytes
end up in the payload. bam_dmux_cmd_data() keeps them through
skb_trim(skb, hdr->len), so skb->len can be up to 4 bytes too long when
it reaches netif_receive_skb().

The visible impact looks small. rmnet_map_validate_packet_len() stops
cleanly on short trailing data, and ip_rcv()/ipv6_rcv() trim to the IP
total length. It is also not clear from the tree whether the firmware
sets pad in 0xffff mode.

If pad is subtracted, hdr->pad comes from the remote side. It would need
to be checked against rx_len - sizeof(*hdr) to avoid an unsigned
underflow.

>  	switch (hdr->cmd) {
>  	case BAM_DMUX_CMD_DATA:
> -		bam_dmux_cmd_data(skb_dma);
> +		bam_dmux_cmd_data(skb_dma, rx_len);
>  		break;

[ ... ]

-- 
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: 14+ 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 17:06   ` netdev-bot+sashiko
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 [this message]
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 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=179640396883.3146.15360849304828602379@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