Skip to contentSkip to conversation

ipv4: fib: Allow modules to dump FIB tables

PATCH Superseded Jiri Pirko 4 participants 27 messages Nov 30, 2016 – Dec 2, 2016

Subsystems (6)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jiri Pirko

author maintainer
#0 lore raw

v3 cover ipv4: fib: Allow modules to dump FIB tables

From: Jiri Pirko <[email protected]>

Ido says:

In kernel 4.9 the switchdev-specific FIB offload mechanism was replaced by a new FIB notification chain to which modules could register in order to be notified about the addition and deletion of FIB entries. The motivation for this change was that switchdev drivers need to be able to reflect the entire FIB table and not only FIBs configured on top of the port netdevs themselves. This is useful in case of in-band management.

The fundamental problem with this approach is that upon registration listeners lose all the information previously sent in the chain and thus have an incomplete view of the FIB tables, which can result in packet loss. This patchset fixes that by introducing a new API to dump the FIB tables.

The entire dump process is done under RCU and thus the FIB notification chain is converted to be atomic. The listeners are modified accordingly. This is done in the first seven patches.

The eighth and ninth patches add a change sequence counter to ensure the integrity of the FIB dump and a sysctl to set the number of retries, respectively. The tenth patch finally introduces the FIB dump itself.

The last two patches modify current listeners of the FIB notification chain to invoke the dump during their init.

v2->v3:
- Add sysctl to set the number of FIB dump retries
(Hannes Frederic Sowa).
- Read the sequence counter under RTNL to ensure synchronization between the dump process and other processes changing the routing tables (Hannes Frederic Sowa).
- Pass a callback to the dump function to be executed prior to a retry.
- Limit the dump to a single net namespace.

v1->v2:
- Add a sequence counter to ensure the integrity of the FIB dump (David S. Miller, Hannes Frederic Sowa).
- Protect notifications from re-ordering in listeners by using an ordered workqueue (Hannes Frederic Sowa).
- Introduce fib_info_hold() (Jiri Pirko).
- Relieve rocker from the need to invoke the FIB dump by registering to the FIB notification chain prior to ports creation.

Ido Schimmel (12):
ipv4: fib: Export free_fib_info()
ipv4: fib: Add fib_info_hold() helper
mlxsw: core: Create an ordered workqueue for FIB offload
mlxsw: spectrum_router: Implement FIB offload in deferred work
rocker: Create an ordered workqueue for FIB offload
rocker: Implement FIB offload in deferred work
ipv4: fib: Convert FIB notification chain to be atomic
ipv4: fib: Allow for consistent FIB dumping
ipv4: fib: Add sysctl to limit number of FIB dump retries
ipv4: fib: Add an API to request a FIB dump
mlxsw: spectrum_router: Request a dump of FIB tables during init
rocker: Register FIB notifier before creating ports

 Documentation/networking/ip-sysctl.txt             |   8 ++
 drivers/net/ethernet/mellanox/mlxsw/core.c         |  22 +++
 drivers/net/ethernet/mellanox/mlxsw/core.h         |   2 +
 .../net/ethernet/mellanox/mlxsw/spectrum_router.c  |  95 +++++++++++--
 drivers/net/ethernet/rocker/rocker.h               |   1 +
 drivers/net/ethernet/rocker/rocker_main.c          |  78 +++++++++--
 drivers/net/ethernet/rocker/rocker_ofdpa.c         |   1 +
 include/net/ip_fib.h                               |   9 ++
 include/net/netns/ipv4.h                           |   4 +
 net/ipv4/fib_frontend.c                            |   3 +
 net/ipv4/fib_semantics.c                           |   1 +
 net/ipv4/fib_trie.c                                | 147 ++++++++++++++++++++-
 net/ipv4/sysctl_net_ipv4.c                         |   7 +
 13 files changed, 352 insertions(+), 26 deletions(-)
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH v3 1/12 ipv4: fib: Export free_fib_info()

From: Ido Schimmel <[email protected]>

The FIB notification chain is going to be converted to an atomic chain, which means switchdev drivers will have to offload FIB entries in deferred work, as hardware operations entail sleeping.

However, while the work is queued fib info might be freed, so a reference must be taken. To release the reference (and potentially free the fib info) fib_info_put() will be called, which in turn calls free_fib_info().

Export free_fib_info() so that modules will be able to invoke fib_info_put().

---
 net/ipv4/fib_semantics.c | 1 +
 1 file changed, 1 insertion(+)
net/ipv4/fib_semantics.c +1 -0
index 388d3e2..c1bc1e9 100644
@@ -234,6 +234,7 @@ void free_fib_info(struct fib_info *fi)
 #endif
 	call_rcu(&fi->rcu, free_fib_info_rcu);
 }
