Skip to content

Commit cf51580

Browse files
committed
Merge branch 'netdev_lockdep_set_classes'
Eric Dumazet says: ==================== net: better lockdep annotations Introduction of qdisc->running seqcount added lockdep false positives. While chasing the bug, it came to me that we had a lot of copies of the same stuff in virtual drivers. This patch series has the qdisc->running fix (considers that a trylock is attempted in lockdep terminology), and adds a generic helper so that we no longer have to patch many virtual drivers when a new per-device or per-qdisc lock is added. Thanks to David Ahern for reporting the issue and testing my patches :) ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 5362855 + 0d7dd79 commit cf51580

File tree

12 files changed

+33
-117
lines changed

12 files changed

+33
-117
lines changed

drivers/net/bonding/bond_main.c

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4607,28 +4607,6 @@ static int bond_check_params(struct bond_params *params)
46074607
return 0;
46084608
}
46094609

4610-
static struct lock_class_key bonding_netdev_xmit_lock_key;
4611-
static struct lock_class_key bonding_netdev_addr_lock_key;
4612-
static struct lock_class_key bonding_tx_busylock_key;
4613-
static struct lock_class_key bonding_qdisc_running_key;
4614-
4615-
static void bond_set_lockdep_class_one(struct net_device *dev,
4616-
struct netdev_queue *txq,
4617-
void *_unused)
4618-
{
4619-
lockdep_set_class(&txq->_xmit_lock,
4620-
&bonding_netdev_xmit_lock_key);
4621-
}
4622-
4623-
static void bond_set_lockdep_class(struct net_device *dev)
4624-
{
4625-
lockdep_set_class(&dev->addr_list_lock,
4626-
&bonding_netdev_addr_lock_key);
4627-
netdev_for_each_tx_queue(dev, bond_set_lockdep_class_one, NULL);
4628-
dev->qdisc_tx_busylock = &bonding_tx_busylock_key;
4629-
dev->qdisc_running_key = &bonding_qdisc_running_key;
4630-
}
4631-
46324610
/* Called from registration process */
46334611
static int bond_init(struct net_device *bond_dev)
46344612
{
@@ -4641,7 +4619,7 @@ static int bond_init(struct net_device *bond_dev)
46414619
if (!bond->wq)
46424620
return -ENOMEM;
46434621

4644-
bond_set_lockdep_class(bond_dev);
4622+
netdev_lockdep_set_classes(bond_dev);
46454623

46464624
list_add_tail(&bond->bond_list, &bn->dev_list);
46474625

drivers/net/ipvlan/ipvlan_main.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,6 @@ static void ipvlan_port_destroy(struct net_device *dev)
8080
kfree_rcu(port, rcu);
8181
}
8282

83-
/* ipvlan network devices have devices nesting below it and are a special
84-
* "super class" of normal network devices; split their locks off into a
85-
* separate class since they always nest.
86-
*/
87-
static struct lock_class_key ipvlan_netdev_xmit_lock_key;
88-
static struct lock_class_key ipvlan_netdev_addr_lock_key;
89-
9083
#define IPVLAN_FEATURES \
9184
(NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST | \
9285
NETIF_F_GSO | NETIF_F_TSO | NETIF_F_UFO | NETIF_F_GSO_ROBUST | \
@@ -96,19 +89,6 @@ static struct lock_class_key ipvlan_netdev_addr_lock_key;
9689
#define IPVLAN_STATE_MASK \
9790
((1<<__LINK_STATE_NOCARRIER) | (1<<__LINK_STATE_DORMANT))
9891

99-
static void ipvlan_set_lockdep_class_one(struct net_device *dev,
100-
struct netdev_queue *txq,
101-
void *_unused)
102-
{
103-
lockdep_set_class(&txq->_xmit_lock, &ipvlan_netdev_xmit_lock_key);
104-
}
105-
106-
static void ipvlan_set_lockdep_class(struct net_device *dev)
107-
{
108-
lockdep_set_class(&dev->addr_list_lock, &ipvlan_netdev_addr_lock_key);
109-
netdev_for_each_tx_queue(dev, ipvlan_set_lockdep_class_one, NULL);
110-
}
111-
11292
static int ipvlan_init(struct net_device *dev)
11393
{
11494
struct ipvl_dev *ipvlan = netdev_priv(dev);
@@ -123,7 +103,7 @@ static int ipvlan_init(struct net_device *dev)
123103
dev->gso_max_segs = phy_dev->gso_max_segs;
124104
dev->hard_header_len = phy_dev->hard_header_len;
125105

126-
ipvlan_set_lockdep_class(dev);
106+
netdev_lockdep_set_classes(dev);
127107

128108
ipvlan->pcpu_stats = alloc_percpu(struct ipvl_pcpu_stats);
129109
if (!ipvlan->pcpu_stats)

drivers/net/macvlan.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,6 @@ static int macvlan_change_mtu(struct net_device *dev, int new_mtu)
788788
* "super class" of normal network devices; split their locks off into a
789789
* separate class since they always nest.
790790
*/
791-
static struct lock_class_key macvlan_netdev_xmit_lock_key;
792791
static struct lock_class_key macvlan_netdev_addr_lock_key;
793792

794793
#define ALWAYS_ON_FEATURES \
@@ -809,20 +808,12 @@ static int macvlan_get_nest_level(struct net_device *dev)
809808
return ((struct macvlan_dev *)netdev_priv(dev))->nest_level;
810809
}
811810

812-
static void macvlan_set_lockdep_class_one(struct net_device *dev,
813-
struct netdev_queue *txq,
814-
void *_unused)
815-
{
816-
lockdep_set_class(&txq->_xmit_lock,
817-
&macvlan_netdev_xmit_lock_key);
818-
}
819-
820811
static void macvlan_set_lockdep_class(struct net_device *dev)
821812
{
813+
netdev_lockdep_set_classes(dev);
822814
lockdep_set_class_and_subclass(&dev->addr_list_lock,
823815
&macvlan_netdev_addr_lock_key,
824816
macvlan_get_nest_level(dev));
825-
netdev_for_each_tx_queue(dev, macvlan_set_lockdep_class_one, NULL);
826817
}
827818

828819
static int macvlan_init(struct net_device *dev)

drivers/net/ppp/ppp_generic.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,13 +1312,9 @@ ppp_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats64)
13121312
return stats64;
13131313
}
13141314

