Skip to contentSkip to conversation

lockless version of netdev_notify_peers

PATCH Applied Lijun Pan 3 participants 6 messages Dec 14, 2020 – Dec 16, 2020

Subsystems (5)
lore
Share & tools
lore

Lijun Pan

author
#0 lore raw

v2 cover lockless version of netdev_notify_peers

This series introduce the lockless version of netdev_notify_peers and then apply it to the relevant drivers.

In v1, a more appropriate name __netdev_notify_peers is used; netdev_notify_peers is converted to call the new helper. In v2, patch 3 calls the new helper where notify variable used to be set true.

Lijun Pan (3):
net: core: introduce __netdev_notify_peers
use __netdev_notify_peers in ibmvnic
use __netdev_notify_peers in hyperv

 drivers/net/ethernet/ibm/ibmvnic.c |  9 +++------
 drivers/net/hyperv/netvsc_drv.c    | 11 ++++-------
 include/linux/netdevice.h          |  1 +
 net/core/dev.c                     | 22 ++++++++++++++++++++--
 4 files changed, 28 insertions(+), 15 deletions(-)
Signature · 1 line
2.23.0
author
#1 lore raw

PATCH v2 1/3 net: core: introduce __netdev_notify_peers

There are some use cases for netdev_notify_peers in the context when rtnl lock is already held. Introduce lockless version of netdev_notify_peers call to save the extra code to call

	call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, dev);
	call_netdevice_notifiers(NETDEV_RESEND_IGMP, dev);

After that, convert netdev_notify_peers to call the new helper.

---
 include/linux/netdevice.h |  1 +
 net/core/dev.c            | 22 ++++++++++++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)
include/linux/netdevice.h +1 -0
index 7bf167993c05..259be67644e3 100644
@@ -4547,6 +4547,7 @@ void __dev_set_rx_mode(struct net_device *dev);
 int dev_set_promiscuity(struct net_device *dev, int inc);
 int dev_set_allmulti(struct net_device *dev, int inc);
 void netdev_state_change(struct net_device *dev);
+void __netdev_notify_peers(struct net_device *dev);
 void netdev_notify_peers(struct net_device *dev);
 void netdev_features_change(struct net_device *dev);
 /* Load a device via the kmod */
net/core/dev.c +20 -2
index bde98cfd166f..43e3b176a30a 100644
@@ -1456,6 +1456,25 @@ void netdev_state_change(struct net_device *dev)
 }
 EXPORT_SYMBOL(netdev_state_change);
 
+/**
+ * __netdev_notify_peers - notify network peers about existence of @dev,
+ * to be called when rtnl lock is already held.
+ * @dev: network device
+ *
+ * Generate traffic such that interested network peers are aware of
+ * @dev, such as by generating a gratuitous ARP. This may be used when
+ * a device wants to inform the rest of the network about some sort of
+ * reconfiguration such as a failover event or virtual machine
+ * migration.
+ */
+void __netdev_notify_peers(struct net_device *dev)
+{
+	ASSERT_RTNL();
+	call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, dev);
+	call_netdevice_notifiers(NETDEV_RESEND_IGMP, dev);
+}
+EXPORT_SYMBOL(__netdev_notify_peers);
+
 /**
  * netdev_notify_peers - notify network peers about existence of @dev
  * @dev: network device
@@ -1469,8 +1488,7 @@ EXPORT_SYMBOL(netdev_state_change);
 void netdev_notify_peers(struct net_device *dev)
 {
 	rtnl_lock();
-	call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, dev);
-	call_netdevice_notifiers(NETDEV_RESEND_IGMP, dev);
+	__netdev_notify_peers(dev);
 	rtnl_unlock();
 }
 EXPORT_SYMBOL(netdev_notify_peers);
Signature · 1 line
2.23.0
author
#2 lore raw

PATCH v2 2/3 use __netdev_notify_peers in ibmvnic

In reply to Lijun Pan

Start to use the lockless version of netdev_notify_peers.

---
 drivers/net/ethernet/ibm/ibmvnic.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/net/ethernet/ibm/ibmvnic.c +3 -6
index a2191392ca4f..f302504faa8a 100644
@@ -2171,10 +2171,8 @@ static int do_reset(struct ibmvnic_adapter *adapter,
 		napi_schedule(&adapter->napi[i]);
 
 	if (adapter->reset_reason == VNIC_RESET_FAILOVER ||
-	    adapter->reset_reason == VNIC_RESET_MOBILITY) {
-		call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, netdev);
-		call_netdevice_notifiers(NETDEV_RESEND_IGMP, netdev);
-	}
+	    adapter->reset_reason == VNIC_RESET_MOBILITY)
+		__netdev_notify_peers(netdev);
 
 	rc = 0;
 
@@ -2249,8 +2247,7 @@ static int do_hard_reset(struct ibmvnic_adapter *adapter,
 		goto out;
 	}
 
-	call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, netdev);
-	call_netdevice_notifiers(NETDEV_RESEND_IGMP, netdev);
+	__netdev_notify_peers(netdev);
 out:
 	/* restore adapter state if reset failed */
 	if (rc)
