Skip to contentSkip to conversation

RDMA/cma: Teach lockdep about the order of rtnl and lock

PATCH In review Jason Gunthorpe 2 participants 2 messages Feb 27, 2020 – Mar 10, 2020 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/cma: Teach lockdep about the order of rtnl and lock

This lock ordering only happens when bonding is enabled and a certain bonding related event fires. However, since it can happen this is a global restriction on lock ordering.

Teach lockdep about the order directly and unconditionally so bugs here are found quickly.

See https://syzkaller.appspot.com/bug?extid=55de90ab5f44172b0c90

---
 drivers/infiniband/core/cma.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

This will trigger siw to fail on module load, maybe other drivers too.

drivers/infiniband/core/cma.c +13 -0
index 5165158a7aaa7d..c623d54ac9f944 100644
@@ -4789,6 +4789,19 @@ static int __init cma_init(void)
 {
 	int ret;
 
+	/*
+	 * There is a rare lock ordering dependency in cma_netdev_callback()
+	 * that only happens when bonding is enabled. Teach lockdep that rtnl
+	 * must never be nested under lock so it can find these without having
+	 * to test with bonding.
+	 */
+	if (IS_ENABLED(CONFIG_LOCKDEP)) {
+		rtnl_lock();
+		mutex_lock(&lock);
+		mutex_unlock(&lock);
+		rtnl_unlock();
+	}
+
 	cma_wq = alloc_ordered_workqueue("rdma_cm", WQ_MEM_RECLAIM);
 	if (!cma_wq)
 		return -ENOMEM;
Signature · 1 line
2.25.0
#1 lore raw
Quoted 7 lines · Jason Gunthorpe

This lock ordering only happens when bonding is enabled and a certain bonding related event fires. However, since it can happen this is a global restriction on lock ordering.

Teach lockdep about the order directly and unconditionally so bugs here are found quickly.

Quoted 6 lines

See https://syzkaller.appspot.com/bug?extid=55de90ab5f44172b0c90

---
 drivers/infiniband/core/cma.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Lets give it a go, applied to for-next

Jason