Michal Suchanek 3c95b4
From 7061eb8cfa902daa1ec71d23b5cddb8b4391e72b Mon Sep 17 00:00:00 2001
Michal Suchanek 3c95b4
From: Lijun Pan <ljp@linux.ibm.com>
Michal Suchanek 3c95b4
Date: Mon, 14 Dec 2020 15:19:28 -0600
Michal Suchanek 3c95b4
Subject: [PATCH] net: core: introduce __netdev_notify_peers
Michal Suchanek 3c95b4
Michal Suchanek 3c95b4
References: bsc#1184114 ltc#192237 bsc#1183871 ltc#192139
Michal Suchanek 3c95b4
Patch-mainline: v5.11-rc1
Michal Suchanek 3c95b4
Git-commit: 7061eb8cfa902daa1ec71d23b5cddb8b4391e72b
Michal Suchanek 3c95b4
Michal Suchanek 3c95b4
There are some use cases for netdev_notify_peers in the context
Michal Suchanek 3c95b4
when rtnl lock is already held. Introduce lockless version
Michal Suchanek 3c95b4
of netdev_notify_peers call to save the extra code to call
Michal Suchanek 3c95b4
	call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, dev);
Michal Suchanek 3c95b4
	call_netdevice_notifiers(NETDEV_RESEND_IGMP, dev);
Michal Suchanek 3c95b4
After that, convert netdev_notify_peers to call the new helper.
Michal Suchanek 3c95b4
Michal Suchanek 3c95b4
Suggested-by: Nathan Lynch <nathanl@linux.ibm.com>
Michal Suchanek 3c95b4
Signed-off-by: Lijun Pan <ljp@linux.ibm.com>
Michal Suchanek 3c95b4
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Michal Suchanek 3c95b4
Acked-by: Michal Suchanek <msuchanek@suse.de>
Michal Suchanek 3c95b4
---
Michal Suchanek 3c95b4
 include/linux/netdevice.h |  1 +
Michal Suchanek 3c95b4
 net/core/dev.c            | 22 ++++++++++++++++++++--
Michal Suchanek 3c95b4
 2 files changed, 21 insertions(+), 2 deletions(-)
Michal Suchanek 3c95b4
Michal Suchanek 3c95b4
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
Michal Suchanek 3c95b4
index 7bf167993c05..259be67644e3 100644
Michal Suchanek 3c95b4
--- a/include/linux/netdevice.h
Michal Suchanek 3c95b4
+++ b/include/linux/netdevice.h
Michal Suchanek 3c95b4
@@ -4547,6 +4547,7 @@ void __dev_set_rx_mode(struct net_device *dev);
Michal Suchanek 3c95b4
 int dev_set_promiscuity(struct net_device *dev, int inc);
Michal Suchanek 3c95b4
 int dev_set_allmulti(struct net_device *dev, int inc);
Michal Suchanek 3c95b4
 void netdev_state_change(struct net_device *dev);
Michal Suchanek 3c95b4
+void __netdev_notify_peers(struct net_device *dev);
Michal Suchanek 3c95b4
 void netdev_notify_peers(struct net_device *dev);
Michal Suchanek 3c95b4
 void netdev_features_change(struct net_device *dev);
Michal Suchanek 3c95b4
 /* Load a device via the kmod */
Michal Suchanek 3c95b4
diff --git a/net/core/dev.c b/net/core/dev.c
Michal Suchanek 3c95b4
index a46334906c94..8fa739259041 100644
Michal Suchanek 3c95b4
--- a/net/core/dev.c
Michal Suchanek 3c95b4
+++ b/net/core/dev.c
Michal Suchanek 3c95b4
@@ -1456,6 +1456,25 @@ void netdev_state_change(struct net_device *dev)
Michal Suchanek 3c95b4
 }
Michal Suchanek 3c95b4
 EXPORT_SYMBOL(netdev_state_change);
Michal Suchanek 3c95b4
 
Michal Suchanek 3c95b4
+/**
Michal Suchanek 3c95b4
+ * __netdev_notify_peers - notify network peers about existence of @dev,
Michal Suchanek 3c95b4
+ * to be called when rtnl lock is already held.
Michal Suchanek 3c95b4
+ * @dev: network device
Michal Suchanek 3c95b4
+ *
Michal Suchanek 3c95b4
+ * Generate traffic such that interested network peers are aware of
Michal Suchanek 3c95b4
+ * @dev, such as by generating a gratuitous ARP. This may be used when
Michal Suchanek 3c95b4
+ * a device wants to inform the rest of the network about some sort of
Michal Suchanek 3c95b4
+ * reconfiguration such as a failover event or virtual machine
Michal Suchanek 3c95b4
+ * migration.
Michal Suchanek 3c95b4
+ */
Michal Suchanek 3c95b4
+void __netdev_notify_peers(struct net_device *dev)
Michal Suchanek 3c95b4
+{
Michal Suchanek 3c95b4
+	ASSERT_RTNL();
Michal Suchanek 3c95b4
+	call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, dev);
Michal Suchanek 3c95b4
+	call_netdevice_notifiers(NETDEV_RESEND_IGMP, dev);
Michal Suchanek 3c95b4
+}
Michal Suchanek 3c95b4
+EXPORT_SYMBOL(__netdev_notify_peers);
Michal Suchanek 3c95b4
+
Michal Suchanek 3c95b4
 /**
Michal Suchanek 3c95b4
  * netdev_notify_peers - notify network peers about existence of @dev
Michal Suchanek 3c95b4
  * @dev: network device
Michal Suchanek 3c95b4
@@ -1469,8 +1488,7 @@ EXPORT_SYMBOL(netdev_state_change);
Michal Suchanek 3c95b4
 void netdev_notify_peers(struct net_device *dev)
Michal Suchanek 3c95b4
 {
Michal Suchanek 3c95b4
 	rtnl_lock();
Michal Suchanek 3c95b4
-	call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, dev);
Michal Suchanek 3c95b4
-	call_netdevice_notifiers(NETDEV_RESEND_IGMP, dev);
Michal Suchanek 3c95b4
+	__netdev_notify_peers(dev);
Michal Suchanek 3c95b4
 	rtnl_unlock();
Michal Suchanek 3c95b4
 }
Michal Suchanek 3c95b4
 EXPORT_SYMBOL(netdev_notify_peers);
Michal Suchanek 3c95b4
-- 
Michal Suchanek 3c95b4
2.26.2
Michal Suchanek 3c95b4