Skip to content

Commit eff7423

Browse files
TaeheeYoodavem330
authored andcommitted
net: core: introduce struct netdev_nested_priv for nested interface infrastructure
Functions related to nested interface infrastructure such as netdev_walk_all_{ upper | lower }_dev() pass both private functions and "data" pointer to handle their own things. At this point, the data pointer type is void *. In order to make it easier to expand common variables and functions, this new netdev_nested_priv structure is added. In the following patch, a new member variable will be added into this struct to fix the lockdep issue. Signed-off-by: Taehee Yoo <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fe8300f commit eff7423

File tree

16 files changed

+183
-95
lines changed

16 files changed

+183
-95
lines changed

drivers/infiniband/core/cache.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -1320,9 +1320,10 @@ struct net_device *rdma_read_gid_attr_ndev_rcu(const struct ib_gid_attr *attr)
13201320
}
13211321
EXPORT_SYMBOL(rdma_read_gid_attr_ndev_rcu);
13221322

1323-
static int get_lower_dev_vlan(struct net_device *lower_dev, void *data)
1323+
static int get_lower_dev_vlan(struct net_device *lower_dev,
1324+
struct netdev_nested_priv *priv)
13241325
{
1325-
u16 *vlan_id = data;
1326+
u16 *vlan_id = (u16 *)priv->data;
13261327

13271328
if (is_vlan_dev(lower_dev))
13281329
*vlan_id = vlan_dev_vlan_id(lower_dev);
@@ -1348,6 +1349,9 @@ static int get_lower_dev_vlan(struct net_device *lower_dev, void *data)
13481349
int rdma_read_gid_l2_fields(const struct ib_gid_attr *attr,
13491350
u16 *vlan_id, u8 *smac)
13501351
{
1352+
struct netdev_nested_priv priv = {
1353+
.data = (void *)vlan_id,
1354+
};
13511355
struct net_device *ndev;
13521356

13531357
rcu_read_lock();
@@ -1368,7 +1372,7 @@ int rdma_read_gid_l2_fields(const struct ib_gid_attr *attr,
13681372
* the lower vlan device for this gid entry.
13691373
*/
13701374
netdev_walk_all_lower_dev_rcu(attr->ndev,
1371-
get_lower_dev_vlan, vlan_id);
1375+
get_lower_dev_vlan, &priv);
13721376
}
13731377
}
13741378
rcu_read_unlock();

drivers/infiniband/core/cma.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -2865,9 +2865,10 @@ struct iboe_prio_tc_map {
28652865
bool found;
28662866
};
28672867

