mirror of
https://github.com/torvalds/linux.git
synced 2024-12-29 06:12:08 +00:00
f47944cc2d
When ipoib interface is going down it takes all of its children with it, under mutex. For each child, dev_change_flags() is called. That function calls ipoib_stop() via the ndo, and causes flush of the workqueue. Sometimes in the workqueue an __ipoib_dev_flush work() is waiting and when invoked tries to get the same mutex, which leads to a deadlock, as seen below. The solution is to switch to rw-sem instead of mutex. The deadlock: [11028.165303] [<ffffffff812b0977>] ? vgacon_scroll+0x107/0x2e0 [11028.171844] [<ffffffff814eaac5>] schedule_timeout+0x215/0x2e0 [11028.178465] [<ffffffff8105a5c3>] ? perf_event_task_sched_out+0x33/0x80 [11028.185962] [<ffffffff814ea743>] wait_for_common+0x123/0x180 [11028.192491] [<ffffffff8105fa40>] ? default_wake_function+0x0/0x20 [11028.199504] [<ffffffff814ea85d>] wait_for_completion+0x1d/0x20 [11028.206224] [<ffffffff8108b4f1>] flush_cpu_workqueue+0x61/0x90 [11028.212948] [<ffffffff8108b5a0>] ? wq_barrier_func+0x0/0x20 [11028.219375] [<ffffffff8108bfc4>] flush_workqueue+0x54/0x80 [11028.225712] [<ffffffffa05a0576>] ipoib_mcast_stop_thread+0x66/0x90 [ib_ipoib] [11028.233988] [<ffffffffa059ccea>] ipoib_ib_dev_down+0x6a/0x100 [ib_ipoib] [11028.241678] [<ffffffffa059849a>] ipoib_stop+0x8a/0x140 [ib_ipoib] [11028.248692] [<ffffffff8142adf1>] dev_close+0x71/0xc0 [11028.254447] [<ffffffff8142a631>] dev_change_flags+0xa1/0x1d0 [11028.261062] [<ffffffffa059851b>] ipoib_stop+0x10b/0x140 [ib_ipoib] [11028.268172] [<ffffffff8142adf1>] dev_close+0x71/0xc0 [11028.273922] [<ffffffff8142a631>] dev_change_flags+0xa1/0x1d0 [11028.280452] [<ffffffff8148f20b>] devinet_ioctl+0x5eb/0x6a0 [11028.286786] [<ffffffff814903b8>] inet_ioctl+0x88/0xa0 [11028.292633] [<ffffffff8141591a>] sock_ioctl+0x7a/0x280 [11028.298576] [<ffffffff81189012>] vfs_ioctl+0x22/0xa0 [11028.304326] [<ffffffff81140540>] ? unmap_region+0x110/0x130 [11028.310756] [<ffffffff811891b4>] do_vfs_ioctl+0x84/0x580 [11028.316897] [<ffffffff81189731>] sys_ioctl+0x81/0xa0 and 11028.017533] [<ffffffff8105a5c3>] ? perf_event_task_sched_out+0x33/0x80 [11028.025030] [<ffffffff8100bb8e>] ? apic_timer_interrupt+0xe/0x20 [11028.031945] [<ffffffff814eb2ae>] __mutex_lock_slowpath+0x13e/0x180 [11028.039053] [<ffffffff814eb14b>] mutex_lock+0x2b/0x50 [11028.044910] [<ffffffffa059f7e7>] __ipoib_ib_dev_flush+0x37/0x210 [ib_ipoib] [11028.052894] [<ffffffffa059fa00>] ? ipoib_ib_dev_flush_light+0x0/0x20 [ib_ipoib] [11028.061363] [<ffffffffa059fa17>] ipoib_ib_dev_flush_light+0x17/0x20 [ib_ipoib] [11028.069738] [<ffffffff8108b120>] worker_thread+0x170/0x2a0 [11028.076068] [<ffffffff81090990>] ? autoremove_wake_function+0x0/0x40 [11028.083374] [<ffffffff8108afb0>] ? worker_thread+0x0/0x2a0 [11028.089709] [<ffffffff81090626>] kthread+0x96/0xa0 [11028.095266] [<ffffffff8100c0ca>] child_rip+0xa/0x20 [11028.100921] [<ffffffff81090590>] ? kthread+0x0/0xa0 [11028.106573] [<ffffffff8100c0c0>] ? child_rip+0x0/0x20 [11028.112423] INFO: task ifconfig:23640 blocked for more than 120 seconds. Signed-off-by: Erez Shitrit <erezsh@mellanox.com> Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com> Signed-off-by: Roland Dreier <roland@purestorage.com>
210 lines
5.2 KiB
C
210 lines
5.2 KiB
C
/*
|
|
* Copyright (c) 2004 Topspin Communications. All rights reserved.
|
|
*
|
|
* This software is available to you under a choice of one of two
|
|
* licenses. You may choose to be licensed under the terms of the GNU
|
|
* General Public License (GPL) Version 2, available from the file
|
|
* COPYING in the main directory of this source tree, or the
|
|
* OpenIB.org BSD license below:
|
|
*
|
|
* Redistribution and use in source and binary forms, with or
|
|
* without modification, are permitted provided that the following
|
|
* conditions are met:
|
|
*
|
|
* - Redistributions of source code must retain the above
|
|
* copyright notice, this list of conditions and the following
|
|
* disclaimer.
|
|
*
|
|
* - Redistributions in binary form must reproduce the above
|
|
* copyright notice, this list of conditions and the following
|
|
* disclaimer in the documentation and/or other materials
|
|
* provided with the distribution.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include "ipoib.h"
|
|
|
|
static ssize_t show_parent(struct device *d, struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct net_device *dev = to_net_dev(d);
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
return sprintf(buf, "%s\n", priv->parent->name);
|
|
}
|
|
static DEVICE_ATTR(parent, S_IRUGO, show_parent, NULL);
|
|
|
|
int __ipoib_vlan_add(struct ipoib_dev_priv *ppriv, struct ipoib_dev_priv *priv,
|
|
u16 pkey, int type)
|
|
{
|
|
int result;
|
|
|
|
priv->max_ib_mtu = ppriv->max_ib_mtu;
|
|
/* MTU will be reset when mcast join happens */
|
|
priv->dev->mtu = IPOIB_UD_MTU(priv->max_ib_mtu);
|
|
priv->mcast_mtu = priv->admin_mtu = priv->dev->mtu;
|
|
set_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags);
|
|
|
|
result = ipoib_set_dev_features(priv, ppriv->ca);
|
|
if (result)
|
|
goto err;
|
|
|
|
priv->pkey = pkey;
|
|
|
|
memcpy(priv->dev->dev_addr, ppriv->dev->dev_addr, INFINIBAND_ALEN);
|
|
priv->dev->broadcast[8] = pkey >> 8;
|
|
priv->dev->broadcast[9] = pkey & 0xff;
|
|
|
|
result = ipoib_dev_init(priv->dev, ppriv->ca, ppriv->port);
|
|
if (result < 0) {
|
|
ipoib_warn(ppriv, "failed to initialize subinterface: "
|
|
"device %s, port %d",
|
|
ppriv->ca->name, ppriv->port);
|
|
goto err;
|
|
}
|
|
|
|
result = register_netdevice(priv->dev);
|
|
if (result) {
|
|
ipoib_warn(priv, "failed to initialize; error %i", result);
|
|
goto register_failed;
|
|
}
|
|
|
|
priv->parent = ppriv->dev;
|
|
|
|
ipoib_create_debug_files(priv->dev);
|
|
|
|
/* RTNL childs don't need proprietary sysfs entries */
|
|
if (type == IPOIB_LEGACY_CHILD) {
|
|
if (ipoib_cm_add_mode_attr(priv->dev))
|
|
goto sysfs_failed;
|
|
if (ipoib_add_pkey_attr(priv->dev))
|
|
goto sysfs_failed;
|
|
if (ipoib_add_umcast_attr(priv->dev))
|
|
goto sysfs_failed;
|
|
|
|
if (device_create_file(&priv->dev->dev, &dev_attr_parent))
|
|
goto sysfs_failed;
|
|
}
|
|
|
|
priv->child_type = type;
|
|
priv->dev->iflink = ppriv->dev->ifindex;
|
|
list_add_tail(&priv->list, &ppriv->child_intfs);
|
|
|
|
return 0;
|
|
|
|
sysfs_failed:
|
|
result = -ENOMEM;
|
|
ipoib_delete_debug_files(priv->dev);
|
|
unregister_netdevice(priv->dev);
|
|
|
|
register_failed:
|
|
ipoib_dev_cleanup(priv->dev);
|
|
|
|
err:
|
|
return result;
|
|
}
|
|
|
|
int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey)
|
|
{
|
|
struct ipoib_dev_priv *ppriv, *priv;
|
|
char intf_name[IFNAMSIZ];
|
|
struct ipoib_dev_priv *tpriv;
|
|
int result;
|
|
|
|
if (!capable(CAP_NET_ADMIN))
|
|
return -EPERM;
|
|
|
|
ppriv = netdev_priv(pdev);
|
|
|
|
snprintf(intf_name, sizeof intf_name, "%s.%04x",
|
|
ppriv->dev->name, pkey);
|
|
priv = ipoib_intf_alloc(intf_name);
|
|
if (!priv)
|
|
return -ENOMEM;
|
|
|
|
if (!rtnl_trylock())
|
|
return restart_syscall();
|
|
|
|
down_write(&ppriv->vlan_rwsem);
|
|
|
|
/*
|
|
* First ensure this isn't a duplicate. We check the parent device and
|
|
* then all of the legacy child interfaces to make sure the Pkey
|
|
* doesn't match.
|
|
*/
|
|
if (ppriv->pkey == pkey) {
|
|
result = -ENOTUNIQ;
|
|
goto out;
|
|
}
|
|
|
|
list_for_each_entry(tpriv, &ppriv->child_intfs, list) {
|
|
if (tpriv->pkey == pkey &&
|
|
tpriv->child_type == IPOIB_LEGACY_CHILD) {
|
|
result = -ENOTUNIQ;
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
result = __ipoib_vlan_add(ppriv, priv, pkey, IPOIB_LEGACY_CHILD);
|
|
|
|
out:
|
|
up_write(&ppriv->vlan_rwsem);
|
|
|
|
if (result)
|
|
free_netdev(priv->dev);
|
|
|
|
rtnl_unlock();
|
|
|
|
return result;
|
|
}
|
|
|
|
int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey)
|
|
{
|
|
struct ipoib_dev_priv *ppriv, *priv, *tpriv;
|
|
struct net_device *dev = NULL;
|
|
|
|
if (!capable(CAP_NET_ADMIN))
|
|
return -EPERM;
|
|
|
|
ppriv = netdev_priv(pdev);
|
|
|
|
if (!rtnl_trylock())
|
|
return restart_syscall();
|
|
|
|
down_write(&ppriv->vlan_rwsem);
|
|
list_for_each_entry_safe(priv, tpriv, &ppriv->child_intfs, list) {
|
|
if (priv->pkey == pkey &&
|
|
priv->child_type == IPOIB_LEGACY_CHILD) {
|
|
unregister_netdevice(priv->dev);
|
|
list_del(&priv->list);
|
|
dev = priv->dev;
|
|
break;
|
|
}
|
|
}
|
|
up_write(&ppriv->vlan_rwsem);
|
|
|
|
rtnl_unlock();
|
|
|
|
if (dev) {
|
|
free_netdev(dev);
|
|
return 0;
|
|
}
|
|
|
|
return -ENODEV;
|
|
}
|