+EXPORT_SYMBOL_GPL(free_fib_info);
 
 void fib_release_info(struct fib_info *fi)
 {
Signature · 1 line
2.7.4
author maintainer
#2 lore raw

PATCH v3 2/12 ipv4: fib: Add fib_info_hold() helper

In reply to Jiri Pirko

From: Ido Schimmel <[email protected]>

As explained in the previous commit, modules are going to need to take a reference on fib info and then drop it using fib_info_put().

Add the fib_info_hold() helper to make the code more readable and also symmetric with fib_info_put().

---
 include/net/ip_fib.h | 5 +++++
 1 file changed, 5 insertions(+)
include/net/ip_fib.h +5 -0
index f390c3b..6c67b93 100644
@@ -397,6 +397,11 @@ static inline void fib_combine_itag(u32 *itag, const struct fib_result *res)
 
 void free_fib_info(struct fib_info *fi);
 
+static inline void fib_info_hold(struct fib_info *fi)
+{
+	atomic_inc(&fi->fib_clntref);
+}
+
 static inline void fib_info_put(struct fib_info *fi)
 {
 	if (atomic_dec_and_test(&fi->fib_clntref))
Signature · 1 line
2.7.4
author maintainer
#3 lore raw

PATCH v3 3/12 mlxsw: core: Create an ordered workqueue for FIB offload

In reply to Jiri Pirko

From: Ido Schimmel <[email protected]>

We're going to start processing FIB entries addition / deletion events in deferred work. These work items must be processed in the order they were submitted or otherwise we can have differences between the kernel's FIB table and the device's.

Solve this by creating an ordered workqueue to which these work items will be submitted to. Note that we can't simply convert the current workqueue to be ordered, as EMADs re-transmissions are also processed in deferred work.

Later on, we can migrate other work items to this workqueue, such as FDB notification processing and nexthop resolution, since they all take the same lock anyway.

---
 drivers/net/ethernet/mellanox/mlxsw/core.c | 22 ++++++++++++++++++++++
 drivers/net/ethernet/mellanox/mlxsw/core.h |  2 ++
 2 files changed, 24 insertions(+)
drivers/net/ethernet/mellanox/mlxsw/core.c +22 -0
index 4dc028b..57a9884 100644
@@ -77,6 +77,7 @@ static const char mlxsw_core_driver_name[] = "mlxsw_core";
 static struct dentry *mlxsw_core_dbg_root;
 
 static struct workqueue_struct *mlxsw_wq;
+static struct workqueue_struct *mlxsw_owq;
 
 struct mlxsw_core_pcpu_stats {
 	u64			trap_rx_packets[MLXSW_TRAP_ID_MAX];
@@ -1900,6 +1901,18 @@ int mlxsw_core_schedule_dw(struct delayed_work *dwork, unsigned long delay)
 }
 EXPORT_SYMBOL(mlxsw_core_schedule_dw);
 
+int mlxsw_core_schedule_odw(struct delayed_work *dwork, unsigned long delay)
+{
+	return queue_delayed_work(mlxsw_owq, dwork, delay);
+}
+EXPORT_SYMBOL(mlxsw_core_schedule_odw);
+
+void mlxsw_core_flush_owq(void)
+{
+	flush_workqueue(mlxsw_owq);
+}
+EXPORT_SYMBOL(mlxsw_core_flush_owq);
+
 static int __init mlxsw_core_module_init(void)
 {
 	int err;
@@ -1907,6 +1920,12 @@ static int __init mlxsw_core_module_init(void)
 	mlxsw_wq = alloc_workqueue(mlxsw_core_driver_name, WQ_MEM_RECLAIM, 0);
 	if (!mlxsw_wq)
 		return -ENOMEM;
+	mlxsw_owq = alloc_ordered_workqueue("%s_ordered", WQ_MEM_RECLAIM,
+					    mlxsw_core_driver_name);
+	if (!mlxsw_owq) {
+		err = -ENOMEM;
+		goto err_alloc_ordered_workqueue;
+	}
 	mlxsw_core_dbg_root = debugfs_create_dir(mlxsw_core_driver_name, NULL);
 	if (!mlxsw_core_dbg_root) {
 		err = -ENOMEM;
@@ -1915,6 +1934,8 @@ static int __init mlxsw_core_module_init(void)
 	return 0;
 
 err_debugfs_create_dir:
+	destroy_workqueue(mlxsw_owq);
+err_alloc_ordered_workqueue:
 	destroy_workqueue(mlxsw_wq);
 	return err;
 }
@@ -1922,6 +1943,7 @@ static int __init mlxsw_core_module_init(void)
 static void __exit mlxsw_core_module_exit(void)
 {
 	debugfs_remove_recursive(mlxsw_core_dbg_root);
+	destroy_workqueue(mlxsw_owq);
 	destroy_workqueue(mlxsw_wq);
 }
 
drivers/net/ethernet/mellanox/mlxsw/core.h +2 -0
index e856b49..a7f94fb 100644
@@ -207,6 +207,8 @@ enum devlink_port_type mlxsw_core_port_type_get(struct mlxsw_core *mlxsw_core,
 						u8 local_port);
 
 int mlxsw_core_schedule_dw(struct delayed_work *dwork, unsigned long delay);
+int mlxsw_core_schedule_odw(struct delayed_work *dwork, unsigned long delay);
+void mlxsw_core_flush_owq(void);
 
 #define MLXSW_CONFIG_PROFILE_SWID_COUNT 8
 
Signature · 1 line
2.7.4
author maintainer
#4 lore raw

PATCH v3 4/12 mlxsw: spectrum_router: Implement FIB offload in deferred work

In reply to Jiri Pirko

From: Ido Schimmel <[email protected]>

FIB offload is currently done in process context with RTNL held, but we're about to dump the FIB tables in RCU critical section, so we can no longer sleep.

Instead, defer the operation to process context using deferred work. Make sure fib info isn't freed while the work is queued by taking a reference on it and releasing it after the operation is done.

Deferring the operation is valid because the upper layers always assume the operation was successful. If it's not, then the driver-specific abort mechanism is called and all routed traffic is directed to slow path.

The work items are submitted to an ordered workqueue to prevent a mismatch between the kernel's FIB table and the device's.

---
 .../net/ethernet/mellanox/mlxsw/spectrum_router.c  | 72 +++++++++++++++++++---
 1 file changed, 62 insertions(+), 10 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +62 -10
index 683f045..14bed1d 100644
@@ -593,6 +593,14 @@ static void mlxsw_sp_router_fib_flush(struct mlxsw_sp *mlxsw_sp);
 
 static void mlxsw_sp_vrs_fini(struct mlxsw_sp *mlxsw_sp)
 {
+	/* At this stage we're guaranteed not to have new incoming
+	 * FIB notifications and the work queue is free from FIBs
+	 * sitting on top of mlxsw netdevs. However, we can still
+	 * have other FIBs queued. Flush the queue before flushing
+	 * the device's tables. No need for locks, as we're the only
+	 * writer.
+	 */
+	mlxsw_core_flush_owq();
 	mlxsw_sp_router_fib_flush(mlxsw_sp);
 	kfree(mlxsw_sp->router.vrs);
 }
@@ -1948,30 +1956,74 @@ static void __mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp)
 	kfree(mlxsw_sp->rifs);
 }
 
-static int mlxsw_sp_router_fib_event(struct notifier_block *nb,
-				     unsigned long event, void *ptr)
+struct mlxsw_sp_fib_event_work {
+	struct delayed_work dw;
+	struct fib_entry_notifier_info fen_info;
+	struct mlxsw_sp *mlxsw_sp;
+	unsigned long event;
+};
+
+static void mlxsw_sp_router_fib_event_work(struct work_struct *work)
 {
-	struct mlxsw_sp *mlxsw_sp = container_of(nb, struct mlxsw_sp, fib_nb);
-	struct fib_entry_notifier_info *fen_info = ptr;
+	struct mlxsw_sp_fib_event_work *fib_work =
+		container_of(work, struct mlxsw_sp_fib_event_work, dw.work);
+	struct mlxsw_sp *mlxsw_sp = fib_work->mlxsw_sp;
 	int err;
 
-	if (!net_eq(fen_info->info.net, &init_net))
-		return NOTIFY_DONE;
-
-	switch (event) {
+	/* Protect internal structures from changes */
+	rtnl_lock();
+	switch (fib_work->event) {
 	case FIB_EVENT_ENTRY_ADD:
-		err = mlxsw_sp_router_fib4_add(mlxsw_sp, fen_info);
+		err = mlxsw_sp_router_fib4_add(mlxsw_sp, &fib_work->fen_info);
 		if (err)
 			mlxsw_sp_router_fib4_abort(mlxsw_sp);
+		fib_info_put(fib_work->fen_info.fi);
 		break;
 	case FIB_EVENT_ENTRY_DEL:
-		mlxsw_sp_router_fib4_del(mlxsw_sp, fen_info);
+		mlxsw_sp_router_fib4_del(mlxsw_sp, &fib_work->fen_info);
+		fib_info_put(fib_work->fen_info.fi);
 		break;
 	case FIB_EVENT_RULE_ADD: /* fall through */
 	case FIB_EVENT_RULE_DEL:
 		mlxsw_sp_router_fib4_abort(mlxsw_sp);
 		break;
 	}
+	rtnl_unlock();
+	kfree(fib_work);
+}
+
+/* Called with rcu_read_lock() */
+static int mlxsw_sp_router_fib_event(struct notifier_block *nb,
+				     unsigned long event, void *ptr)
+{
+	struct mlxsw_sp *mlxsw_sp = container_of(nb, struct mlxsw_sp, fib_nb);
+	struct mlxsw_sp_fib_event_work *fib_work;
+	struct fib_notifier_info *info = ptr;
+
+	if (!net_eq(info->net, &init_net))
+		return NOTIFY_DONE;
+
+	fib_work = kzalloc(sizeof(*fib_work), GFP_ATOMIC);
+	if (WARN_ON(!fib_work))
+		return NOTIFY_BAD;
+
+	INIT_DELAYED_WORK(&fib_work->dw, mlxsw_sp_router_fib_event_work);
+	fib_work->mlxsw_sp = mlxsw_sp;
+	fib_work->event = event;
+
+	switch (event) {
+	case FIB_EVENT_ENTRY_ADD: /* fall through */
+	case FIB_EVENT_ENTRY_DEL:
+		memcpy(&fib_work->fen_info, ptr, sizeof(fib_work->fen_info));
+		/* Take referece on fib_info to prevent it from being
+		 * freed while work is queued. Release it afterwards.
+		 */
+		fib_info_hold(fib_work->fen_info.fi);
+		break;
+	}
+
+	mlxsw_core_schedule_odw(&fib_work->dw, 0);
+
 	return NOTIFY_DONE;
 }
 
Signature · 1 line
2.7.4
author maintainer
#5 lore raw

PATCH v3 5/12 rocker: Create an ordered workqueue for FIB offload

In reply to Jiri Pirko

From: Ido Schimmel <[email protected]>

As explained in the previous commits, we need to process FIB entries addition / deletion events in FIFO order or otherwise we can have a mismatch between the kernel's FIB table and the device's.

Create an ordered workqueue for rocker to which these work items will be submitted to.

---
 drivers/net/ethernet/rocker/rocker.h      |  1 +
 drivers/net/ethernet/rocker/rocker_main.c | 11 +++++++++++
 2 files changed, 12 insertions(+)
drivers/net/ethernet/rocker/rocker.h +1 -0
index 2eb9b49..ee9675d 100644
@@ -72,6 +72,7 @@ struct rocker {
 	struct rocker_dma_ring_info event_ring;
 	struct notifier_block fib_nb;
 	struct rocker_world_ops *wops;
+	struct workqueue_struct *rocker_owq;
 	void *wpriv;
 };
 
drivers/net/ethernet/rocker/rocker_main.c +11 -0
index 67df4cf..424be96 100644
@@ -28,6 +28,7 @@
 #include <linux/if_bridge.h>
 #include <linux/bitops.h>
 #include <linux/ctype.h>
+#include <linux/workqueue.h>
 #include <net/switchdev.h>
 #include <net/rtnetlink.h>
 #include <net/netevent.h>
@@ -2754,6 +2755,13 @@ static int rocker_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		goto err_request_event_irq;
 	}
 
+	rocker->rocker_owq = alloc_ordered_workqueue(rocker_driver_name,
+						     WQ_MEM_RECLAIM);
+	if (!rocker->rocker_owq) {
+		err = -ENOMEM;
+		goto err_alloc_ordered_workqueue;
+	}
+
 	rocker->hw.id = rocker_read64(rocker, SWITCH_ID);
 
 	err = rocker_probe_ports(rocker);
@@ -2771,6 +2779,8 @@ static int rocker_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	return 0;
 
 err_probe_ports:
+	destroy_workqueue(rocker->rocker_owq);
+err_alloc_ordered_workqueue:
 	free_irq(rocker_msix_vector(rocker, ROCKER_MSIX_VEC_EVENT), rocker);
 err_request_event_irq:
 	free_irq(rocker_msix_vector(rocker, ROCKER_MSIX_VEC_CMD), rocker);
@@ -2799,6 +2809,7 @@ static void rocker_remove(struct pci_dev *pdev)
 	unregister_fib_notifier(&rocker->fib_nb);
 	rocker_write32(rocker, CONTROL, ROCKER_CONTROL_RESET);
 	rocker_remove_ports(rocker);
+	destroy_workqueue(rocker->rocker_owq);
 	free_irq(rocker_msix_vector(rocker, ROCKER_MSIX_VEC_EVENT), rocker);
 	free_irq(rocker_msix_vector(rocker, ROCKER_MSIX_VEC_CMD), rocker);
 	rocker_dma_rings_fini(rocker);
Signature · 1 line
2.7.4
author maintainer
#6 lore raw

PATCH v3 6/12 rocker: Implement FIB offload in deferred work

In reply to Jiri Pirko

From: Ido Schimmel <[email protected]>

Convert rocker to offload FIBs in deferred work in a similar fashion to mlxsw, which was converted in the previous commits.

---
 drivers/net/ethernet/rocker/rocker_main.c  | 58 +++++++++++++++++++++++++-----
 drivers/net/ethernet/rocker/rocker_ofdpa.c |  1 +
 2 files changed, 51 insertions(+), 8 deletions(-)
drivers/net/ethernet/rocker/rocker_main.c +50 -8
index 424be96..914e9e1 100644
@@ -2166,28 +2166,70 @@ static const struct switchdev_ops rocker_port_switchdev_ops = {
 	.switchdev_port_obj_dump	= rocker_port_obj_dump,
 };
 
-static int rocker_router_fib_event(struct notifier_block *nb,
-				   unsigned long event, void *ptr)
+struct rocker_fib_event_work {
+	struct work_struct work;
+	struct fib_entry_notifier_info fen_info;
+	struct rocker *rocker;
+	unsigned long event;
+};
+
+static void rocker_router_fib_event_work(struct work_struct *work)
 {
-	struct rocker *rocker = container_of(nb, struct rocker, fib_nb);
-	struct fib_entry_notifier_info *fen_info = ptr;
+	struct rocker_fib_event_work *fib_work =
+		container_of(work, struct rocker_fib_event_work, work);
+	struct rocker *rocker = fib_work->rocker;
 	int err;
 
-	switch (event) {
+	/* Protect internal structures from changes */
+	rtnl_lock();
+	switch (fib_work->event) {
 	case FIB_EVENT_ENTRY_ADD:
-		err = rocker_world_fib4_add(rocker, fen_info);
+		err = rocker_world_fib4_add(rocker, &fib_work->fen_info);
 		if (err)
 			rocker_world_fib4_abort(rocker);
-		else
+		fib_info_put(fib_work->fen_info.fi);
 		break;
 	case FIB_EVENT_ENTRY_DEL:
-		rocker_world_fib4_del(rocker, fen_info);
+		rocker_world_fib4_del(rocker, &fib_work->fen_info);
+		fib_info_put(fib_work->fen_info.fi);
 		break;
 	case FIB_EVENT_RULE_ADD: /* fall through */
 	case FIB_EVENT_RULE_DEL:
 		rocker_world_fib4_abort(rocker);
 		break;
 	}
+	rtnl_unlock();
+	kfree(fib_work);
+}
+
+/* Called with rcu_read_lock() */
+static int rocker_router_fib_event(struct notifier_block *nb,
+				   unsigned long event, void *ptr)
+{
+	struct rocker *rocker = container_of(nb, struct rocker, fib_nb);
+	struct rocker_fib_event_work *fib_work;
+
+	fib_work = kzalloc(sizeof(*fib_work), GFP_ATOMIC);
+	if (WARN_ON(!fib_work))
+		return NOTIFY_BAD;
+
+	INIT_WORK(&fib_work->work, rocker_router_fib_event_work);
+	fib_work->rocker = rocker;
+	fib_work->event = event;
+
+	switch (event) {
+	case FIB_EVENT_ENTRY_ADD: /* fall through */
+	case FIB_EVENT_ENTRY_DEL:
+		memcpy(&fib_work->fen_info, ptr, sizeof(fib_work->fen_info));
+		/* Take referece on fib_info to prevent it from being
+		 * freed while work is queued. Release it afterwards.
+		 */
+		fib_info_hold(fib_work->fen_info.fi);
+		break;
+	}
+
+	queue_work(rocker->rocker_owq, &fib_work->work);
+
 	return NOTIFY_DONE;
 }
 
drivers/net/ethernet/rocker/rocker_ofdpa.c +1 -0
index 4ca4613..7cd76b6 100644
@@ -2516,6 +2516,7 @@ static void ofdpa_fini(struct rocker *rocker)
 	int bkt;
 
 	del_timer_sync(&ofdpa->fdb_cleanup_timer);
+	flush_workqueue(rocker->rocker_owq);
 
 	spin_lock_irqsave(&ofdpa->flow_tbl_lock, flags);
 	hash_for_each_safe(ofdpa->flow_tbl, bkt, tmp, flow_entry, entry)
Signature · 1 line
2.7.4
author maintainer
#7 lore raw

PATCH v3 7/12 ipv4: fib: Convert FIB notification chain to be atomic

In reply to Jiri Pirko

From: Ido Schimmel <[email protected]>

In order not to hold RTNL for long periods of time we're going to dump the FIB tables using RCU.

Convert the FIB notification chain to be atomic, as we can't block in RCU critical sections.

---
 net/ipv4/fib_trie.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
net/ipv4/fib_trie.c +4 -4
index 026f309..9bfce0d 100644
@@ -84,17 +84,17 @@
 #include <trace/events/fib.h>
 #include "fib_lookup.h"
 
-static BLOCKING_NOTIFIER_HEAD(fib_chain);
+static ATOMIC_NOTIFIER_HEAD(fib_chain);
 
 int register_fib_notifier(struct notifier_block *nb)
 {
-	return blocking_notifier_chain_register(&fib_chain, nb);
+	return atomic_notifier_chain_register(&fib_chain, nb);
 }
 EXPORT_SYMBOL(register_fib_notifier);
 
 int unregister_fib_notifier(struct notifier_block *nb)
 {
-	return blocking_notifier_chain_unregister(&fib_chain, nb);
+	return atomic_notifier_chain_unregister(&fib_chain, nb);
 }
 EXPORT_SYMBOL(unregister_fib_notifier);
 
@@ -102,7 +102,7 @@ int call_fib_notifiers(struct net *net, enum fib_event_type event_type,
 		       struct fib_notifier_info *info)
 {
 	info->net = net;
-	return blocking_notifier_call_chain(&fib_chain, event_type, info);
+	return atomic_notifier_call_chain(&fib_chain, event_type, info);
 }
 
 static int call_fib_entry_notifiers(struct net *net,
Signature · 1 line
2.7.4
author maintainer
#8 lore raw

PATCH v3 8/12 ipv4: fib: Allow for consistent FIB dumping

In reply to Jiri Pirko

From: Ido Schimmel <[email protected]>

The next patch will enable listeners of the FIB notification chain to request a dump of the FIB tables. However, since RTNL isn't taken during the dump, it's possible for the FIB tables to change mid-dump, which will result in inconsistency between the listener's table and the kernel's.

Allow listeners to know about changes that occurred mid-dump, by adding a change sequence counter to each net namespace. The counter is incremented just before a notification is sent in the FIB chain.

---
 include/net/netns/ipv4.h | 3 +++
 net/ipv4/fib_frontend.c  | 2 ++
 net/ipv4/fib_trie.c      | 1 +
 3 files changed, 6 insertions(+)
include/net/netns/ipv4.h +3 -0
index 7adf438..f0cf5a1 100644
@@ -135,6 +135,9 @@ struct netns_ipv4 {
 #ifdef CONFIG_IP_ROUTE_MULTIPATH
 	int sysctl_fib_multipath_use_neigh;
 #endif
+
+	unsigned int	fib_seq;	/* protected by rtnl_mutex */
+
 	atomic_t	rt_genid;
 };
 #endif
net/ipv4/fib_frontend.c +2 -0
index 121384b..dbad5a1 100644
@@ -1219,6 +1219,8 @@ static int __net_init ip_fib_net_init(struct net *net)
 	int err;
 	size_t size = sizeof(struct hlist_head) * FIB_TABLE_HASHSZ;
 
+	net->ipv4.fib_seq = 0;
+
 	/* Avoid false sharing : Use at least a full cache line */
 	size = max_t(size_t, size, L1_CACHE_BYTES);
 
net/ipv4/fib_trie.c +1 -0
index 9bfce0d..2891356 100644
@@ -101,6 +101,7 @@ EXPORT_SYMBOL(unregister_fib_notifier);
 int call_fib_notifiers(struct net *net, enum fib_event_type event_type,
 		       struct fib_notifier_info *info)
 {
+	net->ipv4.fib_seq++;
 	info->net = net;
 	return atomic_notifier_call_chain(&fib_chain, event_type, info);
 }
Signature · 1 line
2.7.4
author maintainer
#9 lore raw

PATCH v3 9/12 ipv4: fib: Add sysctl to limit number of FIB dump retries

In reply to Jiri Pirko

From: Ido Schimmel <[email protected]>

When dumping the FIB tables in the next commit, the dump will be considered invalid if notifications were sent in the FIB notification chain mid-dump. In systems where routing changes are frequent, the dump might need to be restarted multiple times.

Add sysctl to limit the number of FIB dump retries, thereby preventing callers from looping for long periods of time.

---
 Documentation/networking/ip-sysctl.txt | 8 ++++++++
 include/net/netns/ipv4.h               | 1 +
 net/ipv4/fib_frontend.c                | 1 +
 net/ipv4/sysctl_net_ipv4.c             | 7 +++++++
 4 files changed, 17 insertions(+)
Documentation/networking/ip-sysctl.txt +8 -0
index 5af48dd..5182b23 100644
@@ -73,6 +73,14 @@ fib_multipath_use_neigh - BOOLEAN
 	0 - disabled
 	1 - enabled
 
+fib_dump_max_retries - INTEGER
+	Maximum number of retries until the FIB dump is aborted. For a
+	given net namespace, a FIB dump is considered invalid if
+	notifications were sent in the FIB notification chain mid-dump.
+	The dump will be retried until it is successful or maximum
+	number of retries has been reached.
+	Default: 5
+
 route/max_size - INTEGER
 	Maximum number of routes allowed in the kernel.  Increase
 	this when using large numbers of interfaces and/or routes.
include/net/netns/ipv4.h +1 -0
index f0cf5a1..71c4ca8 100644
@@ -136,6 +136,7 @@ struct netns_ipv4 {
 	int sysctl_fib_multipath_use_neigh;
 #endif
 
+	int sysctl_fib_dump_max_retries;
 	unsigned int	fib_seq;	/* protected by rtnl_mutex */
 
 	atomic_t	rt_genid;
net/ipv4/fib_frontend.c +1 -0
index dbad5a1..43f7557 100644
@@ -1219,6 +1219,7 @@ static int __net_init ip_fib_net_init(struct net *net)
 	int err;
 	size_t size = sizeof(struct hlist_head) * FIB_TABLE_HASHSZ;
 
+	net->ipv4.sysctl_fib_dump_max_retries = 5;
 	net->ipv4.fib_seq = 0;
 
 	/* Avoid false sharing : Use at least a full cache line */
net/ipv4/sysctl_net_ipv4.c +7 -0
index 80bc36b..046147c 100644
@@ -971,6 +971,13 @@ static struct ctl_table ipv4_net_table[] = {
 		.extra2		= &one,
 	},
 #endif
+	{
+		.procname	= "fib_dump_max_retries",
+		.data		= &init_net.ipv4.sysctl_fib_dump_max_retries,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+	},
 	{ }
 };
 
Signature · 1 line
2.7.4
author maintainer
#10 lore raw

PATCH v3 10/12 ipv4: fib: Add an API to request a FIB dump

In reply to Jiri Pirko

From: Ido Schimmel <[email protected]>

Commit b90eb7549499 ("fib: introduce FIB notification infrastructure") introduced a new notification chain to notify listeners (f.e., switchdev drivers) about addition and deletion of routes.

However, upon registration to the chain the FIB tables can already be populated, which means potential listeners will have an incomplete view of the tables.

Solve that by adding an API to request a FIB dump. The dump itself it done using RCU in order not to starve consumers that need RTNL to make progress.

The integrity of the dump is ensured by reading the FIB change sequence counter before and after the dump. This allows us to avoid the problematic situation in which the dumping process sends a ENTRY_ADD notification following ENTRY_DEL generated by another process holding RTNL.

---
 include/net/ip_fib.h |   4 ++
 net/ipv4/fib_trie.c  | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 142 insertions(+)
include/net/ip_fib.h +4 -0
index 6c67b93..1388bfc 100644
@@ -221,6 +221,10 @@ enum fib_event_type {
 	FIB_EVENT_RULE_DEL,
 };
 
+typedef void fib_dump_cb_t(struct notifier_block *nb);
+
+bool fib_notifier_dump(struct notifier_block *nb, struct net *net,
+		       fib_dump_cb_t *cb);
 int register_fib_notifier(struct notifier_block *nb);
 int unregister_fib_notifier(struct notifier_block *nb);
 int call_fib_notifiers(struct net *net, enum fib_event_type event_type,
net/ipv4/fib_trie.c +138 -0

152 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#11 lore raw

PATCH v3 11/12 mlxsw: spectrum_router: Request a dump of FIB tables during init

In reply to Jiri Pirko

From: Ido Schimmel <[email protected]>

Make sure the device has a complete view of the FIB tables by invoking their dump during module init.

---
 .../net/ethernet/mellanox/mlxsw/spectrum_router.c  | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +23 -0
index 14bed1d..d176047 100644
@@ -2027,8 +2027,23 @@ static int mlxsw_sp_router_fib_event(struct notifier_block *nb,
 	return NOTIFY_DONE;
 }
 
+static void mlxsw_sp_router_fib_dump_flush(struct notifier_block *nb)
+{
+	struct mlxsw_sp *mlxsw_sp = container_of(nb, struct mlxsw_sp, fib_nb);
+
+	/* Flush pending FIB notifications and then flush the device's
+	 * table before requesting another dump. Do that with RTNL held,
+	 * as FIB notification block is already registered.
+	 */
+	mlxsw_core_flush_owq();
+	rtnl_lock();
+	mlxsw_sp_router_fib_flush(mlxsw_sp);
+	rtnl_unlock();
+}
+
 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
 {
+	fib_dump_cb_t *cb = mlxsw_sp_router_fib_dump_flush;
 	int err;
 
 	INIT_LIST_HEAD(&mlxsw_sp->router.nexthop_neighs_list);
@@ -2048,8 +2063,16 @@ int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
 
 	mlxsw_sp->fib_nb.notifier_call = mlxsw_sp_router_fib_event;
 	register_fib_notifier(&mlxsw_sp->fib_nb);
+	if (!fib_notifier_dump(&mlxsw_sp->fib_nb, &init_net, cb)) {
+		err = -EBUSY;
+		goto err_fib_notifier_dump;
+	}
+
 	return 0;
 
+err_fib_notifier_dump:
+	unregister_fib_notifier(&mlxsw_sp->fib_nb);
+	mlxsw_sp_neigh_fini(mlxsw_sp);
 err_neigh_init:
 	mlxsw_sp_vrs_fini(mlxsw_sp);
 err_vrs_init:
Signature · 1 line
2.7.4
#12 lore raw

Re: [patch net-next v3 11/12] mlxsw: spectrum_router: Request a dump of FIB tables during init

Quoted 40 lines · Jiri Pirko

From: Ido Schimmel <[email protected]>

Make sure the device has a complete view of the FIB tables by invoking their dump during module init.

---
 .../net/ethernet/mellanox/mlxsw/spectrum_router.c  | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +15 -0
index 14bed1d..d176047 100644
@@ -2027,8 +2027,23 @@ static int mlxsw_sp_router_fib_event(struct notifier_block *nb,
 	return NOTIFY_DONE;
 }
 
+static void mlxsw_sp_router_fib_dump_flush(struct notifier_block *nb)
+{
+	struct mlxsw_sp *mlxsw_sp = container_of(nb, struct mlxsw_sp, fib_nb);
+
+	/* Flush pending FIB notifications and then flush the device's
+	 * table before requesting another dump. Do that with RTNL held,
+	 * as FIB notification block is already registered.
+	 */
+	mlxsw_core_flush_owq();
+	rtnl_lock();
+	mlxsw_sp_router_fib_flush(mlxsw_sp);
+	rtnl_unlock();
+}
+
 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
 {
+	fib_dump_cb_t *cb = mlxsw_sp_router_fib_dump_flush;
 	int err;
 
 	INIT_LIST_HEAD(&mlxsw_sp->router.nexthop_neighs_list);

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp) · line 2065

Quoted 3 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +0 -0
@@ -2048,8 +2063,16 @@ int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
 
 	mlxsw_sp->fib_nb.notifier_call = mlxsw_sp_router_fib_event;
 	register_fib_notifier(&mlxsw_sp->fib_nb);

Sorry to pick in here again:

There is a race here. You need to protect the registration of the fib notifier as well by the sequence counter. Updates here are not ordered in relation to this code below.

I think just move the register notification into the fib_notifier_dump function, rename it to fib_notifier_init and use it here:

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp) · line 2071

Quoted 6 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +5 -0
+	if (!fib_notifier_dump(&mlxsw_sp->fib_nb, &init_net, cb)) {
+		err = -EBUSY;
+		goto err_fib_notifier_dump;
+	}
+
 	return 0;

Thanks,
Hannes

#13 lore raw

Re: [patch net-next v3 11/12] mlxsw: spectrum_router: Request a dump of FIB tables during init

Hi Hannes,

Quoted 42 lines · Hannes Frederic Sowa
Quoted 41 lines · Jiri Pirko

From: Ido Schimmel <[email protected]>

Make sure the device has a complete view of the FIB tables by invoking their dump during module init.

---
 .../net/ethernet/mellanox/mlxsw/spectrum_router.c  | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +15 -0
index 14bed1d..d176047 100644
@@ -2027,8 +2027,23 @@ static int mlxsw_sp_router_fib_event(struct notifier_block *nb,
 	return NOTIFY_DONE;
 }
 
+static void mlxsw_sp_router_fib_dump_flush(struct notifier_block *nb)
+{
+	struct mlxsw_sp *mlxsw_sp = container_of(nb, struct mlxsw_sp, fib_nb);
+
+	/* Flush pending FIB notifications and then flush the device's
+	 * table before requesting another dump. Do that with RTNL held,
+	 * as FIB notification block is already registered.
+	 */
+	mlxsw_core_flush_owq();
+	rtnl_lock();
+	mlxsw_sp_router_fib_flush(mlxsw_sp);
+	rtnl_unlock();
+}
+
 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
 {
+	fib_dump_cb_t *cb = mlxsw_sp_router_fib_dump_flush;
 	int err;
 
 	INIT_LIST_HEAD(&mlxsw_sp->router.nexthop_neighs_list);
@@ -2048,8 +2063,16 @@ int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
 
Quoted 8 lines

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp) · line 2065

Quoted 2 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +0 -0
 	mlxsw_sp->fib_nb.notifier_call = mlxsw_sp_router_fib_event;
 	register_fib_notifier(&mlxsw_sp->fib_nb);

Sorry to pick in here again:

There is a race here. You need to protect the registration of the fib notifier as well by the sequence counter. Updates here are not ordered in relation to this code below.

You mean updates that can be received after you registered the notifier and until the dump started? I'm aware of that and that's OK. This listener should be able to handle duplicates.

I've a follow up patchset that introduces a new event in switchdev notification chain called SWITCHDEV_SYNC, which is sent when port netdevs are enslaved / released from a master device (points in time where kernel<->device can get out of sync). It will invoke re-propagation of configuration from different parts of the stack (e.g. bridge driver, 8021q driver, fib/neigh code), which can result in duplicates.

Quoted 2 lines

I think just move the register notification into the fib_notifier_dump function, rename it to fib_notifier_init and use it here:

I separated the two on purpose. For example, rocker only needs to register notifier, but doesn't need the dump.

Quoted 11 lines

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp) · line 2071

Quoted 7 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +5 -0
+	if (!fib_notifier_dump(&mlxsw_sp->fib_nb, &init_net, cb)) {
+		err = -EBUSY;
+		goto err_fib_notifier_dump;
+	}
+
 	return 0;

Thanks,
Hannes

#14 lore raw

Re: [patch net-next v3 11/12] mlxsw: spectrum_router: Request a dump of FIB tables during init

Quoted 50 lines · Ido Schimmel

Hi Hannes,

Quoted 47 lines · Hannes Frederic Sowa
Quoted 40 lines · Jiri Pirko

From: Ido Schimmel <[email protected]>

Make sure the device has a complete view of the FIB tables by invoking their dump during module init.

---
 .../net/ethernet/mellanox/mlxsw/spectrum_router.c  | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +15 -0
index 14bed1d..d176047 100644
@@ -2027,8 +2027,23 @@ static int mlxsw_sp_router_fib_event(struct notifier_block *nb,
 	return NOTIFY_DONE;
 }
 
+static void mlxsw_sp_router_fib_dump_flush(struct notifier_block *nb)
+{
+	struct mlxsw_sp *mlxsw_sp = container_of(nb, struct mlxsw_sp, fib_nb);
+
+	/* Flush pending FIB notifications and then flush the device's
+	 * table before requesting another dump. Do that with RTNL held,
+	 * as FIB notification block is already registered.
+	 */
+	mlxsw_core_flush_owq();
+	rtnl_lock();
+	mlxsw_sp_router_fib_flush(mlxsw_sp);
+	rtnl_unlock();
+}
+
 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
 {
+	fib_dump_cb_t *cb = mlxsw_sp_router_fib_dump_flush;
 	int err;
 
 	INIT_LIST_HEAD(&mlxsw_sp->router.nexthop_neighs_list);

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp) · line 2065

Quoted 3 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +0 -0
@@ -2048,8 +2063,16 @@ int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
 
 	mlxsw_sp->fib_nb.notifier_call = mlxsw_sp_router_fib_event;
 	register_fib_notifier(&mlxsw_sp->fib_nb);

Sorry to pick in here again:

Quoted 7 lines
Quoted 3 lines

There is a race here. You need to protect the registration of the fib notifier as well by the sequence counter. Updates here are not ordered in relation to this code below.

You mean updates that can be received after you registered the notifier and until the dump started? I'm aware of that and that's OK. This listener should be able to handle duplicates.

I am not concerned about duplicates, but about ordering deletes and getting an add from the RCU code you will add the node to hw while it is deleted in the software path. You probably will ignore the delete because nothing is installed in hw and later add the node which was actually deleted but just reordered which happend on another CPU, no?

Quoted 7 lines

I've a follow up patchset that introduces a new event in switchdev notification chain called SWITCHDEV_SYNC, which is sent when port netdevs are enslaved / released from a master device (points in time where kernel<->device can get out of sync). It will invoke re-propagation of configuration from different parts of the stack (e.g. bridge driver, 8021q driver, fib/neigh code), which can result in duplicates.

Okay, understood. I wonder how we can protect against accidentally abort calls actually. E.g. if I start to inject routes into my routing domain how can I make sure the box doesn't die after I try to insert enough routes. Do we need to touch quagga etc?

Thanks,
Hannes

#15 lore raw

Re: [patch net-next v3 11/12] mlxsw: spectrum_router: Request a dump of FIB tables during init

Quoted 57 lines · Hannes Frederic Sowa
Quoted 48 lines · Ido Schimmel
Quoted 47 lines · Hannes Frederic Sowa
Quoted 40 lines · Jiri Pirko

From: Ido Schimmel <[email protected]>

Make sure the device has a complete view of the FIB tables by invoking their dump during module init.

---
 .../net/ethernet/mellanox/mlxsw/spectrum_router.c  | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +15 -0
index 14bed1d..d176047 100644
@@ -2027,8 +2027,23 @@ static int mlxsw_sp_router_fib_event(struct notifier_block *nb,
 	return NOTIFY_DONE;
 }
 
+static void mlxsw_sp_router_fib_dump_flush(struct notifier_block *nb)
+{
+	struct mlxsw_sp *mlxsw_sp = container_of(nb, struct mlxsw_sp, fib_nb);
+
+	/* Flush pending FIB notifications and then flush the device's
+	 * table before requesting another dump. Do that with RTNL held,
+	 * as FIB notification block is already registered.
+	 */
+	mlxsw_core_flush_owq();
+	rtnl_lock();
+	mlxsw_sp_router_fib_flush(mlxsw_sp);
+	rtnl_unlock();
+}
+
 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
 {
+	fib_dump_cb_t *cb = mlxsw_sp_router_fib_dump_flush;
 	int err;
 
 	INIT_LIST_HEAD(&mlxsw_sp->router.nexthop_neighs_list);

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp) · line 2065

Quoted 3 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +0 -0
@@ -2048,8 +2063,16 @@ int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
 
 	mlxsw_sp->fib_nb.notifier_call = mlxsw_sp_router_fib_event;
 	register_fib_notifier(&mlxsw_sp->fib_nb);

Sorry to pick in here again:

Quoted 7 lines
Quoted 3 lines

There is a race here. You need to protect the registration of the fib notifier as well by the sequence counter. Updates here are not ordered in relation to this code below.

You mean updates that can be received after you registered the notifier and until the dump started? I'm aware of that and that's OK. This listener should be able to handle duplicates.

Quoted 5 lines

I am not concerned about duplicates, but about ordering deletes and getting an add from the RCU code you will add the node to hw while it is deleted in the software path. You probably will ignore the delete because nothing is installed in hw and later add the node which was actually deleted but just reordered which happend on another CPU, no?

Are you referring to reordering in the workqueue? We already covered this using an ordered workqueue, which has one context of execution system-wide.

Quoted 8 lines
Quoted 7 lines

I've a follow up patchset that introduces a new event in switchdev notification chain called SWITCHDEV_SYNC, which is sent when port netdevs are enslaved / released from a master device (points in time where kernel<->device can get out of sync). It will invoke re-propagation of configuration from different parts of the stack (e.g. bridge driver, 8021q driver, fib/neigh code), which can result in duplicates.

Quoted 4 lines

Okay, understood. I wonder how we can protect against accidentally abort calls actually. E.g. if I start to inject routes into my routing domain how can I make sure the box doesn't die after I try to insert enough routes. Do we need to touch quagga etc?

The whole point of moving abort mechanism to the driver is that the system won't die, but instead routing will be done in the kernel. If you respect hardware limitations, then there's no reason for abort mechanism to kick in.

#16 lore raw

Re: [patch net-next v3 11/12] mlxsw: spectrum_router: Request a dump of FIB tables during init

Quoted 64 lines · Ido Schimmel
Quoted 57 lines · Hannes Frederic Sowa
Quoted 48 lines · Ido Schimmel
Quoted 47 lines · Hannes Frederic Sowa
Quoted 40 lines · Jiri Pirko

From: Ido Schimmel <[email protected]>

Make sure the device has a complete view of the FIB tables by invoking their dump during module init.

---
 .../net/ethernet/mellanox/mlxsw/spectrum_router.c  | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +15 -0
index 14bed1d..d176047 100644
@@ -2027,8 +2027,23 @@ static int mlxsw_sp_router_fib_event(struct notifier_block *nb,
 	return NOTIFY_DONE;
 }
 
+static void mlxsw_sp_router_fib_dump_flush(struct notifier_block *nb)
+{
+	struct mlxsw_sp *mlxsw_sp = container_of(nb, struct mlxsw_sp, fib_nb);
+
+	/* Flush pending FIB notifications and then flush the device's
+	 * table before requesting another dump. Do that with RTNL held,
+	 * as FIB notification block is already registered.
+	 */
+	mlxsw_core_flush_owq();
+	rtnl_lock();
+	mlxsw_sp_router_fib_flush(mlxsw_sp);
+	rtnl_unlock();
+}
+
 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
 {
+	fib_dump_cb_t *cb = mlxsw_sp_router_fib_dump_flush;
 	int err;
 
 	INIT_LIST_HEAD(&mlxsw_sp->router.nexthop_neighs_list);

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp) · line 2065

Quoted 3 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +0 -0
@@ -2048,8 +2063,16 @@ int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
 
 	mlxsw_sp->fib_nb.notifier_call = mlxsw_sp_router_fib_event;
 	register_fib_notifier(&mlxsw_sp->fib_nb);

Sorry to pick in here again:

Quoted 7 lines
Quoted 3 lines

There is a race here. You need to protect the registration of the fib notifier as well by the sequence counter. Updates here are not ordered in relation to this code below.

You mean updates that can be received after you registered the notifier and until the dump started? I'm aware of that and that's OK. This listener should be able to handle duplicates.

Quoted 5 lines

I am not concerned about duplicates, but about ordering deletes and getting an add from the RCU code you will add the node to hw while it is deleted in the software path. You probably will ignore the delete because nothing is installed in hw and later add the node which was actually deleted but just reordered which happend on another CPU, no?

Quoted 3 lines

Are you referring to reordering in the workqueue? We already covered this using an ordered workqueue, which has one context of execution system-wide.

Ups, sorry, I missed that mail. Probably read it on the mobile phone and it became invisible for me later on. Busy day... ;)

The reordering in the workqueue seems fine to me and also still necessary.

Basically, if you delete a node right now the kernel might simply do a RCU_INIT_POINTER(ptr_location, NULL), which has absolutely no barriers or synchronization with the reader side. Thus you might get a callback from the notifier for a delete event on the one CPU and you end up queueing this fib entry after the delete queue, because the RCU walk isn't protected by any means.

Looking closer at this series again, I overlooked the fact that you fetch fib_seq using a rtnl_lock and rtnl_unlock pair, which first of all orders fetching of fib_seq and thus the RCU dumping after any concurrent executing fib table update, also the mutex_lock and unlock provide proper acquire and release fences, so the CPU indeed sees the effect of a RCU_INIT_POINTER update done on another CPU, because they pair with the rtnl_unlock which might happen on the other CPU.

My question is if this is a bit of luck and if we should make this explicit by putting the registration itself under the protection of the sequence counter. I favor the additional protection, e.g. if we some day actually we optimize the fib_seq code? Otherwise we might probably document this fact. :)

Quoted 13 lines
Quoted 8 lines
Quoted 7 lines

I've a follow up patchset that introduces a new event in switchdev notification chain called SWITCHDEV_SYNC, which is sent when port netdevs are enslaved / released from a master device (points in time where kernel<->device can get out of sync). It will invoke re-propagation of configuration from different parts of the stack (e.g. bridge driver, 8021q driver, fib/neigh code), which can result in duplicates.

Quoted 4 lines

Okay, understood. I wonder how we can protect against accidentally abort calls actually. E.g. if I start to inject routes into my routing domain how can I make sure the box doesn't die after I try to insert enough routes. Do we need to touch quagga etc?

Quoted 4 lines

The whole point of moving abort mechanism to the driver is that the system won't die, but instead routing will be done in the kernel. If you respect hardware limitations, then there's no reason for abort mechanism to kick in.

Quick follow-up question: How can I quickly find out the hw limitations via the kernel api?

Thanks,
Hannes

#17 lore raw

Re: [patch net-next v3 11/12] mlxsw: spectrum_router: Request a dump of FIB tables during init

Quoted 65 lines · Hannes Frederic Sowa
Quoted 64 lines · Ido Schimmel
Quoted 62 lines · Hannes Frederic Sowa
Quoted 48 lines · Ido Schimmel
Quoted 47 lines · Hannes Frederic Sowa
Quoted 40 lines · Jiri Pirko

From: Ido Schimmel <[email protected]>

Make sure the device has a complete view of the FIB tables by invoking their dump during module init.

---
 .../net/ethernet/mellanox/mlxsw/spectrum_router.c  | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +15 -0
index 14bed1d..d176047 100644
@@ -2027,8 +2027,23 @@ static int mlxsw_sp_router_fib_event(struct notifier_block *nb,
 	return NOTIFY_DONE;
 }
 
+static void mlxsw_sp_router_fib_dump_flush(struct notifier_block *nb)
+{
+	struct mlxsw_sp *mlxsw_sp = container_of(nb, struct mlxsw_sp, fib_nb);
+
+	/* Flush pending FIB notifications and then flush the device's
+	 * table before requesting another dump. Do that with RTNL held,
+	 * as FIB notification block is already registered.
+	 */
+	mlxsw_core_flush_owq();
+	rtnl_lock();
+	mlxsw_sp_router_fib_flush(mlxsw_sp);
+	rtnl_unlock();
+}
+
 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
 {
+	fib_dump_cb_t *cb = mlxsw_sp_router_fib_dump_flush;
 	int err;
 
 	INIT_LIST_HEAD(&mlxsw_sp->router.nexthop_neighs_list);

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp) · line 2065

Quoted 3 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +0 -0
@@ -2048,8 +2063,16 @@ int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
 
 	mlxsw_sp->fib_nb.notifier_call = mlxsw_sp_router_fib_event;
 	register_fib_notifier(&mlxsw_sp->fib_nb);

Sorry to pick in here again:

Quoted 7 lines
Quoted 3 lines

There is a race here. You need to protect the registration of the fib notifier as well by the sequence counter. Updates here are not ordered in relation to this code below.

You mean updates that can be received after you registered the notifier and until the dump started? I'm aware of that and that's OK. This listener should be able to handle duplicates.

I am not concerned about duplicates, but about ordering deletes and getting an add from the RCU code you will add the node to hw while it is deleted in the software path. You probably will ignore the delete because nothing is installed in hw and later add the node which was actually deleted but just reordered which happend on another CPU, no?

Quoted 6 lines
Quoted 3 lines

Are you referring to reordering in the workqueue? We already covered this using an ordered workqueue, which has one context of execution system-wide.

Ups, sorry, I missed that mail. Probably read it on the mobile phone and it became invisible for me later on. Busy day... ;)

