@@ -1278,7 +1278,8 @@ devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *por
1278
1278
static int devlink_nl_port_fill (struct sk_buff * msg ,
1279
1279
struct devlink_port * devlink_port ,
1280
1280
enum devlink_command cmd , u32 portid , u32 seq ,
1281
- int flags , struct netlink_ext_ack * extack )
1281
+ int flags , struct netlink_ext_ack * extack ,
1282
+ bool rtnl_held )
1282
1283
{
1283
1284
struct devlink * devlink = devlink_port -> devlink ;
1284
1285
void * hdr ;
@@ -1293,7 +1294,8 @@ static int devlink_nl_port_fill(struct sk_buff *msg,
1293
1294
goto nla_put_failure ;
1294
1295
1295
1296
/* Hold rtnl lock while accessing port's netdev attributes. */
1296
- rtnl_lock ();
1297
+ if (!rtnl_held )
1298
+ rtnl_lock ();
1297
1299
spin_lock_bh (& devlink_port -> type_lock );
1298
1300
if (nla_put_u16 (msg , DEVLINK_ATTR_PORT_TYPE , devlink_port -> type ))
1299
1301
goto nla_put_failure_type_locked ;
@@ -1321,7 +1323,8 @@ static int devlink_nl_port_fill(struct sk_buff *msg,
1321
1323
goto nla_put_failure_type_locked ;
1322
1324
}
1323
1325
spin_unlock_bh (& devlink_port -> type_lock );
1324
- rtnl_unlock ();
1326
+ if (!rtnl_held )
1327
+ rtnl_unlock ();
1325
1328
if (devlink_nl_port_attrs_put (msg , devlink_port ))
1326
1329
goto nla_put_failure ;
1327
1330
if (devlink_nl_port_function_attrs_put (msg , devlink_port , extack ))
@@ -1336,14 +1339,15 @@ static int devlink_nl_port_fill(struct sk_buff *msg,
1336
1339
1337
1340
nla_put_failure_type_locked :
1338
1341
spin_unlock_bh (& devlink_port -> type_lock );
1339
- rtnl_unlock ();
1342
+ if (!rtnl_held )
1343
+ rtnl_unlock ();
1340
1344
nla_put_failure :
1341
1345
genlmsg_cancel (msg , hdr );
1342
1346
return - EMSGSIZE ;
1343
1347
}
1344
1348
1345
- static void devlink_port_notify (struct devlink_port * devlink_port ,
1346
- enum devlink_command cmd )
1349
+ static void __devlink_port_notify (struct devlink_port * devlink_port ,
1350
+ enum devlink_command cmd , bool rtnl_held )
1347
1351
{
1348
1352
struct devlink * devlink = devlink_port -> devlink ;
1349
1353
struct sk_buff * msg ;
@@ -1358,7 +1362,8 @@ static void devlink_port_notify(struct devlink_port *devlink_port,
1358
1362
if (!msg )
1359
1363
return ;
1360
1364
1361
- err = devlink_nl_port_fill (msg , devlink_port , cmd , 0 , 0 , 0 , NULL );
1365
+ err = devlink_nl_port_fill (msg , devlink_port , cmd , 0 , 0 , 0 , NULL ,
1366
+ rtnl_held );
1362
1367
if (err ) {
1363
1368
nlmsg_free (msg );
1364
1369
return ;
@@ -1368,6 +1373,12 @@ static void devlink_port_notify(struct devlink_port *devlink_port,
1368
1373
0 , DEVLINK_MCGRP_CONFIG , GFP_KERNEL );
1369
1374
}
1370
1375
1376
+ static void devlink_port_notify (struct devlink_port * devlink_port ,
1377
+ enum devlink_command cmd )
1378
+ {
1379
+ __devlink_port_notify (devlink_port , cmd , false);
1380
+ }
1381
+
1371
1382
static void devlink_rate_notify (struct devlink_rate * devlink_rate ,
1372
1383
enum devlink_command cmd )
1373
1384
{
@@ -1531,7 +1542,7 @@ static int devlink_nl_cmd_port_get_doit(struct sk_buff *skb,
1531
1542
1532
1543
err = devlink_nl_port_fill (msg , devlink_port , DEVLINK_CMD_PORT_NEW ,
1533
1544
info -> snd_portid , info -> snd_seq , 0 ,
1534
- info -> extack );
1545
+ info -> extack , false );
1535
1546
if (err ) {
1536
1547
nlmsg_free (msg );
1537
1548
return err ;
@@ -1561,7 +1572,8 @@ static int devlink_nl_cmd_port_get_dumpit(struct sk_buff *msg,
1561
1572
DEVLINK_CMD_NEW ,
1562
1573
NETLINK_CB (cb -> skb ).portid ,
1563
1574
cb -> nlh -> nlmsg_seq ,
1564
- NLM_F_MULTI , cb -> extack );
1575
+ NLM_F_MULTI , cb -> extack ,
1576
+ false);
1565
1577
if (err ) {
1566
1578
devl_unlock (devlink );
1567
1579
devlink_put (devlink );
@@ -1773,7 +1785,8 @@ static int devlink_port_new_notify(struct devlink *devlink,
1773
1785
}
1774
1786
1775
1787
err = devlink_nl_port_fill (msg , devlink_port , DEVLINK_CMD_NEW ,
1776
- info -> snd_portid , info -> snd_seq , 0 , NULL );
1788
+ info -> snd_portid , info -> snd_seq , 0 , NULL ,
1789
+ false);
1777
1790
if (err )
1778
1791
goto out ;
1779
1792
@@ -10033,7 +10046,7 @@ static void devlink_port_type_netdev_checks(struct devlink_port *devlink_port,
10033
10046
10034
10047
static void __devlink_port_type_set (struct devlink_port * devlink_port ,
10035
10048
enum devlink_port_type type ,
10036
- void * type_dev )
10049
+ void * type_dev , bool rtnl_held )
10037
10050
{
10038
10051
struct net_device * netdev = type_dev ;
10039
10052
@@ -10060,7 +10073,7 @@ static void __devlink_port_type_set(struct devlink_port *devlink_port,
10060
10073
break ;
10061
10074
}
10062
10075
spin_unlock_bh (& devlink_port -> type_lock );
10063
- devlink_port_notify (devlink_port , DEVLINK_CMD_PORT_NEW );
10076
+ __devlink_port_notify (devlink_port , DEVLINK_CMD_PORT_NEW , rtnl_held );
10064
10077
}
10065
10078
10066
10079
/**
@@ -10077,7 +10090,8 @@ void devlink_port_type_eth_set(struct devlink_port *devlink_port,
10077
10090
"devlink port type for port %d set to Ethernet without a software interface reference, device type not supported by the kernel?\n" ,
10078
10091
devlink_port -> index );
10079
10092
10080
- __devlink_port_type_set (devlink_port , DEVLINK_PORT_TYPE_ETH , netdev );
10093
+ __devlink_port_type_set (devlink_port , DEVLINK_PORT_TYPE_ETH , netdev ,
10094
+ false);
10081
10095
}
10082
10096
EXPORT_SYMBOL_GPL (devlink_port_type_eth_set );
10083
10097
@@ -10090,7 +10104,8 @@ EXPORT_SYMBOL_GPL(devlink_port_type_eth_set);
10090
10104
void devlink_port_type_ib_set (struct devlink_port * devlink_port ,
10091
10105
struct ib_device * ibdev )
10092
10106
{
10093
- __devlink_port_type_set (devlink_port , DEVLINK_PORT_TYPE_IB , ibdev );
10107
+ __devlink_port_type_set (devlink_port , DEVLINK_PORT_TYPE_IB , ibdev ,
10108
+ false);
10094
10109
}
10095
10110
EXPORT_SYMBOL_GPL (devlink_port_type_ib_set );
10096
10111
@@ -10101,7 +10116,8 @@ EXPORT_SYMBOL_GPL(devlink_port_type_ib_set);
10101
10116
*/
10102
10117
void devlink_port_type_clear (struct devlink_port * devlink_port )
10103
10118
{
10104
- __devlink_port_type_set (devlink_port , DEVLINK_PORT_TYPE_NOTSET , NULL );
10119
+ __devlink_port_type_set (devlink_port , DEVLINK_PORT_TYPE_NOTSET , NULL ,
10120
+ false);
10105
10121
}
10106
10122
EXPORT_SYMBOL_GPL (devlink_port_type_clear );
10107
10123
0 commit comments