1. 25 Jun, 2024 5 commits
    • Kuniyuki Iwashima's avatar
      af_unix: Don't acquire unix_state_lock() for sock_i_ino(). · b380b181
      Kuniyuki Iwashima authored
      sk_diag_dump_peer() and sk_diag_dump() call unix_state_lock() for
      sock_i_ino() which reads SOCK_INODE(sk->sk_socket)->i_ino, but it's
      protected by sk->sk_callback_lock.
      
      Let's remove unnecessary unix_state_lock().
      Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      b380b181
    • Kuniyuki Iwashima's avatar
      af_unix: Define locking order for U_LOCK_SECOND in unix_stream_connect(). · 98f706de
      Kuniyuki Iwashima authored
      While a SOCK_(STREAM|SEQPACKET) socket connect()s to another, we hold
      two locks of them by unix_state_lock() and unix_state_lock_nested() in
      unix_stream_connect().
      
      Before unix_state_lock_nested(), the following is guaranteed by checking
      sk->sk_state:
      
        1. The first socket is TCP_LISTEN
        2. The second socket is not the first one
        3. Simultaneous connect() must fail
      
      So, the client state can be TCP_CLOSE or TCP_LISTEN or TCP_ESTABLISHED.
      
      Let's define the expected states as unix_state_lock_cmp_fn() instead of
      using unix_state_lock_nested().
      
      Note that 2. is detected by debug_spin_lock_before() and 3. cannot be
      expressed as lock_cmp_fn.
      Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      98f706de
    • Kuniyuki Iwashima's avatar
      af_unix: Don't retry after unix_state_lock_nested() in unix_stream_connect(). · 1ca27e0c
      Kuniyuki Iwashima authored
      When a SOCK_(STREAM|SEQPACKET) socket connect()s to another one, we need
      to lock the two sockets to check their states in unix_stream_connect().
      
      We use unix_state_lock() for the server and unix_state_lock_nested() for
      client with tricky sk->sk_state check to avoid deadlock.
      
      The possible deadlock scenario are the following:
      
        1) Self connect()
        2) Simultaneous connect()
      
      The former is simple, attempt to grab the same lock, and the latter is
      AB-BA deadlock.
      
      After the server's unix_state_lock(), we check the server socket's state,
      and if it's not TCP_LISTEN, connect() fails with -EINVAL.
      
      Then, we avoid the former deadlock by checking the client's state before
      unix_state_lock_nested().  If its state is not TCP_LISTEN, we can make
      sure that the client and the server are not identical based on the state.
      
      Also, the latter deadlock can be avoided in the same way.  Due to the
      server sk->sk_state requirement, AB-BA deadlock could happen only with
      TCP_LISTEN sockets.  So, if the client's state is TCP_LISTEN, we can
      give up the second lock to avoid the deadlock.
      
        CPU 1                 CPU 2                  CPU 3
        connect(A -> B)       connect(B -> A)        listen(A)
        ---                   ---                    ---
        unix_state_lock(B)
        B->sk_state == TCP_LISTEN
        READ_ONCE(A->sk_state) == TCP_CLOSE
                                  ^^^^^^^^^
                                  ok, will lock A    unix_state_lock(A)
                   .--------------'                  WRITE_ONCE(A->sk_state, TCP_LISTEN)
                   |                                 unix_state_unlock(A)
                   |
                   |          unix_state_lock(A)
                   |          A->sk_sk_state == TCP_LISTEN
                   |          READ_ONCE(B->sk_state) == TCP_LISTEN
                   v                                    ^^^^^^^^^^
        unix_state_lock_nested(A)                       Don't lock B !!
      
      Currently, while checking the client's state, we also check if it's
      TCP_ESTABLISHED, but this is unlikely and can be checked after we know
      the state is not TCP_CLOSE.
      
      Moreover, if it happens after the second lock, we now jump to the restart
      label, but it's unlikely that the server is not found during the retry,
      so the jump is mostly to revist the client state check.
      
      Let's remove the retry logic and check the state against TCP_CLOSE first.
      Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      1ca27e0c
    • Kuniyuki Iwashima's avatar
      af_unix: Define locking order for U_LOCK_SECOND in unix_state_double_lock(). · ed998228
      Kuniyuki Iwashima authored
      unix_dgram_connect() and unix_dgram_{send,recv}msg() lock the socket
      and peer in ascending order of the socket address.
      
      Let's define the order as unix_state_lock_cmp_fn() instead of using
      unix_state_lock_nested().
      Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Reviewed-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      ed998228
    • Kuniyuki Iwashima's avatar
      af_unix: Define locking order for unix_table_double_lock(). · 3955802f
      Kuniyuki Iwashima authored
      When created, AF_UNIX socket is put into net->unx.table.buckets[],
      and the hash is stored in sk->sk_hash.
      
        * unbound socket  : 0 <= sk_hash <= UNIX_HASH_MOD
      
      When bind() is called, the socket could be moved to another bucket.
      
        * pathname socket : 0 <= sk_hash <= UNIX_HASH_MOD
        * abstract socket : UNIX_HASH_MOD + 1 <= sk_hash <= UNIX_HASH_MOD * 2 + 1
      
      Then, we call unix_table_double_lock() which locks a single bucket
      or two.
      
      Let's define the order as unix_table_lock_cmp_fn() instead of using
      spin_lock_nested().
      
      The locking is always done in ascending order of sk->sk_hash, which
      is the index of buckets/locks array allocated by kvmalloc_array().
      
        sk_hash_A < sk_hash_B
        <=> &locks[sk_hash_A].dep_map < &locks[sk_hash_B].dep_map
      
      So, the relation of two sk->sk_hash can be derived from the addresses
      of dep_map in the array of locks.
      Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Reviewed-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      3955802f
  2. 24 Jun, 2024 17 commits
  3. 23 Jun, 2024 1 commit
  4. 22 Jun, 2024 2 commits
    • Sean Anderson's avatar
      net: xilinx: axienet: Enable multicast by default · 185d7211
      Sean Anderson authored
      We support multicast addresses, so enable it by default.
      Signed-off-by: default avatarSean Anderson <sean.anderson@linux.dev>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      185d7211
    • Jakub Kicinski's avatar
      Merge tag 'linux-can-next-for-6.11-20240621' of... · e9212f9d
      Jakub Kicinski authored
      Merge tag 'linux-can-next-for-6.11-20240621' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next
      
      Marc Kleine-Budde says:
      
      ====================
      pull-request: can-next 2024-06-21
      
      The first 2 patches are by Andy Shevchenko, one cleans up the includes
      in the mcp251x driver, the other one updates the sja100 plx_pci driver
      to make use of predefines PCI subvendor ID.
      
      Mans Rullgard's patch cleans up the Kconfig help text of for the slcan
      driver.
      
      Oliver Hartkopp provides a patch to update the documentation, which
      removes the ISO 15675-2 specification version where possible.
      
      The next 2 patches are by Harini T and update the documentation of the
      xilinx_can driver.
      
      Francesco Valla provides documentation for the ISO 15765-2 protocol.
      
      A patch by Dr. David Alan Gilbert removes an unused struct from the
      mscan driver.
      
      12 patches are by Martin Jocic. The first three add support for 3 new
      devices to the kvaser_usb driver. The remaining 9 first clean up the
      kvaser_pciefd driver, and then add support for MSI.
      
      Krzysztof Kozlowski contributes 3 patches simplifies the CAN SPI
      drivers by making use of spi_get_device_match_data().
      
      The last patch is by Martin Hundebøll, which reworks the m_can driver
      to not enable the CAN transceiver during probe.
      
      * tag 'linux-can-next-for-6.11-20240621' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next: (24 commits)
        can: m_can: don't enable transceiver when probing
        can: mcp251xfd: simplify with spi_get_device_match_data()
        can: mcp251x: simplify with spi_get_device_match_data()
        can: hi311x: simplify with spi_get_device_match_data()
        can: kvaser_pciefd: Add MSI interrupts
        can: kvaser_pciefd: Move reset of DMA RX buffers to the end of the ISR
        can: kvaser_pciefd: Change name of return code variable
        can: kvaser_pciefd: Rename board_irq to pci_irq
        can: kvaser_pciefd: Add unlikely
        can: kvaser_pciefd: Add inline
        can: kvaser_pciefd: Remove unnecessary comment
        can: kvaser_pciefd: Skip redundant NULL pointer check in ISR
        can: kvaser_pciefd: Group #defines together
        can: kvaser_usb: Add support for Kvaser Mini PCIe 1xCAN
        can: kvaser_usb: Add support for Kvaser USBcan Pro 5xCAN
        can: kvaser_usb: Add support for Vining 800
        can: mscan: remove unused struct 'mscan_state'
        Documentation: networking: document ISO 15765-2
        can: xilinx_can: Document driver description to list all supported IPs
        can: isotp: remove ISO 15675-2 specification version where possible
        ...
      ====================
      
      Link: https://patch.msgid.link/20240621080201.305471-1-mkl@pengutronix.deSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      e9212f9d
  5. 21 Jun, 2024 15 commits