netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] net: let lockdep compare instance locks
@ 2025-05-17 20:08 Jakub Kicinski
  2025-05-18  3:50 ` Stanislav Fomichev
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jakub Kicinski @ 2025-05-17 20:08 UTC (permalink / raw)
  To: davem
  Cc: netdev, edumazet, pabeni, andrew+netdev, horms, kuniyu, sdf,
	Jakub Kicinski

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().

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v2:
 - drop the speculative small rtnl handling
v1: https://lore.kernel.org/20250516012459.1385997-1-kuba@kernel.org
---
 include/net/netdev_lock.h | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/include/net/netdev_lock.h b/include/net/netdev_lock.h
index 2a753813f849..c345afecd4c5 100644
--- a/include/net/netdev_lock.h
+++ b/include/net/netdev_lock.h
@@ -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)				\
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next v2] net: let lockdep compare instance locks
  2025-05-17 20:08 [PATCH net-next v2] net: let lockdep compare instance locks Jakub Kicinski
@ 2025-05-18  3:50 ` Stanislav Fomichev
  2025-05-18 19:32 ` Kuniyuki Iwashima
  2025-05-21  1:20 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Stanislav Fomichev @ 2025-05-18  3:50 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms, kuniyu,
	sdf

On 05/17, Jakub Kicinski wrote:
> 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().
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> v2:
>  - drop the speculative small rtnl handling

Acked-by: Stanislav Fomichev <sdf@fomichev.me>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next v2] net: let lockdep compare instance locks
  2025-05-17 20:08 [PATCH net-next v2] net: let lockdep compare instance locks Jakub Kicinski
  2025-05-18  3:50 ` Stanislav Fomichev
@ 2025-05-18 19:32 ` Kuniyuki Iwashima
  2025-05-21  1:20 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Kuniyuki Iwashima @ 2025-05-18 19:32 UTC (permalink / raw)
  To: kuba; +Cc: andrew+netdev, davem, edumazet, horms, kuniyu, netdev, pabeni,
	sdf

From: Jakub Kicinski <kuba@kernel.org>
Date: Sat, 17 May 2025 13:08:10 -0700
> 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().
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>


> ---
> v2:
>  - drop the speculative small rtnl handling
> v1: https://lore.kernel.org/20250516012459.1385997-1-kuba@kernel.org
> ---
>  include/net/netdev_lock.h | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/include/net/netdev_lock.h b/include/net/netdev_lock.h
> index 2a753813f849..c345afecd4c5 100644
> --- a/include/net/netdev_lock.h
> +++ b/include/net/netdev_lock.h
> @@ -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)				\
> -- 
> 2.49.0
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next v2] net: let lockdep compare instance locks
  2025-05-17 20:08 [PATCH net-next v2] net: let lockdep compare instance locks Jakub Kicinski
  2025-05-18  3:50 ` Stanislav Fomichev
  2025-05-18 19:32 ` Kuniyuki Iwashima
@ 2025-05-21  1:20 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-05-21  1:20 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms, kuniyu,
	sdf

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Sat, 17 May 2025 13:08:10 -0700 you wrote:
> 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().
> 
> [...]

Here is the summary with links:
  - [net-next,v2] net: let lockdep compare instance locks
    https://git.kernel.org/netdev/net-next/c/4c2bd7913f52

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-05-21  1:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-17 20:08 [PATCH net-next v2] net: let lockdep compare instance locks Jakub Kicinski
2025-05-18  3:50 ` Stanislav Fomichev
2025-05-18 19:32 ` Kuniyuki Iwashima
2025-05-21  1:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).