]> www.infradead.org Git - users/hch/configfs.git/commitdiff
af_unix: Remove U_LOCK_DIAG.
authorKuniyuki Iwashima <kuniyu@amazon.com>
Thu, 20 Jun 2024 20:56:18 +0000 (13:56 -0700)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 25 Jun 2024 09:10:18 +0000 (11:10 +0200)
sk_diag_dump_icons() acquires embryo's lock by unix_state_lock_nested()
to fetch its peer.

The embryo's ->peer is set to NULL only when its parent listener is
close()d.  Then, unix_release_sock() is called for each embryo after
unlinking skb by skb_dequeue().

In sk_diag_dump_icons(), we hold the parent's recvq lock, so we need
not acquire unix_state_lock_nested(), and peer is always non-NULL.

Let's remove unnecessary unix_state_lock_nested() and non-NULL test
for peer.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
include/net/af_unix.h
net/unix/diag.c

index fd813ad73ab863e0d9499485dd775d99a35d76bd..c42645199cee3b90f2e1858fa3d4e24f49231086 100644 (file)
@@ -98,7 +98,6 @@ struct unix_sock {
 #define unix_state_unlock(s)   spin_unlock(&unix_sk(s)->lock)
 enum unix_socket_lock_class {
        U_LOCK_NORMAL,
-       U_LOCK_DIAG, /* used while dumping icons, see sk_diag_dump_icons(). */
        U_LOCK_GC_LISTENER, /* used for listening socket while determining gc
                             * candidates to close a small race window.
                             */
index d2d66727b0da586de3d3fb26cd523ad719e77cb2..9138af8b465e0e533f584ab92b7e75dfdedcaee3 100644 (file)
@@ -73,20 +73,9 @@ static int sk_diag_dump_icons(struct sock *sk, struct sk_buff *nlskb)
 
                buf = nla_data(attr);
                i = 0;
-               skb_queue_walk(&sk->sk_receive_queue, skb) {
-                       struct sock *req, *peer;
-
-                       req = skb->sk;
-                       /*
-                        * The state lock is outer for the same sk's
-                        * queue lock. With the other's queue locked it's
-                        * OK to lock the state.
-                        */
-                       unix_state_lock_nested(req, U_LOCK_DIAG);
-                       peer = unix_sk(req)->peer;
-                       buf[i++] = (peer ? sock_i_ino(peer) : 0);
-                       unix_state_unlock(req);
-               }
+               skb_queue_walk(&sk->sk_receive_queue, skb)
+                       buf[i++] = sock_i_ino(unix_peer(skb->sk));
+
                spin_unlock(&sk->sk_receive_queue.lock);
        }