net: usb: lan78xx: limit size of local TSO packets
PATCH 1/1 net: usb: lan78xx: limit size of local TSO packets
lan78xx_tx_bh() makes sure to not exceed MAX_SINGLE_PACKET_SIZE bytes in the aggregated packets it builds, but does nothing to prevent large GSO packets being submitted.
Pierre-Francois reported various hangs when/if TSO is enabled.
For localy generated packets, we can use netif_set_gso_max_size() to limit the size of TSO packets.
Note that forwarded packets could still hit the issue, so a complete fix might require implementing .ndo_features_check for this driver, forcing a software segmentation if the size of the TSO packet exceeds MAX_SINGLE_PACKET_SIZE.
--- drivers/net/usb/lan78xx.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/usb/lan78xx.c +1 -0
@@ -3750,6 +3750,7 @@ static int lan78xx_probe(struct usb_interface *intf,/* MTU range: 68 - 9000 */ netdev->max_mtu =MAX_SINGLE_PACKET_SIZE ; +netif_set_gso_max_size (netdev,MAX_SINGLE_PACKET_SIZE -MAX_HEADER ); dev->ep_blkin = (intf->cur_altsetting)->endpoint +0 ; dev->ep_blkout = (intf->cur_altsetting)->endpoint +1 ;
Signature · 1 line
2.25.0.rc1.283.g88dfdc4193-goog
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Mon, 13 Jan 2020 09:27:11 -0800
Quoted 14 lines
lan78xx_tx_bh()makes sure to not exceedMAX_SINGLE_PACKET_SIZEbytes in the aggregated packets it builds, but does nothing to prevent large GSO packets being submitted.Pierre-Francois reported various hangs when/if TSO is enabled.
For localy generated packets, we can use
netif_set_gso_max_size()to limit the size of TSO packets.Note that forwarded packets could still hit the issue, so a complete fix might require implementing .ndo_features_check for this driver, forcing a software segmentation if the size of the TSO packet exceeds
MAX_SINGLE_PACKET_SIZE.
Quoted 4 lines
Fixes 55d7de9de6c3 ("Microchip's LAN7800 family USB 2/3 to 10/100/1000 Ethernet device driver")Signed-off-by Eric Dumazet <[email protected]>Reported-by RENARD Pierre-Francois <[email protected]>
Applied and queued up for -stable, thanks Eric.
Following on from Eric comment below, is this patch suitable for the forwarded packets case? I'm not familiar enough to be sure, and not aware of any way to test it. I've testing ethernet functionality on a Pi3B+ and see no regressions.
Content of format patch of the commit, if it seems OK I'll submit a proper patch email.
From b7f06bf6298904b106c38b4bac06a6fcebeee47e Mon Sep 17 00:00:00 2001
From: James Hughes <[email protected]>
Date: Wed, 15 Jan 2020 13:41:54 +0000
Subject: [PATCH] net: usb: lan78xx: Add .ndo_features_check
As reported by Eric Dumazet, the driver does not handle skb's over a certain size in all possible cases. Most cases have been fixed, this patch should ensure that forwarded TSO packets that are greater than MAX_SINGLE_PACKET_SIZE - header size are software segmented and handled correctly.
--- drivers/net/usb/lan78xx.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/net/usb/lan78xx.c +15 -0
@@ -31,6 +31,7 @@#include <linux/mdio.h> #include <linux/phy.h> #include <net/ip6_checksum.h> +#include <net/vxlan.h> #include <linux/interrupt.h> #include <linux/irqdomain.h> #include <linux/irq.h>
@@ -3733,6 +3734,19 @@ static void lan78xx_tx_timeout(struct net_device *net)tasklet_schedule (&dev->bh); } +static netdev_features_t lan78xx_features_check (struct sk_buff *skb, +struct net_device *netdev, +netdev_features_t features) +{ +if (skb_shinfo (skb)->gso_size >MAX_SINGLE_PACKET_SIZE -MAX_HEADER ) + features &= ~NETIF_F_TSO ; + + features =vlan_features_check (skb, features); + features =vxlan_features_check (skb, features); + +return features; +} +static const struct net_device_ops lan78xx_netdev_ops = { .ndo_open = lan78xx_open, .ndo_stop = lan78xx_stop,
@@ -3746,6 +3760,7 @@ static const struct net_device_ops lan78xx_netdev_ops = { .ndo_set_features = lan78xx_set_features, .ndo_vlan_rx_add_vid = lan78xx_vlan_rx_add_vid, .ndo_vlan_rx_kill_vid = lan78xx_vlan_rx_kill_vid, + .ndo_features_check = lan78xx_features_check, };static void lan78xx_stat_monitor (struct timer_list *t)
Signature · 1 line
2.17.1
Quoted 41 lines · Eric Dumazet
lan78xx_tx_bh()makes sure to not exceedMAX_SINGLE_PACKET_SIZEbytes in the aggregated packets it builds, but does nothing to prevent large GSO packets being submitted.Pierre-Francois reported various hangs when/if TSO is enabled.
For localy generated packets, we can use
netif_set_gso_max_size()to limit the size of TSO packets.Note that forwarded packets could still hit the issue, so a complete fix might require implementing .ndo_features_check for this driver, forcing a software segmentation if the size of the TSO packet exceeds
MAX_SINGLE_PACKET_SIZE.Fixes 55d7de9de6c3 ("Microchip's LAN7800 family USB 2/3 to 10/100/1000 Ethernet device driver")Signed-off-by Eric Dumazet <[email protected]>Reported-by RENARD Pierre-Francois <[email protected]>Cc Stefan Wahren <[email protected]>Cc Woojung Huh <[email protected]>Cc Microchip Linux Driver Support <[email protected]>--- drivers/net/usb/lan78xx.c | 1 + 1 file changed, 1 insertion(+)drivers/net/usb/lan78xx.c +1
-1@@ -3750,6 +3750,7 @@ static int lan78xx_probe(struct usb_interface *intf,/* MTU range: 68 - 9000 */ netdev->max_mtu =MAX_SINGLE_PACKET_SIZE ; +netif_set_gso_max_size (netdev,MAX_SINGLE_PACKET_SIZE -MAX_HEADER ); dev->ep_blkin = (intf->cur_altsetting)->endpoint +0 ; dev->ep_blkout = (intf->cur_altsetting)->endpoint +1 ; --2.25.0.rc1.283.g88dfdc4193-goog
Signature · 3 lines
James Hughes Principal Software Engineer, Raspberry Pi (Trading) Ltd
Quoted 38 lines · James Hughes
Following on from Eric comment below, is this patch suitable for the forwarded packets case? I'm not familiar enough to be sure, and not aware of any way to test it. I've testing ethernet functionality on a Pi3B+ and see no regressions.
Content of format patch of the commit, if it seems OK I'll submit a proper patch email.
From
b7f06bf6298904b106c38b4bac06a6fcebeee47eMon Sep 17 00:00:00 2001
From: James Hughes <[email protected]>
Date: Wed, 15 Jan 2020 13:41:54 +0000
Subject: [PATCH] net: usb: lan78xx: Add .ndo_features_checkAs reported by Eric Dumazet, the driver does not handle skb's over a certain size in all possible cases. Most cases have been fixed, this patch should ensure that forwarded TSO packets that are greater than
MAX_SINGLE_PACKET_SIZE- header size are software segmented and handled correctly.Signed-off-by James Hughes <[email protected]>--- drivers/net/usb/lan78xx.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)drivers/net/usb/lan78xx.c +1
-0@@ -31,6 +31,7 @@#include <linux/mdio.h> #include <linux/phy.h> #include <net/ip6_checksum.h> +#include <net/vxlan.h> #include <linux/interrupt.h> #include <linux/irqdomain.h> #include <linux/irq.h>
drivers/net/usb/lan78xx.c static void lan78xx_tx_timeout(struct net_device *net) · line 3743
Quoted 10 lines
drivers/net/usb/lan78xx.c +6
-0@@ -3733,6 +3734,19 @@ static void lan78xx_tx_timeout(struct net_device *net)tasklet_schedule (&dev->bh); } +static netdev_features_t lan78xx_features_check (struct sk_buff *skb, +struct net_device *netdev, +netdev_features_t features) +{ +if (skb_shinfo (skb)->gso_size >MAX_SINGLE_PACKET_SIZE -MAX_HEADER ) + features &= ~NETIF_F_TSO ;
Here gso_size is the payload size of each segment (typically around 1428 bytes)
What you need here is testing the whole packet length (no need to care about MAX_HEADER btw)
Also prefer ~NETIF_F_GSO_MASK (otherwise IPv6 will still be broken)
if (skb->len > MAX_SINGLE_PACKET_SIZE)
features &= ~NETIF_F_GSO_MASK;
+
Quoted 69 lines
drivers/net/usb/lan78xx.c +7
-1+ features =vlan_features_check (skb, features); + features =vxlan_features_check (skb, features); + +return features; +} +static const struct net_device_ops lan78xx_netdev_ops = { .ndo_open = lan78xx_open, .ndo_stop = lan78xx_stop,@@ -3746,6 +3760,7 @@ static const struct net_device_ops lan78xx_netdev_ops = { .ndo_set_features = lan78xx_set_features, .ndo_vlan_rx_add_vid = lan78xx_vlan_rx_add_vid, .ndo_vlan_rx_kill_vid = lan78xx_vlan_rx_kill_vid, + .ndo_features_check = lan78xx_features_check, };static void lan78xx_stat_monitor (struct timer_list *t) --2.17.1
Quoted 39 lines · Eric Dumazet
lan78xx_tx_bh()makes sure to not exceedMAX_SINGLE_PACKET_SIZEbytes in the aggregated packets it builds, but does nothing to prevent large GSO packets being submitted.Pierre-Francois reported various hangs when/if TSO is enabled.
For localy generated packets, we can use
netif_set_gso_max_size()to limit the size of TSO packets.Note that forwarded packets could still hit the issue, so a complete fix might require implementing .ndo_features_check for this driver, forcing a software segmentation if the size of the TSO packet exceeds
MAX_SINGLE_PACKET_SIZE.Fixes 55d7de9de6c3 ("Microchip's LAN7800 family USB 2/3 to 10/100/1000 Ethernet device driver")Signed-off-by Eric Dumazet <[email protected]>Reported-by RENARD Pierre-Francois <[email protected]>Cc Stefan Wahren <[email protected]>Cc Woojung Huh <[email protected]>Cc Microchip Linux Driver Support <[email protected]>--- drivers/net/usb/lan78xx.c | 1 + 1 file changed, 1 insertion(+)drivers/net/usb/lan78xx.c +1
-1@@ -3750,6 +3750,7 @@ static int lan78xx_probe(struct usb_interface *intf,/* MTU range: 68 - 9000 */ netdev->max_mtu =MAX_SINGLE_PACKET_SIZE ; +netif_set_gso_max_size (netdev,MAX_SINGLE_PACKET_SIZE -MAX_HEADER ); dev->ep_blkin = (intf->cur_altsetting)->endpoint +0 ; dev->ep_blkout = (intf->cur_altsetting)->endpoint +1 ; --Quoted 2 lines
2.25.0.rc1.283.g88dfdc4193-goog
--
James Hughes
Principal Software Engineer,
Raspberry Pi (Trading) Ltd
Quoted 54 lines · Eric Dumazet
Quoted 38 lines · James Hughes
Following on from Eric comment below, is this patch suitable for the forwarded packets case? I'm not familiar enough to be sure, and not aware of any way to test it. I've testing ethernet functionality on a Pi3B+ and see no regressions.
Content of format patch of the commit, if it seems OK I'll submit a proper patch email.
From
b7f06bf6298904b106c38b4bac06a6fcebeee47eMon Sep 17 00:00:00 2001
From: James Hughes <[email protected]>
Date: Wed, 15 Jan 2020 13:41:54 +0000
Subject: [PATCH] net: usb: lan78xx: Add .ndo_features_checkAs reported by Eric Dumazet, the driver does not handle skb's over a certain size in all possible cases. Most cases have been fixed, this patch should ensure that forwarded TSO packets that are greater than
MAX_SINGLE_PACKET_SIZE- header size are software segmented and handled correctly.Signed-off-by James Hughes <[email protected]>--- drivers/net/usb/lan78xx.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)drivers/net/usb/lan78xx.c +1
-0@@ -31,6 +31,7 @@#include <linux/mdio.h> #include <linux/phy.h> #include <net/ip6_checksum.h> +#include <net/vxlan.h> #include <linux/interrupt.h> #include <linux/irqdomain.h> #include <linux/irq.h> drivers/net/usb/lan78xx.c static void lan78xx_tx_timeout(struct net_device *net) · line 3743
Quoted 10 lines
drivers/net/usb/lan78xx.c +6
-0@@ -3733,6 +3734,19 @@ static void lan78xx_tx_timeout(struct net_device *net)tasklet_schedule (&dev->bh); } +static netdev_features_t lan78xx_features_check (struct sk_buff *skb, +struct net_device *netdev, +netdev_features_t features) +{ +if (skb_shinfo (skb)->gso_size >MAX_SINGLE_PACKET_SIZE -MAX_HEADER ) + features &= ~NETIF_F_TSO ;Here
gso_sizeis the payload size of each segment (typically around 1428 bytes)
Quoted 6 lines
What you need here is testing the whole packet length (no need to care about
MAX_HEADERbtw)Also prefer ~NETIF_F_GSO_MASK (otherwise IPv6 will still be broken)
if (
skb->len>MAX_SINGLE_PACKET_SIZE)
And it seems you need to account for TX_OVERHEAD (8 additional bytes) that are added later in the ndo_start_xmit()
if (skb->len + TX_OVERHEAD > MAX_SINGLE_PACKET_SIZE)
....
Quoted 72 lines
features &= ~NETIF_F_GSO_MASK;+
Quoted 69 lines
drivers/net/usb/lan78xx.c +7
-1+ features =vlan_features_check (skb, features); + features =vxlan_features_check (skb, features); + +return features; +} +static const struct net_device_ops lan78xx_netdev_ops = { .ndo_open = lan78xx_open, .ndo_stop = lan78xx_stop,@@ -3746,6 +3760,7 @@ static const struct net_device_ops lan78xx_netdev_ops = { .ndo_set_features = lan78xx_set_features, .ndo_vlan_rx_add_vid = lan78xx_vlan_rx_add_vid, .ndo_vlan_rx_kill_vid = lan78xx_vlan_rx_kill_vid, + .ndo_features_check = lan78xx_features_check, };static void lan78xx_stat_monitor (struct timer_list *t) --2.17.1
Quoted 39 lines · Eric Dumazet
lan78xx_tx_bh()makes sure to not exceedMAX_SINGLE_PACKET_SIZEbytes in the aggregated packets it builds, but does nothing to prevent large GSO packets being submitted.Pierre-Francois reported various hangs when/if TSO is enabled.
For localy generated packets, we can use
netif_set_gso_max_size()to limit the size of TSO packets.Note that forwarded packets could still hit the issue, so a complete fix might require implementing .ndo_features_check for this driver, forcing a software segmentation if the size of the TSO packet exceeds
MAX_SINGLE_PACKET_SIZE.Fixes 55d7de9de6c3 ("Microchip's LAN7800 family USB 2/3 to 10/100/1000 Ethernet device driver")Signed-off-by Eric Dumazet <[email protected]>Reported-by RENARD Pierre-Francois <[email protected]>Cc Stefan Wahren <[email protected]>Cc Woojung Huh <[email protected]>Cc Microchip Linux Driver Support <[email protected]>--- drivers/net/usb/lan78xx.c | 1 + 1 file changed, 1 insertion(+)drivers/net/usb/lan78xx.c +1
-1@@ -3750,6 +3750,7 @@ static int lan78xx_probe(struct usb_interface *intf,/* MTU range: 68 - 9000 */ netdev->max_mtu =MAX_SINGLE_PACKET_SIZE ; +netif_set_gso_max_size (netdev,MAX_SINGLE_PACKET_SIZE -MAX_HEADER ); dev->ep_blkin = (intf->cur_altsetting)->endpoint +0 ; dev->ep_blkout = (intf->cur_altsetting)->endpoint +1 ; --Quoted 2 lines
2.25.0.rc1.283.g88dfdc4193-goog
--
James Hughes
Principal Software Engineer,
Raspberry Pi (Trading) Ltd
Quoted 61 lines · Eric Dumazet
Quoted 59 lines · Eric Dumazet
Quoted 38 lines · James Hughes
Following on from Eric comment below, is this patch suitable for the forwarded packets case? I'm not familiar enough to be sure, and not aware of any way to test it. I've testing ethernet functionality on a Pi3B+ and see no regressions.
Content of format patch of the commit, if it seems OK I'll submit a proper patch email.
From
b7f06bf6298904b106c38b4bac06a6fcebeee47eMon Sep 17 00:00:00 2001
From: James Hughes <[email protected]>
Date: Wed, 15 Jan 2020 13:41:54 +0000
Subject: [PATCH] net: usb: lan78xx: Add .ndo_features_checkAs reported by Eric Dumazet, the driver does not handle skb's over a certain size in all possible cases. Most cases have been fixed, this patch should ensure that forwarded TSO packets that are greater than
MAX_SINGLE_PACKET_SIZE- header size are software segmented and handled correctly.Signed-off-by James Hughes <[email protected]>--- drivers/net/usb/lan78xx.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)drivers/net/usb/lan78xx.c +1
-0@@ -31,6 +31,7 @@#include <linux/mdio.h> #include <linux/phy.h> #include <net/ip6_checksum.h> +#include <net/vxlan.h> #include <linux/interrupt.h> #include <linux/irqdomain.h> #include <linux/irq.h> drivers/net/usb/lan78xx.c static void lan78xx_tx_timeout(struct net_device *net) · line 3743
Quoted 10 lines
drivers/net/usb/lan78xx.c +6
-0@@ -3733,6 +3734,19 @@ static void lan78xx_tx_timeout(struct net_device *net)tasklet_schedule (&dev->bh); } +static netdev_features_t lan78xx_features_check (struct sk_buff *skb, +struct net_device *netdev, +netdev_features_t features) +{ +if (skb_shinfo (skb)->gso_size >MAX_SINGLE_PACKET_SIZE -MAX_HEADER ) + features &= ~NETIF_F_TSO ;Here
gso_sizeis the payload size of each segment (typically around 1428 bytes)What you need here is testing the whole packet length (no need to care about
MAX_HEADERbtw)Also prefer ~NETIF_F_GSO_MASK (otherwise IPv6 will still be broken)
Quoted 10 lines
Quoted 1 line
if (
skb->len>MAX_SINGLE_PACKET_SIZE)And it seems you need to account for
TX_OVERHEAD(8 additional bytes) that are added later in thendo_start_xmit()if (
skb->len+TX_OVERHEAD>MAX_SINGLE_PACKET_SIZE)
....Quoted 2 lines
features &= ~NETIF_F_GSO_MASK;
Got it, thanks! Will redo the patch as indicated and submit correctly tomorrow.
James
Quoted 64 lines
Quoted 64 lines
+
Quoted 63 lines
drivers/net/usb/lan78xx.c +7
-1+ features =vlan_features_check (skb, features); + features =vxlan_features_check (skb, features); + +return features; +} +static const struct net_device_ops lan78xx_netdev_ops = { .ndo_open = lan78xx_open, .ndo_stop = lan78xx_stop,@@ -3746,6 +3760,7 @@ static const struct net_device_ops lan78xx_netdev_ops = { .ndo_set_features = lan78xx_set_features, .ndo_vlan_rx_add_vid = lan78xx_vlan_rx_add_vid, .ndo_vlan_rx_kill_vid = lan78xx_vlan_rx_kill_vid, + .ndo_features_check = lan78xx_features_check, };static void lan78xx_stat_monitor (struct timer_list *t) --2.17.1
Quoted 41 lines · Eric Dumazet
lan78xx_tx_bh()makes sure to not exceedMAX_SINGLE_PACKET_SIZEbytes in the aggregated packets it builds, but does nothing to prevent large GSO packets being submitted.Pierre-Francois reported various hangs when/if TSO is enabled.
For localy generated packets, we can use
netif_set_gso_max_size()to limit the size of TSO packets.Note that forwarded packets could still hit the issue, so a complete fix might require implementing .ndo_features_check for this driver, forcing a software segmentation if the size of the TSO packet exceeds
MAX_SINGLE_PACKET_SIZE.Fixes 55d7de9de6c3 ("Microchip's LAN7800 family USB 2/3 to 10/100/1000 Ethernet device driver")Signed-off-by Eric Dumazet <[email protected]>Reported-by RENARD Pierre-Francois <[email protected]>Cc Stefan Wahren <[email protected]>Cc Woojung Huh <[email protected]>Cc Microchip Linux Driver Support <[email protected]>--- drivers/net/usb/lan78xx.c | 1 + 1 file changed, 1 insertion(+)drivers/net/usb/lan78xx.c +1
-1@@ -3750,6 +3750,7 @@ static int lan78xx_probe(struct usb_interface *intf,/* MTU range: 68 - 9000 */ netdev->max_mtu =MAX_SINGLE_PACKET_SIZE ; +netif_set_gso_max_size (netdev,MAX_SINGLE_PACKET_SIZE -MAX_HEADER ); dev->ep_blkin = (intf->cur_altsetting)->endpoint +0 ; dev->ep_blkout = (intf->cur_altsetting)->endpoint +1 ; --2.25.0.rc1.283.g88dfdc4193-goog