Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alex Elder" <elder@riscstar.com>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org,
	bpf@vger.kernel.org
Subject: Re: [PATCH net-next v2 06/14] net: stmmac: dma: create a separate dma_device pointer
Date: Sat, 06 Jun 2026 01:01:21 +0000	[thread overview]
Message-ID: <20260606010122.21A211F00899@smtp.kernel.org> (raw)
In-Reply-To: <20260605010022.968612-7-elder@riscstar.com>

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

Pre-existing issues:
- [High] When DMA mapping fails during transmission, the driver either leaks mapped memory (non-TSO path) or causes a permanent hardware TX queue stall (TSO path).
- [High] Kernel panic in the DMA descriptor allocation error path due to a NULL pointer dereference when tearing down uninitialized queues.
--

commit 66acc331f7f048d75e9c4b2fb700576508be93dc
Author: Alex Elder <elder@riscstar.com>
Subject: net: stmmac: dma: create a separate dma_device pointer

The patch separates the DMA device from the MAC device in the stmmac driver.
It adds a dma_device pointer to the stmmac_priv and plat_stmmacenet_data
structures, and updates all DMA operations to use it.

> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 35da51c262484..09d2640a18b3c 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -1730,12 +1730,12 @@ static void stmmac_free_tx_buffer(struct stmmac_priv *priv,
>  	if (tx_q->tx_skbuff_dma[i].buf &&
>  	    tx_q->tx_skbuff_dma[i].buf_type != STMMAC_TXBUF_T_XDP_TX) {
>  		if (tx_q->tx_skbuff_dma[i].map_as_page)
> -			dma_unmap_page(priv->device,
> +			dma_unmap_page(priv->dma_device,
>  				       tx_q->tx_skbuff_dma[i].buf,
>  				       tx_q->tx_skbuff_dma[i].len,
>  				       DMA_TO_DEVICE);
>  		else
> -			dma_unmap_single(priv->device,
> +			dma_unmap_single(priv->dma_device,
>  					 tx_q->tx_skbuff_dma[i].buf,
>  					 tx_q->tx_skbuff_dma[i].len,
>  					 DMA_TO_DEVICE);

[Severity: High]
This is a pre-existing issue, but is there a risk of a NULL pointer
dereference in the DMA descriptor allocation error path?

In the error path of alloc_dma_tx_desc_resources() or
alloc_dma_rx_desc_resources(), if queue allocation fails (e.g., -ENOMEM from
kzalloc_objs), the driver unconditionally cleans up all configured queues,
including those that were never initialized.

When free_dma_rx_desc_resources() or free_dma_tx_desc_resources() processes
an uninitialized queue, it iterates over the descriptor ring and calls
stmmac_free_tx_buffer() or stmmac_free_rx_buffer(). Since tx_skbuff_dma
or buf_pool is NULL for uninitialized queues, attempting to check conditions
like the one above will dereference a pointer relative to NULL, triggering a
panic.

[ ... ]

> @@ -4571,9 +4571,9 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
>  	first = desc;
>  
>  	/* first descriptor: fill Headers on Buf1 */
> -	des = dma_map_single(priv->device, skb->data, skb_headlen(skb),
> +	des = dma_map_single(priv->dma_device, skb->data, skb_headlen(skb),
>  			     DMA_TO_DEVICE);
> -	if (dma_mapping_error(priv->device, des))
> +	if (dma_mapping_error(priv->dma_device, des))
>  		goto dma_map_err;
>  
>  	stmmac_set_desc_addr(priv, first, des);
> @@ -4599,10 +4599,10 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
>  	for (i = 0; i < nfrags; i++) {
>  		const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
>  
> -		des = skb_frag_dma_map(priv->device, frag, 0,
> +		des = skb_frag_dma_map(priv->dma_device, frag, 0,
>  				       skb_frag_size(frag),
>  				       DMA_TO_DEVICE);
> -		if (dma_mapping_error(priv->device, des))
> +		if (dma_mapping_error(priv->dma_device, des))
>  			goto dma_map_err;

[Severity: High]
This is a pre-existing issue, but does a DMA mapping failure here cause a
permanent hardware TX queue stall?

In stmmac_tso_xmit(), intermediate descriptors are eagerly marked with the
OWN=1 bit by stmmac_tso_allocator() before all fragments are mapped. If a
subsequent fragment mapping fails, the code jumps to dma_map_err before
setting the OWN bit on the first descriptor.

The hardware DMA engine won't process the intermediate fragments. Later, when
stmmac_tx_clean() processes the ring, it will encounter the OWN=1 descriptor
and permanently halt, freezing the entire TX queue.

[ ... ]

> @@ -4827,9 +4827,9 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
>  	} else {
>  		bool last_segment = (nfrags == 0);
>  
> -		dma_addr = dma_map_single(priv->device, skb->data,
> +		dma_addr = dma_map_single(priv->dma_device, skb->data,
>  					  nopaged_len, DMA_TO_DEVICE);
> -		if (dma_mapping_error(priv->device, dma_addr))
> +		if (dma_mapping_error(priv->dma_device, dma_addr))
>  			goto dma_map_err;
>  
>  		stmmac_set_tx_skb_dma_entry(tx_q, first_entry, dma_addr,
> @@ -4878,9 +4878,9 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
>  
>  		desc = stmmac_get_tx_desc(priv, tx_q, entry);
>  
> -		dma_addr = skb_frag_dma_map(priv->device, frag, 0, frag_size,
> -					    DMA_TO_DEVICE);
> -		if (dma_mapping_error(priv->device, dma_addr))
> +		dma_addr = skb_frag_dma_map(priv->dma_device, frag, 0,
> +					    frag_size, DMA_TO_DEVICE);
> +		if (dma_mapping_error(priv->dma_device, dma_addr))
>  			goto dma_map_err; /* should reuse desc w/o issues */

[Severity: High]
This is a pre-existing issue, but does this error path lead to a memory leak?

In stmmac_xmit(), if dma_map_single() or skb_frag_dma_map() fails, the code
jumps to dma_map_err without advancing tx_q->cur_tx.

Subsequent transmissions will reuse the same descriptor index and overwrite
the DMA addresses in tx_q->tx_skbuff_dma. This causes a permanent memory leak
of the previously mapped fragments for this skb, as they are never unmapped.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260605010022.968612-1-elder@riscstar.com?part=6

  reply	other threads:[~2026-06-06  1:01 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-05  1:00 [PATCH net-next v2 00/14] net: enable TC956x support Alex Elder
2026-06-05  1:00 ` [PATCH net-next v2 01/14] dt-bindings: net: qca,qca808x: Add regulator properties Alex Elder
2026-06-06  1:01   ` sashiko-bot
2026-06-05  1:00 ` [PATCH net-next v2 02/14] net: phy: qcom: qca808x: Add regulator management Alex Elder
2026-06-06  1:01   ` sashiko-bot
2026-06-05  1:00 ` [PATCH net-next v2 03/14] net: pcs: pcs-xpcs-regmap: support XPCS memory-mapped MDIO bus via regmap Alex Elder
2026-06-05 15:35   ` Maxime Chevallier
2026-06-06  1:01   ` sashiko-bot
2026-06-05  1:00 ` [PATCH net-next v2 04/14] net: pcs: xpcs: re-order xpcs_pre_config() to update after the reset Alex Elder
2026-06-05  1:00 ` [PATCH net-next v2 05/14] net: pcs: pcs-xpcs: select operating mode for 10G-baseR capable PCS Alex Elder
2026-06-06  1:01   ` sashiko-bot
2026-06-05  1:00 ` [PATCH net-next v2 06/14] net: stmmac: dma: create a separate dma_device pointer Alex Elder
2026-06-06  1:01   ` sashiko-bot [this message]
2026-06-05  1:00 ` [PATCH net-next v2 07/14] net: stmmac: dwxgmac2: Add multi MSI interrupt mode Alex Elder
2026-06-05  1:00 ` [PATCH net-next v2 08/14] net: stmmac: dwxgmac2: Add XGMAC 3.01a support Alex Elder
2026-06-05  1:00 ` [PATCH net-next v2 09/14] net: stmmac: dwxgmac2: export symbols for XGMAC 3.01a DMA Alex Elder
2026-06-05  1:00 ` [PATCH net-next v2 10/14] dt-bindings: net: toshiba,tc9654-dwmac: add TC9564 Ethernet bridge Alex Elder
2026-06-05  2:40   ` Rob Herring (Arm)
2026-06-05 12:24     ` Alex Elder
2026-06-05 14:40   ` Rob Herring
2026-06-06  1:01   ` sashiko-bot
2026-06-05  1:00 ` [PATCH net-next v2 11/14] misc: tc956x_pci: add TC956x/QPS615 support Alex Elder
2026-06-06  1:01   ` sashiko-bot
2026-06-05  1:00 ` [PATCH net-next v2 12/14] gpio: tc956x: " Alex Elder
2026-06-06  1:01   ` sashiko-bot
2026-06-05  1:00 ` [PATCH net-next v2 13/14] net: stmmac: " Alex Elder
2026-06-05 14:47   ` Rob Herring
2026-06-05 16:05   ` Maxime Chevallier
2026-06-06  1:01   ` sashiko-bot
2026-06-05  1:00 ` [PATCH net-next v2 14/14] arm64: dts: qcom: qcs6490-rb3gen2: enable TC9564 with a single QCA8081 phy Alex Elder
2026-06-06  1:01   ` sashiko-bot

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=20260606010122.21A211F00899@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=elder@riscstar.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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