Signature · 1 line
2.23.0
author
#3 lore raw

PATCH v2 3/3 use __netdev_notify_peers in hyperv

In reply to Lijun Pan

Start to use the lockless version of netdev_notify_peers. Call the helper where notify variable used to be set true. Remove the notify bool variable and sort the variables in reverse Christmas tree order.

Cc Haiyang Zhang <[email protected]>

---
v2: call the helper where notify variable used to be set true
according to Jakub's review suggestion.

 drivers/net/hyperv/netvsc_drv.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/net/hyperv/netvsc_drv.c +4 -7
index d17bbc75f5e7..f32f28311d57 100644
@@ -2050,11 +2050,11 @@ static void netvsc_link_change(struct work_struct *w)
 		container_of(w, struct net_device_context, dwork.work);
 	struct hv_device *device_obj = ndev_ctx->device_ctx;
 	struct net_device *net = hv_get_drvdata(device_obj);
+	unsigned long flags, next_reconfig, delay;
+	struct netvsc_reconfig *event = NULL;
 	struct netvsc_device *net_device;
 	struct rndis_device *rdev;
-	struct netvsc_reconfig *event = NULL;
-	bool notify = false, reschedule = false;
-	unsigned long flags, next_reconfig, delay;
+	bool reschedule = false;
 
 	/* if changes are happening, comeback later */
 	if (!rtnl_trylock()) {
@@ -2103,7 +2103,7 @@ static void netvsc_link_change(struct work_struct *w)
 			netif_carrier_on(net);
 			netvsc_tx_enable(net_device, net);
 		} else {
-			notify = true;
+			__netdev_notify_peers(net);
 		}
 		kfree(event);
 		break;
@@ -2132,9 +2132,6 @@ static void netvsc_link_change(struct work_struct *w)
 
 	rtnl_unlock();
 
-	if (notify)
-		netdev_notify_peers(net);
-
 	/* link_watch only sends one notification with current state per
 	 * second, handle next reconfig event in 2 seconds.
 	 */
Signature · 1 line
2.23.0
maintainer
#4 lore raw

Re: [PATCH net-next v2 3/3] use __netdev_notify_peers in hyperv

Quoted 10 lines · On Mon, 14 Dec 2020 15:19:30 -0600 Lijun Pan wrote:

Start to use the lockless version of netdev_notify_peers. Call the helper where notify variable used to be set true. Remove the notify bool variable and sort the variables in reverse Christmas tree order.

Cc Haiyang Zhang <[email protected]>

---
v2: call the helper where notify variable used to be set true
according to Jakub's review suggestion.

Can we get an ack for merging via net-next?

Quoted 38 lines
drivers/net/hyperv/netvsc_drv.c +4 -7
index d17bbc75f5e7..f32f28311d57 100644
@@ -2050,11 +2050,11 @@ static void netvsc_link_change(struct work_struct *w)
 		container_of(w, struct net_device_context, dwork.work);
 	struct hv_device *device_obj = ndev_ctx->device_ctx;
 	struct net_device *net = hv_get_drvdata(device_obj);
+	unsigned long flags, next_reconfig, delay;
+	struct netvsc_reconfig *event = NULL;
 	struct netvsc_device *net_device;
 	struct rndis_device *rdev;
-	struct netvsc_reconfig *event = NULL;
-	bool notify = false, reschedule = false;
-	unsigned long flags, next_reconfig, delay;
+	bool reschedule = false;
 
 	/* if changes are happening, comeback later */
 	if (!rtnl_trylock()) {
@@ -2103,7 +2103,7 @@ static void netvsc_link_change(struct work_struct *w)
 			netif_carrier_on(net);
 			netvsc_tx_enable(net_device, net);
 		} else {
-			notify = true;
+			__netdev_notify_peers(net);
 		}
 		kfree(event);
 		break;
@@ -2132,9 +2132,6 @@ static void netvsc_link_change(struct work_struct *w)
 
 	rtnl_unlock();
 
-	if (notify)
-		netdev_notify_peers(net);
-
 	/* link_watch only sends one notification with current state per
 	 * second, handle next reconfig event in 2 seconds.
 	 */
#5 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 9 lines · On Mon, 14 Dec 2020 15:19:27 -0600 you wrote:

This series introduce the lockless version of netdev_notify_peers and then apply it to the relevant drivers.

In v1, a more appropriate name __netdev_notify_peers is used; netdev_notify_peers is converted to call the new helper. In v2, patch 3 calls the new helper where notify variable used to be set true.

[...]

Here is the summary with links:
- [net-next,v2,1/3] net: core: introduce __netdev_notify_peers

    https://git.kernel.org/netdev/net/c/7061eb8cfa90
  - [net-next,v2,2/3] use __netdev_notify_peers in ibmvnic
    https://git.kernel.org/netdev/net/c/6be4666221ca
  - [net-next,v2,3/3] use __netdev_notify_peers in hyperv
    https://git.kernel.org/netdev/net/c/935d8a0a43e3

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