On Dec 06, Maxime Chevallier wrote:
> Hi Lorenzo,
>
> On 12/5/26 18:26, Lorenzo Bianconi wrote:
> > The RX VLAN offload mode is consumed by the receive path: stmmac_rx()
> > and stmmac_dispatch_skb_zc() use hw_vlan_en to decide whether to take
> > the VLAN tag from the RX descriptor, and the software stripping path
> > uses the advertised RX VLAN feature bits.
> >
> > stmmac_set_features() changes that state at runtime, while RX NAPI can
> > run concurrently. A frame received with one setting can therefore be
> > processed after the setting has changed, which may lose a tag that was
> > stripped or duplicate a tag that is still in the frame. The MAC register
> > update also cannot be made atomic with respect to frames already in
> > flight without stopping RX DMA and flushing the descriptor rings.
> >
> > Since this is an RX offload mode change and there is no cheap way to
> > synchronize it with the receive path, only allow it while the interface
> > is down. Mask the RX VLAN feature bits back to their currently advertised
> > state in stmmac_fix_features() when the device is running, so
> > ndo_set_features() never changes the mode under a live RX path. A request
> > made while the interface is running is ignored and is not deferred to the
> > next open; userspace must bring the interface down to change the RX VLAN
> > offload.
> >
> > Fixes: 750011e239a5 ("net: stmmac: Add support for HW-accelerated VLAN stripping")
> > Signed-off-by: Lorenzo Bianconi <lore…@oss.qualcomm.com>
>
> This triggered some new failures on the Netdev CI for 6 stmmac runners:
>
> - https://netdevci.bootlin.com/stmmac/outputs/941929-bootlin-stmmac-rk3568/test-outputs/24-vlan-py/
> - https://netdevci.bootlin.com/stmmac/outputs/941929-bootlin-stmmac-imx8mp/test-outputs/24-vlan-py/
> - https://netdevci.bootlin.com/stmmac/outputs/941929-bootlin-stmmac-jh7110/test-outputs/24-vlan-py/
> - https://netdevci.bootlin.com/stmmac/outputs/941929-bootlin-stmmac-socfpga-agilex5/test-outputs/24-vlan-py/
> - https://netdevci.bootlin.com/stmmac/outputs/941929-bootlin-stmmac-stm32mp1/test-outputs/24-vlan-py/
> - https://netdevci.bootlin.com/stmmac/outputs/941929-bootlin-stmmac-stm32mp2/test-outputs/24-vlan-py/
>
> The test fails precisely because we can't switch offload mode while interface is on.
>
> Besides the selftest, is it worth fixing ? We may have an error on one frame
> while it's being actively reconfigured, I guess a lot of other drivers are
> subject to the same class of problem... Is it a bit too defensive ?
>
> I may be wrong here, I don't know exactly what's the netdev policy regarding
> wether it's OK to have potentially one frame corrupt while the user is
> reconfiguring offloads...
Hi Maxime,
If it is ok to receive corrupted frames during offload reconfiguration, I am fine
to drop this patch, I was just fixing a comment from sashiko that seemed reasonable
to me :)
Regards,
Lorenzo
>
> Maxime
>
> > ---
> > drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > index d32d3e7b1b8c..b978e64399d4 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > @@ -6371,6 +6371,8 @@ static netdev_features_t stmmac_fix_features(struct net_device *dev,
> > netdev_features_t features)
> > {
> > struct stmmac_priv *priv = netdev_priv(dev);
> > + netdev_features_t vlan_rx = NETIF_F_HW_VLAN_CTAG_RX |
> > + NETIF_F_HW_VLAN_STAG_RX;
> >
> > if (priv->plat->rx_coe == STMMAC_RX_COE_NONE)
> > features &= ~NETIF_F_RXCSUM;
> > @@ -6393,6 +6395,15 @@ static netdev_features_t stmmac_fix_features(struct net_device *dev,
> > features &= ~NETIF_F_HW_VLAN_STAG_RX;
> > }
> >
> > + /* The RX VLAN mode cannot be changed while RX is running: frames
> > + * received under the old mode might otherwise be processed with the
> > + * new one. Keep the current mode and defer the change until the
> > + * interface is down.
> > + */
> > + if (netif_running(dev) &&
> > + (features & vlan_rx) != (dev->features & vlan_rx))
> > + features = (features & ~vlan_rx) | (dev->features & vlan_rx);
> > +
> > return features;
> > }
> >
> >
> > ---
> > base-commit: e9d78fc6741ac06d438cf64e314c28e57014432a
> > change-id: 20261205-stmmac-do-not-flip-vlan-offload-613a9cad635b
> >
> > Best regards,
>