Yet another reason not to read emails on your phone ;)

Quoted 1 line

The reordering in the workqueue seems fine to me and also still necessary.

Correct.

Quoted 7 lines

Basically, if you delete a node right now the kernel might simply do a RCU_INIT_POINTER(ptr_location, NULL), which has absolutely no barriers or synchronization with the reader side. Thus you might get a callback from the notifier for a delete event on the one CPU and you end up queueing this fib entry after the delete queue, because the RCU walk isn't protected by any means.

Quoted 7 lines

Looking closer at this series again, I overlooked the fact that you fetch fib_seq using a rtnl_lock and rtnl_unlock pair, which first of all orders fetching of fib_seq and thus the RCU dumping after any concurrent executing fib table update, also the mutex_lock and unlock provide proper acquire and release fences, so the CPU indeed sees the effect of a RCU_INIT_POINTER update done on another CPU, because they pair with the rtnl_unlock which might happen on the other CPU.

Yep, Exactly. I had a feeling this is the issue you were referring to, but then you were the one to suggest the use of RTNL, so I was quite confused.

Quoted 5 lines

My question is if this is a bit of luck and if we should make this explicit by putting the registration itself under the protection of the sequence counter. I favor the additional protection, e.g. if we some day actually we optimize the fib_seq code? Otherwise we might probably document this fact. :)

