Skip to content

Commit a060133

Browse files
committed
Merge branch 'devlink-port-attribute-fixes'
Parav Pandit says: ==================== devlink port attribute fixes This patchset contains 2 small fixes for devlink port attributes. Patch summary: Patch-1 synchronize the devlink port attribute reader with net namespace change operation Patch-2 Ensure to return devlink port's netdevice attributes when netdev and devlink instance belong to same net namespace ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 3cb2e6d + a7b4364 commit a060133

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

net/core/devlink.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,8 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink,
772772
if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX, devlink_port->index))
773773
goto nla_put_failure;
774774

775+
/* Hold rtnl lock while accessing port's netdev attributes. */
776+
rtnl_lock();
775777
spin_lock_bh(&devlink_port->type_lock);
776778
if (nla_put_u16(msg, DEVLINK_ATTR_PORT_TYPE, devlink_port->type))
777779
goto nla_put_failure_type_locked;
@@ -780,9 +782,10 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink,
780782
devlink_port->desired_type))
781783
goto nla_put_failure_type_locked;
782784
if (devlink_port->type == DEVLINK_PORT_TYPE_ETH) {
785+
struct net *net = devlink_net(devlink_port->devlink);
783786
struct net_device *netdev = devlink_port->type_dev;
784787

785-
if (netdev &&
788+
if (netdev && net_eq(net, dev_net(netdev)) &&
786789
(nla_put_u32(msg, DEVLINK_ATTR_PORT_NETDEV_IFINDEX,
787790
netdev->ifindex) ||
788791
nla_put_string(msg, DEVLINK_ATTR_PORT_NETDEV_NAME,
@@ -798,6 +801,7 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink,
798801
goto nla_put_failure_type_locked;
799802
}
800803
spin_unlock_bh(&devlink_port->type_lock);
804+
rtnl_unlock();
801805
if (devlink_nl_port_attrs_put(msg, devlink_port))
802806
goto nla_put_failure;
803807
if (devlink_nl_port_function_attrs_put(msg, devlink_port, extack))
@@ -808,6 +812,7 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink,
808812

809813
nla_put_failure_type_locked:
810814
spin_unlock_bh(&devlink_port->type_lock);
815+
rtnl_unlock();
811816
nla_put_failure:
812817
genlmsg_cancel(msg, hdr);
813818
return -EMSGSIZE;

0 commit comments

Comments
 (0)