2868-
static int get_lower_vlan_dev_tc(struct net_device *dev, void *data)
2868+
static int get_lower_vlan_dev_tc(struct net_device *dev,
2869+
struct netdev_nested_priv *priv)
28692870
{
2870-
struct iboe_prio_tc_map *map = data;
2871+
struct iboe_prio_tc_map *map = (struct iboe_prio_tc_map *)priv->data;
28712872

28722873
if (is_vlan_dev(dev))
28732874
map->output_tc = get_vlan_ndev_tc(dev, map->input_prio);
@@ -2886,16 +2887,18 @@ static int iboe_tos_to_sl(struct net_device *ndev, int tos)
28862887
{
28872888
struct iboe_prio_tc_map prio_tc_map = {};
28882889
int prio = rt_tos2priority(tos);
2890+
struct netdev_nested_priv priv;
28892891

28902892
/* If VLAN device, get it directly from the VLAN netdev */
28912893
if (is_vlan_dev(ndev))
28922894
return get_vlan_ndev_tc(ndev, prio);
28932895

28942896
prio_tc_map.input_prio = prio;
2897+
priv.data = (void *)&prio_tc_map;
28952898
rcu_read_lock();
28962899
netdev_walk_all_lower_dev_rcu(ndev,
28972900
get_lower_vlan_dev_tc,
2898-
&prio_tc_map);
2901+
&priv);
28992902
rcu_read_unlock();
29002903
/* If map is found from lower device, use it; Otherwise
29012904
* continue with the current netdevice to get priority to tc map.

drivers/infiniband/core/roce_gid_mgmt.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,11 @@ struct upper_list {
531531
struct net_device *upper;
532532
};
533533

534-
static int netdev_upper_walk(struct net_device *upper, void *data)
534+
static int netdev_upper_walk(struct net_device *upper,
535+
struct netdev_nested_priv *priv)
535536
{
536537
struct upper_list *entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
537-
struct list_head *upper_list = data;
538+
struct list_head *upper_list = (struct list_head *)priv->data;
538539

539540
if (!entry)
540541
return 0;
@@ -553,12 +554,14 @@ static void handle_netdev_upper(struct ib_device *ib_dev, u8 port,
553554
struct net_device *ndev))
554555
{
555556
struct net_device *ndev = cookie;
557+
struct netdev_nested_priv priv;
556558
struct upper_list *upper_iter;
557559
struct upper_list *upper_temp;
558560
LIST_HEAD(upper_list);
559561

562+
priv.data = &upper_list;
560563
rcu_read_lock();
561-
netdev_walk_all_upper_dev_rcu(ndev, netdev_upper_walk, &upper_list);
564+
netdev_walk_all_upper_dev_rcu(ndev, netdev_upper_walk, &priv);
562565
rcu_read_unlock();
563566

564567
handle_netdev(ib_dev, port, ndev);

drivers/infiniband/ulp/ipoib/ipoib_main.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,10 @@ struct ipoib_walk_data {
342342
struct net_device *result;
343343
};
344344

345-
static int ipoib_upper_walk(struct net_device *upper, void *_data)
345+
static int ipoib_upper_walk(struct net_device *upper,
346+
struct netdev_nested_priv *priv)
346347
{
347-
struct ipoib_walk_data *data = _data;
348+
struct ipoib_walk_data *data = (struct ipoib_walk_data *)priv->data;
348349
int ret = 0;
349350

350351
if (ipoib_is_dev_match_addr_rcu(data->addr, upper)) {
@@ -368,18 +369,20 @@ static int ipoib_upper_walk(struct net_device *upper, void *_data)
368369
static struct net_device *ipoib_get_net_dev_match_addr(
369370
const struct sockaddr *addr, struct net_device *dev)
370371
{
372+
struct netdev_nested_priv priv;
371373
struct ipoib_walk_data data = {
372374
.addr = addr,
373375
};
374376

377+
priv.data = (void *)&data;
375378
rcu_read_lock();
376379
if (ipoib_is_dev_match_addr_rcu(addr, dev)) {
377380
dev_hold(dev);
378381
data.result = dev;
379382
goto out;
380383
}
381384

382-
netdev_walk_all_upper_dev_rcu(dev, ipoib_upper_walk, &data);
385+
netdev_walk_all_upper_dev_rcu(dev, ipoib_upper_walk, &priv);
383386
out:
384387
rcu_read_unlock();
385388
return data.result;

drivers/net/bonding/bond_alb.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -942,9 +942,10 @@ struct alb_walk_data {
942942
bool strict_match;
943943
};
944944

945-
static int alb_upper_dev_walk(struct net_device *upper, void *_data)
945+
static int alb_upper_dev_walk(struct net_device *upper,
946+
struct netdev_nested_priv *priv)
946947
{
947-
struct alb_walk_data *data = _data;
948+
struct alb_walk_data *data = (struct alb_walk_data *)priv->data;
948949
bool strict_match = data->strict_match;
949950
struct bonding *bond = data->bond;
950951
struct slave *slave = data->slave;
@@ -983,21 +984,23 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[],
983984
bool strict_match)
984985
{
985986
struct bonding *bond = bond_get_bond_by_slave(slave);
987+
struct netdev_nested_priv priv;
986988
struct alb_walk_data data = {
987989
.strict_match = strict_match,
988990
.mac_addr = mac_addr,
989991
.slave = slave,
990992
.bond = bond,
991993
};
992994

995+
priv.data = (void *)&data;
993996
/* send untagged */
994997
alb_send_lp_vid(slave, mac_addr, 0, 0);
995998

996999
/* loop through all devices and see if we need to send a packet
9971000
* for that device.
9981001
*/
9991002
rcu_read_lock();
1000-
netdev_walk_all_upper_dev_rcu(bond->dev, alb_upper_dev_walk, &data);
1003+
netdev_walk_all_upper_dev_rcu(bond->dev, alb_upper_dev_walk, &priv);
10011004
rcu_read_unlock();
10021005
}
10031006

drivers/net/bonding/bond_main.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -2511,22 +2511,26 @@ static void bond_mii_monitor(struct work_struct *work)
25112511
}
25122512
}
25132513

2514-
static int bond_upper_dev_walk(struct net_device *upper, void *data)
2514+
static int bond_upper_dev_walk(struct net_device *upper,
2515+
struct netdev_nested_priv *priv)
25152516
{
2516-
__be32 ip = *((__be32 *)data);
2517+
__be32 ip = *(__be32 *)priv->data;
25172518

25182519
return ip == bond_confirm_addr(upper, 0, ip);
25192520
}
25202521

