Skip to content

Commit ab92d68

Browse files
TaeheeYoodavem330
authored andcommitted
net: core: add generic lockdep keys
Some interface types could be nested. (VLAN, BONDING, TEAM, MACSEC, MACVLAN, IPVLAN, VIRT_WIFI, VXLAN, etc..) These interface types should set lockdep class because, without lockdep class key, lockdep always warn about unexisting circular locking. In the current code, these interfaces have their own lockdep class keys and these manage itself. So that there are so many duplicate code around the /driver/net and /net/. This patch adds new generic lockdep keys and some helper functions for it. This patch does below changes. a) Add lockdep class keys in struct net_device - qdisc_running, xmit, addr_list, qdisc_busylock - these keys are used as dynamic lockdep key. b) When net_device is being allocated, lockdep keys are registered. - alloc_netdev_mqs() c) When net_device is being free'd llockdep keys are unregistered. - free_netdev() d) Add generic lockdep key helper function - netdev_register_lockdep_key() - netdev_unregister_lockdep_key() - netdev_update_lockdep_key() e) Remove unnecessary generic lockdep macro and functions f) Remove unnecessary lockdep code of each interfaces. After this patch, each interface modules don't need to maintain their lockdep keys. Signed-off-by: Taehee Yoo <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5343da4 commit ab92d68

File tree

25 files changed

+63
-356
lines changed

25 files changed

+63
-356
lines changed

drivers/net/bonding/bond_main.c

-1
Original file line numberDiff line numberDiff line change
@@ -4769,7 +4769,6 @@ static int bond_init(struct net_device *bond_dev)
47694769
return -ENOMEM;
47704770

47714771
bond->nest_level = SINGLE_DEPTH_NESTING;
4772-
netdev_lockdep_set_classes(bond_dev);
47734772

47744773
list_add_tail(&bond->bond_list, &bn->dev_list);
47754774

drivers/net/ethernet/netronome/nfp/nfp_net_repr.c

-18
Original file line numberDiff line numberDiff line change
@@ -299,22 +299,6 @@ static void nfp_repr_clean(struct nfp_repr *repr)
299299
nfp_port_free(repr->port);
300300
}
301301

302-
static struct lock_class_key nfp_repr_netdev_xmit_lock_key;
303-
static struct lock_class_key nfp_repr_netdev_addr_lock_key;
304-
305-
static void nfp_repr_set_lockdep_class_one(struct net_device *dev,
306-
struct netdev_queue *txq,
307-
void *_unused)
308-
{
309-
lockdep_set_class(&txq->_xmit_lock, &nfp_repr_netdev_xmit_lock_key);
310-
}
311-
312-
static void nfp_repr_set_lockdep_class(struct net_device *dev)
313-
{
314-
lockdep_set_class(&dev->addr_list_lock, &nfp_repr_netdev_addr_lock_key);
315-
netdev_for_each_tx_queue(dev, nfp_repr_set_lockdep_class_one, NULL);
316-
}
317-
318302
int nfp_repr_init(struct nfp_app *app, struct net_device *netdev,
319303
u32 cmsg_port_id, struct nfp_port *port,
320304
struct net_device *pf_netdev)
@@ -324,8 +308,6 @@ int nfp_repr_init(struct nfp_app *app, struct net_device *netdev,
324308
u32 repr_cap = nn->tlv_caps.repr_cap;
325309
int err;
326310

327-
nfp_repr_set_lockdep_class(netdev);
328-
329311
repr->port = port;
330312
repr->dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX, GFP_KERNEL);
331313
if (!repr->dst)

drivers/net/hamradio/bpqether.c