Well, some listeners don't require a dump, but only registration (rocker) and in the future we might only need a dump (e.g., port being moved to a different net namespace). So I'm not sure if bundling both together is a good idea.

Maybe we can keep register_fib_notifier() as-is and add 'bool register' to fib_notifier_dump() so that when set, 'nb' is also registered after RCU walk, but before we check if the dump is consistent (unregistered if inconsistent)?

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 7 lines

I've a follow up patchset that introduces a new event in switchdev notification chain called SWITCHDEV_SYNC, which is sent when port netdevs are enslaved / released from a master device (points in time where kernel<->device can get out of sync). It will invoke re-propagation of configuration from different parts of the stack (e.g. bridge driver, 8021q driver, fib/neigh code), which can result in duplicates.

Okay, understood. I wonder how we can protect against accidentally abort calls actually. E.g. if I start to inject routes into my routing domain how can I make sure the box doesn't die after I try to insert enough routes. Do we need to touch quagga etc?

Quoted 7 lines
Quoted 4 lines

The whole point of moving abort mechanism to the driver is that the system won't die, but instead routing will be done in the kernel. If you respect hardware limitations, then there's no reason for abort mechanism to kick in.

Quick follow-up question: How can I quickly find out the hw limitations via the kernel api?

That's a good question. Currently, you can't. However, we already have a mechanism in place to read device's capabilities from the firmware and we can (and should) expose some of them to the user. The best API for that would be devlink, as it can represent the entire device as opposed to only a port netdev like other tools.