1315-
static struct lock_class_key ppp_tx_busylock;
1316-
static struct lock_class_key ppp_qdisc_running_key;
1317-
13181315
static int ppp_dev_init(struct net_device *dev)
13191316
{
1320-
dev->qdisc_tx_busylock = &ppp_tx_busylock;
1321-
dev->qdisc_running_key = &ppp_qdisc_running_key;
1317+
netdev_lockdep_set_classes(dev);
13221318
return 0;
13231319
}
13241320

drivers/net/team/team.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,25 +1574,6 @@ static const struct team_option team_options[] = {
15741574
},
15751575
};
15761576

1577-
static struct lock_class_key team_netdev_xmit_lock_key;
1578-
static struct lock_class_key team_netdev_addr_lock_key;
1579-
static struct lock_class_key team_tx_busylock_key;
1580-
static struct lock_class_key team_qdisc_running_key;
1581-
1582-
static void team_set_lockdep_class_one(struct net_device *dev,
1583-
struct netdev_queue *txq,
1584-
void *unused)
1585-
{
1586-
lockdep_set_class(&txq->_xmit_lock, &team_netdev_xmit_lock_key);
1587-
}
1588-
1589-
static void team_set_lockdep_class(struct net_device *dev)
1590-
{
1591-
lockdep_set_class(&dev->addr_list_lock, &team_netdev_addr_lock_key);
1592-
netdev_for_each_tx_queue(dev, team_set_lockdep_class_one, NULL);
1593-
dev->qdisc_tx_busylock = &team_tx_busylock_key;
1594-
dev->qdisc_running_key = &team_qdisc_running_key;
1595-
}
15961577

15971578
static int team_init(struct net_device *dev)
15981579
{
@@ -1628,7 +1609,7 @@ static int team_init(struct net_device *dev)
16281609
goto err_options_register;
16291610
netif_carrier_off(dev);
16301611

1631-
team_set_lockdep_class(dev);
1612+
netdev_lockdep_set_classes(dev);
16321613

16331614
return 0;
16341615

drivers/net/vrf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ static int vrf_dev_init(struct net_device *dev)
661661

662662
/* similarly, oper state is irrelevant; set to up to avoid confusion */
663663
dev->operstate = IF_OPER_UP;
664-
664+
netdev_lockdep_set_classes(dev);
665665
return 0;
666666

667667
out_rth:

include/linux/netdevice.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,23 @@ static inline void netdev_for_each_tx_queue(struct net_device *dev,
19461946
f(dev, &dev->_tx[i], arg);
19471947
}
19481948

1949+
#define netdev_lockdep_set_classes(dev) \
1950+
{ \
1951+
static struct lock_class_key qdisc_tx_busylock_key; \
1952+
static struct lock_class_key qdisc_running_key; \
1953+
static struct lock_class_key qdisc_xmit_lock_key; \
1954+
static struct lock_class_key dev_addr_list_lock_key; \
1955+
unsigned int i; \
1956+
\
1957+
(dev)->qdisc_tx_busylock = &qdisc_tx_busylock_key; \
1958+
(dev)->qdisc_running_key = &qdisc_running_key; \
1959+
lockdep_set_class(&(dev)->addr_list_lock, \
1960+
&dev_addr_list_lock_key); \
1961+
for (i = 0; i < (dev)->num_tx_queues; i++) \
1962+
lockdep_set_class(&(dev)->_tx[i]._xmit_lock, \
1963+
&qdisc_xmit_lock_key); \
1964+
}
1965+
19491966
struct netdev_queue *netdev_pick_tx(struct net_device *dev,
19501967
struct sk_buff *skb,
19511968
void *accel_priv);

include/net/sch_generic.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ static inline bool qdisc_run_begin(struct Qdisc *qdisc)
9797
{
9898
if (qdisc_is_running(qdisc))
9999
return false;
100-
write_seqcount_begin(&qdisc->running);
100+
/* Variant of write_seqcount_begin() telling lockdep a trylock
101+
* was attempted.
102+
*/
103+
raw_write_seqcount_begin(&qdisc->running);
104+
seqcount_acquire(&qdisc->running.dep_map, 0, 1, _RET_IP_);
101105
return true;
102106
}
103107

net/bluetooth/6lowpan.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -627,22 +627,9 @@ static netdev_tx_t bt_xmit(struct sk_buff *skb, struct net_device *netdev)
627627
return err < 0 ? NET_XMIT_DROP : err;
628628
}
629629