-22
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,6 @@ struct bpqdev {
107107

108108
static LIST_HEAD(bpq_devices);
109109

110-
/*
111-
* bpqether network devices are paired with ethernet devices below them, so
112-
* form a special "super class" of normal ethernet devices; split their locks
113-
* off into a separate class since they always nest.
114-
*/
115-
static struct lock_class_key bpq_netdev_xmit_lock_key;
116-
static struct lock_class_key bpq_netdev_addr_lock_key;
117-
118-
static void bpq_set_lockdep_class_one(struct net_device *dev,
119-
struct netdev_queue *txq,
120-
void *_unused)
121-
{
122-
lockdep_set_class(&txq->_xmit_lock, &bpq_netdev_xmit_lock_key);
123-
}
124-
125-
static void bpq_set_lockdep_class(struct net_device *dev)
126-
{
127-
lockdep_set_class(&dev->addr_list_lock, &bpq_netdev_addr_lock_key);
128-
netdev_for_each_tx_queue(dev, bpq_set_lockdep_class_one, NULL);
129-
}
130-
131110
/* ------------------------------------------------------------------------ */
132111

133112

@@ -498,7 +477,6 @@ static int bpq_new_device(struct net_device *edev)
498477
err = register_netdevice(ndev);
499478
if (err)
500479
goto error;
501-
bpq_set_lockdep_class(ndev);
502480

503481
/* List protected by RTNL */
504482
list_add_rcu(&bpq->bpq_list, &bpq_devices);

drivers/net/hyperv/netvsc_drv.c

-2
Original file line numberDiff line numberDiff line change
@@ -2335,8 +2335,6 @@ static int netvsc_probe(struct hv_device *dev,
23352335
NETIF_F_HW_VLAN_CTAG_RX;
23362336
net->vlan_features = net->features;
23372337

2338-
netdev_lockdep_set_classes(net);
2339-
23402338
/* MTU range: 68 - 1500 or 65521 */
23412339
net->min_mtu = NETVSC_MTU_MIN;
23422340
if (nvdev->nvsp_version >= NVSP_PROTOCOL_VERSION_2)

drivers/net/ipvlan/ipvlan_main.c

-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ static int ipvlan_init(struct net_device *dev)
131131
dev->gso_max_segs = phy_dev->gso_max_segs;
132132
dev->hard_header_len = phy_dev->hard_header_len;
133133

134-
netdev_lockdep_set_classes(dev);
135-
136134
ipvlan->pcpu_stats = netdev_alloc_pcpu_stats(struct ipvl_pcpu_stats);
137135
if (!ipvlan->pcpu_stats)
138136
return -ENOMEM;

drivers/net/macsec.c

-5
Original file line numberDiff line numberDiff line change
@@ -2750,7 +2750,6 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
27502750

27512751
#define MACSEC_FEATURES \
27522752
(NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST)
2753-
static struct lock_class_key macsec_netdev_addr_lock_key;
27542753

27552754
static int macsec_dev_init(struct net_device *dev)
27562755
{
@@ -3264,10 +3263,6 @@ static int macsec_newlink(struct net *net, struct net_device *dev,
32643263
dev_hold(real_dev);
32653264

32663265
macsec->nest_level = dev_get_nest_level(real_dev) + 1;
3267-
netdev_lockdep_set_classes(dev);
3268-
lockdep_set_class_and_subclass(&dev->addr_list_lock,
3269-
&macsec_netdev_addr_lock_key,
3270-
macsec_get_nest_level(dev));
32713266

32723267
err = netdev_upper_dev_link(real_dev, dev, extack);
32733268
if (err < 0)

drivers/net/macvlan.c

-12
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,6 @@ static int macvlan_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
852852
* "super class" of normal network devices; split their locks off into a
853853
* separate class since they always nest.
854854
*/
855-
static struct lock_class_key macvlan_netdev_addr_lock_key;
856-
857855
#define ALWAYS_ON_OFFLOADS \
858856
(NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_GSO_SOFTWARE | \
859857
NETIF_F_GSO_ROBUST | NETIF_F_GSO_ENCAP_ALL)
@@ -874,14 +872,6 @@ static int macvlan_get_nest_level(struct net_device *dev)
874872
return ((struct macvlan_dev *)netdev_priv(dev))->nest_level;
875873
}
876874

877-
static void macvlan_set_lockdep_class(struct net_device *dev)
878-
{
879-
netdev_lockdep_set_classes(dev);
880-
lockdep_set_class_and_subclass(&dev->addr_list_lock,
881-
&macvlan_netdev_addr_lock_key,
882-
macvlan_get_nest_level(dev));
883-
}
884-
885875
static int macvlan_init(struct net_device *dev)
886876
{
887877
struct macvlan_dev *vlan = netdev_priv(dev);
@@ -900,8 +890,6 @@ static int macvlan_init(struct net_device *dev)
900890
dev->gso_max_segs = lowerdev->gso_max_segs;
901891
dev->hard_header_len = lowerdev->hard_header_len;
902892

903-
macvlan_set_lockdep_class(dev);
904-
905893
vlan->pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats);
906894
if (!vlan->pcpu_stats)
907895
return -ENOMEM;

drivers/net/ppp/ppp_generic.c

-2
Original file line numberDiff line numberDiff line change
@@ -1324,8 +1324,6 @@ static int ppp_dev_init(struct net_device *dev)
13241324
{
13251325
struct ppp *ppp;
13261326

1327-
netdev_lockdep_set_classes(dev);
1328-
13291327
ppp = netdev_priv(dev);
13301328
/* Let the netdevice take a reference on the ppp file. This ensures
13311329
* that ppp_destroy_interface() won't run before the device gets

drivers/net/team/team.c

-2
Original file line numberDiff line numberDiff line change
@@ -1642,8 +1642,6 @@ static int team_init(struct net_device *dev)
16421642
goto err_options_register;
16431643
netif_carrier_off(dev);
16441644

1645-
netdev_lockdep_set_classes(dev);
1646-
16471645
return 0;
16481646

16491647
err_options_register:

drivers/net/vrf.c

-1
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,6 @@ static int vrf_dev_init(struct net_device *dev)
865865

866866
/* similarly, oper state is irrelevant; set to up to avoid confusion */
867867
dev->operstate = IF_OPER_UP;
868-
netdev_lockdep_set_classes(dev);
869868
return 0;
870869

871870
out_rth:

drivers/net/wireless/intersil/hostap/hostap_hw.c

-25
Original file line numberDiff line numberDiff line change
@@ -3041,30 +3041,6 @@ static void prism2_clear_set_tim_queue(local_info_t *local)
30413041
}
30423042
}
30433043

3044-
3045-
/*
3046-
* HostAP uses two layers of net devices, where the inner
3047-
* layer gets called all the time from the outer layer.
3048-
* This is a natural nesting, which needs a split lock type.
3049-
*/
3050-
static struct lock_class_key hostap_netdev_xmit_lock_key;
3051-
static struct lock_class_key hostap_netdev_addr_lock_key;
3052-
3053-
static void prism2_set_lockdep_class_one(struct net_device *dev,
3054-
struct netdev_queue *txq,
3055-
void *_unused)
3056-
{
3057-
lockdep_set_class(&txq->_xmit_lock,
3058-
&hostap_netdev_xmit_lock_key);
3059-
}
3060-
3061-
static void prism2_set_lockdep_class(struct net_device *dev)
3062-
{
3063-
lockdep_set_class(&dev->addr_list_lock,
3064-
&hostap_netdev_addr_lock_key);
3065-
netdev_for_each_tx_queue(dev, prism2_set_lockdep_class_one, NULL);
3066-
}
3067-
30683044
static struct net_device *
30693045
prism2_init_local_data(struct prism2_helper_functions *funcs, int card_idx,
30703046
struct device *sdev)
@@ -3223,7 +3199,6 @@ while (0)
32233199
if (ret >= 0)
32243200
ret = register_netdevice(dev);
32253201

3226-
prism2_set_lockdep_class(dev);
32273202
rtnl_unlock();
32283203
if (ret < 0) {
32293204
printk(KERN_WARNING "%s: register netdevice failed!\n",

include/linux/netdevice.h

+13-22
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ struct dev_ifalias {
925925
struct devlink;
926926
struct tlsdev_ops;
927927

928+
928929
/*
929930
* This structure defines the management hooks for network devices.
930931
* The following hooks can be defined; unless noted otherwise, they are
@@ -1760,9 +1761,13 @@ enum netdev_priv_flags {
17601761
* @phydev: Physical device may attach itself
17611762
* for hardware timestamping
17621763
* @sfp_bus: attached &struct sfp_bus structure.
1763-
*
1764-
* @qdisc_tx_busylock: lockdep class annotating Qdisc->busylock spinlock
1765-
* @qdisc_running_key: lockdep class annotating Qdisc->running seqcount
1764+
* @qdisc_tx_busylock_key: lockdep class annotating Qdisc->busylock
1765+
spinlock
1766+
* @qdisc_running_key: lockdep class annotating Qdisc->running seqcount
1767+
* @qdisc_xmit_lock_key: lockdep class annotating
1768+
* netdev_queue->_xmit_lock spinlock
1769+
* @addr_list_lock_key: lockdep class annotating
1770+
* net_device->addr_list_lock spinlock
17661771
*
17671772
* @proto_down: protocol port state information can be sent to the
17681773
* switch driver and used to set the phys state of the
@@ -2049,8 +2054,10 @@ struct net_device {
20492054
#endif
20502055
struct phy_device *phydev;
20512056
struct sfp_bus *sfp_bus;
2052-
struct lock_class_key *qdisc_tx_busylock;
2053-
struct lock_class_key *qdisc_running_key;
2057+
struct lock_class_key qdisc_tx_busylock_key;
2058+
struct lock_class_key qdisc_running_key;
2059+
struct lock_class_key qdisc_xmit_lock_key;
2060+
struct lock_class_key addr_list_lock_key;
20542061
bool proto_down;
20552062
unsigned wol_enabled:1;
20562063
};
@@ -2128,23 +2135,6 @@ static inline void netdev_for_each_tx_queue(struct net_device *dev,
21282135
f(dev, &dev->_tx[i], arg);
21292136
}
21302137

2131-
#define netdev_lockdep_set_classes(dev) \
2132-
{ \
2133-
static struct lock_class_key qdisc_tx_busylock_key; \
2134-
static struct lock_class_key qdisc_running_key; \
2135-
static struct lock_class_key qdisc_xmit_lock_key; \
2136-
static struct lock_class_key dev_addr_list_lock_key; \
2137-
unsigned int i; \
2138-
\
2139-
(dev)->qdisc_tx_busylock = &qdisc_tx_busylock_key; \
2140-
(dev)->qdisc_running_key = &qdisc_running_key; \
2141-
lockdep_set_class(&(dev)->addr_list_lock, \
2142-
&dev_addr_list_lock_key); \
2143-
for (i = 0; i < (dev)->num_tx_queues; i++) \
2144-
lockdep_set_class(&(dev)->_tx[i]._xmit_lock, \
2145-
&qdisc_xmit_lock_key); \
2146-
}
2147-
21482138
u16 netdev_pick_tx(struct net_device *dev, struct sk_buff *skb,
21492139
struct net_device *sb_dev);
21502140
struct netdev_queue *netdev_core_pick_tx(struct net_device *dev,
@@ -3143,6 +3133,7 @@ static inline void netif_stop_queue(struct net_device *dev)
31433133
}
31443134

31453135
void netif_tx_stop_all_queues(struct net_device *dev);
3136+
void netdev_update_lockdep_key(struct net_device *dev);
31463137

31473138
static inline bool netif_tx_queue_stopped(const struct netdev_queue *dev_queue)
31483139
{

net/8021q/vlan_dev.c

-27
Original file line numberDiff line numberDiff line change
@@ -489,31 +489,6 @@ static void vlan_dev_set_rx_mode(struct net_device *vlan_dev)
489489
dev_uc_sync(vlan_dev_priv(vlan_dev)->real_dev, vlan_dev);
490490
}
491491

492-
/*
493-
* vlan network devices have devices nesting below it, and are a special
494-
* "super class" of normal network devices; split their locks off into a
495-
* separate class since they always nest.
496-
*/
497-
static struct lock_class_key vlan_netdev_xmit_lock_key;
498-
static struct lock_class_key vlan_netdev_addr_lock_key;
499-
500-
static void vlan_dev_set_lockdep_one(struct net_device *dev,
501-
struct netdev_queue *txq,
502-
void *_subclass)
503-
{
504-
lockdep_set_class_and_subclass(&txq->_xmit_lock,
505-
&vlan_netdev_xmit_lock_key,
506-
*(int *)_subclass);
507-
}
508-
509-
static void vlan_dev_set_lockdep_class(struct net_device *dev, int subclass)
510-
{
511-
lockdep_set_class_and_subclass(&dev->addr_list_lock,
512-
&vlan_netdev_addr_lock_key,
513-
subclass);
514-
netdev_for_each_tx_queue(dev, vlan_dev_set_lockdep_one, &subclass);
515-
}
516-
517492
static int vlan_dev_get_lock_subclass(struct net_device *dev)
518493
{
519494
return vlan_dev_priv(dev)->nest_level;
@@ -609,8 +584,6 @@ static int vlan_dev_init(struct net_device *dev)
609584

610585
SET_NETDEV_DEVTYPE(dev, &vlan_type);
611586

612-
vlan_dev_set_lockdep_class(dev, vlan_dev_get_lock_subclass(dev));
613-
614587
vlan->vlan_pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats);
615588
if (!vlan->vlan_pcpu_stats)
616589
return -ENOMEM;

net/batman-adv/soft-interface.c

-32
Original file line numberDiff line numberDiff line change
@@ -740,36 +740,6 @@ static int batadv_interface_kill_vid(struct net_device *dev, __be16 proto,
740740
return 0;
741741
}
742742

743-
/* batman-adv network devices have devices nesting below it and are a special
744-
* "super class" of normal network devices; split their locks off into a
745-
* separate class since they always nest.
746-
*/
747-
static struct lock_class_key batadv_netdev_xmit_lock_key;
748-
static struct lock_class_key batadv_netdev_addr_lock_key;
749-
750-
/**
751-
* batadv_set_lockdep_class_one() - Set lockdep class for a single tx queue
752-
* @dev: device which owns the tx queue
753-
* @txq: tx queue to modify
754-
* @_unused: always NULL
755-
*/
756-
static void batadv_set_lockdep_class_one(struct net_device *dev,
757-
struct netdev_queue *txq,
758-
void *_unused)
759-
{
760-
lockdep_set_class(&txq->_xmit_lock, &batadv_netdev_xmit_lock_key);
761-
}
762-
763-
/**
764-
* batadv_set_lockdep_class() - Set txq and addr_list lockdep class
765-
* @dev: network device to modify
766-
*/
767-
static void batadv_set_lockdep_class(struct net_device *dev)
768-
{
769-
lockdep_set_class(&dev->addr_list_lock, &batadv_netdev_addr_lock_key);
770-
netdev_for_each_tx_queue(dev, batadv_set_lockdep_class_one, NULL);
771-
}
772-
773743
/**
774744
* batadv_softif_init_late() - late stage initialization of soft interface
775745
* @dev: registered network device to modify
@@ -783,8 +753,6 @@ static int batadv_softif_init_late(struct net_device *dev)
783753
int ret;
784754
size_t cnt_len = sizeof(u64) * BATADV_CNT_NUM;
785755

786-
batadv_set_lockdep_class(dev);
787-
788756
bat_priv = netdev_priv(dev);
789757
bat_priv->soft_iface = dev;
790758

net/bluetooth/6lowpan.c

-8
Original file line numberDiff line numberDiff line change
@@ -571,15 +571,7 @@ static netdev_tx_t bt_xmit(struct sk_buff *skb, struct net_device *netdev)
571571
return err < 0 ? NET_XMIT_DROP : err;
572572
}
573573

574-
static int bt_dev_init(struct net_device *dev)
575-
{
576-
netdev_lockdep_set_classes(dev);
577-
578-
return 0;
579-
}
580-
581574
static const struct net_device_ops netdev_ops = {
582-
.ndo_init = bt_dev_init,
583575
.ndo_start_xmit = bt_xmit,
584576
};
585577

0 commit comments

Comments
 (0)