We're also working on making the pipeline more visible to the user, so that it would be easier for users to understand and debug their networks. I believe a colleague of mine (Matty) presented this during the last netdev conference.

#18 lore raw

Re: [patch net-next v3 11/12] mlxsw: spectrum_router: Request a dump of FIB tables during init

On 02.12.2016 00:14, Ido Schimmel wrote:

[...]

Quoted 15 lines
Quoted 7 lines

Basically, if you delete a node right now the kernel might simply do a RCU_INIT_POINTER(ptr_location, NULL), which has absolutely no barriers or synchronization with the reader side. Thus you might get a callback from the notifier for a delete event on the one CPU and you end up queueing this fib entry after the delete queue, because the RCU walk isn't protected by any means.

Quoted 7 lines

Looking closer at this series again, I overlooked the fact that you fetch fib_seq using a rtnl_lock and rtnl_unlock pair, which first of all orders fetching of fib_seq and thus the RCU dumping after any concurrent executing fib table update, also the mutex_lock and unlock provide proper acquire and release fences, so the CPU indeed sees the effect of a RCU_INIT_POINTER update done on another CPU, because they pair with the rtnl_unlock which might happen on the other CPU.

Quoted 3 lines

Yep, Exactly. I had a feeling this is the issue you were referring to, but then you were the one to suggest the use of RTNL, so I was quite confused.

