Re: [PATCH net-next 2/3] net: wwan: qcom_bam_dmux: use DMA transfer size for RX packets

From: netdev-bot+sashiko

Date: Fri Dec 04 2026 - 12:06:21 EST


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