Skip to contentSkip to conversation

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

PATCH In review Linkui Xiao 2 participants 3 messages Sep 17 – Sep 18

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: stmmac: fix the invalid VID programmed by VLAN perfect filtering

From: Linkui Xiao <[email protected]>

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")
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 62c3441911e7..af2d38a2bb3d 100644
@@ -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;
 	}
 
Signature · 1 line
2.25.1
#1 lore raw

Hi,

+Ovidiu

Quoted 14 lines · Linkui Xiao

From: Linkui Xiao <[email protected]>

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.

Quoted 8 lines

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")

Thank you for proposing this fix, however this code is currently being removed :

https://lore.kernel.org/r/[email protected]

So no need for this patch :)

Maxime

#2 lore raw

Hi Maxime,

Quoted 28 lines · Maxime Chevallier

Hi,

+Ovidiu

Quoted 14 lines · Linkui Xiao

From: Linkui Xiao <[email protected]>

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.

Quoted 8 lines

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")
Quoted 5 lines

Thank you for proposing this fix, however this code is currently being removed :

https://lore.kernel.org/r/[email protected]

So no need for this patch :)

Thanks for the heads-up. I'll drop this patch then.

Ovidiu, I'll keep an eye on your series. If the fallback path still needs a valid VID after the removal, feel free to ping me.

Thanks,
Linkui

Quoted 2 lines

Maxime