* [PATCH net v6] net: stmmac: Prevent DSA tags from breaking COE
@ 2024-01-16 12:19 Romain Gantois
2024-01-16 20:56 ` Florian Fainelli
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Romain Gantois @ 2024-01-16 12:19 UTC (permalink / raw)
To: Alexandre Torgue, Jose Abreu, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: Maxime Coquelin, Miquel Raynal, Maxime Chevallier, Sylvain Girard,
Pascal EBERHARD, Richard Tresidder, Linus Walleij,
Vladimir Oltean, Andrew Lunn, Thomas Petazzoni, netdev,
linux-stm32, linux-arm-kernel, stable, Romain Gantois,
Vladimir Oltean
Some DSA tagging protocols change the EtherType field in the MAC header
e.g. DSA_TAG_PROTO_(DSA/EDSA/BRCM/MTK/RTL4C_A/SJA1105). On TX these tagged
frames are ignored by the checksum offload engine and IP header checker of
some stmmac cores.
On RX, the stmmac driver wrongly assumes that checksums have been computed
for these tagged packets, and sets CHECKSUM_UNNECESSARY.
Add an additional check in the stmmac TX and RX hotpaths so that COE is
deactivated for packets with ethertypes that will not trigger the COE and
IP header checks.
Fixes: 6b2c6e4a938f ("net: stmmac: propagate feature flags to vlan")
Cc: <stable@vger.kernel.org>
Reported-by: Richard Tresidder <rtresidd@electromag.com.au>
Link: https://lore.kernel.org/netdev/e5c6c75f-2dfa-4e50-a1fb-6bf4cdb617c2@electromag.com.au/
Reported-by: Romain Gantois <romain.gantois@bootlin.com>
Link: https://lore.kernel.org/netdev/c57283ed-6b9b-b0e6-ee12-5655c1c54495@bootlin.com/
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Romain Gantois <romain.gantois@bootlin.com>
---
Hello everyone,
This is the sixth version of my proposed fix for the stmmac checksum
offloading issue that has recently been reported.
significant changes in v4:
- Removed "inline" from declaration of stmmac_has_ip_ethertype
significant changes in v3:
- Use __vlan_get_protocol to make sure that 8021Q-encapsulated
traffic is checked correctly.
significant changes in v2:
- Replaced the stmmac_link_up-based fix with an ethertype check in the TX
and RX hotpaths.
The Checksum Offloading Engine of some stmmac cores (e.g. DWMAC1000)
computes an incorrect checksum when presented with DSA-tagged packets. This
causes all TCP/UDP transfers to break when the stmmac device is connected
to the CPU port of a DSA switch.
I ran some tests using different tagging protocols with DSA_LOOP, and all
of the protocols that set a custom ethertype field in the MAC header caused
the checksum offload engine to ignore the tagged packets. On TX, this
caused packets to egress with incorrect checksums. On RX, these packets
were similarly ignored by the COE, yet the stmmac driver set
CHECKSUM_UNNECESSARY, wrongly assuming that their checksums had been
verified in hardware.
Version 2 of this patch series fixes this issue by checking ethertype
fields in both the TX and RX hotpaths of the stmmac driver. On TX, if a
non-IP ethertype is detected, the packet is checksummed in software. On
RX, the same condition causes stmmac to avoid setting CHECKSUM_UNNECESSARY.
To measure the performance degradation to the TX/RX hotpaths, I did some
iperf3 runs with 512-byte unfragmented UDP packets.
measured degradation on TX: -466 pps (-0.2%) on RX: -338 pps (-1.2%)
original performances on TX: 22kpps on RX: 27kpps
The performance hit on the RX path can be partly explained by the fact that
the stmmac driver doesn't set CHECKSUM_UNNECESSARY anymore.
The TX performance degradation observed in v2 seems to have improved.
It's not entirely clear to me why that is.
Best Regards,
Romain
Romain Gantois (1):
net: stmmac: Prevent DSA tags from breaking COE
.../net/ethernet/stmicro/stmmac/stmmac_main.c | 23 ++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
--
2.43.0
---
Changes in v6:
- Style fixes
- Link to v5: https://lore.kernel.org/r/20240111-prevent_dsa_tags-v5-1-63e795a4d129@bootlin.com
Changes in v5:
- Added missing "net" tag to subject of patch series
- Link to v4: https://lore.kernel.org/r/20240109-prevent_dsa_tags-v4-1-f888771fa2f6@bootlin.com
---
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 32 ++++++++++++++++++++---
1 file changed, 29 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index c78a96b8eb64..a0e46369ae15 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -4435,6 +4435,28 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
return NETDEV_TX_OK;
}
+/**
+ * stmmac_has_ip_ethertype() - Check if packet has IP ethertype
+ * @skb: socket buffer to check
+ *
+ * Check if a packet has an ethertype that will trigger the IP header checks
+ * and IP/TCP checksum engine of the stmmac core.
+ *
+ * Return: true if the ethertype can trigger the checksum engine, false
+ * otherwise
+ */
+static bool stmmac_has_ip_ethertype(struct sk_buff *skb)
+{
+ int depth = 0;
+ __be16 proto;
+
+ proto = __vlan_get_protocol(skb, eth_header_parse_protocol(skb),
+ &depth);
+
+ return (depth <= ETH_HLEN) &&
+ (proto == htons(ETH_P_IP) || proto == htons(ETH_P_IPV6));
+}
+
/**
* stmmac_xmit - Tx entry point of the driver
* @skb : the socket buffer
@@ -4499,9 +4521,13 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
/* DWMAC IPs can be synthesized to support tx coe only for a few tx
* queues. In that case, checksum offloading for those queues that don't
* support tx coe needs to fallback to software checksum calculation.
+ *
+ * Packets that won't trigger the COE e.g. most DSA-tagged packets will
+ * also have to be checksummed in software.
*/
if (csum_insertion &&
- priv->plat->tx_queues_cfg[queue].coe_unsupported) {
+ (priv->plat->tx_queues_cfg[queue].coe_unsupported ||
+ !stmmac_has_ip_ethertype(skb))) {
if (unlikely(skb_checksum_help(skb)))
goto dma_map_err;
csum_insertion = !csum_insertion;
@@ -5066,7 +5092,7 @@ static void stmmac_dispatch_skb_zc(struct stmmac_priv *priv, u32 queue,
stmmac_rx_vlan(priv->dev, skb);
skb->protocol = eth_type_trans(skb, priv->dev);
- if (unlikely(!coe))
+ if (unlikely(!coe) || !stmmac_has_ip_ethertype(skb))
skb_checksum_none_assert(skb);
else
skb->ip_summed = CHECKSUM_UNNECESSARY;
@@ -5589,7 +5615,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
skb->protocol = eth_type_trans(skb, priv->dev);
- if (unlikely(!coe))
+ if (unlikely(!coe) || !stmmac_has_ip_ethertype(skb))
skb_checksum_none_assert(skb);
else
skb->ip_summed = CHECKSUM_UNNECESSARY;
---
base-commit: a23aa04042187cbde16f470b49d4ad60d32e9206
change-id: 20240108-prevent_dsa_tags-7bb0def0db81
Best regards,
--
Romain Gantois <romain.gantois@bootlin.com>
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net v6] net: stmmac: Prevent DSA tags from breaking COE
2024-01-16 12:19 [PATCH net v6] net: stmmac: Prevent DSA tags from breaking COE Romain Gantois
@ 2024-01-16 20:56 ` Florian Fainelli
2024-01-17 10:10 ` patchwork-bot+netdevbpf
2024-02-01 9:38 ` Richard Tresidder
2 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2024-01-16 20:56 UTC (permalink / raw)
To: Romain Gantois, Alexandre Torgue, Jose Abreu, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Maxime Coquelin, Miquel Raynal, Maxime Chevallier, Sylvain Girard,
Pascal EBERHARD, Richard Tresidder, Linus Walleij,
Vladimir Oltean, Andrew Lunn, Thomas Petazzoni, netdev,
linux-stm32, linux-arm-kernel, stable, Vladimir Oltean
On 1/16/24 04:19, Romain Gantois wrote:
> Some DSA tagging protocols change the EtherType field in the MAC header
> e.g. DSA_TAG_PROTO_(DSA/EDSA/BRCM/MTK/RTL4C_A/SJA1105). On TX these tagged
> frames are ignored by the checksum offload engine and IP header checker of
> some stmmac cores.
>
> On RX, the stmmac driver wrongly assumes that checksums have been computed
> for these tagged packets, and sets CHECKSUM_UNNECESSARY.
>
> Add an additional check in the stmmac TX and RX hotpaths so that COE is
> deactivated for packets with ethertypes that will not trigger the COE and
> IP header checks.
>
> Fixes: 6b2c6e4a938f ("net: stmmac: propagate feature flags to vlan")
> Cc: <stable@vger.kernel.org>
> Reported-by: Richard Tresidder <rtresidd@electromag.com.au>
> Link: https://lore.kernel.org/netdev/e5c6c75f-2dfa-4e50-a1fb-6bf4cdb617c2@electromag.com.au/
> Reported-by: Romain Gantois <romain.gantois@bootlin.com>
> Link: https://lore.kernel.org/netdev/c57283ed-6b9b-b0e6-ee12-5655c1c54495@bootlin.com/
> Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Romain Gantois <romain.gantois@bootlin.com>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
--
Florian
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net v6] net: stmmac: Prevent DSA tags from breaking COE
2024-01-16 12:19 [PATCH net v6] net: stmmac: Prevent DSA tags from breaking COE Romain Gantois
2024-01-16 20:56 ` Florian Fainelli
@ 2024-01-17 10:10 ` patchwork-bot+netdevbpf
2024-02-01 9:38 ` Richard Tresidder
2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-01-17 10:10 UTC (permalink / raw)
To: Romain Gantois
Cc: alexandre.torgue, joabreu, davem, edumazet, kuba, pabeni,
mcoquelin.stm32, miquel.raynal, maxime.chevallier, sylvain.girard,
pascal.eberhard, rtresidd, linus.walleij, olteanv, andrew,
thomas.petazzoni, netdev, linux-stm32, linux-arm-kernel, stable,
vladimir.oltean
Hello:
This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:
On Tue, 16 Jan 2024 13:19:17 +0100 you wrote:
> Some DSA tagging protocols change the EtherType field in the MAC header
> e.g. DSA_TAG_PROTO_(DSA/EDSA/BRCM/MTK/RTL4C_A/SJA1105). On TX these tagged
> frames are ignored by the checksum offload engine and IP header checker of
> some stmmac cores.
>
> On RX, the stmmac driver wrongly assumes that checksums have been computed
> for these tagged packets, and sets CHECKSUM_UNNECESSARY.
>
> [...]
Here is the summary with links:
- [net,v6] net: stmmac: Prevent DSA tags from breaking COE
https://git.kernel.org/netdev/net/c/c2945c435c99
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net v6] net: stmmac: Prevent DSA tags from breaking COE
2024-01-16 12:19 [PATCH net v6] net: stmmac: Prevent DSA tags from breaking COE Romain Gantois
2024-01-16 20:56 ` Florian Fainelli
2024-01-17 10:10 ` patchwork-bot+netdevbpf
@ 2024-02-01 9:38 ` Richard Tresidder
2024-02-01 15:05 ` Jakub Kicinski
2 siblings, 1 reply; 6+ messages in thread
From: Richard Tresidder @ 2024-02-01 9:38 UTC (permalink / raw)
To: Romain Gantois, Alexandre Torgue, Jose Abreu, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: netdev, G Thomas, Rohan
Hi All
Thanks for your work on this patch.
I was wondering if this would make it's way onto the lts kernel branch at some point?
I think this patch relies on at least a few others that don't appear to have been ported across either.
eg: at least 2023-09-18 Rohan G Thomas net: stmmac: Tx coe sw fallback
Just looking at having to abandon the 6.6 lts kernel I'm basing things on as we require this patchset to get our network system working.
Again much appreciated!
Cheers
Richard Tresidder
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net v6] net: stmmac: Prevent DSA tags from breaking COE
2024-02-01 9:38 ` Richard Tresidder
@ 2024-02-01 15:05 ` Jakub Kicinski
2024-02-02 3:10 ` Richard Tresidder
0 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2024-02-01 15:05 UTC (permalink / raw)
To: Richard Tresidder
Cc: Romain Gantois, Alexandre Torgue, Jose Abreu, David S. Miller,
Eric Dumazet, Paolo Abeni, netdev, G Thomas, Rohan
On Thu, 1 Feb 2024 17:38:07 +0800 Richard Tresidder wrote:
> Thanks for your work on this patch.
> I was wondering if this would make it's way onto the lts kernel branch at some point?
> I think this patch relies on at least a few others that don't appear to have been ported across either.
> eg: at least 2023-09-18 Rohan G Thomas net: stmmac: Tx coe sw fallback
>
> Just looking at having to abandon the 6.6 lts kernel I'm basing things on as we require this patchset to get our network system working.
> Again much appreciated!
Hm, it may have gotten missed because of the double space in:
Cc: <stable@vger.kernel.org>
double check if it's present in the stable tree and if not please
request the backport, the info you need to provide is somewhere
in kernel doc's process section.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net v6] net: stmmac: Prevent DSA tags from breaking COE
2024-02-01 15:05 ` Jakub Kicinski
@ 2024-02-02 3:10 ` Richard Tresidder
0 siblings, 0 replies; 6+ messages in thread
From: Richard Tresidder @ 2024-02-02 3:10 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Romain Gantois, Alexandre Torgue, Jose Abreu, David S. Miller,
Eric Dumazet, Paolo Abeni, netdev, G Thomas, Rohan
Richard Tresidder
On 1/02/2024 11:05 pm, Jakub Kicinski wrote:
> On Thu, 1 Feb 2024 17:38:07 +0800 Richard Tresidder wrote:
>> Thanks for your work on this patch.
>> I was wondering if this would make it's way onto the lts kernel branch at some point?
>> I think this patch relies on at least a few others that don't appear to have been ported across either.
>> eg: at least 2023-09-18 Rohan G Thomas net: stmmac: Tx coe sw fallback
>>
>> Just looking at having to abandon the 6.6 lts kernel I'm basing things on as we require this patchset to get our network system working.
>> Again much appreciated!
> Hm, it may have gotten missed because of the double space in:
> Cc: <stable@vger.kernel.org>
> double check if it's present in the stable tree and if not please
> request the backport, the info you need to provide is somewhere
> in kernel doc's process section.
>
Hi Jakub
Thanks for the hint.
I just found these patches noted in the stable mailing list on the 29th of Jan as part of the [PATCH 6.6] series
So yep my bad I was looking in the wrong spot.
[PATCH 6.6 008/331] net: stmmac: Tx coe sw fallback
[PATCH 6.6 009/331] net: stmmac: Prevent DSA tags from breaking COE
Cheers
Richard Tresidder
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-02-02 3:17 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-16 12:19 [PATCH net v6] net: stmmac: Prevent DSA tags from breaking COE Romain Gantois
2024-01-16 20:56 ` Florian Fainelli
2024-01-17 10:10 ` patchwork-bot+netdevbpf
2024-02-01 9:38 ` Richard Tresidder
2024-02-01 15:05 ` Jakub Kicinski
2024-02-02 3:10 ` Richard Tresidder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).