From: Paolo Abeni <pabeni@redhat.com>
To: j.raczynski@samsung.com
Cc: netdev@vger.kernel.org, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, mcoquelin.stm32@gmail.com,
alexandre.torgue@foss.st.com, linux-kernel@vger.kernel.org,
k.domagalski@samsung.com, k.tegowski@samsung.com,
cs0617.lee@samsung.com
Subject: Re: [PATCH net-next v2 3/3] include/stmmac: Increase max DMA/MTL channel count from 8 to 16
Date: Thu, 4 Jun 2026 15:16:06 +0200 [thread overview]
Message-ID: <20260604131606.185700-1-pabeni@redhat.com> (raw)
In-Reply-To: <20260601162537.553512-4-j.raczynski@samsung.com>
From: AI Reviewer <ai@example.com>
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://sashiko.dev/
---
include/stmmac: Increase max DMA/MTL channel count from 8 to 16
Newer XGMAC hardware does support up to 16 DMA/MTL queues. Add support for
these after previous modifications of driver to accommodate for that.
> diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
> index 4430b967abdeb..a9d19e2c388c6 100644
> --- a/include/linux/stmmac.h
> +++ b/include/linux/stmmac.h
> @@ -15,9 +15,9 @@
> #include <linux/platform_device.h>
> #include <linux/phylink.h>
>
> -#define MTL_MAX_RX_QUEUES 8
> -#define MTL_MAX_TX_QUEUES 8
> -#define STMMAC_CH_MAX 8
> +#define MTL_MAX_RX_QUEUES 16
> +#define MTL_MAX_TX_QUEUES 16
> +#define STMMAC_CH_MAX 16
[Severity: High]
Does increasing these limits to 16 cause undefined behavior and silent register
truncation in the hardware configuration functions when queue >= 8?
In dwxgmac2_core.c:dwxgmac2_tx_queue_prio(), when queue >= 8, the logic
only subtracts 4:
if (queue >= 4)
queue -= 4;
This leaves queue >= 4, which causes XGMAC_PSTC_SHIFT(queue) to shift by >= 32
bits, overflowing the 32-bit integer.
A similar regression occurs in dwmac4_core.c:dwmac4_tx_queue_priority() where
it shifts by GMAC_TXQCTRL_PSTQX_SHIFT(queue).
Additionally, in dwmac4_core.c:dwmac4_rx_queue_routing(), the queue variable
is masked against a 3-bit bitmask, which silently truncates any queue >= 8:
value |= (queue << route_possibilities[packet-1].reg_shift) &
route_possibilities[packet - 1].reg_mask;
Finally, dwmac4_core.c:dwmac4_map_mtl_dma() only maps queues up to 7 (using
MAP0 and MAP1):
if (queue < 4) {
...
} else {
value = readl(ioaddr + MTL_RXQ_DMA_MAP1);
value &= ~MTL_RXQ_DMA_QXMDMACH_MASK(queue - 4);
For queue >= 8, the shift calculation overflows and corrupts register data.
Should these hardware configuration functions be updated to handle the expanded
queue limits?
[Severity: Critical]
This is a pre-existing issue, but does missing bounds checking on the device
tree properties expose an out-of-bounds array access during device probe?
In stmmac_platform.c:stmmac_mtl_setup(), the device tree property
snps,tx-queues-to-use is parsed and clamped only to 255 (U8_MAX):
if (!of_property_read_u32(tx_node, "snps,tx-queues-to-use", &value)) {
if (value > U8_MAX)
value = U8_MAX;
plat->tx_queues_to_use = value;
}
Later in stmmac_main.c:stmmac_hw_setup(), it attempts to dynamically clamp
this value to the hardware capabilities:
if (priv->dma_cap.number_tx_queues &&
priv->plat->tx_queues_to_use > priv->dma_cap.number_tx_queues) {
priv->plat->tx_queues_to_use = priv->dma_cap.number_tx_queues;
}
However, if the hardware feature registers report 0 (which happens for older
GMAC versions), this check is bypassed. The driver fails to clamp the
requested queues against the static internal array limit MTL_MAX_TX_QUEUES.
As a result, in stmmac_main.c:init_dma_tx_desc_rings(), the initialization
loop iterates up to the unvalidated tx_queues_to_use:
for (queue = 0; queue < tx_queue_cnt; queue++)
__init_dma_tx_desc_rings(priv, dma_conf, queue);
This will overrun the bounds of arrays embedded in struct stmmac_priv (like
dma_conf->tx_queue) if the device tree configuration exceeds the static array
limits. Should we add a strict bounds check against MTL_MAX_TX_QUEUES and
MTL_MAX_RX_QUEUES during probe?
--
This is an AI-generated review.
prev parent reply other threads:[~2026-06-04 13:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20260601162617eucas1p2efc386a4d9f9e7e98e8acb83f9c550d6@eucas1p2.samsung.com>
2026-06-01 16:25 ` [PATCH net-next v2 0/3] xgmac: Support for 16 MTL/DMA queues Jakub Raczynski
2026-06-01 16:25 ` [PATCH net-next v2 1/3] net/stmmac/dwxgmac: Modify DMA functions for future hardware Jakub Raczynski
2026-06-03 11:46 ` Jakub Raczynski
2026-06-03 12:45 ` Larysa Zaremba
2026-06-06 2:02 ` Jakub Kicinski
2026-06-01 16:25 ` [PATCH net-next v2 2/3] net/stmmac/dwxgmac: Extend MTL/DMA support to 16 queues Jakub Raczynski
2026-06-03 14:23 ` Larysa Zaremba
2026-06-01 16:25 ` [PATCH net-next v2 3/3] include/stmmac: Increase max DMA/MTL channel count from 8 to 16 Jakub Raczynski
2026-06-04 13:16 ` Paolo Abeni [this message]
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=20260604131606.185700-1-pabeni@redhat.com \
--to=pabeni@redhat.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andrew+netdev@lunn.ch \
--cc=cs0617.lee@samsung.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=j.raczynski@samsung.com \
--cc=k.domagalski@samsung.com \
--cc=k.tegowski@samsung.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev@vger.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