Skip to content

Commit 20776b4

Browse files
ravi-prevaskuba-moo
authored andcommitted
net: switchdev: don't set port_obj_info->handled true when -EOPNOTSUPP
It's not true that switchdev_port_obj_notify() only inspects the ->handled field of "struct switchdev_notifier_port_obj_info" if call_switchdev_blocking_notifiers() returns 0 - there's a WARN_ON() triggering for a non-zero return combined with ->handled not being true. But the real problem here is that -EOPNOTSUPP is not being properly handled. The wrapper functions switchdev_handle_port_obj_add() et al change a return value of -EOPNOTSUPP to 0, and the treatment of ->handled in switchdev_port_obj_notify() seems to be designed to change that back to -EOPNOTSUPP in case nobody actually acted on the notifier (i.e., everybody returned -EOPNOTSUPP). Currently, as soon as some device down the stack passes the check_cb() check, ->handled gets set to true, which means that switchdev_port_obj_notify() cannot actually ever return -EOPNOTSUPP. This, for example, means that the detection of hardware offload support in the MRP code is broken: switchdev_port_obj_add() used by br_mrp_switchdev_send_ring_test() always returns 0, so since the MRP code thinks the generation of MRP test frames has been offloaded, no such frames are actually put on the wire. Similarly, br_mrp_switchdev_set_ring_role() also always returns 0, causing mrp->ring_role_offloaded to be set to 1. To fix this, continue to set ->handled true if any callback returns success or any error distinct from -EOPNOTSUPP. But if all the callbacks return -EOPNOTSUPP, make sure that ->handled stays false, so the logic in switchdev_port_obj_notify() can propagate that information. Fixes: 9a9f26e ("bridge: mrp: Connect MRP API with the switchdev API") Fixes: f30f060 ("switchdev: Add helpers to aid traversal through lower devices") Reviewed-by: Petr Machata <petrm@nvidia.com> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> Link: https://lore.kernel.org/r/20210125124116.102928-1-rasmus.villemoes@prevas.dk Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 2bd2974 commit 20776b4

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

‎net/switchdev/switchdev.c‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,11 @@ static int __switchdev_handle_port_obj_add(struct net_device *dev,
460460
extack = switchdev_notifier_info_to_extack(&port_obj_info->info);
461461

462462
if (check_cb(dev)) {
463-
/* This flag is only checked if the return value is success. */
464-
port_obj_info->handled = true;
465-
return add_cb(dev, port_obj_info->obj, port_obj_info->trans,
466-
extack);
463+
err = add_cb(dev, port_obj_info->obj, port_obj_info->trans,
464+
extack);
465+
if (err != -EOPNOTSUPP)
466+
port_obj_info->handled = true;
467+
return err;
467468
}
468469

469470
/* Switch ports might be stacked under e.g. a LAG. Ignore the
@@ -515,9 +516,10 @@ static int __switchdev_handle_port_obj_del(struct net_device *dev,
515516
int err = -EOPNOTSUPP;
516517

517518
if (check_cb(dev)) {
518-
/* This flag is only checked if the return value is success. */
519-
port_obj_info->handled = true;
520-
return del_cb(dev, port_obj_info->obj);
519+
err = del_cb(dev, port_obj_info->obj);
520+
if (err != -EOPNOTSUPP)
521+
port_obj_info->handled = true;
522+
return err;
521523
}
522524

523525
/* Switch ports might be stacked under e.g. a LAG. Ignore the
@@ -568,9 +570,10 @@ static int __switchdev_handle_port_attr_set(struct net_device *dev,
568570
int err = -EOPNOTSUPP;
569571

570572
if (check_cb(dev)) {
571-
port_attr_info->handled = true;
572-
return set_cb(dev, port_attr_info->attr,
573-
port_attr_info->trans);
573+
err = set_cb(dev, port_attr_info->attr, port_attr_info->trans);
574+
if (err != -EOPNOTSUPP)
575+
port_attr_info->handled = true;
576+
return err;
574577
}
575578

576579
/* Switch ports might be stacked under e.g. a LAG. Ignore the

0 commit comments

Comments
 (0)