Skip to content

Commit 8b8e6e7

Browse files
ffainellikuba-moo
authored andcommitted
net: systemport: Add global locking for descriptor lifecycle
The descriptor list is a shared resource across all of the transmit queues, and the locking mechanism used today only protects concurrency across a given transmit queue between the transmit and reclaiming. This creates an opportunity for the SYSTEMPORT hardware to work on corrupted descriptors if we have multiple producers at once which is the case when using multiple transmit queues. This was particularly noticeable when using multiple flows/transmit queues and it showed up in interesting ways in that UDP packets would get a correct UDP header checksum being calculated over an incorrect packet length. Similarly TCP packets would get an equally correct checksum computed by the hardware over an incorrect packet length. The SYSTEMPORT hardware maintains an internal descriptor list that it re-arranges when the driver produces a new descriptor anytime it writes to the WRITE_PORT_{HI,LO} registers, there is however some delay in the hardware to re-organize its descriptors and it is possible that concurrent TX queues eventually break this internal allocation scheme to the point where the length/status part of the descriptor gets used for an incorrect data buffer. The fix is to impose a global serialization for all TX queues in the short section where we are writing to the WRITE_PORT_{HI,LO} registers which solves the corruption even with multiple concurrent TX queues being used. Fixes: 80105be ("net: systemport: add Broadcom SYSTEMPORT Ethernet MAC driver") Signed-off-by: Florian Fainelli <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 5c15b31 commit 8b8e6e7

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

drivers/net/ethernet/broadcom/bcmsysport.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,11 +1309,11 @@ static netdev_tx_t bcm_sysport_xmit(struct sk_buff *skb,
13091309
struct bcm_sysport_priv *priv = netdev_priv(dev);
13101310
struct device *kdev = &priv->pdev->dev;
13111311
struct bcm_sysport_tx_ring *ring;
1312+
unsigned long flags, desc_flags;
13121313
struct bcm_sysport_cb *cb;
13131314
struct netdev_queue *txq;
13141315
u32 len_status, addr_lo;
13151316
unsigned int skb_len;
1316-
unsigned long flags;
13171317
dma_addr_t mapping;
13181318
u16 queue;
13191319
int ret;
@@ -1373,8 +1373,10 @@ static netdev_tx_t bcm_sysport_xmit(struct sk_buff *skb,
13731373
ring->desc_count--;
13741374

13751375
/* Ports are latched, so write upper address first */
1376+
spin_lock_irqsave(&priv->desc_lock, desc_flags);
13761377
tdma_writel(priv, len_status, TDMA_WRITE_PORT_HI(ring->index));
13771378
tdma_writel(priv, addr_lo, TDMA_WRITE_PORT_LO(ring->index));
1379+
spin_unlock_irqrestore(&priv->desc_lock, desc_flags);
13781380

13791381
/* Check ring space and update SW control flow */
13801382
if (ring->desc_count == 0)
@@ -2013,6 +2015,7 @@ static int bcm_sysport_open(struct net_device *dev)
20132015
}
20142016

20152017
/* Initialize both hardware and software ring */
2018+
spin_lock_init(&priv->desc_lock);
20162019
for (i = 0; i < dev->num_tx_queues; i++) {
20172020
ret = bcm_sysport_init_tx_ring(priv, i);
20182021
if (ret) {

drivers/net/ethernet/broadcom/bcmsysport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ struct bcm_sysport_priv {
711711
int wol_irq;
712712

713713
/* Transmit rings */
714+
spinlock_t desc_lock;
714715
struct bcm_sysport_tx_ring *tx_rings;
715716

716717
/* Receive queue */

0 commit comments

Comments
 (0)