Re: [PATCH v2 2/2] bonding: reuse neigh_setup from slave neigh_parms

From: Kuniyuki Iwashima

Date: Fri Jul 03 2026 - 02:42:22 EST


From: Paritosh Potukuchi <paritoshpotukuchi@xxxxxxxxx>
Date: Wed, 1 Jul 2026 08:16:00 +0000
> bond_neigh_init() currently relies on the slave device's
> ndo_neigh_setup() callback to obtain a neigh_setup() handler.
>
> When an initialized neigh_parms instance already exists for the
> slave device, reuse the neigh_setup() callback stored in it instead
> of invoking ndo_neigh_setup() again.
>
> If no neigh_parms instance is found, or no neigh_setup() callback is
> present, retain the existing ndo_neigh_setup() fallback path.
>
> This avoids unnecessary ndo_neigh_setup() invocations while preserving
> existing behaviour.
>
> Signed-off-by: Paritosh Potukuchi <paritosh.potukuchi@xxxxxxx>
> ---
> drivers/net/bonding/bond_main.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index e044fc733b8c..d2e4dae4e97c 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
> @@ -4719,7 +4719,7 @@ static int bond_neigh_init(struct neighbour *n)
> {
> struct bonding *bond = netdev_priv(n->dev);
> const struct net_device_ops *slave_ops;
> - struct neigh_parms parms;
> + struct neigh_parms parms, *p;
> struct slave *slave;
> int ret = 0;
>
> @@ -4727,6 +4727,14 @@ static int bond_neigh_init(struct neighbour *n)
> slave = bond_first_slave_rcu(bond);
> if (!slave)
> goto out;
> +
> + p = neigh_parms_lookup_dev(n->tbl, slave->dev);

This introduces O(n) list traversal while it can be done
with fixed costs (3 dereferences + 1 call).

Since neigh_table is global (arp_tbl or nd_tbl), the O(n)
list traversal could take longer and rather de-optimise.


> +
> + if (p && p->neigh_setup) {
> + ret = p->neigh_setup(n);
> + goto out;
> + }
> +
> slave_ops = slave->dev->netdev_ops;
> if (!slave_ops->ndo_neigh_setup)
> goto out;
> --
> 2.43.0