At that time I actually had in mind that the fib_register would happen under the sequence lock, so I didn't look closely to the memory barrier pairings. I kinda still consider this to be a happy accident. ;)

Quoted 11 lines
Quoted 5 lines

My question is if this is a bit of luck and if we should make this explicit by putting the registration itself under the protection of the sequence counter. I favor the additional protection, e.g. if we some day actually we optimize the fib_seq code? Otherwise we might probably document this fact. :)

Well, some listeners don't require a dump, but only registration (rocker) and in the future we might only need a dump (e.g., port being moved to a different net namespace). So I'm not sure if bundling both together is a good idea.

Quoted 4 lines

Maybe we can keep register_fib_notifier() as-is and add 'bool register' to fib_notifier_dump() so that when set, 'nb' is also registered after RCU walk, but before we check if the dump is consistent (unregistered if inconsistent)?

I really like that. Would you mind adding this?

[...]

Quoted 9 lines
Quoted 2 lines

Quick follow-up question: How can I quickly find out the hw limitations via the kernel api?

That's a good question. Currently, you can't. However, we already have a mechanism in place to read device's capabilities from the firmware and we can (and should) expose some of them to the user. The best API for that would be devlink, as it can represent the entire device as opposed to only a port netdev like other tools.

Quoted 4 lines

