mbox series

[v3,net-next,00/13] af_unix: Replace unix_table_lock with per-hash locks.

Message ID 20211124021431.48956-1-kuniyu@amazon.co.jp (mailing list archive)
Headers show
Series af_unix: Replace unix_table_lock with per-hash locks. | expand

Message

Iwashima, Kuniyuki Nov. 24, 2021, 2:14 a.m. UTC
The hash table of AF_UNIX sockets is protected by a single big lock,
unix_table_lock.  This series replaces it with small per-hash locks.

1st -  2nd : Misc refactoring
3rd -  8th : Separate BSD/abstract address logics
9th - 11th : Prep to save a hash in each socket
12th       : Replace the big lock
13th       : Speed up autobind()

After this series land in bpf-next, I will post another series to support
bpf batching iteration and bpf_(get|set)sockopt for AF_UNIX sockets.


Note to maintainers:
The 12th patch adds two kinds of Sparse warnings on patchwork:

  about unix_table_double_lock/unlock()
    We can avoid this by adding two apparent acquires/releases annotations,
    but there are the same kinds of warnings about unix_state_double_lock().

  about unix_next_socket() and unix_seq_stop() (/proc/net/unix)
    This is because Sparse does not understand logic in unix_next_socket(),
    which leaves a spin lock held until it returns NULL.
    Also, tcp_seq_stop() causes a warning for the same reason.

These warnings seem reasonable, but let me know if there is any better way.
Please see [0] for details.

[0]: https://lore.kernel.org/netdev/20211117001611.74123-1-kuniyu@amazon.co.jp/


Changelog:
  v3:
    Fix `checkpatch.pl --max-line-length=80` warnings.

  v2:
  https://lore.kernel.org/netdev/20211114012428.81743-1-kuniyu@amazon.co.jp/
    12th: Use spin_lock_nested()
    13th: Avoid infinite loop (Eric Dumazet)
    13th: s/initnum/lastnum/

  v1:
  https://lore.kernel.org/netdev/20211106091712.15206-1-kuniyu@amazon.co.jp/


Kuniyuki Iwashima (13):
  af_unix: Use offsetof() instead of sizeof().
  af_unix: Pass struct sock to unix_autobind().
  af_unix: Factorise unix_find_other() based on address types.
  af_unix: Return an error as a pointer in unix_find_other().
  af_unix: Cut unix_validate_addr() out of unix_mkname().
  af_unix: Copy unix_mkname() into unix_find_(bsd|abstract)().
  af_unix: Remove unix_mkname().
  af_unix: Allocate unix_address in unix_bind_(bsd|abstract)().
  af_unix: Remove UNIX_ABSTRACT() macro and test sun_path[0] instead.
  af_unix: Add helpers to calculate hashes.
  af_unix: Save hash in sk_hash.
  af_unix: Replace the big lock with small locks.
  af_unix: Relax race in unix_autobind().

 include/net/af_unix.h                         |   3 +-
 net/unix/af_unix.c                            | 567 ++++++++++--------
 net/unix/diag.c                               |  23 +-
 .../selftests/bpf/progs/bpf_iter_unix.c       |   2 +-
 .../selftests/bpf/progs/bpf_tracing_net.h     |   2 -
 .../bpf/progs/test_skc_to_unix_sock.c         |   2 +-
 6 files changed, 346 insertions(+), 253 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org Nov. 27, 2021, 2:10 a.m. UTC | #1
Hello:

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

On Wed, 24 Nov 2021 11:14:18 +0900 you wrote:
> The hash table of AF_UNIX sockets is protected by a single big lock,
> unix_table_lock.  This series replaces it with small per-hash locks.
> 
> 1st -  2nd : Misc refactoring
> 3rd -  8th : Separate BSD/abstract address logics
> 9th - 11th : Prep to save a hash in each socket
> 12th       : Replace the big lock
> 13th       : Speed up autobind()
> 
> [...]

Here is the summary with links:
  - [v3,net-next,01/13] af_unix: Use offsetof() instead of sizeof().
    https://git.kernel.org/netdev/net-next/c/755662ce78d1
  - [v3,net-next,02/13] af_unix: Pass struct sock to unix_autobind().
    https://git.kernel.org/netdev/net-next/c/f7ed31f4615f
  - [v3,net-next,03/13] af_unix: Factorise unix_find_other() based on address types.
    https://git.kernel.org/netdev/net-next/c/fa39ef0e4729
  - [v3,net-next,04/13] af_unix: Return an error as a pointer in unix_find_other().
    https://git.kernel.org/netdev/net-next/c/aed26f557bbc
  - [v3,net-next,05/13] af_unix: Cut unix_validate_addr() out of unix_mkname().
    https://git.kernel.org/netdev/net-next/c/b8a58aa6fccc
  - [v3,net-next,06/13] af_unix: Copy unix_mkname() into unix_find_(bsd|abstract)().
    https://git.kernel.org/netdev/net-next/c/d2d8c9fddb1c
  - [v3,net-next,07/13] af_unix: Remove unix_mkname().
    https://git.kernel.org/netdev/net-next/c/5c32a3ed64b4
  - [v3,net-next,08/13] af_unix: Allocate unix_address in unix_bind_(bsd|abstract)().
    https://git.kernel.org/netdev/net-next/c/12f21c49ad83
  - [v3,net-next,09/13] af_unix: Remove UNIX_ABSTRACT() macro and test sun_path[0] instead.
    https://git.kernel.org/netdev/net-next/c/5ce7ab4961a9
  - [v3,net-next,10/13] af_unix: Add helpers to calculate hashes.
    https://git.kernel.org/netdev/net-next/c/f452be496a5c
  - [v3,net-next,11/13] af_unix: Save hash in sk_hash.
    https://git.kernel.org/netdev/net-next/c/e6b4b873896f
  - [v3,net-next,12/13] af_unix: Replace the big lock with small locks.
    https://git.kernel.org/netdev/net-next/c/afd20b9290e1
  - [v3,net-next,13/13] af_unix: Relax race in unix_autobind().
    https://git.kernel.org/netdev/net-next/c/9acbc584c3a4

You are awesome, thank you!