net: core: limit nested device depth
Subsystems (20)
PATCH v5 1/10 net: core: limit nested device depth
Current code doesn't limit the number of nested devices. Nested devices would be handled recursively and this needs huge stack memory. So, unlimited nested devices could make stack overflow.
This patch adds upper_level and lower_level, they are common variables and represent maximum lower/upper depth.
When upper/lower device is attached or dettached, {lower/upper}_level are updated. and if maximum depth is bigger than 8, attach routine fails and returns -EMLINK.
In addition, this patch converts recursive routine of netdev_walk_all_{lower/upper} to iterator routine.
Test commands:
ip link add dummy0 type dummy
ip link add link dummy0 name vlan1 type vlan id 1 ip link set vlan1 up
for i in {2..55}
do
let A=$i-1
ip link add vlan$i link vlan$A type vlan id $i
done
ip link del dummy0
Splat looks like:
[ 155.513226][ T908] BUG: KASAN: use-after-free in __unwind_start+0x71/0x850 [ 155.514162][ T908] Write of size 88 at addr ffff8880608a6cc0 by task ip/908 [ 155.515048][ T908] [ 155.515333][ T908] CPU: 0 PID: 908 Comm: ip Not tainted 5.4.0-rc3+ #96 [ 155.516147][ T908] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 155.517233][ T908] Call Trace: [ 155.517627][ T908] [ 155.517918][ T908] Allocated by task 0: [ 155.518412][ T908] (stack is not available) [ 155.518955][ T908] [ 155.519228][ T908] Freed by task 0: [ 155.519885][ T908] (stack is not available) [ 155.520452][ T908] [ 155.520729][ T908] The buggy address belongs to the object at ffff8880608a6ac0 [ 155.520729][ T908] which belongs to the cache names_cache of size 4096 [ 155.522387][ T908] The buggy address is located 512 bytes inside of [ 155.522387][ T908] 4096-byte region [ffff8880608a6ac0, ffff8880608a7ac0) [ 155.523920][ T908] The buggy address belongs to the page: [ 155.524552][ T908] page:ffffea0001822800 refcount:1 mapcount:0 mapping:ffff88806c657cc0 index:0x0 compound_mapcount:0 [ 155.525836][ T908] flags: 0x100000000010200(slab|head) [ 155.526445][ T908] raw: 0100000000010200 ffffea0001813808 ffffea0001a26c08 ffff88806c657cc0 [ 155.527424][ T908] raw: 0000000000000000 0000000000070007 00000001ffffffff 0000000000000000 [ 155.528429][ T908] page dumped because: kasan: bad access detected [ 155.529158][ T908] [ 155.529410][ T908] Memory state around the buggy address: [ 155.530060][ T908] ffff8880608a6b80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 155.530971][ T908] ffff8880608a6c00: fb fb fb fb fb f1 f1 f1 f1 00 f2 f2 f2 f3 f3 f3 [ 155.531889][ T908] >ffff8880608a6c80: f3 fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 155.532806][ T908] ^ [ 155.533509][ T908] ffff8880608a6d00: fb fb fb fb fb fb fb fb fb f1 f1 f1 f1 00 00 00 [ 155.534436][ T908] ffff8880608a6d80: f2 f3 f3 f3 f3 fb fb fb 00 00 00 00 00 00 00 00
[ ... ]
---
v4 -> v5 :
- Move variables position
- Fix iterator routine
v3 -> v4 :
- This patch is not changed
v2 -> v3 :
- Modify nesting infra code to use iterator instead of recursive
v1 -> v2 :
- This patch is not changed
include/linux/netdevice.h | 4 + net/core/dev.c | 272 +++++++++++++++++++++++++++++++------- 2 files changed, 231 insertions(+), 45 deletions(-)
include/linux/netdevice.h +4 -0
@@ -1649,6 +1649,8 @@ enum netdev_priv_flags {* @perm_addr: Permanent hw address * @addr_assign_type: Hw address assignment type * @addr_len: Hardware address length +* @upper_level: Maximum depth level of upper devices. +* @lower_level: Maximum depth level of lower devices. * @neigh_priv_len: Used in neigh_alloc() * @dev_id: Used to differentiate devices that share * the same link layer address
@@ -1875,6 +1877,8 @@ struct net_device {unsigned char perm_addr[MAX_ADDR_LEN ];unsigned char addr_assign_type;unsigned char addr_len; +unsigned char upper_level; +unsigned char lower_level;unsigned short neigh_priv_len;unsigned short dev_id;unsigned short dev_port;
net/core/dev.c +227 -45
342 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v5 2/10 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.
---
v5 :
- Initial patch
drivers/net/bonding/bond_main.c | 1 - .../net/ethernet/netronome/nfp/nfp_net_repr.c | 18 --- drivers/net/hamradio/bpqether.c | 22 --- drivers/net/hyperv/netvsc_drv.c | 2 - drivers/net/ipvlan/ipvlan_main.c | 2 - drivers/net/macsec.c | 5 - drivers/net/macvlan.c | 12 -- drivers/net/ppp/ppp_generic.c | 2 - drivers/net/team/team.c | 2 - drivers/net/vrf.c | 1 - .../net/wireless/intersil/hostap/hostap_hw.c | 25 ---- include/linux/netdevice.h | 35 ++--- net/8021q/vlan_dev.c | 27 ---- net/batman-adv/soft-interface.c | 32 ----- net/bluetooth/6lowpan.c | 8 -- net/bridge/br_device.c | 8 -- net/core/dev.c | 127 ++++++------------ net/core/rtnetlink.c | 1 + net/dsa/master.c | 5 - net/dsa/slave.c | 12 -- net/ieee802154/6lowpan/core.c | 8 -- net/l2tp/l2tp_eth.c | 1 - net/netrom/af_netrom.c | 23 ---- net/rose/af_rose.c | 23 ---- net/sched/sch_generic.c | 17 +-- 25 files changed, 63 insertions(+), 356 deletions(-)
drivers/net/bonding/bond_main.c +0 -1
@@ -4769,7 +4769,6 @@ static int bond_init(struct net_device *bond_dev)return -ENOMEM ; bond->nest_level =SINGLE_DEPTH_NESTING ; -netdev_lockdep_set_classes (bond_dev);list_add_tail (&bond->bond_list, &bn->dev_list);
drivers/net/ethernet/netronome/nfp/nfp_net_repr.c +0 -18
@@ -299,22 +299,6 @@ static void nfp_repr_clean(struct nfp_repr *repr)nfp_port_free (repr->port); } -static struct lock_class_key nfp_repr_netdev_xmit_lock_key; -static struct lock_class_key nfp_repr_netdev_addr_lock_key; - -static void nfp_repr_set_lockdep_class_one (struct net_device *dev, -struct netdev_queue *txq, -void *_unused) -{ -lockdep_set_class (&txq->_xmit_lock, &nfp_repr_netdev_xmit_lock_key); -} - -static void nfp_repr_set_lockdep_class (struct net_device *dev) -{ -lockdep_set_class (&dev->addr_list_lock, &nfp_repr_netdev_addr_lock_key); -netdev_for_each_tx_queue (dev, nfp_repr_set_lockdep_class_one,NULL ); -} -int nfp_repr_init (struct nfp_app *app,struct net_device *netdev,u32 cmsg_port_id,struct nfp_port *port,struct net_device *pf_netdev)
@@ -324,8 +308,6 @@ int nfp_repr_init(struct nfp_app *app, struct net_device *netdev,u32 repr_cap = nn->tlv_caps.repr_cap;int err; -nfp_repr_set_lockdep_class (netdev); - repr->port = port; repr->dst =metadata_dst_alloc (0 ,METADATA_HW_PORT_MUX ,GFP_KERNEL );if (!repr->dst)
drivers/net/hamradio/bpqether.c +0 -22
@@ -107,27 +107,6 @@ struct bpqdev {static LIST_HEAD (bpq_devices); -/* -* bpqether network devices are paired with ethernet devices below them, so -* form a special "super class" of normal ethernet devices; split their locks -* off into a separate class since they always nest. -*/ -static struct lock_class_key bpq_netdev_xmit_lock_key; -static struct lock_class_key bpq_netdev_addr_lock_key; - -static void bpq_set_lockdep_class_one (struct net_device *dev, -struct netdev_queue *txq, -void *_unused) -{ -lockdep_set_class (&txq->_xmit_lock, &bpq_netdev_xmit_lock_key); -} - -static void bpq_set_lockdep_class (struct net_device *dev) -{ -lockdep_set_class (&dev->addr_list_lock, &bpq_netdev_addr_lock_key); -netdev_for_each_tx_queue (dev, bpq_set_lockdep_class_one,NULL ); -} -/* ------------------------------------------------------------------------ */
@@ -498,7 +477,6 @@ static int bpq_new_device(struct net_device *edev) err =register_netdevice (ndev);if (err) goto error; -bpq_set_lockdep_class (ndev);/* List protected by RTNL */ list_add_rcu (&bpq->bpq_list, &bpq_devices);
drivers/net/hyperv/netvsc_drv.c +0 -2
@@ -2335,8 +2335,6 @@ static int netvsc_probe(struct hv_device *dev,NETIF_F_HW_VLAN_CTAG_RX ; net->vlan_features = net->features; -netdev_lockdep_set_classes (net); -/* MTU range: 68 - 1500 or 65521 */ net->min_mtu =NETVSC_MTU_MIN ;if (nvdev->nvsp_version >=NVSP_PROTOCOL_VERSION_2 )
drivers/net/ipvlan/ipvlan_main.c +0 -2
@@ -131,8 +131,6 @@ static int ipvlan_init(struct net_device *dev) dev->gso_max_segs = phy_dev->gso_max_segs; dev->hard_header_len = phy_dev->hard_header_len; -netdev_lockdep_set_classes (dev); - ipvlan->pcpu_stats = netdev_alloc_pcpu_stats(struct ipvl_pcpu_stats);if (!ipvlan->pcpu_stats)return -ENOMEM ;
drivers/net/macsec.c +0 -5
@@ -2750,7 +2750,6 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,#define MACSEC_FEATURES \ (NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST) -static struct lock_class_key macsec_netdev_addr_lock_key;static int macsec_dev_init (struct net_device *dev) {
@@ -3264,10 +3263,6 @@ static int macsec_newlink(struct net *net, struct net_device *dev,dev_hold (real_dev); macsec->nest_level =dev_get_nest_level (real_dev) +1 ; -netdev_lockdep_set_classes (dev); -lockdep_set_class_and_subclass (&dev->addr_list_lock, - &macsec_netdev_addr_lock_key, -macsec_get_nest_level (dev)); err =netdev_upper_dev_link (real_dev, dev, extack);if (err <0 )
drivers/net/macvlan.c +0 -12
@@ -852,8 +852,6 @@ static int macvlan_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)* "super class" of normal network devices; split their locks off into a * separate class since they always nest. */ -static struct lock_class_key macvlan_netdev_addr_lock_key; -#define ALWAYS_ON_OFFLOADS \ (NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_GSO_SOFTWARE | \ NETIF_F_GSO_ROBUST | NETIF_F_GSO_ENCAP_ALL)
@@ -874,14 +872,6 @@ static int macvlan_get_nest_level(struct net_device *dev)return ((struct macvlan_dev *)netdev_priv (dev))->nest_level; } -static void macvlan_set_lockdep_class (struct net_device *dev) -{ -netdev_lockdep_set_classes (dev); -lockdep_set_class_and_subclass (&dev->addr_list_lock, - &macvlan_netdev_addr_lock_key, -macvlan_get_nest_level (dev)); -} -static int macvlan_init (struct net_device *dev) {struct macvlan_dev *vlan =netdev_priv (dev);
@@ -900,8 +890,6 @@ static int macvlan_init(struct net_device *dev) dev->gso_max_segs = lowerdev->gso_max_segs; dev->hard_header_len = lowerdev->hard_header_len; -macvlan_set_lockdep_class (dev); - vlan->pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats);if (!vlan->pcpu_stats)return -ENOMEM ;
drivers/net/ppp/ppp_generic.c +0 -2
@@ -1324,8 +1324,6 @@ static int ppp_dev_init(struct net_device *dev) {struct ppp *ppp; -netdev_lockdep_set_classes (dev); - ppp =netdev_priv (dev);/* Let the netdevice take a reference on the ppp file. This ensures * that ppp_destroy_interface() won't run before the device gets
drivers/net/team/team.c +0 -2
@@ -1642,8 +1642,6 @@ static int team_init(struct net_device *dev) goto err_options_register;netif_carrier_off (dev); -netdev_lockdep_set_classes (dev); -return 0 ; err_options_register:
drivers/net/vrf.c +0 -1
@@ -865,7 +865,6 @@ static int vrf_dev_init(struct net_device *dev)/* similarly, oper state is irrelevant; set to up to avoid confusion */ dev->operstate =IF_OPER_UP ; -netdev_lockdep_set_classes (dev);return 0 ; out_rth:
drivers/net/wireless/intersil/hostap/hostap_hw.c +0 -25
@@ -3041,30 +3041,6 @@ static void prism2_clear_set_tim_queue(local_info_t *local) } } - -/* -* HostAP uses two layers of net devices, where the inner -* layer gets called all the time from the outer layer. -* This is a natural nesting, which needs a split lock type. -*/ -static struct lock_class_key hostap_netdev_xmit_lock_key; -static struct lock_class_key hostap_netdev_addr_lock_key; - -static void prism2_set_lockdep_class_one (struct net_device *dev, -struct netdev_queue *txq, -void *_unused) -{ -lockdep_set_class (&txq->_xmit_lock, - &hostap_netdev_xmit_lock_key); -} - -static void prism2_set_lockdep_class (struct net_device *dev) -{ -lockdep_set_class (&dev->addr_list_lock, - &hostap_netdev_addr_lock_key); -netdev_for_each_tx_queue (dev, prism2_set_lockdep_class_one,NULL ); -} -static struct net_device *prism2_init_local_data (struct prism2_helper_functions *funcs,int card_idx,struct device *sdev)
@@ -3223,7 +3199,6 @@ while (0)if (ret >=0 ) ret =register_netdevice (dev); -prism2_set_lockdep_class (dev);rtnl_unlock ();if (ret <0 ) { printk(KERN_WARNING "%s: register netdevice failed!\n",
include/linux/netdevice.h +13 -22
@@ -925,6 +925,7 @@ struct dev_ifalias {struct devlink ;struct tlsdev_ops ; +/* * This structure defines the management hooks for network devices. * The following hooks can be defined; unless noted otherwise, they are
@@ -1760,9 +1761,13 @@ enum netdev_priv_flags {* @phydev: Physical device may attach itself * for hardware timestamping * @sfp_bus: attached &struct sfp_bus structure. -* -* @qdisc_tx_busylock: lockdep class annotating Qdisc->busylock spinlock -* @qdisc_running_key: lockdep class annotating Qdisc->running seqcount +* @qdisc_tx_busylock_key: lockdep class annotating Qdisc->busylock +spinlock +* @qdisc_running_key: lockdep class annotating Qdisc->running seqcount +* @qdisc_xmit_lock_key: lockdep class annotating +* netdev_queue->_xmit_lock spinlock +* @addr_list_lock_key: lockdep class annotating +* net_device->addr_list_lock spinlock * * @proto_down: protocol port state information can be sent to the * switch driver and used to set the phys state of the
@@ -2049,8 +2054,10 @@ struct net_device {#endif struct phy_device *phydev;struct sfp_bus *sfp_bus; -struct lock_class_key *qdisc_tx_busylock; -struct lock_class_key *qdisc_running_key; +struct lock_class_key qdisc_tx_busylock_key; +struct lock_class_key qdisc_running_key; +struct lock_class_key qdisc_xmit_lock_key; +struct lock_class_key addr_list_lock_key;bool proto_down; unsigned wol_enabled:1; };
@@ -2128,23 +2135,6 @@ static inline void netdev_for_each_tx_queue(struct net_device *dev,f (dev, &dev->_tx[i], arg); } -#define netdev_lockdep_set_classes (dev) \ -{ \ - static struct lock_class_key qdisc_tx_busylock_key; \ - static struct lock_class_key qdisc_running_key; \ - static struct lock_class_key qdisc_xmit_lock_key; \ - static struct lock_class_key dev_addr_list_lock_key; \ - unsigned int i; \ - \ - (dev)->qdisc_tx_busylock = &qdisc_tx_busylock_key; \ - (dev)->qdisc_running_key = &qdisc_running_key; \ - lockdep_set_class(&(dev)->addr_list_lock, \ - &dev_addr_list_lock_key); \ - for (i = 0; i < (dev)->num_tx_queues; i++) \ - lockdep_set_class(&(dev)->_tx[i]._xmit_lock, \ - &qdisc_xmit_lock_key); \ -} -u16 netdev_pick_tx (struct net_device *dev,struct sk_buff *skb,struct net_device *sb_dev); 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) }void netif_tx_stop_all_queues (struct net_device *dev); +void netdev_update_lockdep_key (struct net_device *dev);static inline bool netif_tx_queue_stopped (const struct netdev_queue *dev_queue) {
net/8021q/vlan_dev.c +0 -27
@@ -489,31 +489,6 @@ static void vlan_dev_set_rx_mode(struct net_device *vlan_dev)dev_uc_sync (vlan_dev_priv (vlan_dev)->real_dev, vlan_dev); } -/* -* vlan network devices have devices nesting below it, and are a special -* "super class" of normal network devices; split their locks off into a -* separate class since they always nest. -*/ -static struct lock_class_key vlan_netdev_xmit_lock_key; -static struct lock_class_key vlan_netdev_addr_lock_key; - -static void vlan_dev_set_lockdep_one (struct net_device *dev, -struct netdev_queue *txq, -void *_subclass) -{ -lockdep_set_class_and_subclass (&txq->_xmit_lock, - &vlan_netdev_xmit_lock_key, - *(int *)_subclass); -} - -static void vlan_dev_set_lockdep_class (struct net_device *dev,int subclass) -{ -lockdep_set_class_and_subclass (&dev->addr_list_lock, - &vlan_netdev_addr_lock_key, - subclass); -netdev_for_each_tx_queue (dev, vlan_dev_set_lockdep_one, &subclass); -} -static int vlan_dev_get_lock_subclass (struct net_device *dev) {return vlan_dev_priv (dev)->nest_level;
@@ -609,8 +584,6 @@ static int vlan_dev_init(struct net_device *dev)SET_NETDEV_DEVTYPE (dev, &vlan_type); -vlan_dev_set_lockdep_class (dev,vlan_dev_get_lock_subclass (dev)); - vlan->vlan_pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats);if (!vlan->vlan_pcpu_stats)return -ENOMEM ;
net/batman-adv/soft-interface.c +0 -32
@@ -740,36 +740,6 @@ static int batadv_interface_kill_vid(struct net_device *dev, __be16 proto,return 0 ; } -/* batman-adv network devices have devices nesting below it and are a special -* "super class" of normal network devices; split their locks off into a -* separate class since they always nest. -*/ -static struct lock_class_key batadv_netdev_xmit_lock_key; -static struct lock_class_key batadv_netdev_addr_lock_key; - -/** -* batadv_set_lockdep_class_one() - Set lockdep class for a single tx queue -* @dev: device which owns the tx queue -* @txq: tx queue to modify -* @_unused: always NULL -*/ -static void batadv_set_lockdep_class_one (struct net_device *dev, -struct netdev_queue *txq, -void *_unused) -{ -lockdep_set_class (&txq->_xmit_lock, &batadv_netdev_xmit_lock_key); -} - -/** -* batadv_set_lockdep_class() - Set txq and addr_list lockdep class -* @dev: network device to modify -*/ -static void batadv_set_lockdep_class (struct net_device *dev) -{ -lockdep_set_class (&dev->addr_list_lock, &batadv_netdev_addr_lock_key); -netdev_for_each_tx_queue (dev, batadv_set_lockdep_class_one,NULL ); -} -/** * batadv_softif_init_late() - late stage initialization of soft interface * @dev: registered network device to modify
@@ -783,8 +753,6 @@ static int batadv_softif_init_late(struct net_device *dev)int ret;size_t cnt_len =sizeof (u64) *BATADV_CNT_NUM ; -batadv_set_lockdep_class (dev); - bat_priv =netdev_priv (dev); bat_priv->soft_iface = dev;
net/bluetooth/6lowpan.c +0 -8
@@ -571,15 +571,7 @@ static netdev_tx_t bt_xmit(struct sk_buff *skb, struct net_device *netdev)return err <0 ?NET_XMIT_DROP : err; } -static int bt_dev_init (struct net_device *dev) -{ -netdev_lockdep_set_classes (dev); - -return 0 ; -} -static const struct net_device_ops netdev_ops = { - .ndo_init = bt_dev_init, .ndo_start_xmit = bt_xmit, };
net/bridge/br_device.c +0 -8
@@ -24,8 +24,6 @@const struct nf_br_ops __rcu *nf_br_ops__read_mostly ;EXPORT_SYMBOL_GPL (nf_br_ops); -static struct lock_class_key bridge_netdev_addr_lock_key; -/* net device transmit always called with BH disabled */ netdev_tx_t br_dev_xmit (struct sk_buff *skb,struct net_device *dev) {
@@ -108,11 +106,6 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } -static void br_set_lockdep_class (struct net_device *dev) -{ -lockdep_set_class (&dev->addr_list_lock, &bridge_netdev_addr_lock_key); -} -static int br_dev_init (struct net_device *dev) {struct net_bridge *br =netdev_priv (dev);
@@ -150,7 +143,6 @@ static int br_dev_init(struct net_device *dev)br_mdb_hash_fini (br);br_fdb_hash_fini (br); } -br_set_lockdep_class (dev);return err; }
net/core/dev.c +43 -84
163 lines not on this page · raw message
net/core/rtnetlink.c +1 -0
@@ -2355,6 +2355,7 @@ static int do_set_master(struct net_device *dev, int ifindex, err = ops->ndo_del_slave (upper_dev, dev);if (err)return err; +netdev_update_lockdep_key (dev); }else {return -EOPNOTSUPP ; }
net/dsa/master.c +0 -5
@@ -310,8 +310,6 @@ static void dsa_master_reset_mtu(struct net_device *dev)rtnl_unlock (); } -static struct lock_class_key dsa_master_addr_list_lock_key; -int dsa_master_setup (struct net_device *dev,struct dsa_port *cpu_dp) {int ret;
@@ -325,9 +323,6 @@ int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp)wmb (); dev->dsa_ptr = cpu_dp; -lockdep_set_class (&dev->addr_list_lock, - &dsa_master_addr_list_lock_key); - ret =dsa_master_ethtool_setup (dev);if (ret)return ret;
net/dsa/slave.c +0 -12
@@ -1341,15 +1341,6 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)return ret; } -static struct lock_class_key dsa_slave_netdev_xmit_lock_key; -static void dsa_slave_set_lockdep_class_one (struct net_device *dev, -struct netdev_queue *txq, -void *_unused) -{ -lockdep_set_class (&txq->_xmit_lock, - &dsa_slave_netdev_xmit_lock_key); -} -int dsa_slave_suspend (struct net_device *slave_dev) {struct dsa_port *dp =dsa_slave_to_port (slave_dev);
@@ -1433,9 +1424,6 @@ int dsa_slave_create(struct dsa_port *port) slave_dev->max_mtu =ETH_MAX_MTU ;SET_NETDEV_DEVTYPE (slave_dev, &dsa_type); -netdev_for_each_tx_queue (slave_dev, dsa_slave_set_lockdep_class_one, -NULL ); -SET_NETDEV_DEV (slave_dev, port->ds->dev); slave_dev->dev.of_node = port->dn; slave_dev->vlan_features = master->vlan_features;
net/ieee802154/6lowpan/core.c +0 -8
@@ -58,13 +58,6 @@ static const struct header_ops lowpan_header_ops = { .create = lowpan_header_create, }; -static int lowpan_dev_init (struct net_device *ldev) -{ -netdev_lockdep_set_classes (ldev); - -return 0 ; -} -static int lowpan_open (struct net_device *dev) {if (!open_count)
@@ -96,7 +89,6 @@ static int lowpan_get_iflink(const struct net_device *dev) }static const struct net_device_ops lowpan_netdev_ops = { - .ndo_init = lowpan_dev_init, .ndo_start_xmit = lowpan_xmit, .ndo_open = lowpan_open, .ndo_stop = lowpan_stop,
net/l2tp/l2tp_eth.c +0 -1
@@ -56,7 +56,6 @@ static int l2tp_eth_dev_init(struct net_device *dev) {eth_hw_addr_random (dev);eth_broadcast_addr (dev->broadcast); -netdev_lockdep_set_classes (dev);return 0 ; }
net/netrom/af_netrom.c +0 -23
@@ -63,28 +63,6 @@ static DEFINE_SPINLOCK(nr_list_lock);static const struct proto_ops nr_proto_ops; -/* -* NETROM network devices are virtual network devices encapsulating NETROM -* frames into AX.25 which will be sent through an AX.25 device, so form a -* special "super class" of normal net devices; split their locks off into a -* separate class since they always nest. -*/ -static struct lock_class_key nr_netdev_xmit_lock_key; -static struct lock_class_key nr_netdev_addr_lock_key; - -static void nr_set_lockdep_one (struct net_device *dev, -struct netdev_queue *txq, -void *_unused) -{ -lockdep_set_class (&txq->_xmit_lock, &nr_netdev_xmit_lock_key); -} - -static void nr_set_lockdep_key (struct net_device *dev) -{ -lockdep_set_class (&dev->addr_list_lock, &nr_netdev_addr_lock_key); -netdev_for_each_tx_queue (dev, nr_set_lockdep_one,NULL ); -} -/* * Socket removal during an interrupt is now safe. */
@@ -1414,7 +1392,6 @@ static int __init nr_proto_init(void)free_netdev (dev); goto fail; } -nr_set_lockdep_key (dev); dev_nr[i] = dev; }
net/rose/af_rose.c +0 -23
@@ -64,28 +64,6 @@ static const struct proto_ops rose_proto_ops;ax25_address rose_callsign; -/* -* ROSE network devices are virtual network devices encapsulating ROSE -* frames into AX.25 which will be sent through an AX.25 device, so form a -* special "super class" of normal net devices; split their locks off into a -* separate class since they always nest. -*/ -static struct lock_class_key rose_netdev_xmit_lock_key; -static struct lock_class_key rose_netdev_addr_lock_key; - -static void rose_set_lockdep_one (struct net_device *dev, -struct netdev_queue *txq, -void *_unused) -{ -lockdep_set_class (&txq->_xmit_lock, &rose_netdev_xmit_lock_key); -} - -static void rose_set_lockdep_key (struct net_device *dev) -{ -lockdep_set_class (&dev->addr_list_lock, &rose_netdev_addr_lock_key); -netdev_for_each_tx_queue (dev, rose_set_lockdep_one,NULL ); -} -/* * Convert a ROSE address into text. */
@@ -1533,7 +1511,6 @@ static int __init rose_proto_init(void)free_netdev (dev); goto fail; } -rose_set_lockdep_key (dev); dev_rose[i] = dev; }
net/sched/sch_generic.c +6 -11
@@ -799,9 +799,6 @@ struct Qdisc_ops pfifo_fast_ops __read_mostly = { };EXPORT_SYMBOL (pfifo_fast_ops); -static struct lock_class_key qdisc_tx_busylock; -static struct lock_class_key qdisc_running_key; -struct Qdisc *qdisc_alloc (struct netdev_queue *dev_queue,const struct Qdisc_ops *ops,struct netlink_ext_ack *extack)
@@ -854,17 +851,9 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue, }spin_lock_init (&sch->busylock); -lockdep_set_class (&sch->busylock, - dev->qdisc_tx_busylock ?: &qdisc_tx_busylock); -/* seqlock has the same scope of busylock, for NOLOCK qdisc */ spin_lock_init (&sch->seqlock); -lockdep_set_class (&sch->busylock, - dev->qdisc_tx_busylock ?: &qdisc_tx_busylock); -seqcount_init (&sch->running); -lockdep_set_class (&sch->running, - dev->qdisc_running_key ?: &qdisc_running_key); sch->ops = ops; sch->flags = ops->static_flags;
@@ -875,6 +864,12 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,dev_hold (dev);refcount_set (&sch->refcnt,1 ); +if (sch != &noop_qdisc) { +lockdep_set_class (&sch->busylock, &dev->qdisc_tx_busylock_key); +lockdep_set_class (&sch->seqlock, &dev->qdisc_tx_busylock_key); +lockdep_set_class (&sch->running, &dev->qdisc_running_key); + } +return sch; errout1:kfree (p);
Signature · 1 line
2.17.1
PATCH v5 3/10 bonding: fix unexpected IFF_BONDING bit unset
In reply to Taehee YooThe IFF_BONDING means bonding master or bonding slave device. ->ndo_add_slave() sets IFF_BONDING flag and ->ndo_del_slave() unsets IFF_BONDING flag.
bond0<--bond1
Both bond0 and bond1 are bonding device and these should keep having IFF_BONDING flag until they are removed.
But bond1 would lose IFF_BONDING at ->ndo_del_slave() because that routine do not check whether the slave device is the bonding type or not. This patch adds the interface type check routine before removing IFF_BONDING flag.
Test commands:
ip link add bond0 type bond
ip link add bond1 type bond
ip link set bond1 master bond0
ip link set bond1 nomaster
ip link del bond1 type bond
ip link add bond1 type bond
Splat looks like:
[ 226.665555] proc_dir_entry 'bonding/bond1' already registered [ 226.666440] WARNING: CPU: 0 PID: 737 at fs/proc/generic.c:361 proc_register+0x2a9/0x3e0 [ 226.667571] Modules linked in: bonding af_packet sch_fq_codel ip_tables x_tables unix [ 226.668662] CPU: 0 PID: 737 Comm: ip Not tainted 5.4.0-rc3+ #96 [ 226.669508] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 226.670652] RIP: 0010:proc_register+0x2a9/0x3e0 [ 226.671612] Code: 89 fa 48 c1 ea 03 80 3c 02 00 0f 85 39 01 00 00 48 8b 04 24 48 89 ea 48 c7 c7 a0 0b 14 9f 48 8b b0 e 0 00 00 00 e8 07 e7 88 ff <0f> 0b 48 c7 c7 40 2d a5 9f e8 59 d6 23 01 48 8b 4c 24 10 48 b8 00 [ 226.675007] RSP: 0018:ffff888050e17078 EFLAGS: 00010282 [ 226.675761] RAX: dffffc0000000008 RBX: ffff88805fdd0f10 RCX: ffffffff9dd344e2 [ 226.676757] RDX: 0000000000000001 RSI: 0000000000000008 RDI: ffff88806c9f6b8c [ 226.677751] RBP: ffff8880507160f3 R08: ffffed100d940019 R09: ffffed100d940019 [ 226.678761] R10: 0000000000000001 R11: ffffed100d940018 R12: ffff888050716008 [ 226.679757] R13: ffff8880507160f2 R14: dffffc0000000000 R15: ffffed100a0e2c1e [ 226.680758] FS: 00007fdc217cc0c0(0000) GS:ffff88806c800000(0000) knlGS:0000000000000000 [ 226.681886] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 226.682719] CR2: 00007f49313424d0 CR3: 0000000050e46001 CR4: 00000000000606f0 [ 226.683727] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 226.684725] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 226.685681] Call Trace: [ 226.687089] proc_create_seq_private+0xb3/0xf0 [ 226.687778] bond_create_proc_entry+0x1b3/0x3f0 [bonding] [ 226.691458] bond_netdev_event+0x433/0x970 [bonding] [ 226.692139] ? __module_text_address+0x13/0x140 [ 226.692779] notifier_call_chain+0x90/0x160 [ 226.693401] register_netdevice+0x9b3/0xd80 [ 226.694010] ? alloc_netdev_mqs+0x854/0xc10 [ 226.694629] ? netdev_change_features+0xa0/0xa0 [ 226.695278] ? rtnl_create_link+0x2ed/0xad0 [ 226.695849] bond_newlink+0x2a/0x60 [bonding] [ 226.696422] __rtnl_newlink+0xb9f/0x11b0 [ 226.696968] ? rtnl_link_unregister+0x220/0x220
[ ... ]
---
v2 -> v5 :
- This patch is not changed
v1 -> v2 :
- Do not add a new priv_flag.
drivers/net/bonding/bond_main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/bonding/bond_main.c +4 -2
@@ -1816,7 +1816,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,slave_disable_netpoll (new_slave); err_close: - slave_dev->priv_flags &= ~IFF_BONDING ; +if (!netif_is_bond_master (slave_dev)) + slave_dev->priv_flags &= ~IFF_BONDING ;dev_close (slave_dev); err_restore_mac:
@@ -2017,7 +2018,8 @@ static int __bond_release_one(struct net_device *bond_dev,else dev_set_mtu (slave_dev, slave->original_mtu); - slave_dev->priv_flags &= ~IFF_BONDING ; +if (!netif_is_bond_master (slave_dev)) + slave_dev->priv_flags &= ~IFF_BONDING ;bond_free_slave (slave);
Signature · 1 line
2.17.1
PATCH v5 4/10 bonding: use dynamic lockdep key instead of subclass
In reply to Taehee YooAll bonding device has same lockdep key and subclass is initialized with nest_level.
But actual nest_level value can be changed when a lower device is attached. And at this moment, the subclass should be updated but it seems to be unsafe.
So this patch makes bonding use dynamic lockdep key instead of the subclass.
Test commands:
ip link add bond0 type bond
for i in {1..5}
do
let A=$i-1
ip link add bond$i type bond
ip link set bond$i master bond$A
done
ip link set bond5 master bond0
Splat looks like:
[ 307.992912] WARNING: possible recursive locking detected
[ 307.993656] 5.4.0-rc3+ #96 Tainted: G W
[ 307.994367] --------------------------------------------
[ 307.995092] ip/761 is trying to acquire lock:
[ 307.995710] ffff8880513aac60 (&(&bond->stats_lock)->rlock#2/2){+.+.}, at: bond_get_stats+0xb8/0x500 [bonding]
[ 307.997045]
but task is already holding lock:
[ 307.997923] ffff88805fcbac60 (&(&bond->stats_lock)->rlock#2/2){+.+.}, at: bond_get_stats+0xb8/0x500 [bonding]
[ 307.999215]
other info that might help us debug this:
[ 308.000251] Possible unsafe locking scenario: [ 308.001137] CPU0 [ 308.001533] ---- [ 308.001915] lock(&(&bond->stats_lock)->rlock#2/2); [ 308.002609] lock(&(&bond->stats_lock)->rlock#2/2); [ 308.003302] *** DEADLOCK ***
[ 308.004310] May be due to missing lock nesting notation
[ 308.005319] 3 locks held by ip/761:
[ 308.005830] #0: ffffffff9fcc42b0 (rtnl_mutex){+.+.}, at: rtnetlink_rcv_msg+0x466/0x8a0
[ 308.006894] #1: ffff88805fcbac60 (&(&bond->stats_lock)->rlock#2/2){+.+.}, at: bond_get_stats+0xb8/0x500 [bonding]
[ 308.008243] #2: ffffffff9f9219c0 (rcu_read_lock){....}, at: bond_get_stats+0x9f/0x500 [bonding]
[ 308.009422]
stack backtrace:
[ 308.010124] CPU: 0 PID: 761 Comm: ip Tainted: G W 5.4.0-rc3+ #96
[ 308.011097] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
[ 308.012179] Call Trace:
[ 308.012601] dump_stack+0x7c/0xbb
[ 308.013089] __lock_acquire+0x269d/0x3de0
[ 308.013669] ? register_lock_class+0x14d0/0x14d0
[ 308.014318] lock_acquire+0x164/0x3b0
[ 308.014858] ? bond_get_stats+0xb8/0x500 [bonding]
[ 308.015520] _raw_spin_lock_nested+0x2e/0x60
[ 308.016129] ? bond_get_stats+0xb8/0x500 [bonding]
[ 308.017215] bond_get_stats+0xb8/0x500 [bonding]
[ 308.018454] ? bond_arp_rcv+0xf10/0xf10 [bonding]
[ 308.019710] ? rcu_read_lock_held+0x90/0xa0
[ 308.020605] ? rcu_read_lock_sched_held+0xc0/0xc0
[ 308.021286] ? bond_get_stats+0x9f/0x500 [bonding]
[ 308.021953] dev_get_stats+0x1ec/0x270
[ 308.022508] bond_get_stats+0x1d1/0x500 [bonding]---
v4 -> v5 :
- qdisc part is merged into second patch
v1 -> v4 :
- This patch is not changed
drivers/net/bonding/bond_main.c | 10 +++++++--- include/net/bonding.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/net/bonding/bond_main.c +7 -3
@@ -3459,7 +3459,7 @@ static void bond_get_stats(struct net_device *bond_dev,struct list_head *iter;struct slave *slave; -spin_lock_nested (&bond->stats_lock,bond_get_nest_level (bond_dev)); +spin_lock (&bond->stats_lock);memcpy (stats, &bond->bond_stats,sizeof (*stats));rcu_read_lock ();
@@ -4297,8 +4297,6 @@ void bond_setup(struct net_device *bond_dev) {struct bonding *bond =netdev_priv (bond_dev); -spin_lock_init (&bond->mode_lock); -spin_lock_init (&bond->stats_lock); bond->params = bonding_defaults;/* Initialize pointers */
@@ -4367,6 +4365,7 @@ static void bond_uninit(struct net_device *bond_dev)list_del (&bond->bond_list); +lockdep_unregister_key (&bond->stats_lock_key);bond_debug_unregister (bond); }
@@ -4772,6 +4771,11 @@ static int bond_init(struct net_device *bond_dev) bond->nest_level =SINGLE_DEPTH_NESTING ; +spin_lock_init (&bond->mode_lock); +spin_lock_init (&bond->stats_lock); +lockdep_register_key (&bond->stats_lock_key); +lockdep_set_class (&bond->stats_lock, &bond->stats_lock_key); +list_add_tail (&bond->bond_list, &bn->dev_list);bond_prepare_sysfs_group (bond);
include/net/bonding.h +1 -0
@@ -239,6 +239,7 @@ struct bonding {struct dentry *debug_dir;#endif /* CONFIG_DEBUG_FS */ struct rtnl_link_stats64 bond_stats; +struct lock_class_key stats_lock_key; };#define bond_slave_get_rcu (dev) \
Signature · 1 line
2.17.1
PATCH v5 5/10 team: fix nested locking lockdep warning
In reply to Taehee Yooteam interface could be nested and it's lock variable could be nested too. But this lock uses static lockdep key and there is no nested locking handling code such as mutex_lock_nested() and so on.
so the Lockdep would warn about the circular locking scenario that couldn't happen.
In order to fix, this patch makes the team module to use dynamic lock key instead of static key.
Test commands:
ip link add team0 type team
ip link add team1 type team
ip link set team0 master team1
ip link set team0 nomaster
ip link set team1 master team0
ip link set team1 nomaster
Splat that looks like:
[ 40.364352] WARNING: possible recursive locking detected
[ 40.364964] 5.4.0-rc3+ #96 Not tainted
[ 40.365405] --------------------------------------------
[ 40.365973] ip/750 is trying to acquire lock:
[ 40.366542] ffff888060b34c40 (&team->lock){+.+.}, at: team_set_mac_address+0x151/0x290 [team]
[ 40.367689]
but task is already holding lock:
[ 40.368729] ffff888051201c40 (&team->lock){+.+.}, at: team_del_slave+0x29/0x60 [team]
[ 40.370280]
other info that might help us debug this:
[ 40.371159] Possible unsafe locking scenario:[ 40.371942] CPU0 [ 40.372338] ---- [ 40.372673] lock(&team->lock); [ 40.373115] lock(&team->lock); [ 40.373549] *** DEADLOCK ***
[ 40.374432] May be due to missing lock nesting notation
[ 40.375338] 2 locks held by ip/750:
[ 40.375851] #0: ffffffffabcc42b0 (rtnl_mutex){+.+.}, at: rtnetlink_rcv_msg+0x466/0x8a0
[ 40.376927] #1: ffff888051201c40 (&team->lock){+.+.}, at: team_del_slave+0x29/0x60 [team]
[ 40.377989]
stack backtrace:
[ 40.378650] CPU: 0 PID: 750 Comm: ip Not tainted 5.4.0-rc3+ #96
[ 40.379368] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
[ 40.380574] Call Trace:
[ 40.381208] dump_stack+0x7c/0xbb
[ 40.381959] __lock_acquire+0x269d/0x3de0
[ 40.382817] ? register_lock_class+0x14d0/0x14d0
[ 40.383784] ? check_chain_key+0x236/0x5d0
[ 40.384518] lock_acquire+0x164/0x3b0
[ 40.385074] ? team_set_mac_address+0x151/0x290 [team]
[ 40.385805] __mutex_lock+0x14d/0x14c0
[ 40.386371] ? team_set_mac_address+0x151/0x290 [team]
[ 40.387038] ? team_set_mac_address+0x151/0x290 [team]
[ 40.387632] ? mutex_lock_io_nested+0x1380/0x1380
[ 40.388245] ? team_del_slave+0x60/0x60 [team]
[ 40.388752] ? rcu_read_lock_sched_held+0x90/0xc0
[ 40.389304] ? rcu_read_lock_bh_held+0xa0/0xa0
[ 40.389819] ? lock_acquire+0x164/0x3b0
[ 40.390285] ? lockdep_rtnl_is_held+0x16/0x20
[ 40.390797] ? team_port_get_rtnl+0x90/0xe0 [team]
[ 40.391353] ? __module_text_address+0x13/0x140
[ 40.391886] ? team_set_mac_address+0x151/0x290 [team]
[ 40.392547] team_set_mac_address+0x151/0x290 [team]
[ 40.393111] dev_set_mac_address+0x1f0/0x3f0[ ... ]
---
v4 -> v5 :
- qdisc part is merge into second patch
v1 -> v4 :
- This patch is not changed
drivers/net/team/team.c | 16 +++++++++++++--- include/linux/if_team.h | 1 + 2 files changed, 14 insertions(+), 3 deletions(-)
drivers/net/team/team.c +13 -3
@@ -1615,7 +1615,6 @@ static int team_init(struct net_device *dev)int err; team->dev = dev; -mutex_init (&team->lock);team_set_no_mode (team); team->pcpu_stats = netdev_alloc_pcpu_stats(struct team_pcpu_stats);
@@ -1642,6 +1641,9 @@ static int team_init(struct net_device *dev) goto err_options_register;netif_carrier_off (dev); +lockdep_register_key (&team->team_lock_key); +__mutex_init (&team->lock,"team->team_lock_key" , &team->team_lock_key); +return 0 ; err_options_register:
@@ -1671,6 +1673,7 @@ static void team_uninit(struct net_device *dev)team_queue_override_fini (team);mutex_unlock (&team->lock);netdev_change_features (dev); +lockdep_unregister_key (&team->team_lock_key); }static void team_destructor (struct net_device *dev)
@@ -1974,8 +1977,15 @@ static int team_del_slave(struct net_device *dev, struct net_device *port_dev) err =team_port_del (team, port_dev);mutex_unlock (&team->lock); -if (!err) -netdev_change_features (dev); +if (err) +return err; + +if (netif_is_team_master (port_dev)) { +lockdep_unregister_key (&team->team_lock_key); +lockdep_register_key (&team->team_lock_key); +lockdep_set_class (&team->lock, &team->team_lock_key); + } +netdev_change_features (dev);return err; }
include/linux/if_team.h +1 -0
@@ -223,6 +223,7 @@ struct team {atomic_t count_pending;struct delayed_work dw; } mcast_rejoin; +struct lock_class_key team_lock_key;long mode_priv[TEAM_MODE_PRIV_LONGS ]; };
Signature · 1 line
2.17.1
PATCH v5 6/10 macsec: fix refcnt leak in module exit routine
In reply to Taehee YooWhen a macsec interface is created, it increases a refcnt to a lower device(real device). when macsec interface is deleted, the refcnt is decreased in macsec_free_netdev(), which is ->priv_destructor() of macsec interface.
The problem scenario is this.
When nested macsec interfaces are exiting, the exit routine of the macsec module makes refcnt leaks.
Test commands:
ip link add dummy0 type dummy
ip link add macsec0 link dummy0 type macsec
ip link add macsec1 link macsec0 type macsec
modprobe -rv macsec
[ 208.629433] unregister_netdevice: waiting for macsec0 to become free. Usage count = 1
Steps of exit routine of macsec module are below.
1. Calls ->dellink() in __rtnl_link_unregister().
2. Checks refcnt and wait refcnt to be 0 if refcnt is not 0 in netdev_run_todo().
3. Calls ->priv_destruvtor() in netdev_run_todo().
Step2 checks refcnt, but step3 decreases refcnt.
So, step2 waits forever.
This patch makes the macsec module do not hold a refcnt of the lower device because it already holds a refcnt of the lower device with netdev_upper_dev_link().
---
v1 -> v5 :
- This patch is not changed
drivers/net/macsec.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/net/macsec.c +0 -4
@@ -3000,12 +3000,10 @@ static const struct nla_policy macsec_rtnl_policy[IFLA_MACSEC_MAX + 1] = {static void macsec_free_netdev (struct net_device *dev) {struct macsec_dev *macsec =macsec_priv (dev); -struct net_device *real_dev = macsec->real_dev;free_percpu (macsec->stats);free_percpu (macsec->secy.tx_sc.stats); -dev_put (real_dev); }static void macsec_setup (struct net_device *dev)
@@ -3260,8 +3258,6 @@ static int macsec_newlink(struct net *net, struct net_device *dev,if (err <0 )return err; -dev_hold (real_dev); - macsec->nest_level =dev_get_nest_level (real_dev) +1 ; err =netdev_upper_dev_link (real_dev, dev, extack);
Signature · 1 line
2.17.1
PATCH v5 7/10 net: core: add ignore flag to netdev_adjacent structure
In reply to Taehee YooIn order to link an adjacent node, netdev_upper_dev_link() is used and in order to unlink an adjacent node, netdev_upper_dev_unlink() is used. unlink operation does not fail, but link operation can fail.
In order to exchange adjacent nodes, we should unlink an old adjacent node first. then, link a new adjacent node.
If link operation is failed, we should link an old adjacent node again. But this link operation can fail too.
It eventually breaks the adjacent link relationship.
This patch adds an ignore flag into the netdev_adjacent structure. If this flag is set, netdev_upper_dev_link() ignores an old adjacent node for a moment.
This patch also adds new functions for other modules. netdev_adjacent_change_prepare() netdev_adjacent_change_commit() netdev_adjacent_change_abort()
netdev_adjacent_change_prepare() inserts new device into adjacent list but new device is not allowed to use immediately.
If netdev_adjacent_change_prepare() fails, it internally rollbacks adjacent list so that we don't need any other action. netdev_adjacent_change_commit() deletes old device in the adjacent list and allows new device to use.netdev_adjacent_change_abort() rollbacks adjacent list.
---
v4 -> v5 :
- This patch is not changed
v3 -> v4 :
- Add missing static keyword in the dev.c
- Expose netdev_adjacent_change_{prepare/commit/abort} instead of netdev_adjacent_dev_{enable/disable}
v2 -> v3 :
- Modify nesting infra code to use iterator instead of recursive
v1 -> v2 :
- This patch is not changed
include/linux/netdevice.h | 10 ++ net/core/dev.c | 230 ++++++++++++++++++++++++++++++++++---- 2 files changed, 219 insertions(+), 21 deletions(-)
include/linux/netdevice.h +10 -0
@@ -4324,6 +4324,16 @@ int netdev_master_upper_dev_link(struct net_device *dev, struct netlink_ext_ack *extack);void netdev_upper_dev_unlink (struct net_device *dev,struct net_device *upper_dev); +int netdev_adjacent_change_prepare (struct net_device *old_dev, +struct net_device *new_dev, +struct net_device *dev, +struct netlink_ext_ack *extack); +void netdev_adjacent_change_commit (struct net_device *old_dev, +struct net_device *new_dev, +struct net_device *dev); +void netdev_adjacent_change_abort (struct net_device *old_dev, +struct net_device *new_dev, +struct net_device *dev);void netdev_adjacent_rename_links (struct net_device *dev,char *oldname);void *netdev_lower_dev_get_private (struct net_device *dev,struct net_device *lower_dev);
net/core/dev.c +209 -21
365 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v5 8/10 vxlan: add adjacent link to limit depth level
In reply to Taehee YooCurrent vxlan code doesn't limit the number of nested devices. Nested devices would be handled recursively and this routine needs huge stack memory. So, unlimited nested devices could make stack overflow.
In order to fix this issue, this patch adds adjacent links. The adjacent link APIs internally check the depth level.
Test commands:
ip link add dummy0 type dummy
ip link add vxlan0 type vxlan id 0 group 239.1.1.1 dev dummy0 \
dstport 4789
for i in {1..100}
do
let A=$i-1
ip link add vxlan$i type vxlan id $i group 239.1.1.1 \
dev vxlan$A dstport 4789
done
ip link del dummy0The top upper link is vxlan100 and the lowest link is vxlan0. When vxlan0 is deleting, the upper devices will be deleted recursively. It needs huge stack memory so it makes stack overflow.
Splat looks like:
[ 229.628477] ============================================================================= [ 229.629785] BUG page->ptl (Not tainted): Padding overwritten. 0x0000000026abf214-0x0000000091f6abb2 [ 229.629785] ----------------------------------------------------------------------------- [ 229.629785] [ 229.655439] ================================================================== [ 229.629785] INFO: Slab 0x00000000ff7cfda8 objects=19 used=19 fp=0x00000000fe33776c flags=0x200000000010200 [ 229.655688] BUG: KASAN: stack-out-of-bounds in unmap_single_vma+0x25a/0x2e0 [ 229.655688] Read of size 8 at addr ffff888113076928 by task vlan-network-in/2334 [ 229.655688] [ 229.629785] Padding 0000000026abf214: 00 80 14 0d 81 88 ff ff 68 91 81 14 81 88 ff ff ........h....... [ 229.629785] Padding 0000000001e24790: 38 91 81 14 81 88 ff ff 68 91 81 14 81 88 ff ff 8.......h....... [ 229.629785] Padding 00000000b39397c8: 33 30 62 a7 ff ff ff ff ff eb 60 22 10 f1 ff 1f 30b.......`".... [ 229.629785] Padding 00000000bc98f53a: 80 60 07 13 81 88 ff ff 00 80 14 0d 81 88 ff ff .`.............. [ 229.629785] Padding 000000002aa8123d: 68 91 81 14 81 88 ff ff f7 21 17 a7 ff ff ff ff h........!...... [ 229.629785] Padding 000000001c8c2369: 08 81 14 0d 81 88 ff ff 03 02 00 00 00 00 00 00 ................ [ 229.629785] Padding 000000004e290c5d: 21 90 a2 21 10 ed ff ff 00 00 00 00 00 fc ff df !..!............ [ 229.629785] Padding 000000000e25d731: 18 60 07 13 81 88 ff ff c0 8b 13 05 81 88 ff ff .`.............. [ 229.629785] Padding 000000007adc7ab3: b3 8a b5 41 00 00 00 00 ...A.... [ 229.629785] FIX page->ptl: Restoring 0x0000000026abf214-0x0000000091f6abb2=0x5a
[ ... ]
---
v4 -> v5 :
- This patch is not changed
v3 -> v4 :
- Fix wrong usage netdev_upper_dev_link() in the vxlan.c
- Preserve reverse christmas tree variable ordering in the vxlan.c
v1 -> v3 :
- This patch is not changed
drivers/net/vxlan.c | 53 ++++++++++++++++++++++++++++++++++++--------- include/net/vxlan.h | 1 + 2 files changed, 44 insertions(+), 10 deletions(-)
drivers/net/vxlan.c +43 -10
@@ -3566,10 +3566,13 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev, {struct vxlan_net *vn =net_generic (net, vxlan_net_id);struct vxlan_dev *vxlan =netdev_priv (dev); +struct net_device *remote_dev =NULL ;struct vxlan_fdb *f =NULL ;bool unregister = false; +struct vxlan_rdst *dst;int err; + dst = &vxlan->default_dst; err =vxlan_dev_configure (net, dev, conf, false, extack);if (err)return err;
@@ -3577,14 +3580,14 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev, dev->ethtool_ops = &vxlan_ethtool_ops;/* create an fdb entry for a valid default destination */ -if (!vxlan_addr_any (&vxlan->default_dst.remote_ip)) { +if (!vxlan_addr_any (&dst->remote_ip)) { err =vxlan_fdb_create (vxlan, all_zeros_mac, - &vxlan->default_dst.remote_ip, + &dst->remote_ip,NUD_REACHABLE |NUD_PERMANENT , vxlan->cfg.dst_port, - vxlan->default_dst.remote_vni, - vxlan->default_dst.remote_vni, - vxlan->default_dst.remote_ifindex, + dst->remote_vni, + dst->remote_vni, + dst->remote_ifindex,NTF_SELF , &f);if (err)return err;
@@ -3595,26 +3598,41 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev, goto errout; unregister = true; +if (dst->remote_ifindex) { + remote_dev =__dev_get_by_index (net, dst->remote_ifindex); +if (!remote_dev) + goto errout; + + err =netdev_upper_dev_link (remote_dev, dev, extack); +if (err) + goto errout; + } + err =rtnl_configure_link (dev,NULL );if (err) - goto errout; + goto unlink;if (f) { -vxlan_fdb_insert (vxlan, all_zeros_mac, - vxlan->default_dst.remote_vni, f); +vxlan_fdb_insert (vxlan, all_zeros_mac, dst->remote_vni, f);/* notify default fdb entry */ err =vxlan_fdb_notify (vxlan, f,first_remote_rtnl (f),RTM_NEWNEIGH , true, extack);if (err) {vxlan_fdb_destroy (vxlan, f, false, false); +if (remote_dev) +netdev_upper_dev_unlink (remote_dev, dev); goto unregister; } }list_add (&vxlan->next, &vn->vxlan_list); +if (remote_dev) + dst->remote_dev = remote_dev;return 0 ; - +unlink: +if (remote_dev) +netdev_upper_dev_unlink (remote_dev, dev); errout:/* unregister_netdevice() destroys the default FDB entry with deletion * notification. But the addition notification was not sent yet, so
@@ -3932,11 +3950,12 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], struct netlink_ext_ack *extack) {struct vxlan_dev *vxlan =netdev_priv (dev); -struct vxlan_rdst *dst = &vxlan->default_dst;struct net_device *lowerdev;struct vxlan_config conf; +struct vxlan_rdst *dst;int err; + dst = &vxlan->default_dst; err =vxlan_nl2conf (tb, data, dev, &conf, true, extack);if (err)return err;
@@ -3946,6 +3965,11 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],if (err)return err; + err =netdev_adjacent_change_prepare (dst->remote_dev, lowerdev, dev, + extack); +if (err) +return err; +/* handle default dst entry */ if (!vxlan_addr_equal (&conf.remote_ip, &dst->remote_ip)) {u32 hash_index =fdb_head_index (vxlan, all_zeros_mac, conf.vni);
@@ -3962,6 +3986,8 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], NTF_SELF, true, extack);if (err) {spin_unlock_bh (&vxlan->hash_lock[hash_index]); +netdev_adjacent_change_abort (dst->remote_dev, + lowerdev, dev);return err; } }
@@ -3979,6 +4005,11 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],if (conf.age_interval != vxlan->cfg.age_interval)mod_timer (&vxlan->age_timer, jiffies); +netdev_adjacent_change_commit (dst->remote_dev, lowerdev, dev); +if (lowerdev && lowerdev != dst->remote_dev) + dst->remote_dev = lowerdev; + +netdev_update_lockdep_key (lowerdev);vxlan_config_apply (dev, &conf, lowerdev, vxlan->net, true);return 0 ; }
@@ -3991,6 +4022,8 @@ static void vxlan_dellink(struct net_device *dev, struct list_head *head)list_del (&vxlan->next);unregister_netdevice_queue (dev, head); +if (vxlan->default_dst.remote_dev) +netdev_upper_dev_unlink (vxlan->default_dst.remote_dev, dev); }static size_t vxlan_get_size (const struct net_device *dev)
include/net/vxlan.h +1 -0
@@ -197,6 +197,7 @@ struct vxlan_rdst { u8 offloaded:1;__be32 remote_vni;u32 remote_ifindex; +struct net_device *remote_dev;struct list_head list;struct rcu_head rcu;struct dst_cache dst_cache;
Signature · 1 line
2.17.1
PATCH v5 9/10 net: remove unnecessary variables and callback
In reply to Taehee YooThis patch removes variables and callback these are related to the nested device structure.
devices that can be nested have their own nest_level variable that represents the depth of nested devices.
In the previous patch, new {lower/upper}_level variables are added and they replace old private nest_level variable.
So, this patch removes all 'nest_level' variables.
In order to avoid lockdep warning, ->ndo_get_lock_subclass() was added to get lockdep subclass value, which is actually lower nested depth value. But now, they use the dynamic lockdep key to avoid lockdep warning instead of the subclass.
So, this patch removes ->ndo_get_lock_subclass() callback.
---
v1 -> v5 :
- This patch is not changed
drivers/net/bonding/bond_alb.c | 2 +- drivers/net/bonding/bond_main.c | 15 --------------- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 2 +- drivers/net/macsec.c | 9 --------- drivers/net/macvlan.c | 7 ------- include/linux/if_macvlan.h | 1 - include/linux/if_vlan.h | 11 ----------- include/linux/netdevice.h | 12 ------------ include/net/bonding.h | 1 - net/8021q/vlan.c | 1 - net/8021q/vlan_dev.c | 6 ------ net/core/dev.c | 19 ------------------- net/core/dev_addr_lists.c | 12 ++++++------ net/smc/smc_core.c | 2 +- net/smc/smc_pnet.c | 2 +- 15 files changed, 10 insertions(+), 92 deletions(-)
drivers/net/bonding/bond_alb.c +1 -1
@@ -952,7 +952,7 @@ static int alb_upper_dev_walk(struct net_device *upper, void *_data)struct bond_vlan_tag *tags;if (is_vlan_dev (upper) && - bond->nest_level ==vlan_get_encap_level (upper) -1 ) { + bond->dev->lower_level == upper->lower_level -1 ) {if (upper->addr_assign_type ==NET_ADDR_STOLEN ) { alb_send_lp_vid(slave, mac_addr, vlan_dev_vlan_proto(upper),
drivers/net/bonding/bond_main.c +0 -15
@@ -1733,8 +1733,6 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev, goto err_upper_unlink; } - bond->nest_level =dev_get_nest_level (bond_dev) +1 ; -/* If the mode uses primary, then the following is handled by * bond_change_active_slave(). */
@@ -1957,9 +1955,6 @@ static int __bond_release_one(struct net_device *bond_dev,if (!bond_has_slaves (bond)) {bond_set_carrier (bond);eth_hw_addr_random (bond_dev); - bond->nest_level =SINGLE_DEPTH_NESTING ; - }else { - bond->nest_level =dev_get_nest_level (bond_dev) +1 ; }unblock_netpoll_tx ();
@@ -3444,13 +3439,6 @@ static void bond_fold_stats(struct rtnl_link_stats64 *_res, } } -static int bond_get_nest_level (struct net_device *bond_dev) -{ -struct bonding *bond =netdev_priv (bond_dev); - -return bond->nest_level; -} -static void bond_get_stats (struct net_device *bond_dev,struct rtnl_link_stats64 *stats) {
@@ -4270,7 +4258,6 @@ static const struct net_device_ops bond_netdev_ops = { .ndo_neigh_setup = bond_neigh_setup, .ndo_vlan_rx_add_vid = bond_vlan_rx_add_vid, .ndo_vlan_rx_kill_vid = bond_vlan_rx_kill_vid, - .ndo_get_lock_subclass = bond_get_nest_level, #ifdef CONFIG_NET_POLL_CONTROLLER .ndo_netpoll_setup = bond_netpoll_setup, .ndo_netpoll_cleanup = bond_netpoll_cleanup,
@@ -4769,8 +4756,6 @@ static int bond_init(struct net_device *bond_dev)if (!bond->wq)return -ENOMEM ; - bond->nest_level =SINGLE_DEPTH_NESTING ; -spin_lock_init (&bond->mode_lock);spin_lock_init (&bond->stats_lock);lockdep_register_key (&bond->stats_lock_key);
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +1 -1
@@ -3160,7 +3160,7 @@ static int add_vlan_pop_action(struct mlx5e_priv *priv,struct mlx5_esw_flow_attr *attr, u32 *action) { - int nest_level = vlan_get_encap_level(attr->parse_attr->filter_dev); + int nest_level = attr->parse_attr->filter_dev->lower_level;struct flow_action_entry vlan_act = { .id =FLOW_ACTION_VLAN_POP , };
drivers/net/macsec.c +0 -9
@@ -267,7 +267,6 @@ struct macsec_dev {struct pcpu_secy_stats __percpu *stats;struct list_head secys;struct gro_cells gro_cells; -unsigned int nest_level; };/**
@@ -2957,11 +2956,6 @@ static int macsec_get_iflink(const struct net_device *dev)return macsec_priv (dev)->real_dev->ifindex; } -static int macsec_get_nest_level (struct net_device *dev) -{ -return macsec_priv (dev)->nest_level; -} -static const struct net_device_ops macsec_netdev_ops = { .ndo_init = macsec_dev_init, .ndo_uninit = macsec_dev_uninit,
@@ -2975,7 +2969,6 @@ static const struct net_device_ops macsec_netdev_ops = { .ndo_start_xmit = macsec_start_xmit, .ndo_get_stats64 = macsec_get_stats64, .ndo_get_iflink = macsec_get_iflink, - .ndo_get_lock_subclass = macsec_get_nest_level, };static const struct device_type macsec_type = {
@@ -3258,8 +3251,6 @@ static int macsec_newlink(struct net *net, struct net_device *dev,if (err <0 )return err; - macsec->nest_level =dev_get_nest_level (real_dev) +1 ; - err =netdev_upper_dev_link (real_dev, dev, extack);if (err <0 ) goto unregister;
drivers/net/macvlan.c +0 -7
@@ -867,11 +867,6 @@ static int macvlan_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)#define MACVLAN_STATE_MASK \ ((1<<__LINK_STATE_NOCARRIER) | (1<<__LINK_STATE_DORMANT)) -static int macvlan_get_nest_level (struct net_device *dev) -{ -return ((struct macvlan_dev *)netdev_priv (dev))->nest_level; -} -static int macvlan_init (struct net_device *dev) {struct macvlan_dev *vlan =netdev_priv (dev);
@@ -1149,7 +1144,6 @@ static const struct net_device_ops macvlan_netdev_ops = { .ndo_fdb_add = macvlan_fdb_add, .ndo_fdb_del = macvlan_fdb_del, .ndo_fdb_dump = ndo_dflt_fdb_dump, - .ndo_get_lock_subclass = macvlan_get_nest_level, #ifdef CONFIG_NET_POLL_CONTROLLER .ndo_poll_controller = macvlan_dev_poll_controller, .ndo_netpoll_setup = macvlan_dev_netpoll_setup,
@@ -1433,7 +1427,6 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev, vlan->dev = dev; vlan->port = port; vlan->set_features =MACVLAN_FEATURES ; - vlan->nest_level =dev_get_nest_level (lowerdev) +1 ; vlan->mode =MACVLAN_MODE_VEPA ;if (data && data[IFLA_MACVLAN_MODE ])
include/linux/if_macvlan.h +0 -1
@@ -29,7 +29,6 @@ struct macvlan_dev {netdev_features_t set_features;enum macvlan_mode mode;u16 flags; -int nest_level;unsigned int macaddr_count;#ifdef CONFIG_NET_POLL_CONTROLLER struct netpoll *netpoll;
include/linux/if_vlan.h +0 -11
@@ -182,7 +182,6 @@ struct vlan_dev_priv {#ifdef CONFIG_NET_POLL_CONTROLLER struct netpoll *netpoll;#endif -unsigned int nest_level; };static inline struct vlan_dev_priv *vlan_dev_priv (const struct net_device *dev)
@@ -221,11 +220,6 @@ extern void vlan_vids_del_by_dev(struct net_device *dev,extern bool vlan_uses_dev (const struct net_device *dev); -static inline int vlan_get_encap_level (struct net_device *dev) -{ -BUG_ON (!is_vlan_dev (dev)); -return vlan_dev_priv (dev)->nest_level; -}#else static inline struct net_device * __vlan_find_dev_deep_rcu(struct net_device *real_dev,
@@ -295,11 +289,6 @@ static inline bool vlan_uses_dev(const struct net_device *dev) {return false; } -static inline int vlan_get_encap_level (struct net_device *dev) -{ -BUG (); -return 0 ; -}#endif /**
include/linux/netdevice.h +0 -12
@@ -1422,7 +1422,6 @@ struct net_device_ops {void (*ndo_dfwd_del_station)(struct net_device *pdev,void *priv); -int (*ndo_get_lock_subclass)(struct net_device *dev);int (*ndo_set_tx_maxrate)(struct net_device *dev,int queue_index,u32 maxrate);
@@ -4051,16 +4050,6 @@ static inline void netif_addr_lock(struct net_device *dev)spin_lock (&dev->addr_list_lock); } -static inline void netif_addr_lock_nested (struct net_device *dev) -{ -int subclass =SINGLE_DEPTH_NESTING ; - -if (dev->netdev_ops->ndo_get_lock_subclass) - subclass = dev->netdev_ops->ndo_get_lock_subclass (dev); - -spin_lock_nested (&dev->addr_list_lock, subclass); -} -static inline void netif_addr_lock_bh (struct net_device *dev) {spin_lock_bh (&dev->addr_list_lock);
@@ -4345,7 +4334,6 @@ void netdev_lower_state_changed(struct net_device *lower_dev,extern u8 netdev_rss_key[NETDEV_RSS_KEY_LEN ]__read_mostly ;void netdev_rss_key_fill (void *buffer,size_t len); -int dev_get_nest_level (struct net_device *dev);int skb_checksum_help (struct sk_buff *skb);int skb_crc32c_csum_help (struct sk_buff *skb); int skb_csum_hwoffload_help(struct sk_buff *skb,
include/net/bonding.h +0 -1
@@ -203,7 +203,6 @@ struct bonding {struct slave __rcu *primary_slave;struct bond_up_slave __rcu *slave_arr;/* Array of usable slaves */ bool force_primary; -u32 nest_level;s32 slave_cnt;/* never change this value outside the attach/detach wrappers */ int (*recv_probe)(const struct sk_buff *,struct bonding *,struct slave *);
net/8021q/vlan.c +0 -1
@@ -172,7 +172,6 @@ int register_vlan_dev(struct net_device *dev, struct netlink_ext_ack *extack)if (err <0 ) goto out_uninit_mvrp; - vlan->nest_level =dev_get_nest_level (real_dev) +1 ; err =register_netdevice (dev);if (err <0 ) goto out_uninit_mvrp;
net/8021q/vlan_dev.c +0 -6
@@ -489,11 +489,6 @@ static void vlan_dev_set_rx_mode(struct net_device *vlan_dev)dev_uc_sync (vlan_dev_priv (vlan_dev)->real_dev, vlan_dev); } -static int vlan_dev_get_lock_subclass (struct net_device *dev) -{ -return vlan_dev_priv (dev)->nest_level; -} -static const struct header_ops vlan_header_ops = { .create = vlan_dev_hard_header, .parse = eth_header_parse,
@@ -785,7 +780,6 @@ static const struct net_device_ops vlan_netdev_ops = { .ndo_netpoll_cleanup = vlan_dev_netpoll_cleanup, #endif .ndo_fix_features = vlan_dev_fix_features, - .ndo_get_lock_subclass = vlan_dev_get_lock_subclass, .ndo_get_iflink = vlan_dev_get_iflink, };
net/core/dev.c +0 -19
@@ -7615,25 +7615,6 @@ void *netdev_lower_dev_get_private(struct net_device *dev,EXPORT_SYMBOL (netdev_lower_dev_get_private); -int dev_get_nest_level (struct net_device *dev) -{ -struct net_device *lower =NULL ; -struct list_head *iter; -int max_nest =-1 ; -int nest; - -ASSERT_RTNL (); - -netdev_for_each_lower_dev (dev, lower, iter) { - nest =dev_get_nest_level (lower); -if (max_nest < nest) - max_nest = nest; - } - -return max_nest +1 ; -} -EXPORT_SYMBOL (dev_get_nest_level); -/** * netdev_lower_change - Dispatch event about lower device state change * @lower_dev: device
net/core/dev_addr_lists.c +6 -6
@@ -637,7 +637,7 @@ int dev_uc_sync(struct net_device *to, struct net_device *from)if (to->addr_len != from->addr_len)return -EINVAL ; -netif_addr_lock_nested (to); +netif_addr_lock (to); err =__hw_addr_sync (&to->uc, &from->uc, to->addr_len);if (!err)__dev_set_rx_mode (to);
@@ -667,7 +667,7 @@ int dev_uc_sync_multiple(struct net_device *to, struct net_device *from)if (to->addr_len != from->addr_len)return -EINVAL ; -netif_addr_lock_nested (to); +netif_addr_lock (to); err =__hw_addr_sync_multiple (&to->uc, &from->uc, to->addr_len);if (!err)__dev_set_rx_mode (to);
@@ -691,7 +691,7 @@ void dev_uc_unsync(struct net_device *to, struct net_device *from)return ;netif_addr_lock_bh (from); -netif_addr_lock_nested (to); +netif_addr_lock (to);__hw_addr_unsync (&to->uc, &from->uc, to->addr_len);__dev_set_rx_mode (to);netif_addr_unlock (to);
@@ -858,7 +858,7 @@ int dev_mc_sync(struct net_device *to, struct net_device *from)if (to->addr_len != from->addr_len)return -EINVAL ; -netif_addr_lock_nested (to); +netif_addr_lock (to); err =__hw_addr_sync (&to->mc, &from->mc, to->addr_len);if (!err)__dev_set_rx_mode (to);
@@ -888,7 +888,7 @@ int dev_mc_sync_multiple(struct net_device *to, struct net_device *from)if (to->addr_len != from->addr_len)return -EINVAL ; -netif_addr_lock_nested (to); +netif_addr_lock (to); err =__hw_addr_sync_multiple (&to->mc, &from->mc, to->addr_len);if (!err)__dev_set_rx_mode (to);
@@ -912,7 +912,7 @@ void dev_mc_unsync(struct net_device *to, struct net_device *from)return ;netif_addr_lock_bh (from); -netif_addr_lock_nested (to); +netif_addr_lock (to);__hw_addr_unsync (&to->mc, &from->mc, to->addr_len);__dev_set_rx_mode (to);netif_addr_unlock (to);
net/smc/smc_core.c +1 -1
@@ -561,7 +561,7 @@ int smc_vlan_by_tcpsk(struct socket *clcsock, struct smc_init_info *ini) }rtnl_lock (); - nest_lvl =dev_get_nest_level (ndev); + nest_lvl = ndev->lower_level;for (i =0 ; i < nest_lvl; i++) {struct list_head *lower = &ndev->adj_list.lower;
net/smc/smc_pnet.c +1 -1
@@ -718,7 +718,7 @@ static struct net_device *pnet_find_base_ndev(struct net_device *ndev)int i, nest_lvl;rtnl_lock (); - nest_lvl =dev_get_nest_level (ndev); + nest_lvl = ndev->lower_level;for (i =0 ; i < nest_lvl; i++) {struct list_head *lower = &ndev->adj_list.lower;
Signature · 1 line
2.17.1
PATCH v5 10/10 virt_wifi: fix refcnt leak in module exit routine
In reply to Taehee Yoovirt_wifi_newlink() calls netdev_upper_dev_link() and it internally holds reference count of lower interface.
Current code does not release a reference count of the lower interface when the lower interface is being deleted.
So, reference count leaks occur.
Test commands:
ip link add dummy0 type dummy
ip link add vw1 link dummy0 type virt_wifi
ip link del dummy0
Splat looks like:
[ 133.787526][ T788] WARNING: CPU: 1 PID: 788 at net/core/dev.c:8274 rollback_registered_many+0x835/0xc80 [ 133.788355][ T788] Modules linked in: virt_wifi cfg80211 dummy team af_packet sch_fq_codel ip_tables x_tables unix [ 133.789377][ T788] CPU: 1 PID: 788 Comm: ip Not tainted 5.4.0-rc3+ #96 [ 133.790069][ T788] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 133.791167][ T788] RIP: 0010:rollback_registered_many+0x835/0xc80 [ 133.791906][ T788] Code: 00 4d 85 ff 0f 84 b5 fd ff ff ba c0 0c 00 00 48 89 de 4c 89 ff e8 9b 58 04 00 48 89 df e8 30 [ 133.794317][ T788] RSP: 0018:ffff88805ba3f338 EFLAGS: 00010202 [ 133.795080][ T788] RAX: ffff88805e57e801 RBX: ffff88805ba34000 RCX: ffffffffa9294723 [ 133.796045][ T788] RDX: 1ffff1100b746816 RSI: 0000000000000008 RDI: ffffffffabcc4240 [ 133.797006][ T788] RBP: ffff88805ba3f4c0 R08: fffffbfff5798849 R09: fffffbfff5798849 [ 133.797993][ T788] R10: 0000000000000001 R11: fffffbfff5798848 R12: dffffc0000000000 [ 133.802514][ T788] R13: ffff88805ba3f440 R14: ffff88805ba3f400 R15: ffff88805ed622c0 [ 133.803237][ T788] FS: 00007f2e9608c0c0(0000) GS:ffff88806cc00000(0000) knlGS:0000000000000000 [ 133.804002][ T788] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 133.804664][ T788] CR2: 00007f2e95610603 CR3: 000000005f68c004 CR4: 00000000000606e0 [ 133.805363][ T788] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 133.806073][ T788] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 133.806787][ T788] Call Trace: [ 133.807069][ T788] ? generic_xdp_install+0x310/0x310 [ 133.807612][ T788] ? lock_acquire+0x164/0x3b0 [ 133.808077][ T788] ? is_bpf_text_address+0x5/0xf0 [ 133.808640][ T788] ? deref_stack_reg+0x9c/0xd0 [ 133.809138][ T788] ? __nla_validate_parse+0x98/0x1ab0 [ 133.809944][ T788] unregister_netdevice_many.part.122+0x13/0x1b0 [ 133.810599][ T788] rtnl_delete_link+0xbc/0x100 [ 133.811073][ T788] ? rtnl_af_register+0xc0/0xc0 [ 133.811672][ T788] rtnl_dellink+0x30e/0x8a0 [ 133.812205][ T788] ? is_bpf_text_address+0x5/0xf0
[ ... ]
[ 144.110530][ T788] unregister_netdevice: waiting for dummy0 to become free. Usage count = 1
This patch adds notifier routine to delete upper interface before deleting lower interface.
---
v4 -> v5 :
- Log message update
- Fix wrong error value in error path of __init routine
- hold module refcnt when interface is created
v4 :
- Initial patch
drivers/net/wireless/virt_wifi.c | 54 ++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-)
drivers/net/wireless/virt_wifi.c +52 -2
@@ -548,6 +548,7 @@ static int virt_wifi_newlink(struct net *src_net, struct net_device *dev, priv->is_connected = false; priv->is_up = false;INIT_DELAYED_WORK (&priv->connect, virt_wifi_connect_complete); +__module_get (THIS_MODULE );return 0 ; unregister_netdev:
@@ -578,6 +579,7 @@ static void virt_wifi_dellink(struct net_device *dev,netdev_upper_dev_unlink (priv->lowerdev, dev);unregister_netdevice_queue (dev, head); +module_put (THIS_MODULE );/* Deleting the wiphy is handled in the module destructor. */ }
@@ -590,6 +592,42 @@ static struct rtnl_link_ops virt_wifi_link_ops = { .priv_size = sizeof(struct virt_wifi_netdev_priv), }; +static inline bool netif_is_virt_wifi_dev (const struct net_device *dev) +{ +return rcu_access_pointer (dev->rx_handler) == virt_wifi_rx_handler; +} + +static int virt_wifi_event (struct notifier_block *this,unsigned long event, +void *ptr) +{ +struct net_device *lower_dev =netdev_notifier_info_to_dev (ptr); +struct virt_wifi_netdev_priv *priv; +struct net_device *upper_dev; +LIST_HEAD (list_kill); + +if (!netif_is_virt_wifi_dev (lower_dev)) +return NOTIFY_DONE ; + +switch (event) { +case NETDEV_UNREGISTER : + priv =rtnl_dereference (lower_dev->rx_handler_data); +if (!priv) +return NOTIFY_DONE ; + + upper_dev = priv->upperdev; + + upper_dev->rtnl_link_ops->dellink (upper_dev, &list_kill); +unregister_netdevice_many (&list_kill); +break ; + } + +return NOTIFY_DONE ; +} + +static struct notifier_block virt_wifi_notifier = { + .notifier_call = virt_wifi_event, +}; +/* Acquires and releases the rtnl lock. */ static int __init virt_wifi_init_module (void ) {
@@ -598,14 +636,25 @@ static int __init virt_wifi_init_module(void)/* Guaranteed to be locallly-administered and not multicast. */ eth_random_addr (fake_router_bssid); + err =register_netdevice_notifier (&virt_wifi_notifier); +if (err) +return err; + + err = -ENOMEM ; common_wiphy =virt_wifi_make_wiphy ();if (!common_wiphy) -return -ENOMEM ; + goto notifier; err =rtnl_link_register (&virt_wifi_link_ops);if (err) -virt_wifi_destroy_wiphy (common_wiphy); + goto destroy_wiphy; +return 0 ; + +destroy_wiphy: +virt_wifi_destroy_wiphy (common_wiphy); +notifier: +unregister_netdevice_notifier (&virt_wifi_notifier);return err; }
@@ -615,6 +664,7 @@ static void __exit virt_wifi_cleanup_module(void)/* Will delete any devices that depend on the wiphy. */ rtnl_link_unregister (&virt_wifi_link_ops);virt_wifi_destroy_wiphy (common_wiphy); +unregister_netdevice_notifier (&virt_wifi_notifier); }module_init (virt_wifi_init_module);
Signature · 1 line
2.17.1
Quoted 4 lines · Taehee Yoo
Current code doesn't limit the number of nested devices. Nested devices would be handled recursively and this needs huge stack memory. So, unlimited nested devices could make stack overflow.
Quoted 8 lines
This patch adds
upper_levelandlower_level, they are common variables and represent maximum lower/upper depth.
When upper/lower device is attached or dettached, {lower/upper}_level are updated. and if maximum depth is bigger than 8, attach routine fails and returns-EMLINK.In addition, this patch converts recursive routine of netdev_walk_all_{lower/upper} to iterator routine.
They were made recursive because of a particular setup. Did you verify your changes did not break it? See commits starting with 5bb61cb5fd115bed1814f6b97417e0f397da3c79
Quoted 6 lines
Test commands:
ip link add dummy0 type dummy
ip link add link dummy0 name vlan1 type vlan id 1 ip link set vlan1 up
Quoted 7 lines
for i in {2..55}
do
let A=$i-1ip link add vlan$i link vlan$A type vlan id $i
done
ip link del dummy0
8 levels of nested vlan seems like complete nonsense. Why not just limit that stacking and not mess with the rest which can affect real use cases?
Quoted 1 line · David Ahern
Hi David,
Thank you for the review!
Quoted 11 lines · Taehee Yoo
Quoted 10 lines
Current code doesn't limit the number of nested devices. Nested devices would be handled recursively and this needs huge stack memory. So, unlimited nested devices could make stack overflow.
This patch adds
upper_levelandlower_level, they are common variables and represent maximum lower/upper depth.
When upper/lower device is attached or dettached, {lower/upper}_level are updated. and if maximum depth is bigger than 8, attach routine fails and returns-EMLINK.
Quoted 7 lines
Quoted 2 lines
In addition, this patch converts recursive routine of netdev_walk_all_{lower/upper} to iterator routine.
They were made recursive because of a particular setup. Did you verify your changes did not break it? See commits starting with
5bb61cb5fd115bed1814f6b97417e0f397da3c79
I didn't change the actual logic of walking APIs.
These walking iterator APIs work as DFS.
So it doesn't break existing codes.
Quoted 10 lines
Quoted 10 lines
Test commands:
ip link add dummy0 type dummy
ip link add link dummy0 name vlan1 type vlan id 1 ip link set vlan1 upfor i in {2..55}
do
let A=$i-1
Quoted 6 lines
Quoted 3 lines
ip link add vlan$i link vlan$A type vlan id $i
done
ip link del dummy08 levels of nested vlan seems like complete nonsense. Why not just limit that stacking and not mess with the rest which can affect real use cases?
VLAN, BONDING, TEAM, MACSEC, MACVLAN, IPVLAN, VIRT_WIFI, and VXLAN These interface types can be nested and these could be combined.
team6
|
vlan5
|
team4
|
macvlan3
|
bond2
|
vlan1
|dummy0
There are so many similar cases even they are not real use cases. So I think generic code is needed.
Thank you
Taehee Yoo