Commit d91bb0d0 authored by Bernd Eckstein's avatar Bernd Eckstein Committed by Stefan Bader

usbnet: ipheth: fix racing condition

BugLink: https://bugs.launchpad.net/bugs/1836666

[ Upstream commit 94d250fa ]

Fix a racing condition in ipheth.c that can lead to slow performance.

Bug: In ipheth_tx(), netif_wake_queue() may be called on the callback
ipheth_sndbulk_callback(), _before_ netif_stop_queue() is called.
When this happens, the queue is stopped longer than it needs to be,
thus reducing network performance.

Fix: Move netif_stop_queue() in front of usb_submit_urb(). Now the order
is always correct. In case, usb_submit_urb() fails, the queue is woken up
again as callback will not fire.

Testing: This racing condition is usually not noticeable, as it has to
occur very frequently to slowdown the network. The callback from the USB
is usually triggered slow enough, so the situation does not appear.
However, on a Ubuntu Linux on VMWare Workstation, running on Windows 10,
the we loose the race quite often and the following speedup can be noticed:

Without this patch: Download:  4.10 Mbit/s, Upload:  4.01 Mbit/s
With this patch:    Download: 36.23 Mbit/s, Upload: 17.61 Mbit/s
Signed-off-by: default avatarOliver Zweigle <Oliver.Zweigle@faro.com>
Signed-off-by: default avatarBernd Eckstein <3ernd.Eckstein@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 2b99bb53
...@@ -437,17 +437,18 @@ static int ipheth_tx(struct sk_buff *skb, struct net_device *net) ...@@ -437,17 +437,18 @@ static int ipheth_tx(struct sk_buff *skb, struct net_device *net)
dev); dev);
dev->tx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; dev->tx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
netif_stop_queue(net);
retval = usb_submit_urb(dev->tx_urb, GFP_ATOMIC); retval = usb_submit_urb(dev->tx_urb, GFP_ATOMIC);
if (retval) { if (retval) {
dev_err(&dev->intf->dev, "%s: usb_submit_urb: %d\n", dev_err(&dev->intf->dev, "%s: usb_submit_urb: %d\n",
__func__, retval); __func__, retval);
dev->net->stats.tx_errors++; dev->net->stats.tx_errors++;
dev_kfree_skb_any(skb); dev_kfree_skb_any(skb);
netif_wake_queue(net);
} else { } else {
dev->net->stats.tx_packets++; dev->net->stats.tx_packets++;
dev->net->stats.tx_bytes += skb->len; dev->net->stats.tx_bytes += skb->len;
dev_consume_skb_any(skb); dev_consume_skb_any(skb);
netif_stop_queue(net);
} }
return NETDEV_TX_OK; return NETDEV_TX_OK;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment