Skip to contentSkip to conversation

ibmvnic: correctly call NAPI APIs

PATCH Applied Lijun Pan 2 participants 5 messages Apr 14, 2021

Subsystems (4)
lore
Share & tools
lore

Lijun Pan

author
#0 lore raw

cover ibmvnic: correctly call NAPI APIs

This series correct some misuse of NAPI APIs in the driver.

Lijun Pan (3):
ibmvnic: avoid calling napi_disable() twice
ibmvnic: remove duplicate napi_schedule call in do_reset function
ibmvnic: remove duplicate napi_schedule call in open function

 drivers/net/ethernet/ibm/ibmvnic.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
Signature · 1 line
2.23.0
author
#1 lore raw

PATCH 1/3 ibmvnic: avoid calling napi_disable() twice

__ibmvnic_open calls napi_disable without checking whether NAPI polling has already been disabled or not. This could cause napi_disable being called twice, which could generate deadlock. For example, the first napi_disable will spin until NAPI_STATE_SCHED is cleared by napi_complete_done, then set it again.
When napi_disable is called the second time, it will loop infinitely because no dev->poll will be running to clear NAPI_STATE_SCHED.

To prevent above scenario from happening, call ibmvnic_napi_disable() which checks if napi is disabled or not before calling napi_disable.

Fixes bfc32f297337 ("ibmvnic: Move resource initialization to its own routine")
---
 drivers/net/ethernet/ibm/ibmvnic.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/ibm/ibmvnic.c +1 -2
index 110a0d0eaabb..2d27f8aa0d4b 100644
@@ -1149,8 +1149,7 @@ static int __ibmvnic_open(struct net_device *netdev)
 
 	rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_UP);
 	if (rc) {
-		for (i = 0; i < adapter->req_rx_queues; i++)
-			napi_disable(&adapter->napi[i]);
+		ibmvnic_napi_disable(adapter);
 		release_resources(adapter);
 		return rc;
 	}
Signature · 1 line
2.23.0
author
#2 lore raw

PATCH 2/3 ibmvnic: remove duplicate napi_schedule call in do_reset function

In reply to Lijun Pan

During adapter reset, do_reset/do_hard_reset calls ibmvnic_open(), which will calls napi_schedule if previous state is VNIC_CLOSED (i.e, the reset case, and "ifconfig down" case). So there is no need for do_reset to call napi_schedule again at the end of the function though napi_schedule will neglect the request if napi is already scheduled.

Fixes ed651a10875f ("ibmvnic: Updated reset handling")
---
 drivers/net/ethernet/ibm/ibmvnic.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/net/ethernet/ibm/ibmvnic.c +1 -5
index 2d27f8aa0d4b..f4bd63216672 100644
@@ -1921,7 +1921,7 @@ static int do_reset(struct ibmvnic_adapter *adapter,
 	u64 old_num_rx_queues, old_num_tx_queues;
 	u64 old_num_rx_slots, old_num_tx_slots;
 	struct net_device *netdev = adapter->netdev;
-	int i, rc;
+	int rc;
 
 	netdev_dbg(adapter->netdev,
 		   "[S:%d FOP:%d] Reset reason %d, reset_state %d\n",
@@ -2110,10 +2110,6 @@ static int do_reset(struct ibmvnic_adapter *adapter,
 	/* refresh device's multicast list */
 	ibmvnic_set_multi(netdev);
 
-	/* kick napi */
-	for (i = 0; i < adapter->req_rx_queues; i++)
-		napi_schedule(&adapter->napi[i]);
-
 	if (adapter->reset_reason == VNIC_RESET_FAILOVER ||
 	    adapter->reset_reason == VNIC_RESET_MOBILITY)
 		__netdev_notify_peers(netdev);
Signature · 1 line
2.23.0
author
#3 lore raw

PATCH 3/3 ibmvnic: remove duplicate napi_schedule call in open function

In reply to Lijun Pan

Remove the unnecessary napi_schedule() call in __ibmvnic_open() since interrupt_rx() calls napi_schedule_prep/__napi_schedule during every receive interrupt.

Fixes ed651a10875f ("ibmvnic: Updated reset handling")
---
 drivers/net/ethernet/ibm/ibmvnic.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/net/ethernet/ibm/ibmvnic.c +0 -5
index f4bd63216672..ffb2a91750c7 100644
@@ -1156,11 +1156,6 @@ static int __ibmvnic_open(struct net_device *netdev)
 
 	netif_tx_start_all_queues(netdev);
 
-	if (prev_state == VNIC_CLOSED) {
-		for (i = 0; i < adapter->req_rx_queues; i++)
-			napi_schedule(&adapter->napi[i]);
-	}
-
 	adapter->state = VNIC_OPEN;
 	return rc;
 }
Signature · 1 line
2.23.0
#4 lore raw
In reply to Lijun Pan
This series was applied to netdev/net.git (refs/heads/master):

Hello:

This series was applied to netdev/net.git (refs/heads/master):

Quoted 8 lines · On Wed, 14 Apr 2021 02:46:13 -0500 you wrote:

This series correct some misuse of NAPI APIs in the driver.

Lijun Pan (3):
ibmvnic: avoid calling napi_disable() twice
ibmvnic: remove duplicate napi_schedule call in do_reset function
ibmvnic: remove duplicate napi_schedule call in open function

[...]

Here is the summary with links:
- [net,1/3] ibmvnic: avoid calling napi_disable() twice

    https://git.kernel.org/netdev/net/c/0775ebc4cf85
  - [net,2/3] ibmvnic: remove duplicate napi_schedule call in do_reset function
    https://git.kernel.org/netdev/net/c/d3a6abccbd27
  - [net,3/3] ibmvnic: remove duplicate napi_schedule call in open function
    https://git.kernel.org/netdev/net/c/7c451f3ef676

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html