Skip to content

Commit 4c2bd79

Browse files
committed
net: let lockdep compare instance locks
AFAIU always returning -1 from lockdep's compare function basically disables checking of dependencies between given locks. Try to be a little more precise about what guarantees that instance locks won't deadlock. Right now we only nest them under protection of rtnl_lock. Mostly in unregister_netdevice_many() and dev_close_many(). Acked-by: Stanislav Fomichev <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 6a7e8b5 commit 4c2bd79

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

include/net/netdev_lock.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,15 @@ static inline void netdev_unlock_ops_compat(struct net_device *dev)
9999
static inline int netdev_lock_cmp_fn(const struct lockdep_map *a,
100100
const struct lockdep_map *b)
101101
{
102-
/* Only lower devices currently grab the instance lock, so no
103-
* real ordering issues can occur. In the near future, only
104-
* hardware devices will grab instance lock which also does not
105-
* involve any ordering. Suppress lockdep ordering warnings
106-
* until (if) we start grabbing instance lock on pure SW
107-
* devices (bond/team/veth/etc).
108-
*/
109102
if (a == b)
110103
return 0;
111-
return -1;
104+
105+
/* Allow locking multiple devices only under rtnl_lock,
106+
* the exact order doesn't matter.
107+
* Note that upper devices don't lock their ops, so nesting
108+
* mostly happens in batched device removal for now.
109+
*/
110+
return lockdep_rtnl_is_held() ? -1 : 1;
112111
}
113112

114113
#define netdev_lockdep_set_classes(dev) \

0 commit comments

Comments
 (0)