All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Hans Ulli Kroll <ulli.kroll@googlemail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org
Subject: Re: [PATCH net] net: ethernet: cortina: Locking fixes
Date: Sat, 11 May 2024 23:11:29 +0200	[thread overview]
Message-ID: <Zj_fAddoi7wqHufL@qmqm.qmqm.pl> (raw)
In-Reply-To: <20240509-gemini-ethernet-locking-v1-1-afd00a528b95@linaro.org>

On Thu, May 09, 2024 at 09:44:54AM +0200, Linus Walleij wrote:
> 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>
> ---
>  drivers/net/ethernet/cortina/gemini.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 705c3eb19cd3..d1fbadbf86d4 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c
> @@ -1107,10 +1107,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)
> @@ -1119,6 +1122,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);
>  }
>  

Looks good, though spinlock looks necessary only around the ENABLE0
rmw, as the 'if (en)' part is resetting the "triggered" flag of the
interrupt (acking earlier-ignored interrupts).

>  static void gmac_tx_irq(struct net_device *netdev, unsigned int txq_num)
> @@ -1415,15 +1420,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);
> +

This doesn't look right: one, those are different registers, two it is
an IRQ-acking write.  In this case it is important that readl() is ordered
before writel(), but the spinlock doesn't guarantee that.

> @@ -1726,10 +1735,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);

This, too, is a IRQ-acking write that doesn't seem to gain much by
running inside the spin-locked section.

Best Regards
Michał Mirosław

      parent reply	other threads:[~2024-05-11 21:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-09  7:44 [PATCH net] net: ethernet: cortina: Locking fixes Linus Walleij
2024-05-10 13:38 ` Simon Horman
2024-05-10 13:46 ` Simon Horman
2024-05-11  2:30 ` patchwork-bot+netdevbpf
2024-05-11 21:11 ` Michał Mirosław [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zj_fAddoi7wqHufL@qmqm.qmqm.pl \
    --to=mirq-linux@rere.qmqm.pl \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ulli.kroll@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.