From: Taehee Yoo <ap420073@gmail.com>
To: davem@davemloft.net, netdev@vger.kernel.org,
linux-wireless@vger.kernel.org, jakub.kicinski@netronome.com,
johannes@sipsolutions.net, j.vosburgh@gmail.com,
vfalico@gmail.com, andy@greyhouse.net, jiri@resnulli.us,
sd@queasysnail.net, roopa@cumulusnetworks.com,
saeedm@mellanox.com, manishc@marvell.com, rahulv@marvell.com,
kys@microsoft.com, haiyangz@microsoft.com,
stephen@networkplumber.org, sashal@kernel.org, hare@suse.de,
varun@chelsio.com, ubraun@linux.ibm.com, kgraul@linux.ibm.com,
jay.vosburgh@canonical.com, schuffelen@google.com, bjorn@mork.no
Cc: ap420073@gmail.com
Subject: [PATCH net v5 04/10] bonding: use dynamic lockdep key instead of subclass
Date: Mon, 21 Oct 2019 18:47:53 +0000 [thread overview]
Message-ID: <20191021184759.13125-4-ap420073@gmail.com> (raw)
In-Reply-To: <20191021184759.13125-1-ap420073@gmail.com>
All 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]
Fixes: d3fff6c443fe ("net: add netdev_lockdep_set_classes() helper")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
---
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(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 92713b93f66f..6a6273590288 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -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);
diff --git a/include/net/bonding.h b/include/net/bonding.h
index f7fe45689142..334909feb2bb 100644
--- a/include/net/bonding.h
+++ b/include/net/bonding.h
@@ -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) \
--
2.17.1
next prev parent reply other threads:[~2019-10-21 18:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-21 18:47 [PATCH net v5 01/10] net: core: limit nested device depth Taehee Yoo
2019-10-21 18:47 ` [PATCH net v5 02/10] net: core: add generic lockdep keys Taehee Yoo
2019-10-21 18:47 ` [PATCH net v5 03/10] bonding: fix unexpected IFF_BONDING bit unset Taehee Yoo
2019-10-21 18:47 ` Taehee Yoo [this message]
2019-10-21 18:47 ` [PATCH net v5 05/10] team: fix nested locking lockdep warning Taehee Yoo
2019-10-21 18:47 ` [PATCH net v5 06/10] macsec: fix refcnt leak in module exit routine Taehee Yoo
2019-10-21 18:47 ` [PATCH net v5 07/10] net: core: add ignore flag to netdev_adjacent structure Taehee Yoo
2019-10-21 18:47 ` [PATCH net v5 08/10] vxlan: add adjacent link to limit depth level Taehee Yoo
2019-10-21 18:47 ` [PATCH net v5 09/10] net: remove unnecessary variables and callback Taehee Yoo
2019-10-21 18:47 ` [PATCH net v5 10/10] virt_wifi: fix refcnt leak in module exit routine Taehee Yoo
2019-10-22 0:51 ` [PATCH net v5 01/10] net: core: limit nested device depth David Ahern
2019-10-22 16:40 ` Taehee Yoo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191021184759.13125-4-ap420073@gmail.com \
--to=ap420073@gmail.com \
--cc=andy@greyhouse.net \
--cc=bjorn@mork.no \
--cc=davem@davemloft.net \
--cc=haiyangz@microsoft.com \
--cc=hare@suse.de \
--cc=j.vosburgh@gmail.com \
--cc=jakub.kicinski@netronome.com \
--cc=jay.vosburgh@canonical.com \
--cc=jiri@resnulli.us \
--cc=johannes@sipsolutions.net \
--cc=kgraul@linux.ibm.com \
--cc=kys@microsoft.com \
--cc=linux-wireless@vger.kernel.org \
--cc=manishc@marvell.com \
--cc=netdev@vger.kernel.org \
--cc=rahulv@marvell.com \
--cc=roopa@cumulusnetworks.com \
--cc=saeedm@mellanox.com \
--cc=sashal@kernel.org \
--cc=schuffelen@google.com \
--cc=sd@queasysnail.net \
--cc=stephen@networkplumber.org \
--cc=ubraun@linux.ibm.com \
--cc=varun@chelsio.com \
--cc=vfalico@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.