We're also working on making the pipeline more visible to the user, so that it would be easier for users to understand and debug their networks. I believe a colleague of mine (Matty) presented this during the last netdev conference.

Thanks, I will look it up!

Bye,
Hannes

#19 lore raw

Re: [patch net-next v3 11/12] mlxsw: spectrum_router: Request a dump of FIB tables during init

Quoted 1 line · Hannes Frederic Sowa

I really like that. Would you mind adding this?

Yes. I'll send another version to Jiri today after testing and hopefully we can submit today / tomorrow. I think Linus is still undecided about -rc8 and I would like to get this in 4.10.

Quoted 9 lines
Quoted 9 lines
Quoted 2 lines

Quick follow-up question: How can I quickly find out the hw limitations via the kernel api?

That's a good question. Currently, you can't. However, we already have a mechanism in place to read device's capabilities from the firmware and we can (and should) expose some of them to the user. The best API for that would be devlink, as it can represent the entire device as opposed to only a port netdev like other tools.

Quoted 6 lines
Quoted 4 lines

We're also working on making the pipeline more visible to the user, so that it would be easier for users to understand and debug their networks. I believe a colleague of mine (Matty) presented this during the last netdev conference.

Thanks, I will look it up!

Found it:
https://www.youtube.com/watch?v=gwzaKXWIelc&feature=youtu.be&list=PLrninrcyMo3IkTvpvM2LK6gn4NdbFhI0G&t=6892

maintainer
#20 lore raw

Re: [patch net-next v3 11/12] mlxsw: spectrum_router: Request a dump of FIB tables during init

