netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	andrew+netdev@lunn.ch, horms@kernel.org,
	dan.carpenter@linaro.org, Jakub Kicinski <kuba@kernel.org>,
	willy@infradead.org, romieu@fr.zoreil.com, kuniyu@amazon.com
Subject: [PATCH net-next 5/7] eth: niu: fix calling napi_enable() in atomic context
Date: Tue, 21 Jan 2025 14:15:17 -0800	[thread overview]
Message-ID: <20250121221519.392014-6-kuba@kernel.org> (raw)
In-Reply-To: <20250121221519.392014-1-kuba@kernel.org>

napi_enable() may sleep now, take netdev_lock() before np->lock.

Fixes: 413f0271f396 ("net: protect NAPI enablement with netdev_lock()")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/dcfd56bc-de32-4b11-9e19-d8bd1543745d@stanley.mountain
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: willy@infradead.org
CC: romieu@fr.zoreil.com
CC: kuniyu@amazon.com
---
 drivers/net/ethernet/sun/niu.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/sun/niu.c b/drivers/net/ethernet/sun/niu.c
index d7459866d24c..72177fea1cfb 100644
--- a/drivers/net/ethernet/sun/niu.c
+++ b/drivers/net/ethernet/sun/niu.c
@@ -6086,7 +6086,7 @@ static void niu_enable_napi(struct niu *np)
 	int i;
 
 	for (i = 0; i < np->num_ldg; i++)
-		napi_enable(&np->ldg[i].napi);
+		napi_enable_locked(&np->ldg[i].napi);
 }
 
 static void niu_disable_napi(struct niu *np)
@@ -6116,7 +6116,9 @@ static int niu_open(struct net_device *dev)
 	if (err)
 		goto out_free_channels;
 
+	netdev_lock(dev);
 	niu_enable_napi(np);
+	netdev_unlock(dev);
 
 	spin_lock_irq(&np->lock);
 
@@ -6521,6 +6523,7 @@ static void niu_reset_task(struct work_struct *work)
 
 	niu_reset_buffers(np);
 
+	netdev_lock(np->dev);
 	spin_lock_irqsave(&np->lock, flags);
 
 	err = niu_init_hw(np);
@@ -6531,6 +6534,7 @@ static void niu_reset_task(struct work_struct *work)
 	}
 
 	spin_unlock_irqrestore(&np->lock, flags);
+	netdev_unlock(np->dev);
 }
 
 static void niu_tx_timeout(struct net_device *dev, unsigned int txqueue)
@@ -6761,7 +6765,9 @@ static int niu_change_mtu(struct net_device *dev, int new_mtu)
 
 	niu_free_channels(np);
 
+	netdev_lock(dev);
 	niu_enable_napi(np);
+	netdev_unlock(dev);
 
 	err = niu_alloc_channels(np);
 	if (err)
@@ -9937,6 +9943,7 @@ static int __maybe_unused niu_resume(struct device *dev_d)
 
 	spin_lock_irqsave(&np->lock, flags);
 
+	netdev_lock(dev);
 	err = niu_init_hw(np);
 	if (!err) {
 		np->timer.expires = jiffies + HZ;
@@ -9945,6 +9952,7 @@ static int __maybe_unused niu_resume(struct device *dev_d)
 	}
 
 	spin_unlock_irqrestore(&np->lock, flags);
+	netdev_unlock(dev);
 
 	return err;
 }
-- 
2.48.1


  parent reply	other threads:[~2025-01-21 22:15 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-21 22:15 [PATCH net-next 0/7] eth: fix calling napi_enable() in atomic context Jakub Kicinski
2025-01-21 22:15 ` [PATCH net-next 1/7] eth: tg3: " Jakub Kicinski
2025-01-21 23:06   ` Michael Chan
2025-01-21 23:49     ` Jakub Kicinski
2025-01-22  7:41   ` Michael Chan
2025-01-22 14:27     ` Jakub Kicinski
2025-01-22 23:48       ` Jakub Kicinski
2025-01-23 10:48         ` Simon Horman
2025-01-22 14:10   ` Eric Dumazet
2025-01-21 22:15 ` [PATCH net-next 2/7] eth: forcedeth: remove local wrappers for napi enable/disable Jakub Kicinski
2025-01-22  8:40   ` Zhu Logan
2025-01-22 13:46   ` Eric Dumazet
2025-01-21 22:15 ` [PATCH net-next 3/7] eth: forcedeth: fix calling napi_enable() in atomic context Jakub Kicinski
2025-01-22  8:42   ` Zhu Logan
2025-01-22 13:44   ` Eric Dumazet
2025-01-21 22:15 ` [PATCH net-next 4/7] eth: 8139too: " Jakub Kicinski
2025-01-22 14:12   ` Eric Dumazet
2025-01-21 22:15 ` Jakub Kicinski [this message]
2025-01-22 14:15   ` [PATCH net-next 5/7] eth: niu: " Eric Dumazet
2025-01-21 22:15 ` [PATCH net-next 6/7] eth: via-rhine: " Jakub Kicinski
2025-01-22 14:20   ` Eric Dumazet
2025-01-21 22:15 ` [PATCH net-next 7/7] wifi: mt76: move napi_enable() from under BH Jakub Kicinski
2025-01-22 14:25   ` Eric Dumazet
2025-01-22 14:36     ` 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=20250121221519.392014-6-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=dan.carpenter@linaro.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuniyu@amazon.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=romieu@fr.zoreil.com \
    --cc=willy@infradead.org \
    /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).