]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: ethernet: cortina: Locking fixes
authorLinus Walleij <linus.walleij@linaro.org>
Thu, 9 May 2024 07:44:54 +0000 (09:44 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 16 Jun 2024 11:39:25 +0000 (13:39 +0200)
[ Upstream commit 812552808f7ff71133fc59768cdc253c5b8ca1bf ]

This fixes a probably long standing problem in the Cortina
Gemini ethernet driver: there are some paths in the code
where the IRQ registers are written without taking the proper
locks.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20240509-gemini-ethernet-locking-v1-1-afd00a528b95@linaro.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/cortina/gemini.c

index 675c6dda45e248d9d85dda6b1a2ae1c146c23950..0c8c92ff7704f34ebc6423a13715c6658e5ca14d 100644 (file)
@@ -1108,10 +1108,13 @@ static void gmac_tx_irq_enable(struct net_device *netdev,
 {
        struct gemini_ethernet_port *port = netdev_priv(netdev);
        struct gemini_ethernet *geth = port->geth;
+       unsigned long flags;
        u32 val, mask;
 
        netdev_dbg(netdev, "%s device %d\n", __func__, netdev->dev_id);
 
+       spin_lock_irqsave(&geth->irq_lock, flags);
+
        mask = GMAC0_IRQ0_TXQ0_INTS << (6 * netdev->dev_id + txq);
 
        if (en)
@@ -1120,6 +1123,8 @@ static void gmac_tx_irq_enable(struct net_device *netdev,
        val = readl(geth->base + GLOBAL_INTERRUPT_ENABLE_0_REG);
        val = en ? val | mask : val & ~mask;
        writel(val, geth->base + GLOBAL_INTERRUPT_ENABLE_0_REG);
+
+       spin_unlock_irqrestore(&geth->irq_lock, flags);
 }
 
 static void gmac_tx_irq(struct net_device *netdev, unsigned int txq_num)
@@ -1426,15 +1431,19 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget)
        union gmac_rxdesc_3 word3;
        struct page *page = NULL;
        unsigned int page_offs;
+       unsigned long flags;
        unsigned short r, w;
        union dma_rwptr rw;
        dma_addr_t mapping;
        int frag_nr = 0;
 
+       spin_lock_irqsave(&geth->irq_lock, flags);
        rw.bits32 = readl(ptr_reg);
        /* Reset interrupt as all packages until here are taken into account */
        writel(DEFAULT_Q0_INT_BIT << netdev->dev_id,
               geth->base + GLOBAL_INTERRUPT_STATUS_1_REG);
+       spin_unlock_irqrestore(&geth->irq_lock, flags);
+
        r = rw.bits.rptr;
        w = rw.bits.wptr;
 
@@ -1737,10 +1746,9 @@ static irqreturn_t gmac_irq(int irq, void *data)
                gmac_update_hw_stats(netdev);
 
        if (val & (GMAC0_RX_OVERRUN_INT_BIT << (netdev->dev_id * 8))) {
+               spin_lock(&geth->irq_lock);
                writel(GMAC0_RXDERR_INT_BIT << (netdev->dev_id * 8),
                       geth->base + GLOBAL_INTERRUPT_STATUS_4_REG);
-
-               spin_lock(&geth->irq_lock);
                u64_stats_update_begin(&port->ir_stats_syncp);
                ++port->stats.rx_fifo_errors;
                u64_stats_update_end(&port->ir_stats_syncp);