[PATCH net] net: stmmac: fix the invalid VID programmed by VLAN perfect filtering

From: Linkui Xiao

Date: Thu Sep 17 2026 - 08:33:46 EST


From: Linkui Xiao <xiaolinkui@xxxxxxxxxx>

for_each_set_bit() leaves its iterator equal to the bitmap size once the
loop terminates, so the 'vid' read after the loop in stmmac_vlan_update()
is always VLAN_N_VID (4096) and never the last VLAN ID that was found.

Cores that do not support VLAN hash filtering (dma_cap.vlhash == 0) fall
back to the single VID perfect match filter and hand that value straight
to the MAC. vlan_update_hash() therefore programs MAC_VLAN_Tag with
VID 4096, a value that can never match an incoming 802.1Q tag, so the
perfect filter ends up discarding all VLAN tagged traffic. Both
stmmac_test_vlanfilt_perfect() and stmmac_test_dvlanfilt_perfect() walk
this path and fail as a result.

Remember the VID while iterating so that the last active VLAN ID is the
one passed to the perfect match filter. When hash filtering is available
'hash' is non-zero as soon as at least one VID is active, so
vlan_update_hash() keeps ignoring 'pmatch' and nothing changes there.

Fixes: c7ab0b8088d7 ("net: stmmac: Fallback to VLAN Perfect filtering if HASH is not available")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Linkui Xiao <xiaolinkui@xxxxxxxxxx>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 62c3441911e7..af2d38a2bb3d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -6844,13 +6844,13 @@ static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_double)
crc = bitrev32(~stmmac_vid_crc32_le(vid_le)) >> 28;
hash |= (1 << crc);
count++;
+ pmatch = vid;
}

if (!priv->dma_cap.vlhash) {
if (count > 2) /* VID = 0 always passes filter */
return -EOPNOTSUPP;

- pmatch = vid;
hash = 0;
}

--
2.25.1