In reply to Ido Schimmel

Hannes and Ido,

It looks like we are very close to having this in mergable shape, can you guys work out this final issue and figure out if it really is a merge stopped or not?

Thanks.

#21 lore raw

Re: [patch net-next v3 11/12] mlxsw: spectrum_router: Request a dump of FIB tables during init

Quoted 6 lines · David Miller

Hannes and Ido,

It looks like we are very close to having this in mergable shape, can you guys work out this final issue and figure out if it really is a merge stopped or not?

Sure, if the fib notification register could be done under protection of the sequence counter I don't see any more problems.

The sync handler is nice to have and can be done in a later patch series.

#22 lore raw

Re: [patch net-next v3 11/12] mlxsw: spectrum_router: Request a dump of FIB tables during init

Quoted 10 lines · Hannes Frederic Sowa
Quoted 6 lines · David Miller

Hannes and Ido,

It looks like we are very close to having this in mergable shape, can you guys work out this final issue and figure out if it really is a merge stopped or not?

Sure, if the fib notification register could be done under protection of the sequence counter I don't see any more problems.

Did you maybe miss my reply yesterday? Because I was trying to understand what "ordering" you're referring to, but didn't receive a reply from you.

Quoted 1 line

The sync handler is nice to have and can be done in a later patch series.

Sync handler?

#23 lore raw

Re: [patch net-next v3 11/12] mlxsw: spectrum_router: Request a dump of FIB tables during init

Quoted 9 lines · Ido Schimmel
Quoted 8 lines · Hannes Frederic Sowa
Quoted 6 lines · David Miller

Hannes and Ido,

It looks like we are very close to having this in mergable shape, can you guys work out this final issue and figure out if it really is a merge stopped or not?

Quoted 6 lines
Quoted 2 lines

Sure, if the fib notification register could be done under protection of the sequence counter I don't see any more problems.

Did you maybe miss my reply yesterday? Because I was trying to understand what "ordering" you're referring to, but didn't receive a reply from you.

Oh, strange, I am pretty sure I replied to that. Let me resend it.

Quoted 3 lines
Quoted 1 line

The sync handler is nice to have and can be done in a later patch series.

Sync handler?

I was talking about SWITCHDEV_SYNC.

Bye,
Hannes

#24 lore raw

Re: [patch net-next v3 11/12] mlxsw: spectrum_router: Request a dump of FIB tables during init

Quoted 10 lines · Hannes Frederic Sowa
Quoted 9 lines · Ido Schimmel
Quoted 8 lines · Hannes Frederic Sowa
Quoted 6 lines · David Miller

Hannes and Ido,

It looks like we are very close to having this in mergable shape, can you guys work out this final issue and figure out if it really is a merge stopped or not?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Sure, if the fib notification register could be done under protection of the sequence counter I don't see any more problems.

Did you maybe miss my reply yesterday? Because I was trying to understand what "ordering" you're referring to, but didn't receive a reply from you.

Oh, strange, I am pretty sure I replied to that. Let me resend it.

:)

I did get this reply, and then replied myself here:
https://marc.info/?l=linux-netdev&m=148053017425465&w=2

#25 lore raw

Re: [patch net-next v3 11/12] mlxsw: spectrum_router: Request a dump of FIB tables during init

In reply to Ido Schimmel
Quoted 50 lines · Ido Schimmel

Hi Hannes,

Quoted 47 lines · Hannes Frederic Sowa
Quoted 40 lines · Jiri Pirko

From: Ido Schimmel <[email protected]>

Make sure the device has a complete view of the FIB tables by invoking their dump during module init.

---
 .../net/ethernet/mellanox/mlxsw/spectrum_router.c  | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +15 -0
index 14bed1d..d176047 100644
@@ -2027,8 +2027,23 @@ static int mlxsw_sp_router_fib_event(struct notifier_block *nb,
 	return NOTIFY_DONE;
 }
 
+static void mlxsw_sp_router_fib_dump_flush(struct notifier_block *nb)
+{
+	struct mlxsw_sp *mlxsw_sp = container_of(nb, struct mlxsw_sp, fib_nb);
+
+	/* Flush pending FIB notifications and then flush the device's
+	 * table before requesting another dump. Do that with RTNL held,
+	 * as FIB notification block is already registered.
+	 */
+	mlxsw_core_flush_owq();
+	rtnl_lock();
+	mlxsw_sp_router_fib_flush(mlxsw_sp);
+	rtnl_unlock();
+}
+
 int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
 {
+	fib_dump_cb_t *cb = mlxsw_sp_router_fib_dump_flush;
 	int err;
 
 	INIT_LIST_HEAD(&mlxsw_sp->router.nexthop_neighs_list);

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp) · line 2065

Quoted 3 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +0 -0
@@ -2048,8 +2063,16 @@ int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
 
 	mlxsw_sp->fib_nb.notifier_call = mlxsw_sp_router_fib_event;
 	register_fib_notifier(&mlxsw_sp->fib_nb);

Sorry to pick in here again:

Quoted 7 lines
Quoted 3 lines

There is a race here. You need to protect the registration of the fib notifier as well by the sequence counter. Updates here are not ordered in relation to this code below.

You mean updates that can be received after you registered the notifier and until the dump started? I'm aware of that and that's OK. This listener should be able to handle duplicates.

I am not concerned about duplicates, but about ordering deletes and getting an add from the RCU code you will add the node to hw while it is deleted in the software path. You probably will ignore the delete because nothing is installed in hw and later add the node which was actually deleted but just reordered which happend on another CPU, no?

Quoted 7 lines

I've a follow up patchset that introduces a new event in switchdev notification chain called SWITCHDEV_SYNC, which is sent when port netdevs are enslaved / released from a master device (points in time where kernel<->device can get out of sync). It will invoke re-propagation of configuration from different parts of the stack (e.g. bridge driver, 8021q driver, fib/neigh code), which can result in duplicates.

Okay, understood. I wonder how we can protect against accidentally abort calls actually. E.g. if I start to inject routes into my routing domain how can I make sure the box doesn't die after I try to insert enough routes. Do we need to touch quagga etc?

Thanks,
Hannes

author maintainer
#26 lore raw

PATCH v3 12/12 rocker: Register FIB notifier before creating ports

In reply to Jiri Pirko

From: Ido Schimmel <[email protected]>

Unlike mlxsw, rocker only supports the reflection of routes pointing to its own netdevs. Therefore, instead of requesting a FIB dump during init, simply register the FIB notifier before creating the ports.

---
 drivers/net/ethernet/rocker/rocker_main.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/ethernet/rocker/rocker_main.c +5 -4
index 914e9e1..8c9c90a 100644
@@ -2804,6 +2804,9 @@ static int rocker_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		goto err_alloc_ordered_workqueue;
 	}
 
+	rocker->fib_nb.notifier_call = rocker_router_fib_event;
+	register_fib_notifier(&rocker->fib_nb);
+
 	rocker->hw.id = rocker_read64(rocker, SWITCH_ID);
 
 	err = rocker_probe_ports(rocker);
@@ -2812,15 +2815,13 @@ static int rocker_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		goto err_probe_ports;
 	}
 
-	rocker->fib_nb.notifier_call = rocker_router_fib_event;
-	register_fib_notifier(&rocker->fib_nb);
-
 	dev_info(&pdev->dev, "Rocker switch with id %*phN\n",
 		 (int)sizeof(rocker->hw.id), &rocker->hw.id);
 
 	return 0;
 
 err_probe_ports:
+	unregister_fib_notifier(&rocker->fib_nb);
 	destroy_workqueue(rocker->rocker_owq);
 err_alloc_ordered_workqueue:
 	free_irq(rocker_msix_vector(rocker, ROCKER_MSIX_VEC_EVENT), rocker);
@@ -2848,9 +2849,9 @@ static void rocker_remove(struct pci_dev *pdev)
 {
 	struct rocker *rocker = pci_get_drvdata(pdev);
 
+	rocker_remove_ports(rocker);
 	unregister_fib_notifier(&rocker->fib_nb);
 	rocker_write32(rocker, CONTROL, ROCKER_CONTROL_RESET);
-	rocker_remove_ports(rocker);
 	destroy_workqueue(rocker->rocker_owq);
 	free_irq(rocker_msix_vector(rocker, ROCKER_MSIX_VEC_EVENT), rocker);
 	free_irq(rocker_msix_vector(rocker, ROCKER_MSIX_VEC_CMD), rocker);
Signature · 1 line
2.7.4