mbox series

[v4,net-next,00/11] af_unix: Remove spin_lock_nested() and convert to lock_cmp_fn.

Message ID 20240620205623.60139-1-kuniyu@amazon.com (mailing list archive)
Headers show
Series af_unix: Remove spin_lock_nested() and convert to lock_cmp_fn. | expand

Message

Kuniyuki Iwashima June 20, 2024, 8:56 p.m. UTC
This series removes spin_lock_nested() in AF_UNIX and instead
defines the locking orders as functions tied to each lock by
lockdep_set_lock_cmp_fn().

When the defined function returns a negative value, lockdep
considers it will not cause deadlock.  (See ->cmp_fn() in
check_deadlock() and check_prev_add().)

When we cannot define the total ordering, we return -1 for
the allowed ordering and otherwise 0 as undefined. [0]

[0]: https://lore.kernel.org/netdev/thzkgbuwuo3knevpipu4rzsh5qgmwhklihypdgziiruabvh46f@uwdkpcfxgloo/


Changes:
  v4:
    * Patch 4
      * Make unix_state_lock_cmp_fn() symmetric.

  v3: https://lore.kernel.org/netdev/20240614200715.93150-1-kuniyu@amazon.com/
    * Patch 3
      * Cache sk->sk_state
      * s/unix_state_lock()/unix_state_unlock()/
    * Patch 8
      * Add embryo -> listener locking order

  v2: https://lore.kernel.org/netdev/20240611222905.34695-1-kuniyu@amazon.com/
   * Patch 1 & 2
      * Use (((l) > (r)) - ((l) < (r))) for comparison

  v1: https://lore.kernel.org/netdev/20240610223501.73191-1-kuniyu@amazon.com/


Kuniyuki Iwashima (11):
  af_unix: Define locking order for unix_table_double_lock().
  af_unix: Define locking order for U_LOCK_SECOND in
    unix_state_double_lock().
  af_unix: Don't retry after unix_state_lock_nested() in
    unix_stream_connect().
  af_unix: Define locking order for U_LOCK_SECOND in
    unix_stream_connect().
  af_unix: Don't acquire unix_state_lock() for sock_i_ino().
  af_unix: Remove U_LOCK_DIAG.
  af_unix: Remove U_LOCK_GC_LISTENER.
  af_unix: Define locking order for U_RECVQ_LOCK_EMBRYO in
    unix_collect_skb().
  af_unix: Set sk_peer_pid/sk_peer_cred locklessly for new socket.
  af_unix: Remove put_pid()/put_cred() in copy_peercred().
  af_unix: Don't use spin_lock_nested() in copy_peercred().

 include/net/af_unix.h |  14 ----
 net/unix/af_unix.c    | 151 ++++++++++++++++++++++++++++--------------
 net/unix/diag.c       |  47 ++++---------
 net/unix/garbage.c    |   8 +--
 4 files changed, 117 insertions(+), 103 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org June 25, 2024, 9:30 a.m. UTC | #1
Hello:

This series was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Thu, 20 Jun 2024 13:56:12 -0700 you wrote:
> This series removes spin_lock_nested() in AF_UNIX and instead
> defines the locking orders as functions tied to each lock by
> lockdep_set_lock_cmp_fn().
> 
> When the defined function returns a negative value, lockdep
> considers it will not cause deadlock.  (See ->cmp_fn() in
> check_deadlock() and check_prev_add().)
> 
> [...]

Here is the summary with links:
  - [v4,net-next,01/11] af_unix: Define locking order for unix_table_double_lock().
    https://git.kernel.org/netdev/net-next/c/3955802f160b
  - [v4,net-next,02/11] af_unix: Define locking order for U_LOCK_SECOND in unix_state_double_lock().
    https://git.kernel.org/netdev/net-next/c/ed99822817cb
  - [v4,net-next,03/11] af_unix: Don't retry after unix_state_lock_nested() in unix_stream_connect().
    https://git.kernel.org/netdev/net-next/c/1ca27e0c8c13
  - [v4,net-next,04/11] af_unix: Define locking order for U_LOCK_SECOND in unix_stream_connect().
    https://git.kernel.org/netdev/net-next/c/98f706de445b
  - [v4,net-next,05/11] af_unix: Don't acquire unix_state_lock() for sock_i_ino().
    https://git.kernel.org/netdev/net-next/c/b380b18102a0
  - [v4,net-next,06/11] af_unix: Remove U_LOCK_DIAG.
    https://git.kernel.org/netdev/net-next/c/c4da4661d985
  - [v4,net-next,07/11] af_unix: Remove U_LOCK_GC_LISTENER.
    https://git.kernel.org/netdev/net-next/c/7202cb591624
  - [v4,net-next,08/11] af_unix: Define locking order for U_RECVQ_LOCK_EMBRYO in unix_collect_skb().
    https://git.kernel.org/netdev/net-next/c/8647ece4814f
  - [v4,net-next,09/11] af_unix: Set sk_peer_pid/sk_peer_cred locklessly for new socket.
    https://git.kernel.org/netdev/net-next/c/faf489e6896d
  - [v4,net-next,10/11] af_unix: Remove put_pid()/put_cred() in copy_peercred().
    https://git.kernel.org/netdev/net-next/c/e4bd881d9871
  - [v4,net-next,11/11] af_unix: Don't use spin_lock_nested() in copy_peercred().
    https://git.kernel.org/netdev/net-next/c/22e5751b0524

You are awesome, thank you!