netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH net-next 0/3] lockless version of
@ 2020-12-06  5:21 Lijun Pan
  2020-12-06  5:21 ` [RFC PATCH net-next 1/3] net: core: introduce netdev_notify_peers_locked Lijun Pan
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Lijun Pan @ 2020-12-06  5:21 UTC (permalink / raw)
  To: netdev; +Cc: Lijun Pan

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

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

 drivers/net/ethernet/ibm/ibmvnic.c |  9 +++------
 drivers/net/hyperv/netvsc_drv.c    |  6 +++---
 include/linux/netdevice.h          |  1 +
 net/core/dev.c                     | 19 +++++++++++++++++++
 4 files changed, 26 insertions(+), 9 deletions(-)

-- 
2.23.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [RFC PATCH net-next 1/3] net: core: introduce netdev_notify_peers_locked
  2020-12-06  5:21 [RFC PATCH net-next 0/3] lockless version of Lijun Pan
@ 2020-12-06  5:21 ` Lijun Pan
  2020-12-08 23:49   ` Jakub Kicinski
  2020-12-06  5:21 ` [RFC PATCH net-next 2/3] use netdev_notify_peers_locked in ibmvnic Lijun Pan
  2020-12-06  5:21 ` [RFC PATCH net-next 3/3] use netdev_notify_peers_locked in hyperv Lijun Pan
  2 siblings, 1 reply; 5+ messages in thread
From: Lijun Pan @ 2020-12-06  5:21 UTC (permalink / raw)
  To: netdev; +Cc: Lijun Pan, Nathan Lynch

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);

Suggested-by: Nathan Lynch <nathanl@linux.ibm.com>
Signed-off-by: Lijun Pan <ljp@linux.ibm.com>
---
 include/linux/netdevice.h |  1 +
 net/core/dev.c            | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 964b494b0e8d..dec16d462672 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -4492,6 +4492,7 @@ 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_locked(struct net_device *dev);
 void netdev_features_change(struct net_device *dev);
 /* Load a device via the kmod */
 void dev_load(struct net *net, const char *name);
diff --git a/net/core/dev.c b/net/core/dev.c
index 82dc6b48e45f..20c1ab886222 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1488,6 +1488,25 @@ void netdev_notify_peers(struct net_device *dev)
 }
 EXPORT_SYMBOL(netdev_notify_peers);
 
+/**
+ * netdev_notify_peers_locked - notify network peers about existence of @dev,
+ * to be called in the context 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_locked(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_locked);
+
 static int __dev_open(struct net_device *dev, struct netlink_ext_ack *extack)
 {
 	const struct net_device_ops *ops = dev->netdev_ops;
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC PATCH net-next 2/3] use netdev_notify_peers_locked in ibmvnic
  2020-12-06  5:21 [RFC PATCH net-next 0/3] lockless version of Lijun Pan
  2020-12-06  5:21 ` [RFC PATCH net-next 1/3] net: core: introduce netdev_notify_peers_locked Lijun Pan
@ 2020-12-06  5:21 ` Lijun Pan
  2020-12-06  5:21 ` [RFC PATCH net-next 3/3] use netdev_notify_peers_locked in hyperv Lijun Pan
  2 siblings, 0 replies; 5+ messages in thread
From: Lijun Pan @ 2020-12-06  5:21 UTC (permalink / raw)
  To: netdev; +Cc: Lijun Pan

Start to use the lockless version of netdev_notify_peers.

Signed-off-by: Lijun Pan <ljp@linux.ibm.com>
---
 drivers/net/ethernet/ibm/ibmvnic.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index df589ad6f271..25d610ab93bc 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -2075,10 +2075,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_locked(netdev);
 
 	rc = 0;
 
@@ -2148,8 +2146,7 @@ static int do_hard_reset(struct ibmvnic_adapter *adapter,
 	if (rc)
 		return IBMVNIC_OPEN_FAILED;
 
-	call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, netdev);
-	call_netdevice_notifiers(NETDEV_RESEND_IGMP, netdev);
+	netdev_notify_peers_locked(netdev);
 
 	return 0;
 }
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC PATCH net-next 3/3] use netdev_notify_peers_locked in hyperv
  2020-12-06  5:21 [RFC PATCH net-next 0/3] lockless version of Lijun Pan
  2020-12-06  5:21 ` [RFC PATCH net-next 1/3] net: core: introduce netdev_notify_peers_locked Lijun Pan
  2020-12-06  5:21 ` [RFC PATCH net-next 2/3] use netdev_notify_peers_locked in ibmvnic Lijun Pan
@ 2020-12-06  5:21 ` Lijun Pan
  2 siblings, 0 replies; 5+ messages in thread
From: Lijun Pan @ 2020-12-06  5:21 UTC (permalink / raw)
  To: netdev; +Cc: Lijun Pan, Haiyang Zhang

Start to use the lockless version of netdev_notify_peers.

Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Lijun Pan <ljp@linux.ibm.com>
---
 drivers/net/hyperv/netvsc_drv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 261e6e55a907..5483ad697d19 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -2129,10 +2129,10 @@ static void netvsc_link_change(struct work_struct *w)
 		break;
 	}
 
-	rtnl_unlock();
-
 	if (notify)
-		netdev_notify_peers(net);
+		netdev_notify_peers_locked(net);
+
+	rtnl_unlock();
 
 	/* link_watch only sends one notification with current state per
 	 * second, handle next reconfig event in 2 seconds.
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [RFC PATCH net-next 1/3] net: core: introduce netdev_notify_peers_locked
  2020-12-06  5:21 ` [RFC PATCH net-next 1/3] net: core: introduce netdev_notify_peers_locked Lijun Pan
@ 2020-12-08 23:49   ` Jakub Kicinski
  0 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2020-12-08 23:49 UTC (permalink / raw)
  To: Lijun Pan; +Cc: netdev, Nathan Lynch

On Sat,  5 Dec 2020 23:21:25 -0600 Lijun Pan wrote:
> 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);
> 
> Suggested-by: Nathan Lynch <nathanl@linux.ibm.com>
> Signed-off-by: Lijun Pan <ljp@linux.ibm.com>

> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -1488,6 +1488,25 @@ void netdev_notify_peers(struct net_device *dev)
>  }
>  EXPORT_SYMBOL(netdev_notify_peers);

Why not convert netdev_notify_peers to call the new helper?
That way the chance they will get out of sync is way smaller.

> +/**
> + * netdev_notify_peers_locked - notify network peers about existence of @dev,
> + * to be called in the context 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_locked(struct net_device *dev)

I think __netdev_notify_peers() would be a more typical name for
a core kernel function like this.

> +{
> +	ASSERT_RTNL();
> +	call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, dev);
> +	call_netdevice_notifiers(NETDEV_RESEND_IGMP, dev);
> +}
> +EXPORT_SYMBOL(netdev_notify_peers_locked);

Otherwise LGTM, seems like a good cleanup.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-12-08 23:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-06  5:21 [RFC PATCH net-next 0/3] lockless version of Lijun Pan
2020-12-06  5:21 ` [RFC PATCH net-next 1/3] net: core: introduce netdev_notify_peers_locked Lijun Pan
2020-12-08 23:49   ` Jakub Kicinski
2020-12-06  5:21 ` [RFC PATCH net-next 2/3] use netdev_notify_peers_locked in ibmvnic Lijun Pan
2020-12-06  5:21 ` [RFC PATCH net-next 3/3] use netdev_notify_peers_locked in hyperv Lijun Pan

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).