25212522
static bool bond_has_this_ip(struct bonding *bond, __be32 ip)
25222523
{
2524+
struct netdev_nested_priv priv = {
2525+
.data = (void *)&ip,
2526+
};
25232527
bool ret = false;
25242528

25252529
if (ip == bond_confirm_addr(bond->dev, 0, ip))
25262530
return true;
25272531

25282532
rcu_read_lock();
2529-
if (netdev_walk_all_upper_dev_rcu(bond->dev, bond_upper_dev_walk, &ip))
2533+
if (netdev_walk_all_upper_dev_rcu(bond->dev, bond_upper_dev_walk, &priv))
25302534
ret = true;
25312535
rcu_read_unlock();
25322536

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c

+26-11
Original file line numberDiff line numberDiff line change
@@ -5396,9 +5396,10 @@ static int ixgbe_fwd_ring_up(struct ixgbe_adapter *adapter,
53965396
return err;
53975397
}
53985398

5399-
static int ixgbe_macvlan_up(struct net_device *vdev, void *data)
5399+
static int ixgbe_macvlan_up(struct net_device *vdev,
5400+
struct netdev_nested_priv *priv)
54005401
{
5401-
struct ixgbe_adapter *adapter = data;
5402+
struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)priv->data;
54025403
struct ixgbe_fwd_adapter *accel;
54035404

54045405
if (!netif_is_macvlan(vdev))
@@ -5415,8 +5416,12 @@ static int ixgbe_macvlan_up(struct net_device *vdev, void *data)
54155416

54165417
static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
54175418
{
5419+
struct netdev_nested_priv priv = {
5420+
.data = (void *)adapter,
5421+
};
5422+
54185423
netdev_walk_all_upper_dev_rcu(adapter->netdev,
5419-
ixgbe_macvlan_up, adapter);
5424+
ixgbe_macvlan_up, &priv);
54205425
}
54215426

54225427
static void ixgbe_configure(struct ixgbe_adapter *adapter)
@@ -9023,9 +9028,10 @@ static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
90239028
}
90249029

90259030
#endif /* CONFIG_IXGBE_DCB */
9026-
static int ixgbe_reassign_macvlan_pool(struct net_device *vdev, void *data)
9031+
static int ixgbe_reassign_macvlan_pool(struct net_device *vdev,
9032+
struct netdev_nested_priv *priv)
90279033
{
9028-
struct ixgbe_adapter *adapter = data;
9034+
struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)priv->data;
90299035
struct ixgbe_fwd_adapter *accel;
90309036
int pool;
90319037

@@ -9062,13 +9068,16 @@ static int ixgbe_reassign_macvlan_pool(struct net_device *vdev, void *data)
90629068
static void ixgbe_defrag_macvlan_pools(struct net_device *dev)
90639069
{
90649070
struct ixgbe_adapter *adapter = netdev_priv(dev);
9071+
struct netdev_nested_priv priv = {
9072+
.data = (void *)adapter,
9073+
};
90659074

90669075
/* flush any stale bits out of the fwd bitmask */
90679076
bitmap_clear(adapter->fwd_bitmask, 1, 63);
90689077

90699078
/* walk through upper devices reassigning pools */
90709079
netdev_walk_all_upper_dev_rcu(dev, ixgbe_reassign_macvlan_pool,
9071-
adapter);
9080+
&priv);
90729081
}
90739082

