netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Francois Romieu <romieu@fr.zoreil.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: davem@davemloft.net, netdev@vger.kernel.org, edumazet@google.com,
	pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org,
	dan.carpenter@linaro.org, kuniyu@amazon.com
Subject: Re: [PATCH net v2 4/7] eth: 8139too: fix calling napi_enable() in atomic context
Date: Thu, 23 Jan 2025 23:48:35 +0100	[thread overview]
Message-ID: <20250123224835.GA2034432@electric-eye.fr.zoreil.com> (raw)
In-Reply-To: <20250123004520.806855-5-kuba@kernel.org>

Jakub Kicinski <kuba@kernel.org> :
> napi_enable() may sleep now, take netdev_lock() before tp->lock and
> tp->rx_lock.
[...]
> diff --git a/drivers/net/ethernet/realtek/8139too.c b/drivers/net/ethernet/realtek/8139too.c
> index 9ce0e8a64ba8..a73dcaffa8c5 100644
> --- a/drivers/net/ethernet/realtek/8139too.c
> +++ b/drivers/net/ethernet/realtek/8139too.c
> @@ -1684,6 +1684,7 @@ static void rtl8139_tx_timeout_task (struct work_struct *work)
>  	if (tmp8 & CmdTxEnb)
>  		RTL_W8 (ChipCmd, CmdRxEnb);
>  
> +	netdev_lock(dev);
>  	spin_lock_bh(&tp->rx_lock);
>  	/* Disable interrupts by clearing the interrupt mask. */
>  	RTL_W16 (IntrMask, 0x0000);
> @@ -1694,11 +1695,12 @@ static void rtl8139_tx_timeout_task (struct work_struct *work)
>  	spin_unlock_irq(&tp->lock);
>  
>  	/* ...and finally, reset everything */
> -	napi_enable(&tp->napi);
> +	napi_enable_locked(&tp->napi);
>  	rtl8139_hw_start(dev);
>  	netif_wake_queue(dev);
>  
>  	spin_unlock_bh(&tp->rx_lock);
> +	netdev_unlock(dev);
>  }

I wonder why the old-style napi_enable could not be moved right before
spin_lock_bh(&tp->rx_lock) above.

/me checks...

The napi poll handler of the driver only does Rx processing. Tx completion
is performed in the IRQ handler [*]. rtl8139_tx_timeout_task is only triggered
after Tx timeout. The bh locked section above provides exclusion against the
whole content of the napi poll handler 

If a request for the napi poll handler is instantly racing with the timeout
task right before spin_lock_bh(&tp->rx_lock) ... CmdTxEnb may be enabled early
in rtl8139_rx_err. :o(

RTL_W8(ChipCmd, CmdRxEnb) above is PCI posted and thus already racy wrt
CmdTxEnb but simply moving napi_enable can't be formally claimed to be
safe. Too bad.

Acked-by: Francois Romieu <romieu@fr.zoreil.com>

[*] Not that uncommon pre subprime crisis napi design style btw.

-- 
Ueimor

  reply	other threads:[~2025-01-23 22:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-23  0:45 [PATCH net v2 0/7] eth: fix calling napi_enable() in atomic context Jakub Kicinski
2025-01-23  0:45 ` [PATCH net v2 1/7] eth: tg3: " Jakub Kicinski
2025-01-23  7:23   ` Michael Chan
2025-01-23  0:45 ` [PATCH net v2 2/7] eth: forcedeth: remove local wrappers for napi enable/disable Jakub Kicinski
2025-01-23  0:45 ` [PATCH net v2 3/7] eth: forcedeth: fix calling napi_enable() in atomic context Jakub Kicinski
2025-01-23  0:45 ` [PATCH net v2 4/7] eth: 8139too: " Jakub Kicinski
2025-01-23 22:48   ` Francois Romieu [this message]
2025-01-23  0:45 ` [PATCH net v2 5/7] eth: niu: " Jakub Kicinski
2025-01-23  0:45 ` [PATCH net v2 6/7] eth: via-rhine: " Jakub Kicinski
2025-01-23  8:35   ` Eric Dumazet
2025-01-23  0:45 ` [PATCH net v2 7/7] wifi: mt76: move napi_enable() from under BH Jakub Kicinski

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=20250123224835.GA2034432@electric-eye.fr.zoreil.com \
    --to=romieu@fr.zoreil.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=dan.carpenter@linaro.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@amazon.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).