630-
static struct lock_class_key bt_tx_busylock;
631-
static struct lock_class_key bt_netdev_xmit_lock_key;
632-
static struct lock_class_key bt_qdisc_running_key;
633-
634-
static void bt_set_lockdep_class_one(struct net_device *dev,
635-
struct netdev_queue *txq,
636-
void *_unused)
637-
{
638-
lockdep_set_class(&txq->_xmit_lock, &bt_netdev_xmit_lock_key);
639-
}
640-
641630
static int bt_dev_init(struct net_device *dev)
642631
{
643-
netdev_for_each_tx_queue(dev, bt_set_lockdep_class_one, NULL);
644-
dev->qdisc_tx_busylock = &bt_tx_busylock;
645-
dev->qdisc_running_key = &bt_qdisc_running_key;
632+
netdev_lockdep_set_classes(dev);
646633

647634
return 0;
648635
}

net/ieee802154/6lowpan/core.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,9 @@ static struct header_ops lowpan_header_ops = {
5858
.create = lowpan_header_create,
5959
};
6060

61-
static struct lock_class_key lowpan_tx_busylock;
62-
static struct lock_class_key lowpan_netdev_xmit_lock_key;
63-
static struct lock_class_key lowpan_qdisc_running_key;
64-
65-
static void lowpan_set_lockdep_class_one(struct net_device *ldev,
66-
struct netdev_queue *txq,
67-
void *_unused)
68-
{
69-
lockdep_set_class(&txq->_xmit_lock,
70-
&lowpan_netdev_xmit_lock_key);
71-
}
72-
7361
static int lowpan_dev_init(struct net_device *ldev)
7462
{
75-
netdev_for_each_tx_queue(ldev, lowpan_set_lockdep_class_one, NULL);
76-
ldev->qdisc_tx_busylock = &lowpan_tx_busylock;
77-
ldev->qdisc_running_key = &lowpan_qdisc_running_key;
63+
netdev_lockdep_set_classes(ldev);
7864

7965
return 0;
8066
}

net/l2tp/l2tp_eth.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,14 @@ static inline struct l2tp_eth_net *l2tp_eth_pernet(struct net *net)
6767
return net_generic(net, l2tp_eth_net_id);
6868
}
6969

70-
static struct lock_class_key l2tp_eth_tx_busylock;
71-
static struct lock_class_key l2tp_qdisc_running_key;
72-
7370
static int l2tp_eth_dev_init(struct net_device *dev)
7471
{
7572
struct l2tp_eth *priv = netdev_priv(dev);
7673

7774
priv->dev = dev;
7875
eth_hw_addr_random(dev);
7976
eth_broadcast_addr(dev->broadcast);
80-
dev->qdisc_tx_busylock = &l2tp_eth_tx_busylock;
81-
dev->qdisc_running_key = &l2tp_qdisc_running_key;
77+
netdev_lockdep_set_classes(dev);
8278

8379
return 0;
8480
}

net/sched/sch_generic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ int sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,
137137

138138
HARD_TX_UNLOCK(dev, txq);
139139
} else {
140-
spin_lock_nested(root_lock, SINGLE_DEPTH_NESTING);
140+
spin_lock(root_lock);
141141
return qdisc_qlen(q);
142142
}
143-
spin_lock_nested(root_lock, SINGLE_DEPTH_NESTING);
143+
spin_lock(root_lock);
144144

145145
if (dev_xmit_complete(ret)) {
146146
/* Driver sent out skb successfully or skb was consumed */

0 commit comments

Comments
 (0)