90749083
/**
@@ -9242,14 +9251,18 @@ struct upper_walk_data {
92429251
u8 queue;
92439252
};
92449253

9245-
static int get_macvlan_queue(struct net_device *upper, void *_data)
9254+
static int get_macvlan_queue(struct net_device *upper,
9255+
struct netdev_nested_priv *priv)
92469256
{
92479257
if (netif_is_macvlan(upper)) {
92489258
struct ixgbe_fwd_adapter *vadapter = macvlan_accel_priv(upper);
9249-
struct upper_walk_data *data = _data;
9250-
struct ixgbe_adapter *adapter = data->adapter;
9251-
int ifindex = data->ifindex;
9259+
struct ixgbe_adapter *adapter;
9260+
struct upper_walk_data *data;
9261+
int ifindex;
92529262

9263+
data = (struct upper_walk_data *)priv->data;
9264+
ifindex = data->ifindex;
9265+
adapter = data->adapter;
92539266
if (vadapter && upper->ifindex == ifindex) {
92549267
data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
92559268
data->action = data->queue;
@@ -9265,6 +9278,7 @@ static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
92659278
{
92669279
struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
92679280
unsigned int num_vfs = adapter->num_vfs, vf;
9281+
struct netdev_nested_priv priv;
92689282
struct upper_walk_data data;
92699283
struct net_device *upper;
92709284

@@ -9284,8 +9298,9 @@ static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
92849298
data.ifindex = ifindex;
92859299
data.action = 0;
92869300
data.queue = 0;
9301+
priv.data = (void *)&data;
92879302
if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
9288-
get_macvlan_queue, &data)) {
9303+
get_macvlan_queue, &priv)) {
92899304
*action = data.action;
92909305
*queue = data.queue;
92919306

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

+13-11
Original file line numberDiff line numberDiff line change
@@ -3690,13 +3690,13 @@ bool mlxsw_sp_port_dev_check(const struct net_device *dev)
36903690
return dev->netdev_ops == &mlxsw_sp_port_netdev_ops;
36913691
}
36923692

3693-
static int mlxsw_sp_lower_dev_walk(struct net_device *lower_dev, void *data)
3693+
static int mlxsw_sp_lower_dev_walk(struct net_device *lower_dev,
3694+
struct netdev_nested_priv *priv)
36943695
{
3695-
struct mlxsw_sp_port **p_mlxsw_sp_port = data;
36963696
int ret = 0;
36973697

36983698
if (mlxsw_sp_port_dev_check(lower_dev)) {
3699-
*p_mlxsw_sp_port = netdev_priv(lower_dev);
3699+
priv->data = (void *)netdev_priv(lower_dev);
37003700
ret = 1;
37013701
}
37023702

@@ -3705,15 +3705,16 @@ static int mlxsw_sp_lower_dev_walk(struct net_device *lower_dev, void *data)
37053705

37063706
struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev)
37073707
{
3708-
struct mlxsw_sp_port *mlxsw_sp_port;
3708+
struct netdev_nested_priv priv = {
3709+
.data = NULL,
3710+
};
37093711

37103712
if (mlxsw_sp_port_dev_check(dev))
37113713
return netdev_priv(dev);
37123714

3713-
mlxsw_sp_port = NULL;
3714-
netdev_walk_all_lower_dev(dev, mlxsw_sp_lower_dev_walk, &mlxsw_sp_port);
3715+
netdev_walk_all_lower_dev(dev, mlxsw_sp_lower_dev_walk, &priv);
37153716

3716-
return mlxsw_sp_port;
3717+
return (struct mlxsw_sp_port *)priv.data;
37173718
}
37183719

37193720
struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev)
@@ -3726,16 +3727,17 @@ struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev)
37263727

37273728
struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find_rcu(struct net_device *dev)
37283729
{
3729-
struct mlxsw_sp_port *mlxsw_sp_port;
3730+
struct netdev_nested_priv priv = {
3731+
.data = NULL,
3732+
};
37303733

37313734
if (mlxsw_sp_port_dev_check(dev))
37323735
return netdev_priv(dev);
37333736

3734-
mlxsw_sp_port = NULL;
37353737
netdev_walk_all_lower_dev_rcu(dev, mlxsw_sp_lower_dev_walk,
3736-
&mlxsw_sp_port);
3738+
&priv);
37373739

3738-
return mlxsw_sp_port;
3740+
return (struct mlxsw_sp_port *)priv.data;
37393741
}
37403742

37413743
struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev)

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -7351,9 +7351,10 @@ int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,
73517351
return err;
73527352
}
73537353

7354-
static int __mlxsw_sp_rif_macvlan_flush(struct net_device *dev, void *data)
7354+
static int __mlxsw_sp_rif_macvlan_flush(struct net_device *dev,
7355+
struct netdev_nested_priv *priv)
73557356
{
7356-
struct mlxsw_sp_rif *rif = data;
7357+
struct mlxsw_sp_rif *rif = (struct mlxsw_sp_rif *)priv->data;
73577358

73587359
if (!netif_is_macvlan(dev))
73597360
return 0;
@@ -7364,12 +7365,16 @@ static int __mlxsw_sp_rif_macvlan_flush(struct net_device *dev, void *data)
73647365

73657366
static int mlxsw_sp_rif_macvlan_flush(struct mlxsw_sp_rif *rif)
73667367
{
7368+
struct netdev_nested_priv priv = {
7369+
.data = (void *)rif,
7370+
};
7371+
73677372
if (!netif_is_macvlan_port(rif->dev))
73687373
return 0;
73697374

73707375
netdev_warn(rif->dev, "Router interface is deleted. Upper macvlans will not work\n");
73717376
return netdev_walk_all_upper_dev_rcu(rif->dev,
7372-
__mlxsw_sp_rif_macvlan_flush, rif);
7377+
__mlxsw_sp_rif_macvlan_flush, &priv);
73737378
}
73747379

73757380
static void mlxsw_sp_rif_subport_setup(struct mlxsw_sp_rif *rif,

0 commit comments

Comments
 (0)