Skip to content

Commit

Permalink
net: let lockdep compare instance locks
Browse files Browse the repository at this point in the history
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 <sdf@fomichev.me>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20250517200810.466531-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed May 21, 2025
1 parent 6a7e8b5 commit 4c2bd79
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions include/net/netdev_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,15 @@ static inline void netdev_unlock_ops_compat(struct net_device *dev)
static inline int netdev_lock_cmp_fn(const struct lockdep_map *a,
const struct lockdep_map *b)
{
/* Only lower devices currently grab the instance lock, so no
* real ordering issues can occur. In the near future, only
* hardware devices will grab instance lock which also does not
* involve any ordering. Suppress lockdep ordering warnings
* until (if) we start grabbing instance lock on pure SW
* devices (bond/team/veth/etc).
*/
if (a == b)
return 0;
return -1;

/* Allow locking multiple devices only under rtnl_lock,
* the exact order doesn't matter.
* Note that upper devices don't lock their ops, so nesting
* mostly happens in batched device removal for now.
*/
return lockdep_rtnl_is_held() ? -1 : 1;
}

#define netdev_lockdep_set_classes(dev) \
Expand Down

0 comments on commit 4c2bd79

Please sign in to comment.