History

net: bridge: switchdev: replay all VLAN groups

The major user of replayed switchdev objects is DSA, and so far it hasn't needed information about anything other than bridge port VLANs, so this is all that br_switchdev_vlan_replay() knows to handle. DSA has managed to get by through replicating every VLAN addition on a user port such that the same VLAN is also added on all DSA and CPU ports, but there is a corner case where this does not work. The mv88e6xxx DSA driver currently prints this error message as soon as the first port of a switch joins a bridge: mv88e6085 0x0000000008b96000:00: port 0 failed to add a6:ef:77:c8:5f:3d vid 1 to fdb: -95 where a6:ef:77:c8:5f:3d vid 1 is a local FDB entry corresponding to the bridge MAC address in the default_pvid. The -EOPNOTSUPP is returned by mv88e6xxx_port_db_load_purge() because it tries to map VID 1 to a FID (the ATU is indexed by FID not VID), but fails to do so. This is because ->port_fdb_add() is called before ->port_vlan_add() for VID 1. The abridged timeline of the calls is: br_add_if -> netdev_master_upper_dev_link -> dsa_port_bridge_join -> switchdev_bridge_port_offload -> br_switchdev_vlan_replay (*) -> br_switchdev_fdb_replay -> mv88e6xxx_port_fdb_add -> nbp_vlan_init -> nbp_vlan_add -> mv88e6xxx_port_vlan_add and the issue is that at the time of (*), the bridge port isn't in VID 1 (nbp_vlan_init hasn't been called), therefore br_switchdev_vlan_replay() won't have anything to replay, therefore VID 1 won't be in the VTU by the time mv88e6xxx_port_fdb_add() is called. This happens only when the first port of a switch joins. For further ports, the initial mv88e6xxx_port_vlan_add() is sufficient for VID 1 to be loaded in the VTU (which is switch-wide, not per port). The problem is somewhat unique to mv88e6xxx by chance, because most other drivers offload an FDB entry by VID, so FDBs and VLANs can be added asynchronously with respect to each other, but addressing the issue at the bridge layer makes sense, since what mv88e6xxx requires isn't absurd. To fix this problem, we need to recognize that it isn't the VLAN group of the port that we're interested in, but the VLAN group of the bridge itself (so it isn't a timing issue, but rather insufficient information being passed from switchdev to drivers). As mentioned, currently nbp_switchdev_sync_objs() only calls br_switchdev_vlan_replay() for VLANs corresponding to the port, but the VLANs corresponding to the bridge itself, for local termination, also need to be replayed. In this case, VID 1 is not (yet) present in the port's VLAN group but is present in the bridge's VLAN group. So to fix this bug, DSA is now obligated to explicitly handle VLANs pointing towards the bridge in order to "close this race" (which isn't really a race). As Tobias Waldekranz notices, this also implies that it must explicitly handle port VLANs on foreign interfaces, something that worked implicitly before: https://patchwork.kernel.org/project/netdevbpf/patch/20220209213044.2353153-6-vladimir.oltean@nxp.com/#24735260 So in the end, br_switchdev_vlan_replay() must replay all VLANs from all VLAN groups: all the ports, and the bridge itself.

Vladimir Oltean committed 4 years ago

Commit b28d5801 parent 263029a1 file · +49 −41Browse files

Unified · Split

net/bridge/br_switchdev.c+49−41
@@ -352,51 +352,19 @@ br_switchdev_vlan_replay_one(struct notifier_block *nb, · 351 unmodified lines
352 return notifier_to_errno(err);352 return notifier_to_errno(err);
353}353}
354 354
355static int br_switchdev_vlan_replay(struct net_device *br_dev,355static int br_switchdev_vlan_replay_group(struct notifier_block *nb,
356 struct net_device *dev,356 struct net_device *dev,
357 const void *ctx, bool adding,357 struct net_bridge_vlan_group *vg,
358 struct notifier_block *nb,358 const void *ctx, unsigned long action,
359 struct netlink_ext_ack *extack)359 struct netlink_ext_ack *extack)
360{360{
361 struct net_bridge_vlan_group *vg;
362 struct net_bridge_vlan *v;361 struct net_bridge_vlan *v;
363 struct net_bridge_port *p;
364 struct net_bridge *br;
365 unsigned long action;
366 int err = 0;362 int err = 0;
367 u16 pvid;363 u16 pvid;
368 364
369 ASSERT_RTNL();
370
371 if (!nb)
372 return 0;
373
374 if (!netif_is_bridge_master(br_dev))
375 return -EINVAL;
376
377 if (!netif_is_bridge_master(dev) && !netif_is_bridge_port(dev))
378 return -EINVAL;
379
380 if (netif_is_bridge_master(dev)) {
381 br = netdev_priv(dev);
382 vg = br_vlan_group(br);
383 p = NULL;
384 } else {
385 p = br_port_get_rtnl(dev);
386 if (WARN_ON(!p))
387 return -EINVAL;
388 vg = nbp_vlan_group(p);
389 br = p->br;
390 }
391
392 if (!vg)365 if (!vg)
393 return 0;366 return 0;
394 367
395 if (adding)
396 action = SWITCHDEV_PORT_OBJ_ADD;
397 else
398 action = SWITCHDEV_PORT_OBJ_DEL;
399
400 pvid = br_get_pvid(vg);368 pvid = br_get_pvid(vg);
401 369
402 list_for_each_entry(v, &vg->vlan_list, vlist) {370 list_for_each_entry(v, &vg->vlan_list, vlist) {
@@ -416,7 +384,48 @@ static int br_switchdev_vlan_replay(struct net_device *br_dev, · 13 unmodified lines
416 return err;384 return err;
417 }385 }
418 386
419 return err;387 return 0;
388}
389
390static int br_switchdev_vlan_replay(struct net_device *br_dev,
391 const void *ctx, bool adding,
392 struct notifier_block *nb,
393 struct netlink_ext_ack *extack)
394{
395 struct net_bridge *br = netdev_priv(br_dev);
396 struct net_bridge_port *p;
397 unsigned long action;
398 int err;
399
400 ASSERT_RTNL();
401
402 if (!nb)
403 return 0;
404
405 if (!netif_is_bridge_master(br_dev))
406 return -EINVAL;
407
408 if (adding)
409 action = SWITCHDEV_PORT_OBJ_ADD;
410 else
411 action = SWITCHDEV_PORT_OBJ_DEL;
412
413 err = br_switchdev_vlan_replay_group(nb, br_dev, br_vlan_group(br),
414 ctx, action, extack);
415 if (err)
416 return err;
417
418 list_for_each_entry(p, &br->port_list, list) {
419 struct net_device *dev = p->dev;
420
421 err = br_switchdev_vlan_replay_group(nb, dev,
422 nbp_vlan_group(p),
423 ctx, action, extack);
424 if (err)
425 return err;
426 }
427
428 return 0;
420}429}
421 430
422#ifdef CONFIG_BRIDGE_IGMP_SNOOPING431#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
@@ -682,8 +691,7 @@ static int nbp_switchdev_sync_objs(struct net_bridge_port *p, const void *ctx, · 259 unmodified lines
682 struct net_device *dev = p->dev;691 struct net_device *dev = p->dev;
683 int err;692 int err;
684 693
685 err = br_switchdev_vlan_replay(br_dev, dev, ctx, true, blocking_nb,694 err = br_switchdev_vlan_replay(br_dev, ctx, true, blocking_nb, extack);
686 extack);
687 if (err && err != -EOPNOTSUPP)695 if (err && err != -EOPNOTSUPP)
688 return err;696 return err;
689 697
@@ -711,7 +719,7 @@ static void nbp_switchdev_unsync_objs(struct net_bridge_port *p, · 21 unmodified lines
711 719
712 br_switchdev_mdb_replay(br_dev, dev, ctx, false, blocking_nb, NULL);720 br_switchdev_mdb_replay(br_dev, dev, ctx, false, blocking_nb, NULL);
713 721
714 br_switchdev_vlan_replay(br_dev, dev, ctx, false, blocking_nb, NULL);722 br_switchdev_vlan_replay(br_dev, ctx, false, blocking_nb, NULL);
715}723}
716 724
717/* Let the bridge know that this port is offloaded, so that it can assign a725/* Let the bridge know that this port is offloaded, so that it can assign a

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t